summaryrefslogtreecommitdiffstats
path: root/source/app/app_ui.h
blob: 9d793b6ae2e18f5e793a56ff915e18c407ff8d8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#ifndef APP_UI_H
#define APP_UI_H

// NOTE: RAD Debugger-style dockable UI (identical architecture to mp3_player) extended with
// an infinite hardware-accelerated Vulkan diagram canvas view. every view (Canvas, Outline,
// Inspector, Edges, Layers, Palette, Source, Settings, Profiler, Views, Status) lives in a
// fixed pool and can be docked, split, tabbed, resized, or dragged anywhere.

#define UI_THEME_COLOR(color) (ui_theme.colors[(color)])
#define COLOR_BG          UI_THEME_COLOR(UI_COLOR_BG)
#define COLOR_PANEL       UI_THEME_COLOR(UI_COLOR_PANEL)
#define COLOR_PANEL_EDGE  UI_THEME_COLOR(UI_COLOR_PANEL_EDGE)
#define COLOR_FOCUS_EDGE  UI_THEME_COLOR(UI_COLOR_FOCUS_EDGE)
#define COLOR_TAB         UI_THEME_COLOR(UI_COLOR_TAB)
#define COLOR_TAB_ACTIVE  UI_THEME_COLOR(UI_COLOR_TAB_ACTIVE)
#define COLOR_HEADER      UI_THEME_COLOR(UI_COLOR_HEADER)
#define COLOR_HOVER       UI_THEME_COLOR(UI_COLOR_HOVER)
#define COLOR_SELECTED    UI_THEME_COLOR(UI_COLOR_SELECTED)
#define COLOR_ZEBRA       UI_THEME_COLOR(UI_COLOR_ZEBRA)
#define COLOR_TEXT        UI_THEME_COLOR(UI_COLOR_TEXT)
#define COLOR_TEXT_DIM    UI_THEME_COLOR(UI_COLOR_TEXT_DIM)
#define COLOR_TEXT_FAINT  UI_THEME_COLOR(UI_COLOR_TEXT_FAINT)
#define COLOR_ACCENT      UI_THEME_COLOR(UI_COLOR_ACCENT)
#define COLOR_TRACK       UI_THEME_COLOR(UI_COLOR_TRACK)
#define COLOR_DROP        UI_THEME_COLOR(UI_COLOR_DROP)
#define COLOR_ON_ACCENT   UI_THEME_COLOR(UI_COLOR_ON_ACCENT)
#define COLOR_MARKED      UI_THEME_COLOR(UI_COLOR_MARKED)

#define UI_GAP            (ui_theme.gap)
#define UI_TAB_H          (ui_theme.tab_height)
#define UI_COLUMN_H       (ui_theme.show_columns ? ui_theme.column_height : 0.0f)
#define UI_ROW_H          (ui_theme.row_height)
#define UI_STATUS_H       (ui_theme.status_height)
#define UI_FONT           (ui_theme.font_size)
#define UI_FONT_SMALL     (ui_theme.font_size_small)

#define UI_WIDTH          1400
#define UI_HEIGHT         860
#define UI_MIN_WIDTH      720
#define UI_MIN_HEIGHT     480
#define UI_ZOOM_DEFAULT   1.05f

//- views

typedef enum ViewKind {
	VIEW_NONE,
	VIEW_CANVAS,    // infinite 2D Vulkan diagram canvas (multiple independent cameras allowed!)
	VIEW_OUTLINE,   // watch-style tree of modules -> nodes -> sections -> members
	VIEW_INSPECTOR, // editable properties & members of the active node / edge
	VIEW_EDGES,     // watch-style table of every edge
	VIEW_LAYERS,    // tags / layers visibility & dimming controls
	VIEW_PALETTE,   // one-key node archetypes & architecture templates
	VIEW_SOURCE,    // live text DSL mirror of the diagram
	VIEW_SETTINGS,  // appearance, colors, canvas, layout, behaviour, performance, info
	VIEW_PROFILER,  // frame, memory, heap, arenas, threads, process, gpu, fonts, diagram
	VIEW_VIEWS,     // catalog of every openable view
	VIEW_STATUS,    // bottom status bar (itself a view!)
	VIEW_HELP,      // the user manual (help.txt, baked into the binary)
	VIEW_KIND_COUNT,
} ViewKind;

