add hovered box ratio

This commit is contained in:
jacob 2025-11-06 14:28:31 -06:00
parent 051f166663
commit f7be7a9297
3 changed files with 51 additions and 47 deletions

View File

@ -1993,8 +1993,7 @@ void PP_UpdateUser(void)
// window_border_color = LerpSrgbU32(base_border_color, Color_White, 0.25);
// u32 highlight = LerpSrgbU32(base_border_color, Rgb32F(0.25, 0.25, 0.25), rep.hot);
u32 highlight = LerpSrgbU32(base_border_color, Rgb32F(0.5, 0.5, 0.5), rep.hot);
window_border_color = highlight;
window_border_color = LerpSrgbU32(window_border_color, Rgb32F(0.5, 0.5, 0.5), rep.hot);
}
}
@ -2018,7 +2017,7 @@ void PP_UpdateUser(void)
UI_Push(Rounding, UI_RPIX(0));
UI_Push(ChildLayoutAxis, Axis_X);
UI_Push(Width, UI_FILL(1, 0));
UI_Push(Height, UI_FNT(2, 0));
UI_Push(Height, UI_FNT(2, 1));
UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_Interactable);
UI_PushCP(UI_BuildBox(titlebar_key));
{
@ -2047,29 +2046,42 @@ void PP_UpdateUser(void)
UI_SetNext(Rounding, 0);
UI_PushCP(UI_BuildRow(UI_NilKey));
{
UI_BuildSpacer(UI_PIX(window_border + 1, 0));
f32 padding = 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));
{
u32 count = 10;
for (u32 i = 0; i < count; ++i)
{
UI_BuildDivider(UI_PIX(1, 0), divider_color);
UI_BuildDivider(UI_PIX(1, 1), divider_color);
UI_Key btn_key = UI_KeyF("btn%F", FmtSint(i));
UI_Report rep = UI_ReportFromKey(btn_key);
u32 color = LerpSrgbU32(0, Rgb32(0x10, 0x3c, 0x4c), rep.hot);
u32 border_color = LerpSrgbU32(0, Rgb32(0x00, 0x79, 0xa6), rep.hot);
u32 hovered_color = Rgb32(0x10, 0x3c, 0x4c);
u32 pressed_color = Alpha32F(hovered_color, 0.25);
f32 hot = rep.hot;
f32 active = rep.active;
f32 hovered = rep.hovered;
u32 color = 0;
u32 border_color = 0;
color = LerpSrgbU32(color, hovered_color, hot);
color = LerpSrgbU32(color, pressed_color, active * hovered);
border_color = LerpSrgbU32(border_color, Rgb32(0x00, 0x79, 0xa6), hot);
String button_text = UI_StringF("Button %F", FmtSint(i));
UI_SetNext(BorderColor, border_color);
UI_SetNext(BackgroundColor, color);
UI_SetNext(Rounding, UI_RPIX(2));
UI_SetNext(Rounding, UI_RPIX(5));
UI_SetNext(Width, UI_FILL(1, 0));
UI_SetNext(Height, UI_FNT(1.5, 0));
UI_SetNext(Height, UI_FNT(1.5, 1));
UI_SetNext(Text, button_text);
UI_SetNext(ChildAlignment, UI_Alignment_Center);
UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_Interactable);
@ -2080,11 +2092,11 @@ void PP_UpdateUser(void)
LogInfoF("%F pressed", FmtString(button_text));
}
}
UI_BuildSpacer(UI_PIX(padding, 1));
}
UI_PopCP();
}
UI_BuildSpacer(UI_PIX(window_border + 1, 0));
UI_BuildSpacer(UI_PIX(padding, 1));
}
UI_PopCP();

View File

@ -562,10 +562,10 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags)
if (g->build_arena != 0 && g->back_build_arena != 0)
{
/* Locate boxes */
UI_Box *old_active_box = UI_FrontBoxFromKey(g->active_box);
UI_Box *old_hovered_box = UI_FrontBoxFromKey(g->hovered_box);
UI_Box *old_active_box = UI_FrontBoxFromKey(g->active_box);
UI_Box *hovered_box = 0;
UI_Box *active_box = old_active_box;
UI_Box *hovered_box = active_box;
/* Update cursor pos */
for (u64 cev_index = 0; cev_index < controller_events.count; ++cev_index)
@ -588,8 +588,9 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags)
hovered_box = box;
}
}
box->report.m1_ups = 0;
box->report.m1_downs = 0;
box->report.m1_presses = 0;
box->report.m1_releases = 0;
}
/* Update state from controller events */
@ -604,13 +605,12 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags)
{
if (cev.button == Btn_M1)
{
UI_Box *box = hovered_box;
if (box)
if (hovered_box)
{
++box->report.m1_presses;
box->report.m1_held = 1;
box->report.last_m1_offset = SubVec2(g->cursor_pos, box->p0);
active_box = box;
++hovered_box->report.m1_downs;
hovered_box->report.m1_held = 1;
hovered_box->report.last_m1_offset = SubVec2(g->cursor_pos, hovered_box->p0);
active_box = hovered_box;
}
}
} break;
@ -619,11 +619,14 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags)
{
if (cev.button == Btn_M1)
{
UI_Box *box = active_box;
if (box)
if (active_box)
{
++box->report.m1_releases;
box->report.m1_held = 0;
if (active_box == hovered_box)
{
++active_box->report.m1_presses;
}
++active_box->report.m1_ups;
active_box->report.m1_held = 0;
active_box = 0;
}
}
@ -636,28 +639,15 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags)
{
UI_Box *box = g->boxes_pre[pre_index];
UI_Report *report = &box->report;
f32 target_hot = 0;
f32 target_active = 0;
f32 hot_blend_rate = 1;
f32 active_blend_rate = 1;
if (box == hovered_box)
{
target_hot = 1;
}
else
{
hot_blend_rate = 15 * dt;
}
if (box == active_box)
{
target_active = 1;
}
else
{
active_blend_rate = 15 * dt;
}
report->hot = LerpF32(report->hot, target_hot, hot_blend_rate);
report->active = LerpF32(report->active, target_active, active_blend_rate);
f32 target_hot = box == active_box || (box == hovered_box && (box == active_box || active_box == 0));
f32 target_active = box == active_box;
f32 target_hovered = box == hovered_box;
f32 hot_blend_rate = target_hot == 1 ? 1 : (15 * dt);
f32 active_blend_rate = target_active == 1 ? 1 : (15 * dt);
f32 hovered_blend_rate = target_hovered == 1 ? 1 : (15 * dt);
report->hot = LerpF32(report->hot, target_hot, hot_blend_rate);
report->active = LerpF32(report->active, target_active, active_blend_rate);
report->hovered = LerpF32(report->hovered, target_hovered, hovered_blend_rate);
}
g->hovered_box = hovered_box ? hovered_box->key : UI_NilKey;

View File

@ -177,11 +177,13 @@ Struct(UI_Report)
{
b32 m1_held;
f32 hovered;
f32 hot;
f32 active;
b32 m1_downs;
b32 m1_ups;
b32 m1_presses;
b32 m1_releases;
Vec2 last_m1_offset;
/* Where was this box last rendered in screen coordinates */