eliminate old ui box -> signal path

This commit is contained in:
Ryan Fleury
2024-02-07 16:47:21 -08:00
parent c637ad6ede
commit 0bced47404
-370
View File
@@ -2683,376 +2683,6 @@ ui_signal_from_box(UI_Box *box)
ProfEnd();
return sig;
#if 0
ProfBeginFunction();
UI_Signal result = {box};
result.event_flags = os_get_event_flags();
B32 disabled = !!(box->flags & UI_BoxFlag_Disabled);
B32 is_focused = !!(box->flags & UI_BoxFlag_FocusHot) && !(box->flags & UI_BoxFlag_FocusHotDisabled);
//- rjf: gather events
OS_Event *left_press = 0;
OS_Event *left_release = 0;
OS_Event *right_press = 0;
OS_Event *right_release = 0;
for(OS_Event *evt = ui_state->events->first; evt != 0; evt = evt->next)
{
if(os_handle_match(ui_state->window, evt->window))
{
if(left_press == 0 && evt->kind == OS_EventKind_Press && evt->key == OS_Key_LeftMouseButton)
{
left_press = evt;
}
if(left_release == 0 && evt->kind == OS_EventKind_Release && evt->key == OS_Key_LeftMouseButton)
{
left_release = evt;
}
if(right_press == 0 && evt->kind == OS_EventKind_Press && evt->key == OS_Key_RightMouseButton)
{
right_press = evt;
}
if(right_release == 0 && evt->kind == OS_EventKind_Release && evt->key == OS_Key_RightMouseButton)
{
right_release = evt;
}
}
}
//- rjf: unpack mouse position info
Vec2F32 mouse = ui_state->mouse;
if(left_press != 0) { mouse = left_press->pos; }
if(left_release != 0) { mouse = left_release->pos; }
if(right_press != 0) { mouse = right_press->pos; }
if(right_release != 0) { mouse = right_release->pos; }
B32 mouse_is_over = contains_2f32(box->rect, mouse);
//- rjf: check for parent that is clipping
if(box->flags & (UI_BoxFlag_Clickable|UI_BoxFlag_ViewScroll) && mouse_is_over)
{
for(UI_Box *parent = box->parent; !ui_box_is_nil(parent); parent = parent->parent)
{
if(parent->flags & UI_BoxFlag_Clip)
{
mouse_is_over = mouse_is_over && contains_2f32(parent->rect, mouse);
break;
}
}
}
//- rjf: get default nav ancestor
UI_Box *default_nav_parent = &ui_g_nil_box;
for(UI_Box *p = ui_top_parent(); !ui_box_is_nil(p); p = p->parent)
{
if(p->flags & UI_BoxFlag_DefaultFocusNav)
{
default_nav_parent = p;
break;
}
}
//- rjf: determine if we're under the context menu or not
B32 ctx_menu_is_ancestor = 0;
ProfScope("check context menu ancestor")
{
for(UI_Box *parent = box; !ui_box_is_nil(parent); parent = parent->parent)
{
if(parent == ui_state->ctx_menu_root)
{
ctx_menu_is_ancestor = 1;
break;
}
}
}
//- rjf: clip against floaters
if(mouse_is_over) ProfScope("clip against floaters")
{
if(!ctx_menu_is_ancestor && ui_state->ctx_menu_open != 0 && contains_2f32(ui_state->ctx_menu_root->rect, mouse))
{
mouse_is_over = 0;
}
}
//- rjf: mouse clickability
if(box->flags & UI_BoxFlag_MouseClickable && !ui_key_match(ui_key_zero(), box->key)) ProfScope("clickability")
{
// rjf: hot management
if((ui_key_match(ui_key_zero(), ui_state->active_box_key[UI_MouseButtonKind_Left]) &&
ui_key_match(ui_key_zero(), ui_state->active_box_key[UI_MouseButtonKind_Right])) &&
ui_key_match(ui_key_zero(), ui_state->hot_box_key) &&
mouse_is_over)
{
ui_state->hot_box_key = box->key;
}
else if(ui_key_match(ui_state->hot_box_key, box->key) &&
!mouse_is_over &&
!ui_key_match(ui_state->active_box_key[UI_MouseButtonKind_Left], box->key) &&
!ui_key_match(ui_state->active_box_key[UI_MouseButtonKind_Right], box->key))
{
ui_state->hot_box_key = ui_key_zero();
}
// rjf: active management (left click)
if(!disabled &&
ui_key_match(ui_state->hot_box_key, box->key) &&
ui_key_match(ui_state->active_box_key[UI_MouseButtonKind_Left], ui_key_zero()) &&
left_press != 0)
{
os_eat_event(ui_state->events, left_press);
result.pressed = 1;
ui_state->active_box_key[UI_MouseButtonKind_Left] = box->key;
}
else if(!disabled &&
ui_key_match(ui_state->active_box_key[UI_MouseButtonKind_Left], box->key) &&
left_release != 0)
{
os_eat_event(ui_state->events, left_release);
result.released = 1;
result.clicked = mouse_is_over;
ui_state->hot_box_key = mouse_is_over ? box->key : ui_key_zero();
ui_state->active_box_key[UI_MouseButtonKind_Left] = ui_key_zero();
}
// rjf: active management (right click)
if(!disabled &&
ui_key_match(ui_state->hot_box_key, box->key) &&
ui_key_match(ui_state->active_box_key[UI_MouseButtonKind_Right], ui_key_zero()) &&
right_press != 0)
{
os_eat_event(ui_state->events, right_press);
// NOTE(rjf): Add this in if it ever needs to exist:
// result.right_pressed = 1;
ui_state->active_box_key[UI_MouseButtonKind_Right] = box->key;
}
else if(!disabled &&
ui_key_match(ui_state->active_box_key[UI_MouseButtonKind_Right], box->key) &&
right_release != 0)
{
os_eat_event(ui_state->events, right_release);
// NOTE(rjf): Add this in if it ever needs to exist:
// result.right_released = 1;
result.right_clicked = mouse_is_over;
ui_state->active_box_key[UI_MouseButtonKind_Right] = ui_key_zero();
}
// rjf: dragging
if(ui_key_match(ui_state->active_box_key[UI_MouseButtonKind_Left], box->key))
{
result.dragging = 1;
if(result.pressed)
{
ui_state->drag_start_mouse = mouse;
}
}
}
//- rjf: plain scrolling
if(box->flags & UI_BoxFlag_Scroll)
{
OS_EventList *events = ui_events();
for(OS_Event *event = events->first, *next = 0; event != 0; event = next)
{
next = event->next;
if(os_handle_match(event->window, ui_state->window) && event->flags != OS_EventFlag_Ctrl)
{
switch(event->kind)
{
default:break;
case OS_EventKind_Scroll:
if(mouse_is_over)
{
Vec2F32 delta = event->delta;
if(event->flags & OS_EventFlag_Shift)
{
Swap(F32, delta.x, delta.y);
}
os_eat_event(events, event);
result.scroll.x += (S16)(delta.x/30.f);
result.scroll.y += (S16)(delta.y/30.f);
}break;
}
}
}
}
//- rjf: view scrolling
if(box->first_touched_build_index != box->last_touched_build_index && box->flags & UI_BoxFlag_ViewScroll)
{
OS_EventList *events = ui_events();
for(OS_Event *event = events->first, *next = 0; event != 0; event = next)
{
next = event->next;
if(os_handle_match(event->window, ui_state->window) && event->flags != OS_EventFlag_Ctrl)
{
switch(event->kind)
{
default:break;
case OS_EventKind_Scroll:
if(mouse_is_over)
{
Vec2F32 delta = event->delta;
if(event->flags & OS_EventFlag_Shift)
{
Swap(F32, delta.x, delta.y);
}
if(!(box->flags & UI_BoxFlag_ViewScrollX))
{
delta.x = 0;
}
if(!(box->flags & UI_BoxFlag_ViewScrollY))
{
delta.y = 0;
}
os_eat_event(events, event);
box->view_off_target.x += delta.x;
box->view_off_target.y += delta.y;
}break;
}
}
}
if(box->flags & UI_BoxFlag_ViewClamp)
{
Vec2F32 max_view_off_target =
{
ClampBot(0, box->view_bounds.x - box->fixed_size.x),
ClampBot(0, box->view_bounds.y - box->fixed_size.y),
};
if(box->flags & UI_BoxFlag_ViewClampX) { box->view_off_target.x = Clamp(0, box->view_off_target.x, max_view_off_target.x); }
if(box->flags & UI_BoxFlag_ViewClampY) { box->view_off_target.y = Clamp(0, box->view_off_target.y, max_view_off_target.y); }
}
}
//- rjf: focus + clicks
B32 keyboard_click = 0;
if(!disabled && is_focused && box->flags & UI_BoxFlag_KeyboardClickable)
{
if(os_key_press(ui_events(), ui_window(), 0, OS_Key_Return) != 0)
// TODO(rjf): need to handle case where this would conflict with typing.
// if(os_key_press(ui_events(), ui_window(), 0, OS_Key_Return) != 0 ||
// os_key_press(ui_events(), ui_window(), 0, OS_Key_Space) != 0)
{
keyboard_click = 1;
result.clicked = 1;
result.pressed = 1;
result.keyboard_clicked = 1;
}
}
//- rjf: focus + ctrl+clicks
if(!disabled && is_focused && box->flags & UI_BoxFlag_KeyboardClickable)
{
if(os_key_press(ui_events(), ui_window(), OS_EventFlag_Shift, OS_Key_Return))
{
result.right_clicked = 1;
}
}
//- rjf: focus & ctrl+c
if(is_focused && box->flags & UI_BoxFlag_KeyboardClickable)
{
for(UI_NavActionNode *n = ui_nav_actions()->first, *next = 0; n != 0; n = next)
{
next = n->next;
if(n->v.flags & UI_NavActionFlag_Copy)
{
ui_state->clipboard_copy_key = box->key;
ui_nav_eat_action_node(ui_nav_actions(), n);
}
}
}
//- rjf: focused ancestors and fastpath codepoint -> click
if(box->flags & UI_BoxFlag_Clickable && box->fastpath_codepoint != 0)
{
B32 is_focused = 0;
for(UI_Box *parent = box->parent; !ui_box_is_nil(parent); parent = parent->parent)
{
if(parent->flags & UI_BoxFlag_FocusActive)
{
is_focused = 1;
if(parent->flags & UI_BoxFlag_FocusActiveDisabled ||
!ui_key_match(parent->default_nav_focus_active_key, ui_key_zero()))
{
is_focused = 0;
break;
}
}
}
if(is_focused)
{
Temp scratch = scratch_begin(0, 0);
B32 clicked = 0;
for(UI_NavActionNode *n = ui_nav_actions()->first; n != 0; n = n->next)
{
UI_NavAction *action = &n->v;
if(action->insertion.size != 0)
{
String32 insertion32 = str32_from_8(scratch.arena, action->insertion);
if(insertion32.size == 1 && insertion32.str[0] == box->fastpath_codepoint)
{
clicked = 1;
ui_nav_eat_action_node(ui_nav_actions(), n);
break;
}
}
}
if(clicked)
{
keyboard_click = 1;
result.clicked = 1;
result.pressed = 1;
result.keyboard_clicked = 1;
}
scratch_end(scratch);
}
}
//- rjf: double-clicks
if(!keyboard_click && result.pressed)
{
if(ui_key_match(ui_state->last_click_key[Side_Min], box->key) &&
ui_state->time_since_last_click[Side_Min] < os_double_click_time())
{
result.double_clicked = 1;
}
ui_state->time_since_last_click[Side_Min] = 0;
ui_state->last_click_key[Side_Min] = box->key;
}
//- rjf: clicking on something outside the context menu kills the context menu
if(!ctx_menu_is_ancestor && result.pressed)
{
ui_ctx_menu_close();
}
//- rjf: set hovering status
result.hovering = mouse_is_over && ((ui_key_match(ui_state->hot_box_key, ui_key_zero()) ||
ui_key_match(ui_state->hot_box_key, box->key)) &&
(ui_key_match(ui_state->active_box_key[UI_MouseButtonKind_Left], ui_key_zero()) ||
ui_key_match(ui_state->active_box_key[UI_MouseButtonKind_Left], box->key)));
result.mouse_over = mouse_is_over;
//- rjf: clicking in default nav -> set navigation state to this box
if(box->flags & UI_BoxFlag_ClickToFocus && result.pressed && !ui_box_is_nil(default_nav_parent))
{
default_nav_parent->default_nav_focus_next_hot_key = box->key;
if(!ui_key_match(default_nav_parent->default_nav_focus_active_key, box->key))
{
default_nav_parent->default_nav_focus_next_active_key = ui_key_zero();
}
}
//- rjf: focus & external commit events -> commit
if(is_focused && ui_state->external_focus_commit)
{
ui_state->external_focus_commit = 0;
result.commit = 1;
}
ProfEnd();
return result;
#endif
}
////////////////////////////////