Skip to content

Commit 8f46e2b

Browse files
committed
refactor: extract toolbar snap toggle
1 parent 4cd5248 commit 8f46e2b

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

include/MeshCraft/Application/UI/Toolbar.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Toolbar final {
1919
static void drawDisplayToggles(bool& gizmoLocalSpace, bool& showEdges,
2020
bool& showWireframe, bool& showBoundingBox);
2121
static void drawSurfaceSnap(bool& enabled);
22+
static void drawSnapToggle(bool& enabled, float translate, float rotate, float scale);
2223
};
2324

2425
} // namespace MeshCraft::Application::UI

src/MeshCraft/Application/UI/Toolbar.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,7 @@ float MeshCraftApplication::drawToolbar(float menuBarH, int screenW)
5151
UI::Toolbar::drawDisplayToggles(gizmoLocalSpace_, showEdgeOverlay_,
5252
showWireframeMode_, showBoundingBox_);
5353

54-
// Snap-to-grid toggle button (left-click toggles, right-click configures)
55-
{ bool was = snapEnabled_;
56-
if (was) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.20f, 0.45f, 0.20f, 1.f));
57-
if (ImGui::Button("Snap", ImVec2(44, 30))) snapEnabled_ = !snapEnabled_;
58-
if (was) ImGui::PopStyleColor(); }
59-
if (ImGui::IsItemHovered())
60-
ImGui::SetTooltip("Snap to grid Move: %.2g u Rotate: %.0f° Scale: %.2g\nRight-click to configure",
61-
snapTranslate_, snapRotate_, snapScale_);
54+
UI::Toolbar::drawSnapToggle(snapEnabled_, snapTranslate_, snapRotate_, snapScale_);
6255
if (ImGui::BeginPopupContextItem("##snapcfg")) {
6356
ImGui::TextDisabled("Snap Intervals");
6457
ImGui::Separator();
@@ -255,4 +248,14 @@ void Toolbar::drawSurfaceSnap(bool& enabled) {
255248
ImGui::SameLine();
256249
}
257250

251+
void Toolbar::drawSnapToggle(bool& enabled, float translate, float rotate, float scale) {
252+
const bool wasEnabled = enabled;
253+
if (wasEnabled) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.20f, 0.45f, 0.20f, 1.f));
254+
if (ImGui::Button("Snap", ImVec2(44, 30))) enabled = !enabled;
255+
if (wasEnabled) ImGui::PopStyleColor();
256+
if (ImGui::IsItemHovered())
257+
ImGui::SetTooltip("Snap to grid Move: %.2g u Rotate: %.0f° Scale: %.2g\nRight-click to configure",
258+
translate, rotate, scale);
259+
}
260+
258261
} // namespace MeshCraft::Application::UI

0 commit comments

Comments
 (0)