aboutsummaryrefslogtreecommitdiff
path: root/src/ui/ui_layer.h
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-21 20:55:02 +0200
committerhachem <im@hachem.wtf>2026-09-21 20:55:02 +0200
commit270eda6f558c972ec86ad0580f1d3d18afc83a94 (patch)
tree5944a95bf052ed264372b2eb29c76d2be97e395f /src/ui/ui_layer.h
parent908db452c4268f367e49b027b7e91fc60f5e0a86 (diff)
feat: update ui
Diffstat (limited to 'src/ui/ui_layer.h')
-rw-r--r--src/ui/ui_layer.h99
1 files changed, 69 insertions, 30 deletions
diff --git a/src/ui/ui_layer.h b/src/ui/ui_layer.h
index b913bc4..4479844 100644
--- a/src/ui/ui_layer.h
+++ b/src/ui/ui_layer.h
@@ -3,49 +3,79 @@
#include "workspace.h" // AppActions, UIContext
#include "rendering/view.h"
+#include <string>
+
+struct ImFont;
+
namespace Donut
{
- // the application's docking shell. draws a main menu bar and a full-viewport
- // dock space with a pass-through centre (the live 3D render shows through the
- // middle), then a set of dockable tool panels. ships a few default layouts
- // built with the DockBuilder API and lets the user rearrange, hide, or restore
- // panels like a normal desktop app. draw() returns the View the RenderPath
- // should draw this frame.
+ // the workspaces and the panels they're built from.
+ enum class Tab { Simulation, SceneEditor, Export };
+ enum class Panel { Outliner, Properties, BlackHole, Settings, Export, Stats };
+ inline constexpr int kTabCount = 3;
+ inline constexpr int kPanelCount = 6;
+
+ // the application's docking shell: a main menu bar, a workspace tab strip
+ // ([ Simulation ] [ Scene Editor ] [ Export ]), a bottom status bar, and one
+ // full-viewport dock space per workspace with a pass-through centre so the
+ // live 3D render shows through. every workspace keeps its own dock tree and
+ // its own panel instances, so rearranging one never touches the others, and
+ // ImGui persists all of them in imgui.ini. draw() returns the View the
+ // RenderPath should draw this frame.
class UILayer
{
public:
- UILayer() = default;
+ UILayer();
+
+ // loads the Inter faces and registers the workspace ini section on the
+ // live ImGui context. call once after the device's init_imgui() and before
+ // the first draw(): ImGui reads imgui.ini on its first NewFrame.
+ auto init() -> void;
auto draw(const UIContext& ctx) -> View;
private:
- // which 3D view fills the pass-through centre.
- enum class Mode { Scene, Simulation };
- // a named default arrangement of the panels.
- enum class Layout { Simulation, SceneEditing, Export };
+ // one workspace: a fixed centre view, its own dock tree, its own window
+ // instances of the panels it owns.
+ struct TabState
+ {
+ Tab id = Tab::Simulation;
+ const char* label = nullptr; // "Scene Editor"
+ const char* key = nullptr; // "scene": the ### suffix and dock-id salt
+ View view = View::BlackHole;
+ unsigned int dock_id = 0; // ImHashStr("donut.dock.<key>")
+ std::string name[kPanelCount]; // "Black Hole###scene.black_hole"
+ bool allowed[kPanelCount] = {}; // belongs to this workspace
+ bool defaults[kPanelCount] = {}; // open after a seed / reset
+ bool show[kPanelCount] = {}; // open right now
+ bool reset = false; // rebuild the tree before it's next submitted
+ bool appearing = false; // first frame back: panels mustn't grab focus
+ };
auto draw_menu_bar(const UIContext& ctx) -> void;
- auto build_layout(unsigned int dockspace_id) -> void; // DockBuilder tree
- auto apply_layout(Layout layout) -> void; // preset: view + panels
+ auto draw_tab_strip() -> void;
+ auto draw_status_bar(const UIContext& ctx) -> void;
+ auto build_layout(TabState& tab) -> void; // DockBuilder seed for one workspace
+ auto request_tab(int index) -> void { m_tab_request = index; }
+ auto sync_persisted() -> void;
- auto panel_outliner(const UIContext& ctx) -> void;
- auto panel_properties(const UIContext& ctx) -> void;
- auto panel_black_hole(const UIContext& ctx) -> void;
- auto panel_settings(const UIContext& ctx) -> void;
- auto panel_export(const UIContext& ctx) -> void;
- auto panel_stats(const UIContext& ctx) -> void;
+ auto begin_panel(TabState& tab, Panel p) -> bool;
+ auto draw_panel(const UIContext& ctx, TabState& tab, Panel p) -> void;
+ auto panel_outliner(const UIContext& ctx, TabState& tab) -> void;
+ auto panel_properties(const UIContext& ctx, TabState& tab) -> void;
+ auto panel_black_hole(const UIContext& ctx, TabState& tab) -> void;
+ auto panel_settings(const UIContext& ctx, TabState& tab) -> void;
+ auto panel_export(const UIContext& ctx, TabState& tab) -> void;
+ auto panel_stats(const UIContext& ctx, TabState& tab) -> void;
- Mode m_mode = Mode::Simulation;
- Layout m_layout = Layout::Simulation;
- bool m_rebuild_layout = false; // rebuild the dock tree next frame
- bool m_first_frame = true; // seed the default layout once, if no saved one
+ // styled building blocks the panels share (they need the fonts, hence members)
+ auto section(const char* title, bool default_open = true) -> bool; // collapsible heading
+ auto caption(const char* text) -> void; // muted helper text
+ auto segmented(const char* id, const char* const* labels, int count, int& value) -> bool;
- // panel visibility (defaults match the Simulation layout the app opens in).
- bool m_show_outliner = false;
- bool m_show_properties = false;
- bool m_show_black_hole = true;
- bool m_show_settings = false;
- bool m_show_export = false;
- bool m_show_stats = true;
+ TabState m_tabs[kTabCount];
+ int m_active_tab = 0; // index into m_tabs; the source of truth
+ int m_tab_request = -1; // one-frame programmatic strip selection
+ bool m_first_frame = true;
// properties-panel gizmo op (0 = translate, 1 = scale); cast in the .cpp.
int m_gizmo_op = 0;
@@ -57,5 +87,14 @@ namespace Donut
bool m_exp_color = true, m_exp_redshift = false, m_exp_temperature = false, m_exp_impact = false;
int m_exp_resolution = 1, m_exp_format = 0;
int m_exp_written = 0; bool m_exp_reported = false;
+
+ // typography: two faces, sized at PushFont time (ImGui 1.92 rasterises on demand).
+ ImFont* m_font_body = nullptr; // Inter Regular
+ ImFont* m_font_heading = nullptr; // Inter SemiBold
+
+ // rolling frame-time history (ms) for the diagnostics graph.
+ static constexpr int kFrameHist = 120;
+ float m_frame_hist[kFrameHist] = {};
+ int m_frame_hist_i = 0;
};
}