Skip to content

Commit bd3430d

Browse files
committed
refactor: extract toolbar snap popup
1 parent c87336b commit bd3430d

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

include/MeshCraft/Application/UI/Toolbar.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Toolbar final {
2020
bool& showWireframe, bool& showBoundingBox);
2121
static void drawSurfaceSnap(bool& enabled);
2222
static void drawSnapToggle(bool& enabled, float translate, float rotate, float scale);
23+
static void drawSnapSettings(const std::function<void()>& drawContents);
2324
static void drawProportionalEdit(bool& enabled, float& radius);
2425
static void drawGrid(float& spacing, const std::function<void(float)>& setSpacing);
2526
};

src/MeshCraft/Application/UI/Toolbar.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ float MeshCraftApplication::drawToolbar(float menuBarH, int screenW)
5252
showWireframeMode_, showBoundingBox_);
5353

5454
UI::Toolbar::drawSnapToggle(snapEnabled_, snapTranslate_, snapRotate_, snapScale_);
55-
if (ImGui::BeginPopupContextItem("##snapcfg")) {
55+
UI::Toolbar::drawSnapSettings([this] {
5656
ImGui::TextDisabled("Snap Intervals");
5757
ImGui::Separator();
5858
// Move presets
@@ -103,8 +103,7 @@ float MeshCraftApplication::drawToolbar(float menuBarH, int screenW)
103103
ImGui::NewLine();
104104
ImGui::SetNextItemWidth(120);
105105
ImGui::DragFloat("##ss", &snapScale_, 0.01f, 0.01f, 10.0f, "%.3g", ImGuiSliderFlags_AlwaysClamp);
106-
ImGui::EndPopup();
107-
}
106+
});
108107
ImGui::SameLine();
109108

110109
UI::Toolbar::drawSurfaceSnap(surfaceSnapEnabled_);
@@ -214,6 +213,12 @@ void Toolbar::drawSnapToggle(bool& enabled, float translate, float rotate, float
214213
translate, rotate, scale);
215214
}
216215

216+
void Toolbar::drawSnapSettings(const std::function<void()>& drawContents) {
217+
if (!ImGui::BeginPopupContextItem("##snapcfg")) return;
218+
drawContents();
219+
ImGui::EndPopup();
220+
}
221+
217222
void Toolbar::drawProportionalEdit(bool& enabled, float& radius) {
218223
const bool wasEnabled = enabled;
219224
if (wasEnabled) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.45f, 0.20f, 0.45f, 1.f));

0 commit comments

Comments
 (0)