widget testing

This commit is contained in:
jacob 2025-11-07 19:24:27 -06:00
parent d9b487cea2
commit e0c79dd2b0
6 changed files with 118 additions and 67 deletions

View File

@ -159,10 +159,13 @@ JobDef(PP_VisWorker, sig, job_id)
Vec2 ui_cursor = ui_frame.cursor_pos; Vec2 ui_cursor = ui_frame.cursor_pos;
/* Restore window */ /* Restore window */
{
if (frame_gen == 0) if (frame_gen == 0)
{ {
WND_PushCmd(window_frame, .kind = WND_CmdKind_Restore, .restore = window_restore); WND_PushCmd(window_frame, .kind = WND_CmdKind_Restore, .restore = window_restore);
} }
window_restore = PushString(frame_arena, window_frame.restore);
}
/* Set widget theme */ /* Set widget theme */
PP_WidgetTheme theme = PP_GetWidgetTheme(); PP_WidgetTheme theme = PP_GetWidgetTheme();
@ -181,23 +184,23 @@ JobDef(PP_VisWorker, sig, job_id)
PP_BeginCommandsWidget(&persist.commands_widget); 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; 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; b32 new = !window_frame.fullscreen;
WND_PushCmd(window_frame, .kind = WND_CmdKind_SetFullscreen, .v = new); WND_PushCmd(window_frame, .kind = WND_CmdKind_SetFullscreen, .v = new);
LogInfoF("Toggled fullscreen: %F", FmtSint(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; b32 new = !window_frame.forced_top;
WND_PushCmd(window_frame, .kind = WND_CmdKind_SetForcedTop, .v = new); WND_PushCmd(window_frame, .kind = WND_CmdKind_SetForcedTop, .v = new);
LogInfoF("Toggled topmost: %F", FmtSint(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"); LogErrorF("RAAAAH");
} }

View File

@ -27,12 +27,30 @@ void PP_PushWidgetThemeStyles(PP_WidgetTheme theme)
void PP_BeginCommandsWidget(PP_CommandsWidget *widget) 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(); PP_WidgetTheme theme = PP_GetWidgetTheme();
Vec2 cursor_pos = UI_GetCursorPos(); Vec2 cursor_pos = UI_GetCursorPos();
widget->num_items = 0;
UI_Push(Tag, HashF("commands widget")); UI_Push(Tag, HashF("commands widget"));
UI_Key titlebar_key = UI_KeyF("title bar"); UI_Key titlebar_key = UI_KeyF("title bar");
@ -97,36 +115,31 @@ void PP_BeginCommandsWidget(PP_CommandsWidget *widget)
UI_PopCP(UI_TopCP()); UI_PopCP(UI_TopCP());
} }
f32 padding = theme.window_border;
UI_SetNext(Tint, 0); UI_SetNext(Tint, 0);
UI_SetNext(Rounding, 0); UI_SetNext(Rounding, 0);
UI_PushCP(UI_BuildRow(UI_NilKey)); UI_PushCP(UI_BuildRow(UI_NilKey));
{ {
f32 padding = theme.window_border;
UI_BuildSpacer(UI_PIX(padding, 1)); UI_BuildSpacer(UI_PIX(padding, 1));
{ {
UI_SetNext(Tint, 0); UI_SetNext(Tint, 0);
UI_SetNext(Rounding, 0); UI_SetNext(Rounding, 0);
UI_SetNext(Width, UI_FILL(1, 0)); UI_SetNext(Width, UI_FILL(1, 0));
UI_PushCP(UI_BuildColumn(UI_NilKey)); UI_PushCP(UI_BuildColumn(UI_NilKey));
}
}
}
UI_Report PP_PushItemToCommandsWidget(PP_CommandsWidget *widget, String text)
{ {
PP_WidgetTheme theme = PP_GetWidgetTheme(); for (PP_CommandsWidgetItem *item = widget->build.first_item; item; item = item->next)
{
UI_BuildDivider(UI_PIX(1, 1), theme.divider_color); UI_BuildDivider(UI_PIX(1, 1), theme.divider_color);
UI_Key btn_key = UI_KeyF("btn%F", FmtSint(widget->num_items)); UI_Key btn_key = item->key;
UI_Report rep = UI_ReportFromKey(btn_key); UI_Report btn_rep = UI_ReportFromKey(btn_key);
Vec4 hovered_color = Rgb32(0x103c4c); Vec4 hovered_color = Rgb32(0x103c4c);
Vec4 pressed_color = hovered_color; Vec4 pressed_color = hovered_color;
pressed_color.w = 0.2; pressed_color.w = 0.2;
f32 hot = rep.hot; f32 hot = btn_rep.hot;
f32 active = rep.active; f32 active = btn_rep.active;
f32 hovered = rep.hovered; f32 hovered = btn_rep.hovered;
Vec4 color = theme.window_background_color; Vec4 color = theme.window_background_color;
Vec4 border_color = ZI; Vec4 border_color = ZI;
@ -138,7 +151,6 @@ UI_Report PP_PushItemToCommandsWidget(PP_CommandsWidget *widget, String text)
UI_SetNext(Tint, 0); UI_SetNext(Tint, 0);
UI_PushCP(UI_BuildRow(UI_NilKey)); UI_PushCP(UI_BuildRow(UI_NilKey));
{ {
UI_SetNext(BorderColor, border_color); UI_SetNext(BorderColor, border_color);
UI_SetNext(BackgroundColor, color); UI_SetNext(BackgroundColor, color);
UI_SetNext(Rounding, UI_RPIX(5)); UI_SetNext(Rounding, UI_RPIX(5));
@ -148,26 +160,42 @@ UI_Report PP_PushItemToCommandsWidget(PP_CommandsWidget *widget, String text)
UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_Interactable); UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_Interactable);
UI_PushCP(UI_BuildRow(btn_key)); UI_PushCP(UI_BuildRow(btn_key));
{ {
/* Begin spacer */
UI_BuildSpacer(UI_PIX(20, 1)); UI_BuildSpacer(UI_PIX(20, 1));
UI_BuildLabel(text);
}
UI_PopCP(UI_TopCP());
}
UI_PopCP(UI_TopCP());
++widget->num_items; /* Command label */
return rep; UI_BuildLabel(item->name);
}
/* Middle spacer */
UI_BuildSpacer(UI_FILL(1, 0));
void PP_EndCommandsWidget(PP_CommandsWidget *widget) /* 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));
{ {
PP_WidgetTheme theme = PP_GetWidgetTheme();
f32 padding = theme.window_border; }
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_BuildSpacer(UI_PIX(padding, 1));
}
UI_PopCP(UI_TopCP());
UI_BuildSpacer(UI_PIX(padding, 1)); UI_BuildSpacer(UI_PIX(padding, 1));
UI_PopCP(UI_TopCP()); UI_PopCP(UI_TopCP());
UI_BuildSpacer(UI_PIX(padding, 1));
UI_PopCP(widget->window_cp);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -18,14 +18,27 @@ Struct(PP_WidgetTheme)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Commands widget types //~ Commands widget types
Struct(PP_CommandsWidgetItem)
{
PP_CommandsWidgetItem *next;
String name;
UI_Key key;
};
Struct(PP_CommandsWidget) Struct(PP_CommandsWidget)
{ {
/* Persistent state */ /* Persistent state */
Vec2 pos; Vec2 pos;
/* Per-build state */ /* Per-build state */
UI_Checkpoint window_cp; struct
i64 num_items; {
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 //~ Commands widget
void PP_BeginCommandsWidget(PP_CommandsWidget *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); void PP_EndCommandsWidget(PP_CommandsWidget *widget);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -15,7 +15,7 @@ UI_Box *UI_BuildLabel(String text)
UI_SetNext(Tint, tint); UI_SetNext(Tint, tint);
UI_SetNext(Font, font); UI_SetNext(Font, font);
UI_SetNext(FontSize, font_size); 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(Height, UI_FIT(1));
UI_SetNext(Text, text); UI_SetNext(Text, text);
UI_SetNext(Flags, UI_BoxFlag_DrawText); UI_SetNext(Flags, UI_BoxFlag_DrawText);

View File

@ -655,6 +655,12 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Frame helpers //~ Frame helpers
Arena *UI_GetFrameArena(void)
{
UI_SharedState *g = &UI_shared_state;
return g->build_arena;
}
Vec2 UI_GetCursorPos(void) Vec2 UI_GetCursorPos(void)
{ {
UI_SharedState *g = &UI_shared_state; UI_SharedState *g = &UI_shared_state;

View File

@ -417,6 +417,7 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Frame helpers //~ Frame helpers
Arena *UI_GetFrameArena(void);
Vec2 UI_GetCursorPos(void); Vec2 UI_GetCursorPos(void);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////