typedef struct ScrollList ScrollList;
struct ScrollList {
	f32 offset;
	f32 target;
};

#define VIEW_EXPANDED_WORDS 64 // bitset over node indices (4096 nodes)
#define UI_MAX_COLUMNS      6

typedef struct View View;
struct View {
	u32        kind;
	u32        group;
	s32        cursor;
	ScrollList scroll;
	u64        expanded[VIEW_EXPANDED_WORDS];
	u32        first_visible;
	u32        visible_rows;
	u32        row_count;

	//- per-canvas camera (each VIEW_CANVAS has its own independent pan/zoom!)
	f32        cam_x, cam_y;
	f32        cam_zoom;
	f32        cam_target_x, cam_target_y;
	f32        cam_target_zoom;
	b32        cam_init;
	b32        cam_fit_pending;

	//- table column layout
	u8         column_order[UI_MAX_COLUMNS];
	f32        column_weight[UI_MAX_COLUMNS];
	u32        column_hidden;
	u32        column_count;
};

//- panels

typedef enum PanelKind {
	PANEL_FREE,
	PANEL_LEAF,
	PANEL_SPLIT,
} PanelKind;

#define UI_MAX_PANELS 32
#define UI_MAX_VIEWS  32
#define UI_MAX_TABS   16

typedef struct Panel Panel;
struct Panel {
	u32  kind;
	s32  parent;
	u32  axis;
	s32  children[2];
	f32  ratio;
	u32  tab_count;
	u32  active_tab;
	u8   tabs[UI_MAX_TABS];
	Rect rect;
};

typedef struct Layout Layout;
struct Layout {
	u32   version;
	s32   root;
	s32   focused;
	Panel panels[UI_MAX_PANELS];
	View  views[UI_MAX_VIEWS];
};

#define UI_LAYOUT_VERSION 2

//- overlays & canvas interactions

typedef enum UIOverlay {
	UI_OVERLAY_NONE,
	UI_OVERLAY_SEARCH,  // '/' and '?' fuzzy search over nodes, members, edges, tags
	UI_OVERLAY_COMMAND, // ':' command bar with live completion
	UI_OVERLAY_EDIT,    // inline text edit for inspector / settings / node rename
} UIOverlay;

typedef enum EditTargetKind {
	EDIT_SETTING,
	EDIT_NODE_NAME,
	EDIT_NODE_STEREO,
	EDIT_NODE_TAG,
	EDIT_NODE_NOTE,
	EDIT_NODE_COLOR,
	EDIT_EDGE_LABEL,
	EDIT_EDGE_SRC_MULT,
	EDIT_EDGE_DST_MULT,
	EDIT_EDGE_TAG,
	EDIT_EDGE_COLOR,
	EDIT_SECTION_TITLE,
	EDIT_MEMBER_LINE,   // "[vis] name : type [badge]"
	EDIT_DIAGRAM_TITLE,
} EditTargetKind;

typedef enum CanvasDragMode {
	CANVAS_DRAG_NONE,
	CANVAS_DRAG_PAN,
	CANVAS_DRAG_NODES,
	CANVAS_DRAG_RESIZE,
	CANVAS_DRAG_CONNECT,
	CANVAS_DRAG_MARQUEE,
	CANVAS_DRAG_MINIMAP,
} CanvasDragMode;

typedef struct SearchResult SearchResult;
struct SearchResult {
	u32 kind; // 0 = node, 1 = edge, 2 = member
	s32 index;
	s32 parent_node;
};

