more ui rounding fixes

This commit is contained in:
jacob 2025-11-05 21:17:26 -06:00
parent 0ab934c4bb
commit bbbb0f63d3
3 changed files with 45 additions and 31 deletions

View File

@ -1984,7 +1984,7 @@ void PP_UpdateUser(void)
UI_Push(ChildLayoutAxis, Axis_Y); UI_Push(ChildLayoutAxis, Axis_Y);
UI_Push(FloatingPos, g->lister_pos); UI_Push(FloatingPos, g->lister_pos);
UI_SetNext(Flags, UI_BoxFlag_Floating); UI_SetNext(Flags, UI_BoxFlag_Floating);
g->lister_key = UI_PushCP(UI_BuildBox(HashF("lister")))->key; UI_PushCP(UI_BuildBox(HashF("lister")));
{ {
/* Title bar */ /* Title bar */
UI_PushCP(0); UI_PushCP(0);
@ -1995,7 +1995,8 @@ void PP_UpdateUser(void)
UI_Push(ChildLayoutAxis, Axis_X); UI_Push(ChildLayoutAxis, Axis_X);
UI_Push(Width, UI_FILL(1, 0)); UI_Push(Width, UI_FILL(1, 0));
UI_Push(Height, UI_FNT(2, 0)); UI_Push(Height, UI_FNT(2, 0));
UI_PushCP(UI_BuildBox(0)); UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_DrawHotEffects | UI_BoxFlag_DrawActiveEffects);
g->lister_key = UI_PushCP(UI_BuildBox(HashF("title bar")))->key;
{ {
UI_Push(Width, UI_FILL(1, 0)); UI_Push(Width, UI_FILL(1, 0));

View File

@ -550,7 +550,36 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags)
{ {
active_box = box; active_box = box;
} }
}
/* Update cursor pos */
for (u64 cev_index = 0; cev_index < controller_events.count; ++cev_index)
{
ControllerEvent cev = controller_events.events[cev_index];
if (cev.kind == ControllerEventKind_CursorMove)
{
g->cursor_pos = Vec2FromFields(cev.cursor_pos);
}
}
/* Update hovered box */
if (hovered_box)
{
hovered_box->report.flags &= ~UI_ReportFlag_Hovered;
hovered_box = 0;
}
/* Iterate boxes in reverse render order */
for (u64 pre_index = g->boxes_count; pre_index-- > 0 && hovered_box == 0;)
{
UI_Box *box = g->boxes_pre[pre_index];
if (box->key.hash != 0)
{
if (UI_IsPointInBox(box, g->cursor_pos))
{
box->report.flags |= UI_ReportFlag_Hovered;
hovered_box = box;
}
}
} }
/* Update state from controller events */ /* Update state from controller events */
@ -561,29 +590,6 @@ UI_Frame UI_BeginFrame(UI_FrameFlag frame_flags)
{ {
default: break; default: break;
case ControllerEventKind_CursorMove:
{
g->cursor_pos = Vec2FromFields(cev.cursor_pos);
if (hovered_box)
{
hovered_box->report.flags &= ~UI_ReportFlag_Hovered;
hovered_box = 0;
}
/* Iterate boxes in reverse render order */
for (u64 pre_index = g->boxes_count; pre_index-- > 0 && hovered_box == 0;)
{
UI_Box *box = g->boxes_pre[pre_index];
if (box->key.hash != 0)
{
if (UI_IsPointInBox(box, g->cursor_pos))
{
box->report.flags |= UI_ReportFlag_Hovered;
hovered_box = box;
}
}
}
} break;
case ControllerEventKind_ButtonDown: case ControllerEventKind_ButtonDown:
{ {
if (cev.button == Btn_M1) if (cev.button == Btn_M1)
@ -1046,8 +1052,10 @@ i64 UI_EndFrame(UI_Frame frame)
} }
/* Submit position */ /* Submit position */
box->p0 = RoundVec2(final_pos); Vec2 floored_final_pos = FloorVec2(final_pos);
box->p1 = RoundVec2(AddVec2(final_pos, CeilVec2(dims_vec))); Vec2 ceiled_dims = CeilVec2(dims_vec);
box->p0 = FloorVec2(floored_final_pos);
box->p1 = AddVec2(floored_final_pos, ceiled_dims);
box->report.screen_p0 = box->p0; box->report.screen_p0 = box->p0;
box->report.screen_p1 = box->p1; box->report.screen_p1 = box->p1;
} }
@ -1252,7 +1260,7 @@ i64 UI_EndFrame(UI_Frame frame)
baseline.y += baseline_height / 4; baseline.y += baseline_height / 4;
} break; } break;
} }
baseline = RoundVec2(baseline); baseline = CeilVec2(baseline);
/* Push text rects */ /* Push text rects */

View File

@ -82,9 +82,11 @@ Enum(UI_BoxFlag)
{ {
UI_BoxFlag_None = 0, UI_BoxFlag_None = 0,
UI_BoxFlag_DrawText = (1 << 0), UI_BoxFlag_DrawText = (1 << 0),
UI_BoxFlag_NoTextTruncation = (1 << 1), UI_BoxFlag_DrawHotEffects = (1 << 1),
UI_BoxFlag_Floating = (1 << 2), UI_BoxFlag_DrawActiveEffects = (1 << 2),
UI_BoxFlag_NoFloatingClamp = (1 << 3), UI_BoxFlag_NoTextTruncation = (1 << 3),
UI_BoxFlag_Floating = (1 << 4),
UI_BoxFlag_NoFloatingClamp = (1 << 5),
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -190,6 +192,9 @@ Struct(UI_Report)
UI_ReportFlag flags; UI_ReportFlag flags;
Vec2 activation_offset; Vec2 activation_offset;
f32 hot_ratio;
f32 active_ratio;
Vec2 screen_p0; Vec2 screen_p0;
Vec2 screen_p1; Vec2 screen_p1;
}; };