float mousemove detection & ui mouse position rules down to ui core layer

This commit is contained in:
Ryan Fleury
2024-02-05 09:29:50 -08:00
parent f03f3e4421
commit f2c74cbcb2
5 changed files with 15 additions and 22 deletions
+1 -9
View File
@@ -2881,16 +2881,8 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D
icon_info.icon_kind_text_map[UI_IconKind_CheckFilled] = df_g_icon_kind_text_table[DF_IconKind_CheckFilled];
}
// rjf: form mouse position used for passive UI mouse interaction
Vec2F32 mouse_ui = os_mouse_from_window(ws->os);
if(!os_window_is_focused(ws->os) &&
df_gfx_state->last_time_mousemoved_us+500000 <= os_now_microseconds())
{
mouse_ui = v2f32(-100, -100);
}
// rjf: begin & push initial stack values
ui_begin_build(events, mouse_ui, ws->os, &nav_actions, &icon_info, df_dt(), df_dt());
ui_begin_build(events, ws->os, &nav_actions, &icon_info, df_dt(), df_dt());
ui_push_font(main_font);
ui_push_font_size(main_font_size);
ui_push_pref_width(ui_em(20.f, 1));
-1
View File
@@ -689,7 +689,6 @@ struct DF_GfxState
// rjf: frame request state
U64 num_frames_requested;
U64 last_time_mousemoved_us;
// rjf: history cache
DF_StateDeltaHistory *hist;
-8
View File
@@ -69,14 +69,6 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data)
OS_EventList new_events = os_get_events(scratch.arena, df_gfx_state->num_frames_requested == 0);
os_event_list_concat_in_place(&events, &leftover_events_copy);
os_event_list_concat_in_place(&events, &new_events);
for(OS_Event *e = events.first; e != 0; e = e->next)
{
if(e->kind == OS_EventKind_MouseMove)
{
df_gfx_state->last_time_mousemoved_us = os_now_microseconds();
break;
}
}
}
//- rjf: enable txti change detection
+12 -3
View File
@@ -631,7 +631,7 @@ ui_box_from_key(UI_Key key)
//~ rjf: Top-Level Building API
internal void
ui_begin_build(OS_EventList *events, Vec2F32 mouse, OS_Handle window, UI_NavActionList *nav_actions, UI_IconInfo *icon_info, F32 real_dt, F32 animation_dt)
ui_begin_build(OS_EventList *events, OS_Handle window, UI_NavActionList *nav_actions, UI_IconInfo *icon_info, F32 real_dt, F32 animation_dt)
{
//- rjf: reset per-build ui state
{
@@ -646,12 +646,21 @@ ui_begin_build(OS_EventList *events, Vec2F32 mouse, OS_Handle window, UI_NavActi
ui_state->ctx_menu_changed = 0;
}
//- rjf: detect mouse-moves
for(OS_Event *e = events->first; e != 0; e = e->next)
{
if(e->kind == OS_EventKind_MouseMove && os_handle_match(e->window, window))
{
ui_state->last_time_mousemoved_us = os_now_microseconds();
}
}
//- rjf: fill build phase parameters
{
ui_state->events = events;
ui_state->window = window;
ui_state->nav_actions = nav_actions;
ui_state->mouse = mouse;
ui_state->mouse = (os_window_is_focused(window) || ui_state->last_time_mousemoved_us+500000 >= os_now_microseconds()) ? os_mouse_from_window(window) : v2f32(-100, -100);
ui_state->animation_dt = animation_dt;
MemoryZeroStruct(&ui_state->icon_info);
ui_state->icon_info.icon_font = icon_info->icon_font;
@@ -922,7 +931,7 @@ ui_begin_build(OS_EventList *events, Vec2F32 mouse, OS_Handle window, UI_NavActi
}
//- rjf: setup parent box for tooltip
UI_FixedX(mouse.x+15.f) UI_FixedY(mouse.y) UI_PrefWidth(ui_children_sum(1.f)) UI_PrefHeight(ui_children_sum(1.f))
UI_FixedX(ui_state->mouse.x+15.f) UI_FixedY(ui_state->mouse.y) UI_PrefWidth(ui_children_sum(1.f)) UI_PrefHeight(ui_children_sum(1.f))
{
ui_set_next_child_layout_axis(Axis2_Y);
ui_state->tooltip_root = ui_build_box_from_stringf(0, "###tooltip_%I64x", window.u64[0]);
+2 -1
View File
@@ -426,6 +426,7 @@ struct UI_State
D_FancyRunList string_hover_fancy_runs;
U64 string_hover_begin_us;
U64 string_hover_build_index;
U64 last_time_mousemoved_us;
//- rjf: tooltip state
F32 tooltip_open_t;
@@ -560,7 +561,7 @@ internal UI_Box * ui_box_from_key(UI_Key key);
////////////////////////////////
//~ rjf: Top-Level Building API
internal void ui_begin_build(OS_EventList *events, Vec2F32 mouse, OS_Handle window, UI_NavActionList *nav_actions, UI_IconInfo *icon_info, F32 real_dt, F32 animation_dt);
internal void ui_begin_build(OS_EventList *events, OS_Handle window, UI_NavActionList *nav_actions, UI_IconInfo *icon_info, F32 real_dt, F32 animation_dt);
internal void ui_end_build(void);
internal void ui_calc_sizes_standalone__in_place_rec(UI_Box *root, Axis2 axis);
internal void ui_calc_sizes_upwards_dependent__in_place_rec(UI_Box *root, Axis2 axis);