#define UI_MAX_RESULTS 48

typedef struct App App;
struct App {
	Arena   *arena;
	Arena   *scratch;
	AppArgs  args;
	String8  data_dir;
	u32      ui_generation;

	//- core diagram engine
	Diagram *diagram;

	//- platform & rendering
	PlatformWindow *window;
	VulkanRenderer  renderer;
	FontSystem      fonts;
	DrawList        draw;
	u32             width, height, scale;
	f32             ui_scale; // fractional display scale on top of the integer scale (win32 150% = 2 * 0.75)

	Profiler *profiler;
	Settings  settings;
	Layout    layout;
	String8   font_files[UI_FONT_CHOICES];

	//- shared selection (RAD style: Outline, Canvas, Inspector, Edges all follow!)
	s32 active_node; // -1 none
	s32 active_edge; // -1 none
	b32 pan_to_active;

	//- canvas interaction state
	CanvasDragMode canvas_drag;
	s32            canvas_drag_view;
	s32            canvas_drag_node;
	s32            canvas_hover_node;
	s32            canvas_hover_edge;
	u32            canvas_connect_kind; // EdgeKind for newly dragged edges
	f32            canvas_drag_start_x, canvas_drag_start_y;
	f32            canvas_drag_last_wx, canvas_drag_last_wy;
	f32            canvas_marquee_x0, canvas_marquee_y0, canvas_marquee_x1, canvas_marquee_y1;
	f32            canvas_last_wx, canvas_last_wy; // last world mouse pos (for 'a' add node at cursor)
	b32            canvas_space_held;
	u32            canvas_cursor;

	//- vim state
	u32  count;
	u32  pending;
	char message[160];
	u64  message_ns;

	//- overlays
	UIOverlay      overlay;
	b32            overlay_opened;
	char           input[160];
	u32            input_size;
	b32            search_backward;
	char           last_search[64];
	u32            last_search_size;
	SearchResult   results[UI_MAX_RESULTS];
	u32            result_count;
	s32            result_cursor;
	EditTargetKind edit_kind;
	s32            edit_index; // node / edge / section / member / setting index

	//- panel & column mouse state
	s32 column_drag_view;
	u32 column_drag_column;
	b32 column_drag_active;
	f32 column_drag_x;
	s32 column_resize_view;
	u32 column_resize_index;
	u32 table_cursor;

	s32 drag_view;
	s32 drag_panel;
	b32 drag_active;
	f32 drag_x, drag_y;
	s32 resize_panel;
	u64 last_click_ns;
	f32 last_click_x, last_click_y;
	u32 cursor_shape;

	//- frame timing
	u64 last_frame_ns;
	f32 dt;
	f32 time;
	f32 frame_ms;
	f32 fps;
	b32 animating;
	b32 ticking;
	b32 quit;
};

internal void ui_frame(App *app, PlatformInput *input);
internal void ui_layout_default(Layout *layout);
internal void app_message(App *app, const char *format, ...);
internal void app_apply_settings(App *app);
internal void canvas_fit_view(App *app, View *view, b32 selection_only);
internal void canvas_pan_to_node(App *app, View *view, s32 node_index);

//- hot reload abi
typedef void DesignUiFrame(App *app, PlatformInput *input, int wake_fd);
#define DESIGN_UI_FRAME_SYMBOL "design_ui_frame"
#define DESIGN_UI_SIZE_SYMBOL  "design_ui_app_size"
#define DESIGN_UI_SIGNATURE ((u64)sizeof(App) * 31 + (u64)sizeof(Profiler) * 1009 + (u64)sizeof(Diagram) * 7919 + \
                             (u64)sizeof(DiagramNode) * 104729 + (u64)sizeof(DiagramEdge) * 1299709 + (u64)sizeof(DrawInstance) * 86028121)

#endif // APP_UI_H