mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-07-22 15:37:49 +00:00
begin eliminating separate hook system for view rule uis; shift over to regular views, so there is just one codepath for all visualizers; move ui to event pump system, with permissions stack, so that callers of sub-ui-codepaths can mask off event consumption as needed
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#define UI_FixedHeight(v) DeferLoop(ui_push_fixed_height(v), ui_pop_fixed_height())
|
||||
#define UI_PrefWidth(v) DeferLoop(ui_push_pref_width(v), ui_pop_pref_width())
|
||||
#define UI_PrefHeight(v) DeferLoop(ui_push_pref_height(v), ui_pop_pref_height())
|
||||
#define UI_PermissionFlags(v) DeferLoop(ui_push_permission_flags(v), ui_pop_permission_flags())
|
||||
#define UI_Flags(v) DeferLoop(ui_push_flags(v), ui_pop_flags())
|
||||
#define UI_FocusHot(v) DeferLoop(ui_push_focus_hot(v), ui_pop_focus_hot())
|
||||
#define UI_FocusActive(v) DeferLoop(ui_push_focus_active(v), ui_pop_focus_active())
|
||||
@@ -41,6 +42,7 @@ internal F32 ui_top_fixed_width(void) { UI_StackTopImpl(ui_state, FixedWidth, fi
|
||||
internal F32 ui_top_fixed_height(void) { UI_StackTopImpl(ui_state, FixedHeight, fixed_height) }
|
||||
internal UI_Size ui_top_pref_width(void) { UI_StackTopImpl(ui_state, PrefWidth, pref_width) }
|
||||
internal UI_Size ui_top_pref_height(void) { UI_StackTopImpl(ui_state, PrefHeight, pref_height) }
|
||||
internal UI_PermissionFlags ui_top_permission_flags(void) { UI_StackTopImpl(ui_state, PermissionFlags, permission_flags) }
|
||||
internal UI_BoxFlags ui_top_flags(void) { UI_StackTopImpl(ui_state, Flags, flags) }
|
||||
internal UI_FocusKind ui_top_focus_hot(void) { UI_StackTopImpl(ui_state, FocusHot, focus_hot) }
|
||||
internal UI_FocusKind ui_top_focus_active(void) { UI_StackTopImpl(ui_state, FocusActive, focus_active) }
|
||||
@@ -69,6 +71,7 @@ internal F32 ui_bottom_fixed_width(void) { UI_StackBottomImpl(ui_state, FixedWid
|
||||
internal F32 ui_bottom_fixed_height(void) { UI_StackBottomImpl(ui_state, FixedHeight, fixed_height) }
|
||||
internal UI_Size ui_bottom_pref_width(void) { UI_StackBottomImpl(ui_state, PrefWidth, pref_width) }
|
||||
internal UI_Size ui_bottom_pref_height(void) { UI_StackBottomImpl(ui_state, PrefHeight, pref_height) }
|
||||
internal UI_PermissionFlags ui_bottom_permission_flags(void) { UI_StackBottomImpl(ui_state, PermissionFlags, permission_flags) }
|
||||
internal UI_BoxFlags ui_bottom_flags(void) { UI_StackBottomImpl(ui_state, Flags, flags) }
|
||||
internal UI_FocusKind ui_bottom_focus_hot(void) { UI_StackBottomImpl(ui_state, FocusHot, focus_hot) }
|
||||
internal UI_FocusKind ui_bottom_focus_active(void) { UI_StackBottomImpl(ui_state, FocusActive, focus_active) }
|
||||
@@ -97,6 +100,7 @@ internal F32 ui_push_fixed_width(F32 v) { UI_StackPushImpl(ui_state, FixedWidth,
|
||||
internal F32 ui_push_fixed_height(F32 v) { UI_StackPushImpl(ui_state, FixedHeight, fixed_height, F32, v) }
|
||||
internal UI_Size ui_push_pref_width(UI_Size v) { UI_StackPushImpl(ui_state, PrefWidth, pref_width, UI_Size, v) }
|
||||
internal UI_Size ui_push_pref_height(UI_Size v) { UI_StackPushImpl(ui_state, PrefHeight, pref_height, UI_Size, v) }
|
||||
internal UI_PermissionFlags ui_push_permission_flags(UI_PermissionFlags v) { UI_StackPushImpl(ui_state, PermissionFlags, permission_flags, UI_PermissionFlags, v) }
|
||||
internal UI_BoxFlags ui_push_flags(UI_BoxFlags v) { UI_StackPushImpl(ui_state, Flags, flags, UI_BoxFlags, v) }
|
||||
internal UI_FocusKind ui_push_focus_hot(UI_FocusKind v) { UI_StackPushImpl(ui_state, FocusHot, focus_hot, UI_FocusKind, v) }
|
||||
internal UI_FocusKind ui_push_focus_active(UI_FocusKind v) { UI_StackPushImpl(ui_state, FocusActive, focus_active, UI_FocusKind, v) }
|
||||
@@ -125,6 +129,7 @@ internal F32 ui_pop_fixed_width(void) { UI_StackPopImpl(ui_state, FixedWidth, fi
|
||||
internal F32 ui_pop_fixed_height(void) { UI_StackPopImpl(ui_state, FixedHeight, fixed_height) }
|
||||
internal UI_Size ui_pop_pref_width(void) { UI_StackPopImpl(ui_state, PrefWidth, pref_width) }
|
||||
internal UI_Size ui_pop_pref_height(void) { UI_StackPopImpl(ui_state, PrefHeight, pref_height) }
|
||||
internal UI_PermissionFlags ui_pop_permission_flags(void) { UI_StackPopImpl(ui_state, PermissionFlags, permission_flags) }
|
||||
internal UI_BoxFlags ui_pop_flags(void) { UI_StackPopImpl(ui_state, Flags, flags) }
|
||||
internal UI_FocusKind ui_pop_focus_hot(void) { UI_StackPopImpl(ui_state, FocusHot, focus_hot) }
|
||||
internal UI_FocusKind ui_pop_focus_active(void) { UI_StackPopImpl(ui_state, FocusActive, focus_active) }
|
||||
@@ -153,6 +158,7 @@ internal F32 ui_set_next_fixed_width(F32 v) { UI_StackSetNextImpl(ui_state, Fixe
|
||||
internal F32 ui_set_next_fixed_height(F32 v) { UI_StackSetNextImpl(ui_state, FixedHeight, fixed_height, F32, v) }
|
||||
internal UI_Size ui_set_next_pref_width(UI_Size v) { UI_StackSetNextImpl(ui_state, PrefWidth, pref_width, UI_Size, v) }
|
||||
internal UI_Size ui_set_next_pref_height(UI_Size v) { UI_StackSetNextImpl(ui_state, PrefHeight, pref_height, UI_Size, v) }
|
||||
internal UI_PermissionFlags ui_set_next_permission_flags(UI_PermissionFlags v) { UI_StackSetNextImpl(ui_state, PermissionFlags, permission_flags, UI_PermissionFlags, v) }
|
||||
internal UI_BoxFlags ui_set_next_flags(UI_BoxFlags v) { UI_StackSetNextImpl(ui_state, Flags, flags, UI_BoxFlags, v) }
|
||||
internal UI_FocusKind ui_set_next_focus_hot(UI_FocusKind v) { UI_StackSetNextImpl(ui_state, FocusHot, focus_hot, UI_FocusKind, v) }
|
||||
internal UI_FocusKind ui_set_next_focus_active(UI_FocusKind v) { UI_StackSetNextImpl(ui_state, FocusActive, focus_active, UI_FocusKind, v) }
|
||||
|
||||
@@ -14,6 +14,7 @@ typedef struct UI_FixedWidthNode UI_FixedWidthNode; struct UI_FixedWidthNode{UI_
|
||||
typedef struct UI_FixedHeightNode UI_FixedHeightNode; struct UI_FixedHeightNode{UI_FixedHeightNode *next; F32 v;};
|
||||
typedef struct UI_PrefWidthNode UI_PrefWidthNode; struct UI_PrefWidthNode{UI_PrefWidthNode *next; UI_Size v;};
|
||||
typedef struct UI_PrefHeightNode UI_PrefHeightNode; struct UI_PrefHeightNode{UI_PrefHeightNode *next; UI_Size v;};
|
||||
typedef struct UI_PermissionFlagsNode UI_PermissionFlagsNode; struct UI_PermissionFlagsNode{UI_PermissionFlagsNode *next; UI_PermissionFlags v;};
|
||||
typedef struct UI_FlagsNode UI_FlagsNode; struct UI_FlagsNode{UI_FlagsNode *next; UI_BoxFlags v;};
|
||||
typedef struct UI_FocusHotNode UI_FocusHotNode; struct UI_FocusHotNode{UI_FocusHotNode *next; UI_FocusKind v;};
|
||||
typedef struct UI_FocusActiveNode UI_FocusActiveNode; struct UI_FocusActiveNode{UI_FocusActiveNode *next; UI_FocusKind v;};
|
||||
@@ -45,6 +46,7 @@ UI_FixedWidthNode fixed_width_nil_stack_top;\
|
||||
UI_FixedHeightNode fixed_height_nil_stack_top;\
|
||||
UI_PrefWidthNode pref_width_nil_stack_top;\
|
||||
UI_PrefHeightNode pref_height_nil_stack_top;\
|
||||
UI_PermissionFlagsNode permission_flags_nil_stack_top;\
|
||||
UI_FlagsNode flags_nil_stack_top;\
|
||||
UI_FocusHotNode focus_hot_nil_stack_top;\
|
||||
UI_FocusActiveNode focus_active_nil_stack_top;\
|
||||
@@ -75,6 +77,7 @@ state->fixed_width_nil_stack_top.v = 0;\
|
||||
state->fixed_height_nil_stack_top.v = 0;\
|
||||
state->pref_width_nil_stack_top.v = ui_px(250.f, 1.f);\
|
||||
state->pref_height_nil_stack_top.v = ui_px(30.f, 1.f);\
|
||||
state->permission_flags_nil_stack_top.v = UI_PermissionFlag_All;\
|
||||
state->flags_nil_stack_top.v = 0;\
|
||||
state->focus_hot_nil_stack_top.v = UI_FocusKind_Null;\
|
||||
state->focus_active_nil_stack_top.v = UI_FocusKind_Null;\
|
||||
@@ -107,6 +110,7 @@ struct { UI_FixedWidthNode *top; F32 bottom_val; UI_FixedWidthNode *free; B32 au
|
||||
struct { UI_FixedHeightNode *top; F32 bottom_val; UI_FixedHeightNode *free; B32 auto_pop; } fixed_height_stack;\
|
||||
struct { UI_PrefWidthNode *top; UI_Size bottom_val; UI_PrefWidthNode *free; B32 auto_pop; } pref_width_stack;\
|
||||
struct { UI_PrefHeightNode *top; UI_Size bottom_val; UI_PrefHeightNode *free; B32 auto_pop; } pref_height_stack;\
|
||||
struct { UI_PermissionFlagsNode *top; UI_PermissionFlags bottom_val; UI_PermissionFlagsNode *free; B32 auto_pop; } permission_flags_stack;\
|
||||
struct { UI_FlagsNode *top; UI_BoxFlags bottom_val; UI_FlagsNode *free; B32 auto_pop; } flags_stack;\
|
||||
struct { UI_FocusHotNode *top; UI_FocusKind bottom_val; UI_FocusHotNode *free; B32 auto_pop; } focus_hot_stack;\
|
||||
struct { UI_FocusActiveNode *top; UI_FocusKind bottom_val; UI_FocusActiveNode *free; B32 auto_pop; } focus_active_stack;\
|
||||
@@ -137,6 +141,7 @@ state->fixed_width_stack.top = &state->fixed_width_nil_stack_top; state->fixed_w
|
||||
state->fixed_height_stack.top = &state->fixed_height_nil_stack_top; state->fixed_height_stack.bottom_val = 0; state->fixed_height_stack.free = 0; state->fixed_height_stack.auto_pop = 0;\
|
||||
state->pref_width_stack.top = &state->pref_width_nil_stack_top; state->pref_width_stack.bottom_val = ui_px(250.f, 1.f); state->pref_width_stack.free = 0; state->pref_width_stack.auto_pop = 0;\
|
||||
state->pref_height_stack.top = &state->pref_height_nil_stack_top; state->pref_height_stack.bottom_val = ui_px(30.f, 1.f); state->pref_height_stack.free = 0; state->pref_height_stack.auto_pop = 0;\
|
||||
state->permission_flags_stack.top = &state->permission_flags_nil_stack_top; state->permission_flags_stack.bottom_val = UI_PermissionFlag_All; state->permission_flags_stack.free = 0; state->permission_flags_stack.auto_pop = 0;\
|
||||
state->flags_stack.top = &state->flags_nil_stack_top; state->flags_stack.bottom_val = 0; state->flags_stack.free = 0; state->flags_stack.auto_pop = 0;\
|
||||
state->focus_hot_stack.top = &state->focus_hot_nil_stack_top; state->focus_hot_stack.bottom_val = UI_FocusKind_Null; state->focus_hot_stack.free = 0; state->focus_hot_stack.auto_pop = 0;\
|
||||
state->focus_active_stack.top = &state->focus_active_nil_stack_top; state->focus_active_stack.bottom_val = UI_FocusKind_Null; state->focus_active_stack.free = 0; state->focus_active_stack.auto_pop = 0;\
|
||||
@@ -167,6 +172,7 @@ if(state->fixed_width_stack.auto_pop) { ui_pop_fixed_width(); state->fixed_width
|
||||
if(state->fixed_height_stack.auto_pop) { ui_pop_fixed_height(); state->fixed_height_stack.auto_pop = 0; }\
|
||||
if(state->pref_width_stack.auto_pop) { ui_pop_pref_width(); state->pref_width_stack.auto_pop = 0; }\
|
||||
if(state->pref_height_stack.auto_pop) { ui_pop_pref_height(); state->pref_height_stack.auto_pop = 0; }\
|
||||
if(state->permission_flags_stack.auto_pop) { ui_pop_permission_flags(); state->permission_flags_stack.auto_pop = 0; }\
|
||||
if(state->flags_stack.auto_pop) { ui_pop_flags(); state->flags_stack.auto_pop = 0; }\
|
||||
if(state->focus_hot_stack.auto_pop) { ui_pop_focus_hot(); state->focus_hot_stack.auto_pop = 0; }\
|
||||
if(state->focus_active_stack.auto_pop) { ui_pop_focus_active(); state->focus_active_stack.auto_pop = 0; }\
|
||||
@@ -196,6 +202,7 @@ internal F32 ui_top_fixed_width(void);
|
||||
internal F32 ui_top_fixed_height(void);
|
||||
internal UI_Size ui_top_pref_width(void);
|
||||
internal UI_Size ui_top_pref_height(void);
|
||||
internal UI_PermissionFlags ui_top_permission_flags(void);
|
||||
internal UI_BoxFlags ui_top_flags(void);
|
||||
internal UI_FocusKind ui_top_focus_hot(void);
|
||||
internal UI_FocusKind ui_top_focus_active(void);
|
||||
@@ -224,6 +231,7 @@ internal F32 ui_bottom_fixed_width(void);
|
||||
internal F32 ui_bottom_fixed_height(void);
|
||||
internal UI_Size ui_bottom_pref_width(void);
|
||||
internal UI_Size ui_bottom_pref_height(void);
|
||||
internal UI_PermissionFlags ui_bottom_permission_flags(void);
|
||||
internal UI_BoxFlags ui_bottom_flags(void);
|
||||
internal UI_FocusKind ui_bottom_focus_hot(void);
|
||||
internal UI_FocusKind ui_bottom_focus_active(void);
|
||||
@@ -252,6 +260,7 @@ internal F32 ui_push_fixed_width(F32 v);
|
||||
internal F32 ui_push_fixed_height(F32 v);
|
||||
internal UI_Size ui_push_pref_width(UI_Size v);
|
||||
internal UI_Size ui_push_pref_height(UI_Size v);
|
||||
internal UI_PermissionFlags ui_push_permission_flags(UI_PermissionFlags v);
|
||||
internal UI_BoxFlags ui_push_flags(UI_BoxFlags v);
|
||||
internal UI_FocusKind ui_push_focus_hot(UI_FocusKind v);
|
||||
internal UI_FocusKind ui_push_focus_active(UI_FocusKind v);
|
||||
@@ -280,6 +289,7 @@ internal F32 ui_pop_fixed_width(void);
|
||||
internal F32 ui_pop_fixed_height(void);
|
||||
internal UI_Size ui_pop_pref_width(void);
|
||||
internal UI_Size ui_pop_pref_height(void);
|
||||
internal UI_PermissionFlags ui_pop_permission_flags(void);
|
||||
internal UI_BoxFlags ui_pop_flags(void);
|
||||
internal UI_FocusKind ui_pop_focus_hot(void);
|
||||
internal UI_FocusKind ui_pop_focus_active(void);
|
||||
@@ -308,6 +318,7 @@ internal F32 ui_set_next_fixed_width(F32 v);
|
||||
internal F32 ui_set_next_fixed_height(F32 v);
|
||||
internal UI_Size ui_set_next_pref_width(UI_Size v);
|
||||
internal UI_Size ui_set_next_pref_height(UI_Size v);
|
||||
internal UI_PermissionFlags ui_set_next_permission_flags(UI_PermissionFlags v);
|
||||
internal UI_BoxFlags ui_set_next_flags(UI_BoxFlags v);
|
||||
internal UI_FocusKind ui_set_next_focus_hot(UI_FocusKind v);
|
||||
internal UI_FocusKind ui_set_next_focus_active(UI_FocusKind v);
|
||||
|
||||
@@ -21,6 +21,7 @@ UI_StackTable:
|
||||
{ PrefHeight pref_height UI_Size `ui_px(30.f, 1.f)` }
|
||||
|
||||
//- rjf: flags
|
||||
{ PermissionFlags permission_flags UI_PermissionFlags UI_PermissionFlag_All }
|
||||
{ Flags flags UI_BoxFlags 0 }
|
||||
|
||||
//- rjf: interaction
|
||||
|
||||
@@ -196,20 +196,18 @@ ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size,
|
||||
if(is_focus_active)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
UI_EventList *events = ui_events();
|
||||
for(UI_EventNode *n = events->first, *next = 0; n != 0; n = next)
|
||||
for(UI_Event *evt = 0; ui_next_event(&evt);)
|
||||
{
|
||||
String8 edit_string = str8(edit_buffer, edit_string_size_out[0]);
|
||||
next = n->next;
|
||||
|
||||
// rjf: do not consume anything that doesn't fit a single-line's operations
|
||||
if((n->v.kind != UI_EventKind_Edit && n->v.kind != UI_EventKind_Navigate && n->v.kind != UI_EventKind_Text) || n->v.delta_2s32.y != 0)
|
||||
if((evt->kind != UI_EventKind_Edit && evt->kind != UI_EventKind_Navigate && evt->kind != UI_EventKind_Text) || evt->delta_2s32.y != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// rjf: map this action to an op
|
||||
UI_TxtOp op = ui_single_line_txt_op_from_event(scratch.arena, &n->v, edit_string, *cursor, *mark);
|
||||
UI_TxtOp op = ui_single_line_txt_op_from_event(scratch.arena, evt, edit_string, *cursor, *mark);
|
||||
|
||||
// rjf: perform replace range
|
||||
if(!txt_pt_match(op.range.min, op.range.max) || op.replace.size != 0)
|
||||
@@ -232,7 +230,7 @@ ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size,
|
||||
|
||||
// rjf: consume event
|
||||
{
|
||||
ui_eat_event(events, n);
|
||||
ui_eat_event(evt);
|
||||
changes_made = 1;
|
||||
}
|
||||
}
|
||||
@@ -1354,19 +1352,16 @@ ui_scroll_list_begin(UI_ScrollListParams *params, UI_ScrollPt *scroll_pt, Vec2S6
|
||||
B32 moved = 0;
|
||||
if(params->flags & UI_ScrollListFlag_Nav && cursor_out != 0 && ui_is_focus_active())
|
||||
{
|
||||
UI_EventList *events = ui_events();
|
||||
Vec2S64 cursor = *cursor_out;
|
||||
Vec2S64 mark = mark_out ? *mark_out : cursor;
|
||||
for(UI_EventNode *n = events->first, *next = 0; n != 0; n = next)
|
||||
for(UI_Event *evt = 0; ui_next_event(&evt);)
|
||||
{
|
||||
next = n->next;
|
||||
UI_Event *evt = &n->v;
|
||||
if((evt->delta_2s32.x == 0 && evt->delta_2s32.y == 0) ||
|
||||
evt->flags & UI_EventFlag_Delete)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ui_eat_event(events, n);
|
||||
ui_eat_event(evt);
|
||||
moved = 1;
|
||||
switch(evt->delta_unit)
|
||||
{
|
||||
|
||||
+101
-35
@@ -109,7 +109,7 @@ ui_event_list_push(Arena *arena, UI_EventList *list, UI_Event *v)
|
||||
}
|
||||
|
||||
internal void
|
||||
ui_eat_event(UI_EventList *list, UI_EventNode *node)
|
||||
ui_eat_event_node(UI_EventList *list, UI_EventNode *node)
|
||||
{
|
||||
DLLRemove(list->first, list->last, node);
|
||||
list->count -= 1;
|
||||
@@ -496,12 +496,6 @@ ui_window(void)
|
||||
return ui_state->window;
|
||||
}
|
||||
|
||||
internal UI_EventList *
|
||||
ui_events(void)
|
||||
{
|
||||
return ui_state->events;
|
||||
}
|
||||
|
||||
internal Vec2F32
|
||||
ui_mouse(void)
|
||||
{
|
||||
@@ -526,19 +520,100 @@ ui_dt(void)
|
||||
return ui_state->animation_dt;
|
||||
}
|
||||
|
||||
//- rjf: event pumping
|
||||
|
||||
internal B32
|
||||
ui_next_event(UI_Event **ev)
|
||||
{
|
||||
UI_EventList *events = ui_state->events;
|
||||
UI_EventNode *start_node = events->first;
|
||||
if(ev[0] != 0)
|
||||
{
|
||||
start_node = CastFromMember(UI_EventNode, v, ev[0]);
|
||||
start_node = start_node->next;
|
||||
ev[0] = 0;
|
||||
}
|
||||
if(start_node != 0)
|
||||
{
|
||||
UI_PermissionFlags perms = ui_top_permission_flags();
|
||||
for(UI_EventNode *n = start_node; n != 0; n = n->next)
|
||||
{
|
||||
B32 good = 1;
|
||||
if(!(perms & UI_PermissionFlag_ClicksLeft) &&
|
||||
(n->v.kind == UI_EventKind_Press ||
|
||||
n->v.kind == UI_EventKind_Release) &&
|
||||
(n->v.key == OS_Key_LeftMouseButton))
|
||||
{
|
||||
good = 0;
|
||||
}
|
||||
if(!(perms & UI_PermissionFlag_ClicksMiddle) &&
|
||||
(n->v.kind == UI_EventKind_Press ||
|
||||
n->v.kind == UI_EventKind_Release) &&
|
||||
(n->v.key == OS_Key_MiddleMouseButton))
|
||||
{
|
||||
good = 0;
|
||||
}
|
||||
if(!(perms & UI_PermissionFlag_ClicksRight) &&
|
||||
(n->v.kind == UI_EventKind_Press ||
|
||||
n->v.kind == UI_EventKind_Release) &&
|
||||
(n->v.key == OS_Key_RightMouseButton))
|
||||
{
|
||||
good = 0;
|
||||
}
|
||||
if(!(perms & UI_PermissionFlag_ScrollX) && (n->v.kind == UI_EventKind_Scroll) && (n->v.delta_2f32.x != 0 || n->v.modifiers & OS_EventFlag_Shift))
|
||||
{
|
||||
good = 0;
|
||||
}
|
||||
if(!(perms & UI_PermissionFlag_ScrollY) && (n->v.kind == UI_EventKind_Scroll) && n->v.delta_2f32.y != 0 && !(n->v.modifiers & OS_EventFlag_Shift))
|
||||
{
|
||||
good = 0;
|
||||
}
|
||||
if(!(perms & UI_PermissionFlag_Keyboard) &&
|
||||
(n->v.kind == UI_EventKind_Press ||
|
||||
n->v.kind == UI_EventKind_Release) &&
|
||||
(n->v.key != OS_Key_LeftMouseButton &&
|
||||
n->v.key != OS_Key_MiddleMouseButton &&
|
||||
n->v.key != OS_Key_RightMouseButton))
|
||||
{
|
||||
good = 0;
|
||||
}
|
||||
else if(!(perms & UI_PermissionFlag_Text) && (n->v.kind == UI_EventKind_Text))
|
||||
{
|
||||
good = 0;
|
||||
}
|
||||
if(good)
|
||||
{
|
||||
ev[0] = &n->v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
B32 result = !!ev[0];
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void
|
||||
ui_eat_event(UI_Event *ev)
|
||||
{
|
||||
if(ev != 0)
|
||||
{
|
||||
UI_EventNode *n = CastFromMember(UI_EventNode, v, ev);
|
||||
ui_eat_event_node(ui_state->events, n);
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: event consumption helpers
|
||||
|
||||
internal B32
|
||||
ui_key_press(OS_EventFlags mods, OS_Key key)
|
||||
{
|
||||
UI_EventList *list = ui_events();
|
||||
B32 result = 0;
|
||||
for(UI_EventNode *n = list->first; n != 0; n = n->next)
|
||||
for(UI_Event *evt = 0; ui_next_event(&evt);)
|
||||
{
|
||||
if(n->v.kind == UI_EventKind_Press && n->v.key == key && n->v.modifiers == mods)
|
||||
if(evt->kind == UI_EventKind_Press && evt->key == key && evt->modifiers == mods)
|
||||
{
|
||||
result = 1;
|
||||
ui_eat_event(list, n);
|
||||
ui_eat_event(evt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -548,14 +623,13 @@ ui_key_press(OS_EventFlags mods, OS_Key key)
|
||||
internal B32
|
||||
ui_key_release(OS_EventFlags mods, OS_Key key)
|
||||
{
|
||||
UI_EventList *list = ui_events();
|
||||
B32 result = 0;
|
||||
for(UI_EventNode *n = list->first; n != 0; n = n->next)
|
||||
for(UI_Event *evt = 0; ui_next_event(&evt);)
|
||||
{
|
||||
if(n->v.kind == UI_EventKind_Release && n->v.key == key && n->v.modifiers == mods)
|
||||
if(evt->kind == UI_EventKind_Release && evt->key == key && evt->modifiers == mods)
|
||||
{
|
||||
result = 1;
|
||||
ui_eat_event(list, n);
|
||||
ui_eat_event(evt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -565,16 +639,15 @@ ui_key_release(OS_EventFlags mods, OS_Key key)
|
||||
internal B32
|
||||
ui_text(U32 character)
|
||||
{
|
||||
UI_EventList *list = ui_events();
|
||||
B32 result = 0;
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8 character_text = str8_from_32(scratch.arena, str32(&character, 1));
|
||||
for(UI_EventNode *n = list->first; n != 0; n = n->next)
|
||||
for(UI_Event *evt = 0; ui_next_event(&evt);)
|
||||
{
|
||||
if(n->v.kind == UI_EventKind_Text && str8_match(character_text, n->v.string, 0))
|
||||
if(evt->kind == UI_EventKind_Text && str8_match(character_text, evt->string, 0))
|
||||
{
|
||||
result = 1;
|
||||
ui_eat_event(list, n);
|
||||
ui_eat_event(evt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -585,14 +658,13 @@ ui_text(U32 character)
|
||||
internal B32
|
||||
ui_slot_press(UI_EventActionSlot slot)
|
||||
{
|
||||
UI_EventList *list = ui_events();
|
||||
B32 result = 0;
|
||||
for(UI_EventNode *n = list->first; n != 0; n = n->next)
|
||||
for(UI_Event *evt = 0; ui_next_event(&evt);)
|
||||
{
|
||||
if(n->v.kind == UI_EventKind_Press && n->v.slot == slot)
|
||||
if(evt->kind == UI_EventKind_Press && evt->slot == slot)
|
||||
{
|
||||
result = 1;
|
||||
ui_eat_event(list, n);
|
||||
ui_eat_event(evt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -817,7 +889,7 @@ ui_begin_build(OS_Handle window, UI_EventList *events, UI_IconInfo *icon_info, U
|
||||
}
|
||||
if(taken)
|
||||
{
|
||||
ui_eat_event(events, node);
|
||||
ui_eat_event_node(events, node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1327,12 +1399,10 @@ ui_end_build(void)
|
||||
|
||||
//- rjf: close ctx menu if unconsumed clicks
|
||||
{
|
||||
UI_EventList *events = ui_events();
|
||||
for(UI_EventNode *n = events->first; n != 0; n = n->next)
|
||||
for(UI_Event *evt = 0; ui_next_event(&evt);)
|
||||
{
|
||||
UI_Event *event = &n->v;
|
||||
if(event->kind == UI_EventKind_Press &&
|
||||
(event->key == OS_Key_LeftMouseButton || event->key == OS_Key_RightMouseButton))
|
||||
if(evt->kind == UI_EventKind_Press &&
|
||||
(evt->key == OS_Key_LeftMouseButton || evt->key == OS_Key_RightMouseButton))
|
||||
{
|
||||
ui_ctx_menu_close();
|
||||
}
|
||||
@@ -2489,13 +2559,9 @@ ui_signal_from_box(UI_Box *box)
|
||||
//- rjf: process events related to this box
|
||||
//
|
||||
B32 view_scrolled = 0;
|
||||
for(UI_EventNode *n = ui_state->events->first, *next = 0;
|
||||
n != 0;
|
||||
n = next)
|
||||
for(UI_Event *evt = 0; ui_next_event(&evt);)
|
||||
{
|
||||
B32 taken = 0;
|
||||
next = n->next;
|
||||
UI_Event *evt = &n->v;
|
||||
|
||||
//- rjf: unpack event
|
||||
Vec2F32 evt_mouse = evt->pos;
|
||||
@@ -2675,7 +2741,7 @@ ui_signal_from_box(UI_Box *box)
|
||||
//- rjf: taken -> eat event
|
||||
if(taken)
|
||||
{
|
||||
ui_eat_event(ui_state->events, n);
|
||||
ui_eat_event(evt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
-2
@@ -43,6 +43,25 @@ typedef enum UI_MouseButtonKind
|
||||
}
|
||||
UI_MouseButtonKind;
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Codepath Permissions
|
||||
|
||||
typedef U32 UI_PermissionFlags;
|
||||
enum
|
||||
{
|
||||
UI_PermissionFlag_ClicksLeft = (1<<0),
|
||||
UI_PermissionFlag_ClicksMiddle = (1<<1),
|
||||
UI_PermissionFlag_ClicksRight = (1<<2),
|
||||
UI_PermissionFlag_ScrollX = (1<<3),
|
||||
UI_PermissionFlag_ScrollY = (1<<4),
|
||||
UI_PermissionFlag_Keyboard = (1<<5),
|
||||
UI_PermissionFlag_Text = (1<<6),
|
||||
|
||||
//- rjf bundles
|
||||
UI_PermissionFlag_Clicks = (UI_PermissionFlag_ClicksLeft|UI_PermissionFlag_ClicksMiddle|UI_PermissionFlag_ClicksRight),
|
||||
UI_PermissionFlag_All = 0xffffffff,
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Focus Types
|
||||
|
||||
@@ -656,7 +675,7 @@ internal B32 ui_key_match(UI_Key a, UI_Key b);
|
||||
//~ rjf: Event Type Functions
|
||||
|
||||
internal UI_EventNode *ui_event_list_push(Arena *arena, UI_EventList *list, UI_Event *v);
|
||||
internal void ui_eat_event(UI_EventList *list, UI_EventNode *node);
|
||||
internal void ui_eat_event_node(UI_EventList *list, UI_EventNode *node);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Text Operation Functions
|
||||
@@ -723,12 +742,15 @@ internal UI_State *ui_get_selected_state(void);
|
||||
//- rjf: per-frame info
|
||||
internal Arena * ui_build_arena(void);
|
||||
internal OS_Handle ui_window(void);
|
||||
internal UI_EventList * ui_events(void);
|
||||
internal Vec2F32 ui_mouse(void);
|
||||
internal F_Tag ui_icon_font(void);
|
||||
internal String8 ui_icon_string_from_kind(UI_IconKind icon_kind);
|
||||
internal F32 ui_dt(void);
|
||||
|
||||
//- rjf: event pumping
|
||||
internal B32 ui_next_event(UI_Event **ev);
|
||||
internal void ui_eat_event(UI_Event *ev);
|
||||
|
||||
//- rjf: event consumption helpers
|
||||
internal B32 ui_key_press(OS_EventFlags mods, OS_Key key);
|
||||
internal B32 ui_key_release(OS_EventFlags mods, OS_Key key);
|
||||
@@ -840,6 +862,7 @@ internal F32 ui_top_fixed_width(void);
|
||||
internal F32 ui_top_fixed_height(void);
|
||||
internal UI_Size ui_top_pref_width(void);
|
||||
internal UI_Size ui_top_pref_height(void);
|
||||
internal UI_PermissionFlags ui_top_permission_flags(void);
|
||||
internal UI_BoxFlags ui_top_flags(void);
|
||||
internal UI_FocusKind ui_top_focus_hot(void);
|
||||
internal UI_FocusKind ui_top_focus_active(void);
|
||||
@@ -868,6 +891,7 @@ internal F32 ui_bottom_fixed_width(void);
|
||||
internal F32 ui_bottom_fixed_height(void);
|
||||
internal UI_Size ui_bottom_pref_width(void);
|
||||
internal UI_Size ui_bottom_pref_height(void);
|
||||
internal UI_PermissionFlags ui_bottom_permission_flags(void);
|
||||
internal UI_BoxFlags ui_bottom_flags(void);
|
||||
internal UI_FocusKind ui_bottom_focus_hot(void);
|
||||
internal UI_FocusKind ui_bottom_focus_active(void);
|
||||
@@ -896,6 +920,7 @@ internal F32 ui_push_fixed_width(F32 v);
|
||||
internal F32 ui_push_fixed_height(F32 v);
|
||||
internal UI_Size ui_push_pref_width(UI_Size v);
|
||||
internal UI_Size ui_push_pref_height(UI_Size v);
|
||||
internal UI_PermissionFlags ui_push_permission_flags(UI_PermissionFlags v);
|
||||
internal UI_BoxFlags ui_push_flags(UI_BoxFlags v);
|
||||
internal UI_FocusKind ui_push_focus_hot(UI_FocusKind v);
|
||||
internal UI_FocusKind ui_push_focus_active(UI_FocusKind v);
|
||||
@@ -924,6 +949,7 @@ internal F32 ui_pop_fixed_width(void);
|
||||
internal F32 ui_pop_fixed_height(void);
|
||||
internal UI_Size ui_pop_pref_width(void);
|
||||
internal UI_Size ui_pop_pref_height(void);
|
||||
internal UI_PermissionFlags ui_pop_permission_flags(void);
|
||||
internal UI_BoxFlags ui_pop_flags(void);
|
||||
internal UI_FocusKind ui_pop_focus_hot(void);
|
||||
internal UI_FocusKind ui_pop_focus_active(void);
|
||||
@@ -952,6 +978,7 @@ internal F32 ui_set_next_fixed_width(F32 v);
|
||||
internal F32 ui_set_next_fixed_height(F32 v);
|
||||
internal UI_Size ui_set_next_pref_width(UI_Size v);
|
||||
internal UI_Size ui_set_next_pref_height(UI_Size v);
|
||||
internal UI_PermissionFlags ui_set_next_permission_flags(UI_PermissionFlags v);
|
||||
internal UI_BoxFlags ui_set_next_flags(UI_BoxFlags v);
|
||||
internal UI_FocusKind ui_set_next_focus_hot(UI_FocusKind v);
|
||||
internal UI_FocusKind ui_set_next_focus_active(UI_FocusKind v);
|
||||
@@ -995,6 +1022,7 @@ internal void ui_pop_corner_radius(void);
|
||||
#define UI_FixedHeight(v) DeferLoop(ui_push_fixed_height(v), ui_pop_fixed_height())
|
||||
#define UI_PrefWidth(v) DeferLoop(ui_push_pref_width(v), ui_pop_pref_width())
|
||||
#define UI_PrefHeight(v) DeferLoop(ui_push_pref_height(v), ui_pop_pref_height())
|
||||
#define UI_PermissionFlags(v) DeferLoop(ui_push_permission_flags(v), ui_pop_permission_flags())
|
||||
#define UI_Flags(v) DeferLoop(ui_push_flags(v), ui_pop_flags())
|
||||
#define UI_FocusHot(v) DeferLoop(ui_push_focus_hot(v), ui_pop_focus_hot())
|
||||
#define UI_FocusActive(v) DeferLoop(ui_push_focus_active(v), ui_pop_focus_active())
|
||||
|
||||
Reference in New Issue
Block a user