Skip to content

Commit d4055ef

Browse files
committed
refactor: extract toolbar proportional editing
1 parent 8f46e2b commit d4055ef

2 files changed

Lines changed: 18 additions & 17 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 drawProportionalEdit(bool& enabled, float& radius);
2324
};
2425

2526
} // namespace MeshCraft::Application::UI

src/MeshCraft/Application/UI/Toolbar.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,7 @@ float MeshCraftApplication::drawToolbar(float menuBarH, int screenW)
109109

110110
UI::Toolbar::drawSurfaceSnap(surfaceSnapEnabled_);
111111

112-
// Proportional editing toggle + radius (H1)
113-
{ bool was = propEditEnabled_;
114-
if (was) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.45f, 0.20f, 0.45f, 1.f));
115-
if (ImGui::Button("Prop", ImVec2(40, 30))) propEditEnabled_ = !propEditEnabled_;
116-
if (was) ImGui::PopStyleColor(); }
117-
if (ImGui::IsItemHovered())
118-
ImGui::SetTooltip("Proportional editing: Move influences nearby objects (Gaussian falloff)\nRadius: %.2f u", propEditRadius_);
119-
if (propEditEnabled_) {
120-
ImGui::SameLine();
121-
ImGui::SetNextItemWidth(70);
122-
// AlwaysClamp (AUDIT-0046): same Ctrl+Click out-of-bounds risk; a
123-
// zero/negative proportional-edit radius would break the Gaussian
124-
// falloff math with no other downstream guard.
125-
ImGui::SliderFloat("##propR", &propEditRadius_, 0.5f, 50.0f, "R:%.1f", ImGuiSliderFlags_AlwaysClamp);
126-
if (ImGui::IsItemHovered()) ImGui::SetTooltip("Proportional edit radius (world units)");
127-
}
128-
ImGui::SameLine();
112+
UI::Toolbar::drawProportionalEdit(propEditEnabled_, propEditRadius_);
129113

130114
// Grid cell size button (right-click to configure)
131115
if (ImGui::Button("Grid", ImVec2(40, 30))) {}
@@ -258,4 +242,20 @@ void Toolbar::drawSnapToggle(bool& enabled, float translate, float rotate, float
258242
translate, rotate, scale);
259243
}
260244

245+
void Toolbar::drawProportionalEdit(bool& enabled, float& radius) {
246+
const bool wasEnabled = enabled;
247+
if (wasEnabled) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.45f, 0.20f, 0.45f, 1.f));
248+
if (ImGui::Button("Prop", ImVec2(40, 30))) enabled = !enabled;
249+
if (wasEnabled) ImGui::PopStyleColor();
250+
if (ImGui::IsItemHovered())
251+
ImGui::SetTooltip("Proportional editing: Move influences nearby objects (Gaussian falloff)\nRadius: %.2f u", radius);
252+
if (enabled) {
253+
ImGui::SameLine();
254+
ImGui::SetNextItemWidth(70);
255+
ImGui::SliderFloat("##propR", &radius, 0.5f, 50.0f, "R:%.1f", ImGuiSliderFlags_AlwaysClamp);
256+
if (ImGui::IsItemHovered()) ImGui::SetTooltip("Proportional edit radius (world units)");
257+
}
258+
ImGui::SameLine();
259+
}
260+
261261
} // namespace MeshCraft::Application::UI

0 commit comments

Comments
 (0)