#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_DOCS, // documentation + source link of the selection (or the diagram) 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 UI_OVERLAY_DOC, // multi-line documentation editor } 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, EDIT_NODE_LINK, // "path/in/repo.c:42" or a url EDIT_DIAGRAM_REPO, // repo url (or a template with {path} {line} {ref}) EDIT_DIAGRAM_REF, // branch / tag / commit EDIT_DIAGRAM_ROOT, // local checkout links resolve against } 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, CANVAS_DRAG_BEND, // moving one bend (waypoint) of the selected edge CANVAS_DRAG_MESSAGE, // moving a sequence message up / down } CanvasDragMode; typedef enum DocTargetKind { DOC_TARGET_DIAGRAM, DOC_TARGET_NODE, DOC_TARGET_EDGE, } DocTargetKind; #define DOC_EDIT_CAP KiB(64) // NOTE: the multi-line doc editor. text is utf-8, cursor a byte offset typedef struct DocEditor DocEditor; struct DocEditor { char *text; u32 size; u32 cursor; u32 kind; // DocTargetKind s32 index; // node / edge index u32 target_id; // the node / edge id, so an undo or delete under us is caught f32 scroll; // first visual line b32 changed; b32 discard_armed; // esc once with changes: the next esc throws them away f32 want_x; // column kept across up / down }; typedef enum PngExportState { PNG_IDLE, PNG_PENDING, // set by :export x.png, the next frame starts drawing tiles PNG_TILES, // one tile per frame, read back after the frame is presented } PngExportState; // NOTE: a png larger than the window is drawn as a grid of window sized tiles, one per frame typedef struct PngExport PngExport; struct PngExport { u32 state; // PngExportState char path[512]; f32 scale; // device pixels per world unit Rect world; // what the image shows u32 width, height; u32 tile_w, tile_h; // device pixels, the swapchain size when the export started u32 tiles_x, tiles_y; u32 tile; // the tile drawn last frame (its pixels arrive after vk_render) b32 drawn; // a tile was drawn this frame and will be captured u8 *rgb; b32 quit_after; // --export=x.png char result[256]; }; 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; s32 canvas_drag_edge; // CANVAS_DRAG_BEND / CANVAS_DRAG_MESSAGE s32 canvas_drag_bend; // waypoint index f32 canvas_press_wy; // world y of the press (where a dragged message goes) s32 canvas_hover_marker; // node whose doc marker the mouse is over (tooltip) b32 exporting; // drawing a png tile: no selection, hover or handles f32 canvas_press_x, canvas_press_y; // where the last canvas button press started u32 canvas_cursor; //- vim state u32 count; u32 pending; char message[160]; u64 message_ns; //- overlays UIOverlay overlay; b32 overlay_opened; char input[512]; 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 b32 edit_inline; // drawn inside the floating inspector's row instead of the modal box b32 edit_drawn; // the card drew the inline field this frame (else draw_overlay falls back) //- documentation editor, clipboard, png export DocEditor doc; char *clip; // the yank register (DSL text), malloc'd u64 clip_size; u64 clip_system_hash; // hash of what we last put on the system clipboard Diagram *clip_diagram; // scratch diagram for pasting mermaid / plantuml text PngExport png; //- floating inspector: the Inspector's rows in a small card next to the selection on the canvas. // card_view is never in the layout, it only owns a cursor and a scroll. View card_view; Rect card_rect; // this frame's screen rect, valid while card_visible b32 card_visible; b32 card_focused; // keys go to the card: enter on the canvas, esc / tab leave u32 card_target; // node + 1, or (edge + 1) | CARD_EDGE_BIT. a change resets the cursor u32 card_dismissed; // target closed with the x, stays closed until the selection changes //- 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); internal void start_edit(App *app, EditTargetKind kind, s32 index, const char *initial); internal b32 card_place(App *app, PlatformInput *input, s32 view_index, View *view, Rect rect); internal void card_draw(App *app, PlatformInput *input, s32 panel, Rect canvas, b32 owns_mouse); internal void doc_edit_open(App *app, DocTargetKind kind, s32 index); internal void app_open_link(App *app, s32 node, b32 online); internal void png_export_begin(App *app, const char *path, f32 scale); internal void png_export_collect(App *app); // after vk_render: takes the tile the renderer read back #define CARD_EDGE_BIT 0x80000000u //- 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