Skip to content

Commit 67b38c7

Browse files
committed
refactor: extract toolbar tools UI
1 parent f227bef commit 67b38c7

3 files changed

Lines changed: 75 additions & 40 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include "MeshCraft/Editor/ActiveTool.hpp"
4+
#include "MeshCraft/Mc3/Mc3Object.hpp"
5+
6+
#include <functional>
7+
8+
namespace MeshCraft::Application::UI {
9+
10+
struct ToolbarToolsContext {
11+
ActiveTool& activeTool;
12+
std::function<void(ActiveTool)> selectTool;
13+
std::function<void(Mc3::ObjectType)> addPrimitive;
14+
};
15+
16+
class Toolbar final {
17+
public:
18+
static void drawTools(ToolbarToolsContext& context);
19+
};
20+
21+
} // namespace MeshCraft::Application::UI

plan.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,10 @@ _All items in this workstream are DONE — archived to [`docs/history/plan_20260
577577
Registry results table is likewise now `Application::UI::Registry`; it sees
578578
only entries plus Insert/Remove callbacks, while document mutation, undo,
579579
status reporting, and database lifetime remain in the application. The
580+
first Toolbar slice, `Application::UI::Toolbar`, owns tool/primitive button
581+
rendering and receives only active-tool state plus SelectTool/AddPrimitive
582+
actions; snap, grid, and proportional-edit controls remain for the next
583+
narrow slice. The
580584
historical audit references retain their former paths as time-accurate
581585
evidence.
582586
Static undo-audit and snapshot-lint path checks pass after their tracked

src/MeshCraft/Application/UI/Toolbar.cpp

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "MeshCraft/Application/MeshCraftApplication.hpp"
2+
#include "MeshCraft/Application/UI/Toolbar.hpp"
23
#include "MeshCraft/MeshCraftPrivate.hpp"
34

45
#include <imgui.h>
@@ -40,47 +41,12 @@ float MeshCraftApplication::drawToolbar(float menuBarH, int screenW)
4041
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoScrollbar |
4142
ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoSavedSettings);
4243

43-
// Tool buttons
44-
struct { ActiveTool tool; const char* label; ImVec4 col; } toolBtns[] = {
45-
{ ActiveTool::Select, "Select [Q]", ImVec4(0.31f,0.59f,0.82f,1.f) },
46-
{ ActiveTool::Move, "Move [G]", ImVec4(0.22f,0.74f,0.39f,1.f) },
47-
{ ActiveTool::Rotate, "Rotate [R]", ImVec4(0.80f,0.65f,0.22f,1.f) },
48-
{ ActiveTool::Scale, "Scale [S]", ImVec4(0.82f,0.29f,0.29f,1.f) },
49-
{ ActiveTool::Measure, "Ruler", ImVec4(0.60f,0.82f,0.82f,1.f) },
44+
UI::ToolbarToolsContext toolsContext{
45+
.activeTool = activeTool_,
46+
.selectTool = [this](ActiveTool tool) { activeTool_ = tool; updateWindowTitle(); },
47+
.addPrimitive = [this](Mc3::ObjectType type) { addPrimitive(type); },
5048
};
51-
for (auto& tb : toolBtns) {
52-
bool active = (activeTool_ == tb.tool);
53-
if (active) ImGui::PushStyleColor(ImGuiCol_Button, tb.col);
54-
if (ImGui::Button(tb.label, ImVec2(84, 30))) { activeTool_ = tb.tool; updateWindowTitle(); }
55-
if (active) ImGui::PopStyleColor();
56-
ImGui::SameLine();
57-
}
58-
59-
ImGui::TextDisabled("|");
60-
ImGui::SameLine();
61-
62-
// Add primitive buttons
63-
struct { Mc3::ObjectType type; const char* label; ImVec4 col; } addBtns[] = {
64-
{ Mc3::ObjectType::Box, "+Box", ImVec4(0.82f,0.47f,0.22f,1.f) },
65-
{ Mc3::ObjectType::Sphere, "+Sph", ImVec4(0.22f,0.47f,0.82f,1.f) },
66-
{ Mc3::ObjectType::Cylinder, "+Cyl", ImVec4(0.22f,0.73f,0.39f,1.f) },
67-
{ Mc3::ObjectType::Cone, "+Con", ImVec4(0.73f,0.22f,0.73f,1.f) },
68-
{ Mc3::ObjectType::Plane, "+Pln", ImVec4(0.80f,0.80f,0.22f,1.f) },
69-
{ Mc3::ObjectType::Torus, "+Tor", ImVec4(0.22f,0.70f,0.80f,1.f) },
70-
{ Mc3::ObjectType::Capsule, "+Cap", ImVec4(0.70f,0.35f,0.70f,1.f) },
71-
{ Mc3::ObjectType::Disk, "+Dsk", ImVec4(0.80f,0.65f,0.20f,1.f) },
72-
{ Mc3::ObjectType::Grid, "+Grd", ImVec4(0.30f,0.65f,0.50f,1.f) },
73-
{ Mc3::ObjectType::IcoSphere,"+Ico", ImVec4(0.25f,0.55f,0.80f,1.f) },
74-
};
75-
for (auto& ab : addBtns) {
76-
ImGui::PushStyleColor(ImGuiCol_Button, ab.col);
77-
if (ImGui::Button(ab.label, ImVec2(40, 30))) addPrimitive(ab.type);
78-
ImGui::PopStyleColor();
79-
ImGui::SameLine();
80-
}
81-
82-
ImGui::TextDisabled("|");
83-
ImGui::SameLine();
49+
UI::Toolbar::drawTools(toolsContext);
8450

8551
// Local/World space toggle for gizmo
8652
{
@@ -250,3 +216,47 @@ float MeshCraftApplication::drawToolbar(float menuBarH, int screenW)
250216

251217

252218
} // namespace MeshCraft::Application
219+
220+
namespace MeshCraft::Application::UI {
221+
222+
void Toolbar::drawTools(ToolbarToolsContext& context) {
223+
struct { ActiveTool tool; const char* label; ImVec4 color; } tools[] = {
224+
{ActiveTool::Select, "Select [Q]", {0.31f, 0.59f, 0.82f, 1.f}},
225+
{ActiveTool::Move, "Move [G]", {0.22f, 0.74f, 0.39f, 1.f}},
226+
{ActiveTool::Rotate, "Rotate [R]", {0.80f, 0.65f, 0.22f, 1.f}},
227+
{ActiveTool::Scale, "Scale [S]", {0.82f, 0.29f, 0.29f, 1.f}},
228+
{ActiveTool::Measure, "Ruler", {0.60f, 0.82f, 0.82f, 1.f}},
229+
};
230+
for (const auto& tool : tools) {
231+
const bool active = context.activeTool == tool.tool;
232+
if (active) ImGui::PushStyleColor(ImGuiCol_Button, tool.color);
233+
if (ImGui::Button(tool.label, ImVec2(84, 30))) context.selectTool(tool.tool);
234+
if (active) ImGui::PopStyleColor();
235+
ImGui::SameLine();
236+
}
237+
ImGui::TextDisabled("|");
238+
ImGui::SameLine();
239+
240+
struct { Mc3::ObjectType type; const char* label; ImVec4 color; } primitives[] = {
241+
{Mc3::ObjectType::Box, "+Box", {0.82f, 0.47f, 0.22f, 1.f}},
242+
{Mc3::ObjectType::Sphere, "+Sph", {0.22f, 0.47f, 0.82f, 1.f}},
243+
{Mc3::ObjectType::Cylinder, "+Cyl", {0.22f, 0.73f, 0.39f, 1.f}},
244+
{Mc3::ObjectType::Cone, "+Con", {0.73f, 0.22f, 0.73f, 1.f}},
245+
{Mc3::ObjectType::Plane, "+Pln", {0.80f, 0.80f, 0.22f, 1.f}},
246+
{Mc3::ObjectType::Torus, "+Tor", {0.22f, 0.70f, 0.80f, 1.f}},
247+
{Mc3::ObjectType::Capsule, "+Cap", {0.70f, 0.35f, 0.70f, 1.f}},
248+
{Mc3::ObjectType::Disk, "+Dsk", {0.80f, 0.65f, 0.20f, 1.f}},
249+
{Mc3::ObjectType::Grid, "+Grd", {0.30f, 0.65f, 0.50f, 1.f}},
250+
{Mc3::ObjectType::IcoSphere, "+Ico", {0.25f, 0.55f, 0.80f, 1.f}},
251+
};
252+
for (const auto& primitive : primitives) {
253+
ImGui::PushStyleColor(ImGuiCol_Button, primitive.color);
254+
if (ImGui::Button(primitive.label, ImVec2(40, 30))) context.addPrimitive(primitive.type);
255+
ImGui::PopStyleColor();
256+
ImGui::SameLine();
257+
}
258+
ImGui::TextDisabled("|");
259+
ImGui::SameLine();
260+
}
261+
262+
} // namespace MeshCraft::Application::UI

0 commit comments

Comments
 (0)