From df02fe4bc04afafd2ed7e5d1cd80f9e321de2a9c Mon Sep 17 00:00:00 2001 From: Haroon Qureshi Date: Wed, 11 Mar 2026 05:19:28 -0700 Subject: [PATCH] BodyAddChild PopupContext needs to happen immediately upon triggering it. PiperOrigin-RevId: 881955422 Change-Id: I03675431d78c93550ff2ad6d562daf1a0e3d0d08 --- src/experimental/platform/gui_spec.cc | 33 ++++++++++++++------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/experimental/platform/gui_spec.cc b/src/experimental/platform/gui_spec.cc index 27dbbba3..7d30d31d 100644 --- a/src/experimental/platform/gui_spec.cc +++ b/src/experimental/platform/gui_spec.cc @@ -93,28 +93,29 @@ static void AddEditorButtons(mjsElement* element, mjsElement** selected_element, if (ImGui::SmallButton(ICON_FA_PLUS)) { ImGui::OpenPopupOnItemClick("BodyAddChild", 0); } + + if (ImGui::BeginPopupContextItem("BodyAddChild")) { + mjsBody* body = mjs_asBody(element); + auto option = [&](const char* label, mjtObj type) { + if (ImGui::Selectable(label)) { + *selected_element = editor.AddBodyElement(body, type); + } + }; + option("Camera", mjOBJ_CAMERA); + option("Frame", mjOBJ_FRAME); + option("Geom", mjOBJ_GEOM); + option("Joint", mjOBJ_JOINT); + option("Light", mjOBJ_LIGHT); + option("Site", mjOBJ_SITE); + ImGui::EndPopup(); + } + ImGui::SameLine(); } if (ImGui::SmallButton(ICON_FA_TRASH_CAN)) { editor.DeleteActiveElement(); *selected_element = nullptr; } - - if (ImGui::BeginPopupContextItem("BodyAddChild")) { - mjsBody* body = mjs_asBody(element); - auto option = [&](const char* label, mjtObj type) { - if (ImGui::Selectable(label)) { - *selected_element = editor.AddBodyElement(body, type); - } - }; - option("Camera", mjOBJ_CAMERA); - option("Frame", mjOBJ_FRAME); - option("Geom", mjOBJ_GEOM); - option("Joint", mjOBJ_JOINT); - option("Light", mjOBJ_LIGHT); - option("Site", mjOBJ_SITE); - ImGui::EndPopup(); - } } static void SelectableElement(mjsElement* element,