diff --git a/src/proto/pp_game.c b/src/proto/pp_game.c index edba2f7f..b9b5c553 100644 --- a/src/proto/pp_game.c +++ b/src/proto/pp_game.c @@ -159,9 +159,12 @@ JobDef(PP_VisWorker, sig, job_id) Vec2 ui_cursor = ui_frame.cursor_pos; /* Restore window */ - if (frame_gen == 0) { - WND_PushCmd(window_frame, .kind = WND_CmdKind_Restore, .restore = window_restore); + if (frame_gen == 0) + { + WND_PushCmd(window_frame, .kind = WND_CmdKind_Restore, .restore = window_restore); + } + window_restore = PushString(frame_arena, window_frame.restore); } /* Set widget theme */ @@ -181,23 +184,23 @@ JobDef(PP_VisWorker, sig, job_id) PP_BeginCommandsWidget(&persist.commands_widget); { - if (PP_PushItemToCommandsWidget(&persist.commands_widget, Lit("Debug UI")).m1_presses > 0) + if (PP_PushCommandsWidgetItem(&persist.commands_widget, Lit("Debug UI")).m1_presses > 0) { persist.ui_debug = !persist.ui_debug; } - if (PP_PushItemToCommandsWidget(&persist.commands_widget, Lit("Fullscreen")).m1_presses > 0) + if (PP_PushCommandsWidgetItem(&persist.commands_widget, Lit("Fullscreen")).m1_presses > 0) { b32 new = !window_frame.fullscreen; WND_PushCmd(window_frame, .kind = WND_CmdKind_SetFullscreen, .v = new); LogInfoF("Toggled fullscreen: %F", FmtSint(new)); } - if (PP_PushItemToCommandsWidget(&persist.commands_widget, Lit("Topmost")).m1_presses > 0) + if (PP_PushCommandsWidgetItem(&persist.commands_widget, Lit("Topmost")).m1_presses > 0) { b32 new = !window_frame.forced_top; WND_PushCmd(window_frame, .kind = WND_CmdKind_SetForcedTop, .v = new); LogInfoF("Toggled topmost: %F", FmtSint(new)); } - if (PP_PushItemToCommandsWidget(&persist.commands_widget, Lit("Spawn")).m1_presses > 0) + if (PP_PushCommandsWidgetItem(&persist.commands_widget, Lit("Spawn")).m1_presses > 0) { LogErrorF("RAAAAH"); } diff --git a/src/proto/pp_widgets.c b/src/proto/pp_widgets.c index 9278f557..b79250f8 100644 --- a/src/proto/pp_widgets.c +++ b/src/proto/pp_widgets.c @@ -27,12 +27,30 @@ void PP_PushWidgetThemeStyles(PP_WidgetTheme theme) void PP_BeginCommandsWidget(PP_CommandsWidget *widget) { - widget->window_cp = UI_PushCP(0); + ZeroStruct(&widget->build); + widget->build.cp = UI_PushCP(0); + UI_Push(Tag, HashF("commands widget")); +} +UI_Report PP_PushCommandsWidgetItem(PP_CommandsWidget *widget, String name) +{ + Arena *build_arena = UI_GetFrameArena(); + + UI_Key key = UI_KeyF("btn%F", FmtSint(widget->build.num_items)); + PP_CommandsWidgetItem *item = PushStruct(build_arena, PP_CommandsWidgetItem); + item->name = name; + item->key = key; + QueuePush(widget->build.first_item, widget->build.last_item, item); + + ++widget->build.num_items; + return UI_ReportFromKey(key); +} + +void PP_EndCommandsWidget(PP_CommandsWidget *widget) +{ PP_WidgetTheme theme = PP_GetWidgetTheme(); Vec2 cursor_pos = UI_GetCursorPos(); - widget->num_items = 0; UI_Push(Tag, HashF("commands widget")); UI_Key titlebar_key = UI_KeyF("title bar"); @@ -97,77 +115,87 @@ void PP_BeginCommandsWidget(PP_CommandsWidget *widget) UI_PopCP(UI_TopCP()); } + f32 padding = theme.window_border; UI_SetNext(Tint, 0); UI_SetNext(Rounding, 0); UI_PushCP(UI_BuildRow(UI_NilKey)); { - f32 padding = theme.window_border; UI_BuildSpacer(UI_PIX(padding, 1)); { UI_SetNext(Tint, 0); UI_SetNext(Rounding, 0); UI_SetNext(Width, UI_FILL(1, 0)); UI_PushCP(UI_BuildColumn(UI_NilKey)); + { + for (PP_CommandsWidgetItem *item = widget->build.first_item; item; item = item->next) + { + UI_BuildDivider(UI_PIX(1, 1), theme.divider_color); + + UI_Key btn_key = item->key; + UI_Report btn_rep = UI_ReportFromKey(btn_key); + Vec4 hovered_color = Rgb32(0x103c4c); + Vec4 pressed_color = hovered_color; + pressed_color.w = 0.2; + + f32 hot = btn_rep.hot; + f32 active = btn_rep.active; + f32 hovered = btn_rep.hovered; + + Vec4 color = theme.window_background_color; + Vec4 border_color = ZI; + color = BlendSrgb(color, hovered_color, hot); + color = BlendSrgb(color, pressed_color, active * hovered); + border_color = BlendSrgb(border_color, Rgb32(0x0078a6), hot); + + UI_SetNext(Rounding, 0); + UI_SetNext(Tint, 0); + UI_PushCP(UI_BuildRow(UI_NilKey)); + { + UI_SetNext(BorderColor, border_color); + UI_SetNext(BackgroundColor, color); + UI_SetNext(Rounding, UI_RPIX(5)); + UI_SetNext(Width, UI_FILL(1, 0)); + UI_SetNext(Height, UI_FNT(1.5, 1)); + UI_SetNext(ChildAlignment, UI_Alignment_Left); + UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_Interactable); + UI_PushCP(UI_BuildRow(btn_key)); + { + /* Begin spacer */ + UI_BuildSpacer(UI_PIX(20, 1)); + + /* Command label */ + UI_BuildLabel(item->name); + + /* Middle spacer */ + UI_BuildSpacer(UI_FILL(1, 0)); + + /* Command hotkey button */ + UI_SetNext(Text, UI_StringF("Test")); + UI_SetNext(Width, UI_FIT(1)); + UI_SetNext(Rounding, UI_RPIX(0)); + UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_Interactable); + UI_PushCP(UI_BuildRow(UI_NilKey)); + { + + } + UI_PopCP(UI_TopCP()); + + /* End spacer */ + UI_BuildSpacer(UI_PIX(20, 1)); + } + UI_PopCP(UI_TopCP()); + } + UI_PopCP(UI_TopCP()); + } + } + UI_PopCP(UI_TopCP()); } - } -} - -UI_Report PP_PushItemToCommandsWidget(PP_CommandsWidget *widget, String text) -{ - PP_WidgetTheme theme = PP_GetWidgetTheme(); - UI_BuildDivider(UI_PIX(1, 1), theme.divider_color); - - UI_Key btn_key = UI_KeyF("btn%F", FmtSint(widget->num_items)); - UI_Report rep = UI_ReportFromKey(btn_key); - - Vec4 hovered_color = Rgb32(0x103c4c); - Vec4 pressed_color = hovered_color; - pressed_color.w = 0.2; - - f32 hot = rep.hot; - f32 active = rep.active; - f32 hovered = rep.hovered; - - Vec4 color = theme.window_background_color; - Vec4 border_color = ZI; - color = BlendSrgb(color, hovered_color, hot); - color = BlendSrgb(color, pressed_color, active * hovered); - border_color = BlendSrgb(border_color, Rgb32(0x0078a6), hot); - - UI_SetNext(Rounding, 0); - UI_SetNext(Tint, 0); - UI_PushCP(UI_BuildRow(UI_NilKey)); - { - - UI_SetNext(BorderColor, border_color); - UI_SetNext(BackgroundColor, color); - UI_SetNext(Rounding, UI_RPIX(5)); - UI_SetNext(Width, UI_FILL(1, 0)); - UI_SetNext(Height, UI_FNT(1.5, 1)); - UI_SetNext(ChildAlignment, UI_Alignment_Left); - UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_Interactable); - UI_PushCP(UI_BuildRow(btn_key)); - { - UI_BuildSpacer(UI_PIX(20, 1)); - UI_BuildLabel(text); - } - UI_PopCP(UI_TopCP()); + UI_BuildSpacer(UI_PIX(padding, 1)); } UI_PopCP(UI_TopCP()); - ++widget->num_items; - return rep; -} - - -void PP_EndCommandsWidget(PP_CommandsWidget *widget) -{ - PP_WidgetTheme theme = PP_GetWidgetTheme(); - f32 padding = theme.window_border; UI_BuildSpacer(UI_PIX(padding, 1)); UI_PopCP(UI_TopCP()); - UI_BuildSpacer(UI_PIX(padding, 1)); - UI_PopCP(widget->window_cp); } //////////////////////////////////////////////////////////// diff --git a/src/proto/pp_widgets.h b/src/proto/pp_widgets.h index e057212e..c9c43a0d 100644 --- a/src/proto/pp_widgets.h +++ b/src/proto/pp_widgets.h @@ -18,14 +18,27 @@ Struct(PP_WidgetTheme) //////////////////////////////////////////////////////////// //~ Commands widget types +Struct(PP_CommandsWidgetItem) +{ + PP_CommandsWidgetItem *next; + String name; + UI_Key key; +}; + Struct(PP_CommandsWidget) { /* Persistent state */ Vec2 pos; /* Per-build state */ - UI_Checkpoint window_cp; - i64 num_items; + struct + { + UI_Checkpoint cp; + PP_CommandsWidgetItem *first_item; + PP_CommandsWidgetItem *last_item; + u64 num_items; + } build; + }; //////////////////////////////////////////////////////////// @@ -38,7 +51,7 @@ void PP_PushWidgetTheme(PP_WidgetTheme theme); //~ Commands widget void PP_BeginCommandsWidget(PP_CommandsWidget *widget); -UI_Report PP_PushItemToCommandsWidget(PP_CommandsWidget *widget, String text); +UI_Report PP_PushCommandsWidgetItem(PP_CommandsWidget *widget, String name); void PP_EndCommandsWidget(PP_CommandsWidget *widget); //////////////////////////////////////////////////////////// diff --git a/src/ui/ui_common.c b/src/ui/ui_common.c index 6e369ca3..34e8b058 100644 --- a/src/ui/ui_common.c +++ b/src/ui/ui_common.c @@ -15,7 +15,7 @@ UI_Box *UI_BuildLabel(String text) UI_SetNext(Tint, tint); UI_SetNext(Font, font); UI_SetNext(FontSize, font_size); - UI_SetNext(Width, UI_FIT(0)); + UI_SetNext(Width, UI_FIT(1)); UI_SetNext(Height, UI_FIT(1)); UI_SetNext(Text, text); UI_SetNext(Flags, UI_BoxFlag_DrawText); diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 6935f7db..1a6bd13e 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -655,6 +655,12 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags) //////////////////////////////////////////////////////////// //~ Frame helpers +Arena *UI_GetFrameArena(void) +{ + UI_SharedState *g = &UI_shared_state; + return g->build_arena; +} + Vec2 UI_GetCursorPos(void) { UI_SharedState *g = &UI_shared_state; diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 2a2d233f..843e923b 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -417,6 +417,7 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags); //////////////////////////////////////////////////////////// //~ Frame helpers +Arena *UI_GetFrameArena(void); Vec2 UI_GetCursorPos(void); ////////////////////////////////////////////////////////////