From e41eb9430f54b419ae419aee8487ecaa400731d5 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Mon, 13 May 2024 11:48:42 -0700 Subject: [PATCH] finish pass to convert everything over to ui events, eliminate nav actions; intermix os events & ui event production with commands --- src/df/core/df_core.c | 18 ++ src/df/core/df_core.mdesk | 4 + src/df/core/generated/df_core.meta.c | 6 +- src/df/core/generated/df_core.meta.h | 5 +- src/df/gfx/df_gfx.c | 163 +++++++----- src/df/gfx/df_gfx.h | 2 +- src/df/gfx/df_views.c | 46 ++-- src/raddbg/raddbg.c | 192 ++++++++------ src/ui/ui_basic_widgets.c | 2 +- src/ui/ui_core.c | 382 +++++---------------------- src/ui/ui_core.h | 103 +------- 11 files changed, 347 insertions(+), 576 deletions(-) diff --git a/src/df/core/df_core.c b/src/df/core/df_core.c index 908b4991..29055c8d 100644 --- a/src/df/core/df_core.c +++ b/src/df/core/df_core.c @@ -6490,6 +6490,24 @@ df_push_cmd__root(DF_CmdParams *params, DF_CmdSpec *spec) if(params->voff != 0) { log_msgf("| voff: 0x%I64x\n", params->voff); } if(params->index != 0) { log_msgf("| index: 0x%I64x\n", params->index); } if(params->id != 0) { log_msgf("| id: 0x%I64x\n", params->id); } + if(params->os_event != 0) + { + String8 kind_string = str8_lit(""); + switch(params->os_event->kind) + { + default:{}break; + case OS_EventKind_Press: {kind_string = str8_lit("press");}break; + case OS_EventKind_Release: {kind_string = str8_lit("release");}break; + case OS_EventKind_MouseMove: {kind_string = str8_lit("mousemove");}break; + case OS_EventKind_Text: {kind_string = str8_lit("text");}break; + case OS_EventKind_Scroll: {kind_string = str8_lit("scroll");}break; + case OS_EventKind_WindowLoseFocus:{kind_string = str8_lit("losefocus");}break; + case OS_EventKind_WindowClose: {kind_string = str8_lit("closewindow");}break; + case OS_EventKind_FileDrop: {kind_string = str8_lit("filedrop");}break; + case OS_EventKind_Wakeup: {kind_string = str8_lit("wakeup");}break; + } + log_msgf("| os_event->kind: %S\n", kind_string); + } #undef HandleParamPrint log_msgf("--------------------------------\n"); scratch_end(scratch); diff --git a/src/df/core/df_core.mdesk b/src/df/core/df_core.mdesk index 08c95276..c37e1d23 100644 --- a/src/df/core/df_core.mdesk +++ b/src/df/core/df_core.mdesk @@ -89,6 +89,7 @@ DF_CmdParamSlotTable: {CmdSpec cmd_spec `struct DF_CmdSpec *`} {ViewSpec view_spec `struct DF_ViewSpec *`} {CfgNode cfg_node `struct DF_CfgNode *`} + {OSEvent os_event `struct OS_Event *`} {VirtualAddr vaddr `U64`} {VirtualOff voff `U64`} {Index index `U64`} @@ -114,6 +115,9 @@ DF_CoreCmdTable:// | | | //- rjf: notifications {Error 1 Null Nil 0 0 0 0 0 0 Null "error" "Error" "Notifies of an error." "" } + //- rjf: os event passthrough + {OSEvent 1 Null Nil 0 0 0 0 0 0 Null "os_event" "OS Event" "" "" } + //- rjf: low-level target control operations {LaunchAndRun 0 EntityList Target 0 0 0 0 0 1 Play "launch_and_run" "Launch and Run" "Starts debugging a new instance of a target, then runs." "launch,start,run,target" } {LaunchAndInit 0 EntityList Target 0 0 0 0 0 1 PlayStepForward "launch_and_init" "Launch and Initialize" "Starts debugging a new instance of a target, then stops at the program's entry point." "launch,start,entry,point" } diff --git a/src/df/core/generated/df_core.meta.c b/src/df/core/generated/df_core.meta.c index 3177beb5..4057bad1 100644 --- a/src/df/core/generated/df_core.meta.c +++ b/src/df/core/generated/df_core.meta.c @@ -4,7 +4,7 @@ //- GENERATED CODE C_LINKAGE_BEGIN -Rng1U64 df_g_cmd_param_slot_range_table[21] = +Rng1U64 df_g_cmd_param_slot_range_table[22] = { {0}, {OffsetOf(DF_CmdParams, window), OffsetOf(DF_CmdParams, window) + sizeof(DF_Handle)}, @@ -20,6 +20,7 @@ Rng1U64 df_g_cmd_param_slot_range_table[21] = {OffsetOf(DF_CmdParams, cmd_spec), OffsetOf(DF_CmdParams, cmd_spec) + sizeof(struct DF_CmdSpec *)}, {OffsetOf(DF_CmdParams, view_spec), OffsetOf(DF_CmdParams, view_spec) + sizeof(struct DF_ViewSpec *)}, {OffsetOf(DF_CmdParams, cfg_node), OffsetOf(DF_CmdParams, cfg_node) + sizeof(struct DF_CfgNode *)}, +{OffsetOf(DF_CmdParams, os_event), OffsetOf(DF_CmdParams, os_event) + sizeof(struct OS_Event *)}, {OffsetOf(DF_CmdParams, vaddr), OffsetOf(DF_CmdParams, vaddr) + sizeof(U64)}, {OffsetOf(DF_CmdParams, voff), OffsetOf(DF_CmdParams, voff) + sizeof(U64)}, {OffsetOf(DF_CmdParams, index), OffsetOf(DF_CmdParams, index) + sizeof(U64)}, @@ -216,12 +217,13 @@ DF_CoreCmdKind_Null, DF_CoreCmdKind_Null, }; -DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[214] = +DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[215] = { { str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("exit"), str8_lit_comp("Exits the debugger."), str8_lit_comp("quit,close,abort"), str8_lit_comp("Exit"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_X}, { str8_lit_comp("run_command"), str8_lit_comp("Runs a command from the command palette."), str8_lit_comp("help,cmd"), str8_lit_comp("Run Command"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_CmdSpec, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("error"), str8_lit_comp("Notifies of an error."), str8_lit_comp(""), str8_lit_comp("Error"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, +{ str8_lit_comp("os_event"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("OS Event"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("launch_and_run"), str8_lit_comp("Starts debugging a new instance of a target, then runs."), str8_lit_comp("launch,start,run,target"), str8_lit_comp("Launch and Run"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_EntityList, DF_EntityKind_Target, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*1)}, DF_IconKind_Play}, { str8_lit_comp("launch_and_init"), str8_lit_comp("Starts debugging a new instance of a target, then stops at the program's entry point."), str8_lit_comp("launch,start,entry,point"), str8_lit_comp("Launch and Initialize"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_EntityList, DF_EntityKind_Target, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*1)}, DF_IconKind_PlayStepForward}, { str8_lit_comp("kill"), str8_lit_comp("Kills the specified existing debugged process(es)."), str8_lit_comp("stop,kill"), str8_lit_comp("Kill"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_EntityList, DF_EntityKind_Process, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*1)}, DF_IconKind_Stop}, diff --git a/src/df/core/generated/df_core.meta.h b/src/df/core/generated/df_core.meta.h index c6c96bf5..d8ea126f 100644 --- a/src/df/core/generated/df_core.meta.h +++ b/src/df/core/generated/df_core.meta.h @@ -53,6 +53,7 @@ DF_CoreCmdKind_Null, DF_CoreCmdKind_Exit, DF_CoreCmdKind_RunCommand, DF_CoreCmdKind_Error, +DF_CoreCmdKind_OSEvent, DF_CoreCmdKind_LaunchAndRun, DF_CoreCmdKind_LaunchAndInit, DF_CoreCmdKind_Kill, @@ -378,6 +379,7 @@ DF_CmdParamSlot_TextPoint, DF_CmdParamSlot_CmdSpec, DF_CmdParamSlot_ViewSpec, DF_CmdParamSlot_CfgNode, +DF_CmdParamSlot_OSEvent, DF_CmdParamSlot_VirtualAddr, DF_CmdParamSlot_VirtualOff, DF_CmdParamSlot_Index, @@ -405,6 +407,7 @@ TxtPt text_point; struct DF_CmdSpec * cmd_spec; struct DF_ViewSpec * view_spec; struct DF_CfgNode * cfg_node; +struct OS_Event * os_event; U64 vaddr; U64 voff; U64 index; @@ -1522,7 +1525,7 @@ struct {B32 *value_ptr; String8 name;} DEV_toggle_table[] = {&DEV_updating_indicator, str8_lit_comp("updating_indicator")}, }; C_LINKAGE_BEGIN -extern Rng1U64 df_g_cmd_param_slot_range_table[21]; +extern Rng1U64 df_g_cmd_param_slot_range_table[22]; extern DF_IconKind df_g_entity_kind_icon_kind_table[27]; extern String8 df_g_entity_kind_display_string_table[27]; extern String8 df_g_entity_kind_name_label_table[27]; diff --git a/src/df/gfx/df_gfx.c b/src/df/gfx/df_gfx.c index 9333073b..ee7acbba 100644 --- a/src/df/gfx/df_gfx.c +++ b/src/df/gfx/df_gfx.c @@ -1030,7 +1030,7 @@ df_window_from_os_handle(OS_Handle os) #endif internal void -df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, DF_CmdList *cmds) +df_window_update_and_render(Arena *arena, DF_Window *ws, DF_CmdList *cmds) { ProfBeginFunction(); @@ -1073,8 +1073,8 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D ////////////////////////////// //- rjf: do core-layer commands & batch up commands to be dispatched to views // + UI_EventList events = {0}; B32 panel_reset_done = 0; - UI_EventList events_ui = {0}; ProfScope("do commands") { Temp scratch = scratch_begin(&arena, 1); @@ -1119,6 +1119,36 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D } }break; + //- rjf: OS events + case DF_CoreCmdKind_OSEvent: + { + OS_Event *os_event = params.os_event; + if(os_event != 0 && os_handle_match(os_event->window, ws->os)) + { + UI_Event ui_event = {0}; + UI_EventKind kind = UI_EventKind_Null; + { + switch(os_event->kind) + { + default:{}break; + case OS_EventKind_Press: {kind = UI_EventKind_Press;}break; + case OS_EventKind_Release: {kind = UI_EventKind_Release;}break; + case OS_EventKind_MouseMove: {kind = UI_EventKind_MouseMove;}break; + case OS_EventKind_Text: {kind = UI_EventKind_Text;}break; + case OS_EventKind_Scroll: {kind = UI_EventKind_Scroll;}break; + } + } + ui_event.kind = kind; + ui_event.key = os_event->key; + ui_event.modifiers = os_event->flags; + ui_event.string = os_event->character ? str8_from_32(ui_build_arena(), str32(&os_event->character, 1)) : str8_zero(); + ui_event.pos = os_event->pos; + ui_event.delta_2f32 = os_event->delta; + ui_event.timestamp_us = os_event->timestamp_us; + ui_event_list_push(ui_build_arena(), &events, &ui_event); + } + }break; + //- rjf: command fast path case DF_CoreCmdKind_RunCommand: { @@ -2087,64 +2117,72 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D UI_Event evt = {0}; evt.kind = UI_EventKind_Navigate; evt.flags = UI_EventFlag_PickSelectSide|UI_EventFlag_ZeroDeltaOnSelect|UI_EventFlag_ExplicitDirectional; + evt.delta_unit = UI_EventDeltaUnit_Char; evt.delta_2s32 = v2s32(-1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveRight: { UI_Event evt = {0}; evt.kind = UI_EventKind_Navigate; evt.flags = UI_EventFlag_PickSelectSide|UI_EventFlag_ZeroDeltaOnSelect|UI_EventFlag_ExplicitDirectional; + evt.delta_unit = UI_EventDeltaUnit_Char; evt.delta_2s32 = v2s32(+1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveUp: { UI_Event evt = {0}; evt.kind = UI_EventKind_Navigate; evt.flags = UI_EventFlag_ExplicitDirectional; + evt.delta_unit = UI_EventDeltaUnit_Char; evt.delta_2s32 = v2s32(+0, -1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveDown: { UI_Event evt = {0}; evt.kind = UI_EventKind_Navigate; evt.flags = UI_EventFlag_ExplicitDirectional; + evt.delta_unit = UI_EventDeltaUnit_Char; evt.delta_2s32 = v2s32(+0, +1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveLeftSelect: { UI_Event evt = {0}; evt.kind = UI_EventKind_Navigate; evt.flags = UI_EventFlag_KeepMark|UI_EventFlag_ExplicitDirectional; + evt.delta_unit = UI_EventDeltaUnit_Char; evt.delta_2s32 = v2s32(-1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveRightSelect: { UI_Event evt = {0}; evt.kind = UI_EventKind_Navigate; evt.flags = UI_EventFlag_KeepMark|UI_EventFlag_ExplicitDirectional; + evt.delta_unit = UI_EventDeltaUnit_Char; evt.delta_2s32 = v2s32(+1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveUpSelect: { UI_Event evt = {0}; evt.kind = UI_EventKind_Navigate; evt.flags = UI_EventFlag_KeepMark|UI_EventFlag_ExplicitDirectional; + evt.delta_unit = UI_EventDeltaUnit_Char; evt.delta_2s32 = v2s32(+0, -1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveDownSelect: { UI_Event evt = {0}; evt.kind = UI_EventKind_Navigate; evt.flags = UI_EventFlag_KeepMark|UI_EventFlag_ExplicitDirectional; + evt.delta_unit = UI_EventDeltaUnit_Char; evt.delta_2s32 = v2s32(+0, +1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveLeftChunk: { @@ -2153,7 +2191,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_ExplicitDirectional; evt.delta_unit = UI_EventDeltaUnit_Word; evt.delta_2s32 = v2s32(-1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveRightChunk: { @@ -2162,7 +2200,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_ExplicitDirectional; evt.delta_unit = UI_EventDeltaUnit_Word; evt.delta_2s32 = v2s32(+1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveUpChunk: { @@ -2171,7 +2209,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_ExplicitDirectional; evt.delta_unit = UI_EventDeltaUnit_Word; evt.delta_2s32 = v2s32(+0, -1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveDownChunk: { @@ -2180,7 +2218,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_ExplicitDirectional; evt.delta_unit = UI_EventDeltaUnit_Word; evt.delta_2s32 = v2s32(+0, +1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveUpPage: { @@ -2188,7 +2226,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.kind = UI_EventKind_Navigate; evt.delta_unit = UI_EventDeltaUnit_Page; evt.delta_2s32 = v2s32(+0, -1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveDownPage: { @@ -2196,7 +2234,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.kind = UI_EventKind_Navigate; evt.delta_unit = UI_EventDeltaUnit_Page; evt.delta_2s32 = v2s32(+0, +1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveUpWhole: { @@ -2204,7 +2242,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.kind = UI_EventKind_Navigate; evt.delta_unit = UI_EventDeltaUnit_Whole; evt.delta_2s32 = v2s32(+0, -1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveDownWhole: { @@ -2212,7 +2250,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.kind = UI_EventKind_Navigate; evt.delta_unit = UI_EventDeltaUnit_Whole; evt.delta_2s32 = v2s32(+0, +1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveLeftChunkSelect: { @@ -2221,7 +2259,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_KeepMark|UI_EventFlag_ExplicitDirectional; evt.delta_unit = UI_EventDeltaUnit_Word; evt.delta_2s32 = v2s32(-1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveRightChunkSelect: { @@ -2230,7 +2268,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_KeepMark|UI_EventFlag_ExplicitDirectional; evt.delta_unit = UI_EventDeltaUnit_Word; evt.delta_2s32 = v2s32(+1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveUpChunkSelect: { @@ -2239,7 +2277,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_KeepMark|UI_EventFlag_ExplicitDirectional; evt.delta_unit = UI_EventDeltaUnit_Word; evt.delta_2s32 = v2s32(+0, -1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveDownChunkSelect: { @@ -2248,7 +2286,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_KeepMark|UI_EventFlag_ExplicitDirectional; evt.delta_unit = UI_EventDeltaUnit_Word; evt.delta_2s32 = v2s32(+0, +1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveUpPageSelect: { @@ -2257,7 +2295,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_KeepMark; evt.delta_unit = UI_EventDeltaUnit_Page; evt.delta_2s32 = v2s32(+0, -1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveDownPageSelect: { @@ -2266,7 +2304,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_KeepMark; evt.delta_unit = UI_EventDeltaUnit_Page; evt.delta_2s32 = v2s32(+0, +1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveUpWholeSelect: { @@ -2275,7 +2313,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_KeepMark; evt.delta_unit = UI_EventDeltaUnit_Whole; evt.delta_2s32 = v2s32(+0, -1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveDownWholeSelect: { @@ -2284,7 +2322,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_KeepMark; evt.delta_unit = UI_EventDeltaUnit_Whole; evt.delta_2s32 = v2s32(+0, +1); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveHome: { @@ -2292,7 +2330,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.kind = UI_EventKind_Navigate; evt.delta_unit = UI_EventDeltaUnit_Line; evt.delta_2s32 = v2s32(-1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveEnd: { @@ -2300,7 +2338,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.kind = UI_EventKind_Navigate; evt.delta_unit = UI_EventDeltaUnit_Line; evt.delta_2s32 = v2s32(+1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveHomeSelect: { @@ -2309,7 +2347,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_KeepMark; evt.delta_unit = UI_EventDeltaUnit_Line; evt.delta_2s32 = v2s32(-1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_MoveEndSelect: { @@ -2318,7 +2356,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt.flags = UI_EventFlag_KeepMark; evt.delta_unit = UI_EventDeltaUnit_Line; evt.delta_2s32 = v2s32(+1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_SelectAll: { @@ -2326,75 +2364,77 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D evt1.kind = UI_EventKind_Navigate; evt1.delta_unit = UI_EventDeltaUnit_Whole; evt1.delta_2s32 = v2s32(-1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt1); + ui_event_list_push(ui_build_arena(), &events, &evt1); UI_Event evt2 = {0}; evt2.kind = UI_EventKind_Navigate; evt2.flags = UI_EventFlag_KeepMark; evt2.delta_unit = UI_EventDeltaUnit_Whole; evt2.delta_2s32 = v2s32(+1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt2); + ui_event_list_push(ui_build_arena(), &events, &evt2); }break; case DF_CoreCmdKind_DeleteSingle: { UI_Event evt = {0}; evt.kind = UI_EventKind_Edit; evt.flags = UI_EventFlag_Delete; + evt.delta_unit = UI_EventDeltaUnit_Char; evt.delta_2s32 = v2s32(+1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_DeleteChunk: { UI_Event evt = {0}; evt.kind = UI_EventKind_Edit; evt.flags = UI_EventFlag_Delete; - evt.delta_2s32 = v2s32(+1, +0); evt.delta_unit = UI_EventDeltaUnit_Word; - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + evt.delta_2s32 = v2s32(+1, +0); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_BackspaceSingle: { UI_Event evt = {0}; evt.kind = UI_EventKind_Edit; evt.flags = UI_EventFlag_Delete|UI_EventFlag_ZeroDeltaOnSelect; + evt.delta_unit = UI_EventDeltaUnit_Char; evt.delta_2s32 = v2s32(-1, +0); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_BackspaceChunk: { UI_Event evt = {0}; evt.kind = UI_EventKind_Edit; evt.flags = UI_EventFlag_Delete; - evt.delta_2s32 = v2s32(-1, +0); evt.delta_unit = UI_EventDeltaUnit_Word; - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + evt.delta_2s32 = v2s32(-1, +0); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_Copy: { UI_Event evt = {0}; evt.kind = UI_EventKind_Edit; evt.flags = UI_EventFlag_Copy|UI_EventFlag_KeepMark; - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_Cut: { UI_Event evt = {0}; evt.kind = UI_EventKind_Edit; evt.flags = UI_EventFlag_Copy|UI_EventFlag_Delete; - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_Paste: { UI_Event evt = {0}; evt.kind = UI_EventKind_Text; evt.string = os_get_clipboard_text(ui_build_arena()); - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; case DF_CoreCmdKind_InsertText: { UI_Event evt = {0}; evt.kind = UI_EventKind_Text; evt.string = params.string; - ui_event_list_push(ui_build_arena(), &events_ui, &evt); + ui_event_list_push(ui_build_arena(), &events, &evt); }break; //- rjf: address finding @@ -3199,7 +3239,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D } // rjf: begin & push initial stack values - ui_begin_build(ws->os, &events_ui, &icon_info, df_dt(), df_dt()); + ui_begin_build(ws->os, &events, &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)); @@ -4134,14 +4174,14 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D UI_BackgroundColor(df_rgba_from_theme_color(DF_ThemeColor_ActionBackground)) UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_ActionText)) UI_BorderColor(df_rgba_from_theme_color(DF_ThemeColor_ActionBorder)) - if(ui_clicked(ui_buttonf("OK")) || (ui_key_match(bg_box->default_nav_focus_hot_key, ui_key_zero()) && ui_key_press(ui_events(), 0, OS_Key_Return))) + if(ui_clicked(ui_buttonf("OK")) || (ui_key_match(bg_box->default_nav_focus_hot_key, ui_key_zero()) && ui_key_press(0, OS_Key_Return))) { DF_CmdParams p = df_cmd_params_zero(); df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_ConfirmAccept)); } UI_CornerRadius10(ui_top_font_size()*0.25f) UI_CornerRadius11(ui_top_font_size()*0.25f) - if(ui_clicked(ui_buttonf("Cancel")) || ui_key_press(ui_events(), 0, OS_Key_Esc)) + if(ui_clicked(ui_buttonf("Cancel")) || ui_key_press(0, OS_Key_Esc)) { DF_CmdParams p = df_cmd_params_zero(); df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_ConfirmCancel)); @@ -4701,7 +4741,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D { ui_set_next_fastpath_codepoint(items[idx].codepoint); B32 alt_fastpath_key = 0; - if(ui_key_press(ui_events(), OS_EventFlag_Alt, items[idx].key)) + if(ui_key_press(OS_EventFlag_Alt, items[idx].key)) { alt_fastpath_key = 1; } @@ -5436,14 +5476,14 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D //- rjf: query submission if((ui_is_focus_active() || (window_is_focused && !ui_any_ctx_menu_is_open() && !ws->menu_bar_focused && !ws->query_view_selected)) && - os_key_press(events, ws->os, 0, OS_Key_Esc)) + ui_key_press(0, OS_Key_Esc)) { DF_CmdParams params = df_cmd_params_from_window(ws); df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_CancelQuery)); } if(ui_is_focus_active()) { - if(os_key_press(events, ws->os, 0, OS_Key_Return)) + if(ui_key_press(0, OS_Key_Return)) { Temp scratch = scratch_begin(&arena, 1); DF_View *view = ws->query_view_stack_top; @@ -6364,7 +6404,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D DF_View *view = df_view_from_handle(panel->selected_tab_view); UI_Focus(UI_FocusKind_On) { - if(view->is_filtering && ui_is_focus_active() && ui_key_press(ui_events(), 0, OS_Key_Return)) + if(view->is_filtering && ui_is_focus_active() && ui_key_press(0, OS_Key_Return)) { DF_CmdParams p = df_cmd_params_from_view(ws, panel, view); df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_ApplyFilter)); @@ -6602,7 +6642,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D } } } - if((view->query_string_size != 0 || view->is_filtering) && ui_is_focus_active() && ui_key_press(ui_events(), 0, OS_Key_Esc)) + if((view->query_string_size != 0 || view->is_filtering) && ui_is_focus_active() && ui_key_press(0, OS_Key_Esc)) { DF_CmdParams p = df_cmd_params_from_view(ws, panel, view); df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_ClearFilter)); @@ -7173,7 +7213,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D //////////////////////////// //- rjf: drag/drop cancelling // - if(df_drag_is_active() && ui_key_press(&events_ui, 0, OS_Key_Esc)) + if(df_drag_is_active() && ui_key_press(0, OS_Key_Esc)) { df_drag_kill(); ui_kill_action(); @@ -7182,13 +7222,13 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D //////////////////////////// //- rjf: font size changing // - for(UI_EventNode *n = events_ui.first, *next = 0; n != 0; n = next) + for(UI_EventNode *n = events.first, *next = 0; n != 0; n = next) { next = n->next; UI_Event *event = &n->v; - if(event->kind == OS_EventKind_Scroll && event->flags & OS_EventFlag_Ctrl) + if(event->kind == UI_EventKind_Scroll && event->modifiers & OS_EventFlag_Ctrl) { - ui_eat_event(&events_ui, n); + ui_eat_event(&events, n); if(event->delta_2f32.y < 0) { DF_CmdParams params = df_cmd_params_from_window(ws); @@ -7256,7 +7296,7 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D ////////////////////////////// //- rjf: hover eval cancelling // - if(ws->hover_eval_string.size != 0 && os_key_press(events, ws->os, 0, OS_Key_Esc)) + if(ws->hover_eval_string.size != 0 && ui_key_press(0, OS_Key_Esc)) { MemoryZeroStruct(&ws->hover_eval_string); arena_clear(ws->hover_eval_arena); @@ -10807,7 +10847,7 @@ df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_ { next = n->next; UI_Event *event = &n->v; - if(event->kind == OS_EventKind_Scroll && event->flags & OS_EventFlag_Ctrl) + if(event->kind == UI_EventKind_Scroll && event->modifiers & OS_EventFlag_Ctrl) { ui_eat_event(events, n); if(event->delta_2f32.y < 0) @@ -11411,8 +11451,11 @@ df_do_txt_controls(TXT_TextInfo *info, String8 data, U64 line_count_per_page, Tx for(UI_EventNode *n = events->first, *next = 0; n != 0; n = next) { next = n->next; + if(n->v.kind != UI_EventKind_Navigate && n->v.kind != UI_EventKind_Edit) + { + continue; + } B32 taken = 0; - String8 line = txt_string_from_info_data_line_num(info, data, cursor->line); UI_TxtOp single_line_op = ui_single_line_txt_op_from_event(scratch.arena, &n->v, line, *cursor, *mark); @@ -11445,7 +11488,7 @@ df_do_txt_controls(TXT_TextInfo *info, String8 data, U64 line_count_per_page, Tx } //- rjf: movement down (plain) - if(n->v.delta_unit == UI_EventDeltaUnit_Whole && delta.y > 0 && cursor->line+1 <= line_count) + if(n->v.delta_unit == UI_EventDeltaUnit_Char && delta.y > 0 && cursor->line+1 <= line_count) { cursor->line += 1; cursor->column = Min(*preferred_column, next_line.size+1); @@ -12088,7 +12131,7 @@ df_line_edit(DF_LineEditFlags flags, S32 depth, FuzzyMatchRangeList *matches, Tx } } } - if(is_focus_hot && ui_key_press(ui_events(), 0, OS_Key_F2)) + if(is_focus_hot && ui_key_press(0, OS_Key_F2)) { start_editing_via_typing = 1; } @@ -12123,7 +12166,7 @@ df_line_edit(DF_LineEditFlags flags, S32 depth, FuzzyMatchRangeList *matches, Tx next = n->next; // rjf: do not consume anything that doesn't fit a single-line's operations - if(n->v.delta_2s32.y != 0) + 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) { continue; } diff --git a/src/df/gfx/df_gfx.h b/src/df/gfx/df_gfx.h index 425ea56b..2859b9ac 100644 --- a/src/df/gfx/df_gfx.h +++ b/src/df/gfx/df_gfx.h @@ -899,7 +899,7 @@ internal DF_Window *df_window_open(Vec2F32 size, OS_Handle preferred_monitor, DF internal DF_Window *df_window_from_os_handle(OS_Handle os); -internal void df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, DF_CmdList *cmds); +internal void df_window_update_and_render(Arena *arena, DF_Window *ws, DF_CmdList *cmds); //////////////////////////////// //~ rjf: Eval Viz diff --git a/src/df/gfx/df_views.c b/src/df/gfx/df_views.c index 611c1f2f..9c10ba6f 100644 --- a/src/df/gfx/df_views.c +++ b/src/df/gfx/df_views.c @@ -859,23 +859,23 @@ df_eval_watch_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_EvalW break; } } - if(ui_key_press(ui_events(), 0, OS_Key_F2)) + if(ui_key_press(0, OS_Key_F2)) { edit_begin = 1; } - if(ui_key_press(ui_events(), 0, OS_Key_Return)) + if(ui_key_press(0, OS_Key_Return)) { edit_begin_or_expand = 1; } } if(ewv->input_editing && ui_is_focus_active()) { - if(ui_key_press(ui_events(), 0, OS_Key_Esc)) + if(ui_key_press(0, OS_Key_Esc)) { edit_end = 1; edit_commit = 0; } - if(ui_key_press(ui_events(), 0, OS_Key_Return)) + if(ui_key_press(0, OS_Key_Return)) { edit_end = 1; edit_commit = 1; @@ -1857,7 +1857,7 @@ DF_VIEW_UI_FUNCTION_DEF(Commands) df_cmd_lister_item_array_sort_by_strength__in_place(cmd_array); //- rjf: submit best match when hitting enter w/ no selection - if(cv->selected_cmd_spec == &df_g_nil_cmd_spec && ui_key_press(ui_events(), 0, OS_Key_Return)) + if(cv->selected_cmd_spec == &df_g_nil_cmd_spec && ui_key_press(0, OS_Key_Return)) { DF_CmdParams params = df_cmd_params_from_view(ws, panel, view); if(cmd_array.count > 0) @@ -2196,7 +2196,7 @@ DF_VIEW_UI_FUNCTION_DEF(FileSystem) } //- rjf: submit best match when hitting enter w/ no selection - if(ps->cursor.y == 0 && ui_key_press(ui_events(), 0, OS_Key_Return)) + if(ps->cursor.y == 0 && ui_key_press(0, OS_Key_Return)) { FileProperties query_normalized_with_opt_slash_props = os_properties_from_file_path(query_normalized_with_opt_slash); FileProperties path_query_path_props = os_properties_from_file_path(path_query.path); @@ -2535,7 +2535,7 @@ DF_VIEW_UI_FUNCTION_DEF(SystemProcesses) } //- rjf: submit best match when hitting enter w/ no selection - if(sp->selected_pid == 0 && process_info_array.count > 0 && ui_key_press(ui_events(), 0, OS_Key_Return)) + if(sp->selected_pid == 0 && process_info_array.count > 0 && ui_key_press(0, OS_Key_Return)) { DF_ProcessInfo *info = &process_info_array.v[0]; DF_CmdParams params = df_cmd_params_from_view(ws, panel, view); @@ -2692,7 +2692,7 @@ DF_VIEW_UI_FUNCTION_DEF(EntityLister) df_entity_lister_item_array_sort_by_strength__in_place(ent_arr); //- rjf: submit best match when hitting enter w/ no selection - if(df_entity_is_nil(df_entity_from_handle(fev->selected_entity_handle)) && ent_arr.count != 0 && ui_key_press(ui_events(), 0, OS_Key_Return)) + if(df_entity_is_nil(df_entity_from_handle(fev->selected_entity_handle)) && ent_arr.count != 0 && ui_key_press(0, OS_Key_Return)) { DF_Entity *ent = ent_arr.v[0].entity; DF_CmdParams params = df_cmd_params_from_view(ws, panel, view); @@ -2845,7 +2845,7 @@ DF_VIEW_UI_FUNCTION_DEF(SymbolLister) } //- rjf: submit best match when hitting enter w/ no selection - if(slv->cursor.y == 0 && items.count != 0 && ui_key_press(ui_events(), 0, OS_Key_Return)) + if(slv->cursor.y == 0 && items.count != 0 && ui_key_press(0, OS_Key_Return)) { RDI_Procedure *procedure = rdi_element_from_idx(rdi, procedures, items.v[0].idx); U64 name_size = 0; @@ -3054,23 +3054,23 @@ DF_VIEW_UI_FUNCTION_DEF(Target) break; } } - if(ui_key_press(ui_events(), 0, OS_Key_F2)) + if(ui_key_press(0, OS_Key_F2)) { edit_begin = 1; } - if(ui_key_press(ui_events(), 0, OS_Key_Return)) + if(ui_key_press(0, OS_Key_Return)) { edit_begin = 1; } } if(tv->input_editing) { - if(ui_key_press(ui_events(), 0, OS_Key_Esc)) + if(ui_key_press(0, OS_Key_Esc)) { edit_end = 1; edit_commit = 0; } - if(ui_key_press(ui_events(), 0, OS_Key_Return)) + if(ui_key_press(0, OS_Key_Return)) { edit_end = 1; edit_commit = 1; @@ -3529,19 +3529,19 @@ DF_VIEW_UI_FUNCTION_DEF(FilePathMap) break; } } - if(ui_key_press(ui_events(), 0, OS_Key_F2)) + if(ui_key_press(0, OS_Key_F2)) { edit_begin = 1; } } if(fpms->input_editing) { - if(ui_key_press(ui_events(), 0, OS_Key_Esc)) + if(ui_key_press(0, OS_Key_Esc)) { edit_end = 1; edit_commit = 0; } - if(ui_key_press(ui_events(), 0, OS_Key_Return)) + if(ui_key_press(0, OS_Key_Return)) { edit_end = 1; edit_commit = 1; @@ -3847,19 +3847,19 @@ DF_VIEW_UI_FUNCTION_DEF(AutoViewRules) break; } } - if(ui_key_press(ui_events(), 0, OS_Key_F2)) + if(ui_key_press(0, OS_Key_F2)) { edit_begin = 1; } } if(avrs->input_editing) { - if(ui_key_press(ui_events(), 0, OS_Key_Esc)) + if(ui_key_press(0, OS_Key_Esc)) { edit_end = 1; edit_commit = 0; } - if(ui_key_press(ui_events(), 0, OS_Key_Return)) + if(ui_key_press(0, OS_Key_Return)) { edit_end = 1; edit_commit = 1; @@ -4663,20 +4663,20 @@ DF_VIEW_UI_FUNCTION_DEF(Modules) break; } } - if(ui_key_press(ui_events(), 0, OS_Key_F2) || - ui_key_press(ui_events(), 0, OS_Key_Return)) + if(ui_key_press(0, OS_Key_F2) || + ui_key_press(0, OS_Key_Return)) { edit_begin = 1; } } if(mv->txt_editing && ui_is_focus_active()) { - if(ui_key_press(ui_events(), 0, OS_Key_Esc)) + if(ui_key_press(0, OS_Key_Esc)) { edit_end = 1; edit_commit = 0; } - if(ui_key_press(ui_events(), 0, OS_Key_Return)) + if(ui_key_press(0, OS_Key_Return)) { edit_end = 1; edit_commit = 1; diff --git a/src/raddbg/raddbg.c b/src/raddbg/raddbg.c index 218b7fa8..465fa1b0 100644 --- a/src/raddbg/raddbg.c +++ b/src/raddbg/raddbg.c @@ -11,7 +11,9 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) ProfBeginFunction(); Temp scratch = scratch_begin(0, 0); + ////////////////////////////// //- rjf: begin logging + // if(main_thread_log == 0) { main_thread_log = log_alloc(); @@ -24,13 +26,17 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) log_select(main_thread_log); log_scope_begin(); + ////////////////////////////// //- rjf: tick cache layers + // txt_user_clock_tick(); dasm_user_clock_tick(); geo_user_clock_tick(); tex_user_clock_tick(); + ////////////////////////////// //- rjf: pick target hz + // // TODO(rjf): maximize target, given all windows and their monitors F32 target_hz = os_default_refresh_rate(); if(frame_time_us_history_idx > 32) @@ -66,29 +72,41 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) target_hz = best_target_hz; } + ////////////////////////////// //- rjf: target Hz -> delta time + // F32 dt = 1.f/target_hz; + ////////////////////////////// //- rjf: last frame before sleep -> disable txti change detection + // if(df_gfx_state->num_frames_requested == 0) { txti_set_external_change_detection_enabled(0); } + ////////////////////////////// //- rjf: get events from the OS + // OS_EventList events = {0}; if(os_handle_match(repaint_window_handle, os_handle_zero())) { events = os_get_events(scratch.arena, df_gfx_state->num_frames_requested == 0); } + ////////////////////////////// //- rjf: enable txti change detection + // txti_set_external_change_detection_enabled(1); + ////////////////////////////// //- rjf: begin measuring actual per-frame work + // U64 begin_time_us = os_now_microseconds(); + ////////////////////////////// //- rjf: bind change + // if(!df_gfx_state->confirm_active && df_gfx_state->bind_change_active) { if(os_key_press(&events, os_handle_zero(), 0, OS_Key_Esc)) @@ -136,7 +154,10 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) } } - //- rjf: take hotkeys + ////////////////////////////// + //- rjf: consume events + // + B32 queue_drag_drop = 0; { for(OS_Event *event = events.first, *next = 0; event != 0; @@ -145,7 +166,63 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) next = event->next; DF_Window *window = df_window_from_os_handle(event->window); DF_CmdParams params = window ? df_cmd_params_from_window(window) : df_cmd_params_from_gfx(); - if(event->kind == OS_EventKind_Press) + B32 take = 0; + B32 skip = 0; + + //- rjf: try drag-drop + if(df_drag_is_active() && event->kind == OS_EventKind_Release && event->key == OS_Key_LeftMouseButton) + { + skip = 1; + queue_drag_drop = 1; + } + + //- rjf: try window close + if(!take && event->kind == OS_EventKind_WindowClose && window != 0) + { + take = 1; + DF_CmdParams params = df_cmd_params_from_window(window); + df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_CloseWindow)); + } + + //- rjf: try menu bar operations + { + if(!take && event->kind == OS_EventKind_Press && event->key == OS_Key_Alt && event->flags == 0 && event->is_repeat == 0) + { + take = 1; + df_gfx_request_frame(); + window->menu_bar_focused_on_press = window->menu_bar_focused; + window->menu_bar_key_held = 1; + window->menu_bar_focus_press_started = 1; + } + if(!take && event->kind == OS_EventKind_Release && event->key == OS_Key_Alt && event->flags == 0 && event->is_repeat == 0) + { + take = 1; + df_gfx_request_frame(); + window->menu_bar_key_held = 0; + } + if(window->menu_bar_focused && event->kind == OS_EventKind_Press && event->key == OS_Key_Alt && event->flags == 0 && event->is_repeat == 0) + { + take = 1; + df_gfx_request_frame(); + window->menu_bar_focused = 0; + } + else if(window->menu_bar_focus_press_started && !window->menu_bar_focused && event->kind == OS_EventKind_Release && event->flags == 0 && event->key == OS_Key_Alt && event->is_repeat == 0) + { + take = 1; + df_gfx_request_frame(); + window->menu_bar_focused = !window->menu_bar_focused_on_press; + window->menu_bar_focus_press_started = 0; + } + else if(event->kind == OS_EventKind_Press && event->key == OS_Key_Esc && window->menu_bar_focused && !ui_any_ctx_menu_is_open()) + { + take = 1; + df_gfx_request_frame(); + window->menu_bar_focused = 0; + } + } + + //- rjf: try hotkey presses + if(!take && event->kind == OS_EventKind_Press) { DF_Binding binding = {event->key, event->flags}; DF_CmdSpecList spec_candidates = df_cmd_spec_list_from_binding(scratch.arena, binding); @@ -159,7 +236,7 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) df_cmd_params_mark_slot(¶ms, DF_CmdParamSlot_CmdSpec); } U32 hit_char = os_codepoint_from_event_flags_and_key(event->flags, event->key); - os_eat_event(&events, event); + take = 1; df_push_cmd__root(¶ms, run_spec); if(event->flags & OS_EventFlag_Alt) { @@ -172,7 +249,9 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) } df_gfx_request_frame(); } - else if(event->kind == OS_EventKind_Text) + + //- rjf: try text events + if(!take && event->kind == OS_EventKind_Text) { String32 insertion32 = str32(&event->character, 1); String8 insertion8 = str8_from_32(scratch.arena, insertion32); @@ -181,87 +260,51 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) df_cmd_params_mark_slot(¶ms, DF_CmdParamSlot_String); df_push_cmd__root(¶ms, spec); df_gfx_request_frame(); - os_eat_event(&events, event); + take = 1; if(event->flags & OS_EventFlag_Alt) { window->menu_bar_focus_press_started = 0; } } - } - } - - //- rjf: menu bar focus - { - for(OS_Event *event = events.first, *next = 0; event != 0; event = next) - { - next = event->next; - DF_Window *ws = df_window_from_os_handle(event->window); - if(ws == 0) - { - continue; - } - B32 take = 0; - if(event->kind == OS_EventKind_Press && event->key == OS_Key_Alt && event->flags == 0 && event->is_repeat == 0) + + //- rjf: do fall-through + if(!take) { take = 1; - df_gfx_request_frame(); - ws->menu_bar_focused_on_press = ws->menu_bar_focused; - ws->menu_bar_key_held = 1; - ws->menu_bar_focus_press_started = 1; + params.os_event = event; + df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_OSEvent)); } - if(event->kind == OS_EventKind_Release && event->key == OS_Key_Alt && event->flags == 0 && event->is_repeat == 0) - { - take = 1; - df_gfx_request_frame(); - ws->menu_bar_key_held = 0; - } - if(ws->menu_bar_focused && event->kind == OS_EventKind_Press && event->key == OS_Key_Alt && event->flags == 0 && event->is_repeat == 0) - { - take = 1; - df_gfx_request_frame(); - ws->menu_bar_focused = 0; - } - else if(ws->menu_bar_focus_press_started && !ws->menu_bar_focused && event->kind == OS_EventKind_Release && event->flags == 0 && event->key == OS_Key_Alt && event->is_repeat == 0) - { - take = 1; - df_gfx_request_frame(); - ws->menu_bar_focused = !ws->menu_bar_focused_on_press; - ws->menu_bar_focus_press_started = 0; - } - else if(event->kind == OS_EventKind_Press && event->key == OS_Key_Esc && ws->menu_bar_focused && !ui_any_ctx_menu_is_open()) - { - take = 1; - df_gfx_request_frame(); - ws->menu_bar_focused = 0; - } - if(take) + + //- rjf: take + if(take && !skip) { os_eat_event(&events, event); } } } + ////////////////////////////// //- rjf: gather root-level commands + // DF_CmdList cmds = df_core_gather_root_cmds(scratch.arena); + ////////////////////////////// //- rjf: begin frame + // df_core_begin_frame(scratch.arena, &cmds, dt); df_gfx_begin_frame(scratch.arena, &cmds); + ////////////////////////////// //- rjf: queue drop for drag/drop - if(df_drag_is_active()) + // + if(queue_drag_drop) { - for(OS_Event *event = events.first; event != 0; event = event->next) - { - if(event->kind == OS_EventKind_Release && event->key == OS_Key_LeftMouseButton) - { - df_queue_drag_drop(); - break; - } - } + df_queue_drag_drop(); } + ////////////////////////////// //- rjf: auto-focus moused-over windows while dragging + // if(df_drag_is_active()) { B32 over_focused_window = 0; @@ -292,20 +335,26 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) } } + ////////////////////////////// //- rjf: update & render + // { d_begin_frame(); for(DF_Window *w = df_gfx_state->first_window; w != 0; w = w->next) { - df_window_update_and_render(scratch.arena, &events, w, &cmds); + df_window_update_and_render(scratch.arena, w, &cmds); } } + ////////////////////////////// //- rjf: end frontend frame, send signals, etc. + // df_gfx_end_frame(); df_core_end_frame(); + ////////////////////////////// //- rjf: submit rendering to all windows + // { r_begin_frame(); for(DF_Window *w = df_gfx_state->first_window; w != 0; w = w->next) @@ -317,32 +366,17 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data) r_end_frame(); } - //- rjf: take window closing events - for(OS_Event *e = events.first, *next = 0; e; e = next) - { - next = e->next; - if(e->kind == OS_EventKind_WindowClose) - { - for(DF_Window *w = df_gfx_state->first_window; w != 0; w = w->next) - { - if(os_handle_match(w->os, e->window)) - { - DF_CmdParams params = df_cmd_params_from_window(w); - df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_CloseWindow)); - break; - } - } - os_eat_event(&events, e); - } - } - + ////////////////////////////// //- rjf: determine frame time, record into history + // U64 end_time_us = os_now_microseconds(); U64 frame_time_us = end_time_us-begin_time_us; frame_time_us_history[frame_time_us_history_idx%ArrayCount(frame_time_us_history)] = frame_time_us; frame_time_us_history_idx += 1; + ////////////////////////////// //- rjf: end logging + // { String8 log = log_scope_end(scratch.arena); os_append_data_to_file_path(main_thread_log_path, log); diff --git a/src/ui/ui_basic_widgets.c b/src/ui/ui_basic_widgets.c index 3aced18d..2b7dfa72 100644 --- a/src/ui/ui_basic_widgets.c +++ b/src/ui/ui_basic_widgets.c @@ -200,7 +200,7 @@ ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size, next = n->next; // rjf: do not consume anything that doesn't fit a single-line's operations - if(n->v.delta_2s32.y != 0) + 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) { continue; } diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 14b4c54f..9892f329 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -95,7 +95,7 @@ ui_key_match(UI_Key a, UI_Key b) } //////////////////////////////// -//~ rjf: Event Functions +//~ rjf: Event Type Functions internal UI_EventNode * ui_event_list_push(Arena *arena, UI_EventList *list, UI_Event *v) @@ -115,57 +115,6 @@ ui_eat_event(UI_EventList *list, UI_EventNode *node) list->count -= 1; } -internal B32 -ui_key_press(UI_EventList *list, OS_EventFlags mods, OS_Key key) -{ - B32 result = 0; - for(UI_EventNode *n = list->first; n != 0; n = n->next) - { - if(n->v.kind == UI_EventKind_Press && n->v.key == key && n->v.modifiers == mods) - { - result = 1; - ui_eat_event(list, n); - break; - } - } - return result; -} - -internal B32 -ui_key_release(UI_EventList *list, OS_EventFlags mods, OS_Key key) -{ - B32 result = 0; - for(UI_EventNode *n = list->first; n != 0; n = n->next) - { - if(n->v.kind == UI_EventKind_Release && n->v.key == key && n->v.modifiers == mods) - { - result = 1; - ui_eat_event(list, n); - break; - } - } - return result; -} - -internal B32 -ui_text(UI_EventList *list, U32 character) -{ - 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) - { - if(n->v.kind == UI_EventKind_Text && str8_match(character_text, n->v.string, 0)) - { - result = 1; - ui_eat_event(list, n); - break; - } - } - scratch_end(scratch); - return result; -} - //////////////////////////////// //~ rjf: Text Operation Functions @@ -397,255 +346,6 @@ ui_push_string_replace_range(Arena *arena, String8 string, Rng1S64 col_range, St return result; } -//////////////////////////////// -//~ rjf: Navigation Action List Building & Consumption Functions - -#if 0 -internal void -ui_nav_action_list_push(Arena *arena, UI_NavActionList *list, UI_NavAction action) -{ - UI_NavActionNode *node = push_array(arena, UI_NavActionNode, 1); - DLLPushBack(list->first, list->last, node); - MemoryCopyStruct(&node->v, &action); - list->count += 1; -} - -internal void -ui_nav_eat_action_node(UI_NavActionList *list, UI_NavActionNode *node) -{ - DLLRemove(list->first, list->last, node); - list->count -= 1; -} - -//////////////////////////////// -//~ rjf: High Level Navigation Action => Text Operations - -internal B32 -ui_nav_char_is_scan_boundary(U8 c) -{ - return (char_is_alpha(c) || char_is_digit(c, 10) || c == '_'); -} - -internal S64 -ui_nav_scanned_column_from_column(String8 string, S64 start_column, Side side) -{ - S64 new_column = start_column; - S64 delta = (!!side)*2 - 1; - B32 found_text = 0; - B32 found_non_space = 0; - S64 start_off = delta < 0 ? delta : 0; - for(S64 col = start_column+start_off; 1 <= col && col <= string.size+1; col += delta) - { - U8 byte = (col <= string.size) ? string.str[col-1] : 0; - B32 is_non_space = !char_is_space(byte); - B32 is_name = ui_nav_char_is_scan_boundary(byte); - - if (((side == Side_Min) && (col == 1)) || - ((side == Side_Max) && (col == string.size+1)) || - (found_non_space && !is_non_space) || - (found_text && !is_name)) - { - new_column = col + (!side && col != 1); - break; - } else if (!found_text && is_name) { - found_text = 1; - } else if (!found_non_space && is_non_space ) { - found_non_space = 1; - } - } - return new_column; -} - -internal UI_NavTxtOp -ui_nav_single_line_txt_op_from_action(Arena *arena, UI_NavAction action, String8 line, TxtPt cursor, TxtPt mark) -{ - TxtPt next_cursor = cursor; - TxtPt next_mark = mark; - TxtRng range = {0}; - String8 replace = {0}; - String8 copy = {0}; - UI_NavTxtOpFlags flags = 0; - Vec2S32 delta = action.delta; - Vec2S32 original_delta = delta; - - //- rjf: resolve high-level delta into byte delta, based on unit - switch(action.delta_unit) - { - default:{}break; - case UI_NavDeltaUnit_Element: - { - // TODO(rjf): this should account for multi-byte characters in UTF-8... for now, just assume ASCII and - // no-op - }break; - case UI_NavDeltaUnit_Chunk: - { - delta.x = (S32)ui_nav_scanned_column_from_column(line, cursor.column, delta.x > 0 ? Side_Max : Side_Min) - cursor.column; - }break; - case UI_NavDeltaUnit_Whole: - case UI_NavDeltaUnit_EndPoint: - { - S64 first_nonwhitespace_column = 1; - for(U64 idx = 0; idx < line.size; idx += 1) - { - if(!char_is_space(line.str[idx])) - { - first_nonwhitespace_column = (S64)idx + 1; - break; - } - } - S64 home_dest_column = (cursor.column == first_nonwhitespace_column) ? 1 : first_nonwhitespace_column; - delta.x = (delta.x > 0) ? ((S64)line.size+1 - cursor.column) : (home_dest_column - cursor.column); - }break; - } - - //- rjf: zero delta - if(!txt_pt_match(cursor, mark) && action.flags & UI_NavActionFlag_ZeroDeltaOnSelect) - { - delta = v2s32(0, 0); - } - - //- rjf: form next cursor - if(txt_pt_match(cursor, mark) || !(action.flags & UI_NavActionFlag_ZeroDeltaOnSelect)) - { - next_cursor.column += delta.x; - } - - //- rjf: cap at line - if(action.flags & UI_NavActionFlag_CapAtLine) - { - next_cursor.column = Clamp(1, next_cursor.column, (S64)(line.size+1)); - } - - //- rjf: in some cases, we want to pick a selection side based on the delta - if(!txt_pt_match(cursor, mark) && action.flags & UI_NavActionFlag_PickSelectSide) - { - if(original_delta.x < 0 || original_delta.y < 0) - { - next_cursor = next_mark = txt_pt_min(cursor, mark); - } - else if(original_delta.x > 0 || original_delta.y > 0) - { - next_cursor = next_mark = txt_pt_max(cursor, mark); - } - } - - //- rjf: copying - if(action.flags & UI_NavActionFlag_Copy) - { - if(cursor.line == mark.line) - { - copy = str8_substr(line, r1u64(cursor.column-1, mark.column-1)); - flags |= UI_NavTxtOpFlag_Copy; - } - else - { - flags |= UI_NavTxtOpFlag_Invalid; - } - } - - //- rjf: pasting - if(action.flags & UI_NavActionFlag_Paste) - { - range = txt_rng(cursor, mark); - replace = os_get_clipboard_text(arena); - next_cursor = next_mark = txt_pt(cursor.line, cursor.column+replace.size); - } - - //- rjf: deletion - if(action.flags & UI_NavActionFlag_Delete) - { - TxtPt new_pos = txt_pt_min(next_cursor, next_mark); - range = txt_rng(next_cursor, next_mark); - replace = str8_lit(""); - next_cursor = next_mark = new_pos; - } - - //- rjf: stick mark to cursor, when we don't want to keep it in the same spot - if(!(action.flags & UI_NavActionFlag_KeepMark)) - { - next_mark = next_cursor; - } - - //- rjf: insertion - if(action.insertion.size != 0) - { - range = txt_rng(cursor, mark); - replace = push_str8_copy(arena, action.insertion); - next_cursor = next_mark = txt_pt(range.min.line, range.min.column + action.insertion.size); - } - - //- rjf: replace & commit -> replace entire range - if(action.flags & UI_NavActionFlag_ReplaceAndCommit) - { - range = txt_rng(txt_pt(cursor.line, 1), txt_pt(cursor.line, line.size+1)); - } - - //- rjf: determine if this event should be taken, based on bounds of cursor - { - if(next_cursor.column > line.size+1 || 1 > next_cursor.column || action.delta.y != 0) - { - flags |= UI_NavTxtOpFlag_Invalid; - } - next_cursor.column = Clamp(1, next_cursor.column, line.size+replace.size+1); - next_mark.column = Clamp(1, next_mark.column, line.size+replace.size+1); - } - - //- rjf: build+fill - UI_NavTxtOp op = {0}; - { - op.flags = flags; - op.replace = replace; - op.copy = copy; - op.range = range; - op.cursor = next_cursor; - op.mark = next_mark; - } - return op; -} - -//////////////////////////////// -//~ rjf: Single-Line String Modification - -internal String8 -ui_nav_push_string_replace_range(Arena *arena, String8 string, Rng1S64 col_range, String8 replace) -{ - //- rjf: convert to offset range - Rng1U64 range = - { - (U64)(col_range.min-1), - (U64)(col_range.max-1), - }; - - //- rjf: clamp range - if(range.min > string.size) - { - range.min = 0; - } - if(range.max > string.size) - { - range.max = string.size; - } - - //- rjf: calculate new size - U64 old_size = string.size; - U64 new_size = old_size - (range.max - range.min) + replace.size; - - //- rjf: push+fill new string storage - U8 *push_base = push_array(arena, U8, new_size); - { - MemoryCopy(push_base+0, string.str, range.min); - MemoryCopy(push_base+range.min+replace.size, string.str+range.max, string.size-range.max); - if(replace.str != 0) - { - MemoryCopy(push_base+range.min, replace.str, replace.size); - } - } - - return str8(push_base, new_size); -} - -#endif - //////////////////////////////// //~ rjf: Sizes @@ -826,6 +526,62 @@ ui_dt(void) return ui_state->animation_dt; } +//- 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) + { + if(n->v.kind == UI_EventKind_Press && n->v.key == key && n->v.modifiers == mods) + { + result = 1; + ui_eat_event(list, n); + break; + } + } + return result; +} + +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) + { + if(n->v.kind == UI_EventKind_Release && n->v.key == key && n->v.modifiers == mods) + { + result = 1; + ui_eat_event(list, n); + break; + } + } + return result; +} + +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) + { + if(n->v.kind == UI_EventKind_Text && str8_match(character_text, n->v.string, 0)) + { + result = 1; + ui_eat_event(list, n); + break; + } + } + scratch_end(scratch); + return result; +} + //- rjf: drag data internal Vec2F32 @@ -1008,11 +764,11 @@ ui_begin_build(OS_Handle window, UI_EventList *events, UI_IconInfo *icon_info, F B32 nav_next = 0; B32 nav_prev = 0; Axis2 axis_lock = Axis2_Invalid; - if(ui_key_press(events, 0, OS_Key_Tab)) + if(ui_key_press(0, OS_Key_Tab)) { nav_next = 1; } - if(ui_key_press(events, OS_EventFlag_Shift, OS_Key_Tab)) + if(ui_key_press(OS_EventFlag_Shift, OS_Key_Tab)) { nav_prev = 1; } @@ -1170,7 +926,7 @@ ui_begin_build(OS_Handle window, UI_EventList *events, UI_IconInfo *icon_info, F //- rjf: some child has the active focus -> accept escape keys to pop from the active key stack if(!ui_key_match(ui_key_zero(), nav_root->default_nav_focus_active_key)) { - for(;ui_key_press(events, 0, OS_Key_Esc);) + for(;ui_key_press(0, OS_Key_Esc);) { UI_Box *prev_focus_root = nav_root; for(UI_Box *focus_root = ui_box_from_key(nav_root->default_nav_focus_active_key); @@ -1201,7 +957,7 @@ ui_begin_build(OS_Handle window, UI_EventList *events, UI_IconInfo *icon_info, F for(UI_EventNode *n = events->first; n != 0; n = n->next) { UI_Event *event = &n->v; - if(event->kind == OS_EventKind_Press && + if(event->kind == UI_EventKind_Press && event->key == OS_Key_LeftMouseButton && !contains_2f32(active_box->rect, ui_mouse())) { @@ -1318,7 +1074,7 @@ ui_end_build(void) ProfBeginFunction(); //- rjf: escape -> close context menu - if(ui_state->ctx_menu_open != 0 && ui_key_press(ui_events(), 0, OS_Key_Esc)) + if(ui_state->ctx_menu_open != 0 && ui_key_press(0, OS_Key_Esc)) { ui_ctx_menu_close(); } @@ -2627,7 +2383,7 @@ ui_do_single_line_string_edits(TxtPt *cursor, TxtPt *mark, U64 string_max, Strin next = n->next; // rjf: do not consume anything that doesn't fit a single-line's operations - if(n->v.delta_2s32.y != 0) + 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) { continue; } @@ -2742,7 +2498,7 @@ ui_signal_from_box(UI_Box *box) //- rjf: mouse presses in box -> set hot/active; mark signal accordingly if(box->flags & UI_BoxFlag_MouseClickable && - evt->kind == OS_EventKind_Press && + evt->kind == UI_EventKind_Press && evt_mouse_in_bounds && evt_key_is_mouse) { @@ -2776,7 +2532,7 @@ ui_signal_from_box(UI_Box *box) //- rjf: mouse releases in active box -> unset active; mark signal accordingly if(box->flags & UI_BoxFlag_MouseClickable && - evt->kind == OS_EventKind_Release && + evt->kind == UI_EventKind_Release && ui_key_match(ui_state->active_box_key[evt_mouse_button_kind], box->key) && evt_mouse_in_bounds && evt_key_is_mouse) @@ -2789,7 +2545,7 @@ ui_signal_from_box(UI_Box *box) //- rjf: mouse releases outside active box -> unset hot/active if(box->flags & UI_BoxFlag_MouseClickable && - evt->kind == OS_EventKind_Release && + evt->kind == UI_EventKind_Release && ui_key_match(ui_state->active_box_key[evt_mouse_button_kind], box->key) && !evt_mouse_in_bounds && evt_key_is_mouse) @@ -2803,7 +2559,7 @@ ui_signal_from_box(UI_Box *box) //- rjf: focus is hot & keyboard click -> mark signal if(box->flags & UI_BoxFlag_KeyboardClickable && is_focus_hot && - evt->kind == OS_EventKind_Press && + evt->kind == UI_EventKind_Press && evt->key == OS_Key_Return) { sig.f |= UI_SignalFlag_KeyboardPressed; @@ -2850,7 +2606,7 @@ ui_signal_from_box(UI_Box *box) //- rjf: scrolling if(box->flags & UI_BoxFlag_Scroll && - evt->kind == OS_EventKind_Scroll && + evt->kind == UI_EventKind_Scroll && evt->modifiers != OS_EventFlag_Ctrl && evt_mouse_in_bounds) { @@ -2871,7 +2627,7 @@ ui_signal_from_box(UI_Box *box) //- rjf: view scrolling if(box->flags & UI_BoxFlag_ViewScroll && box->first_touched_build_index != box->last_touched_build_index && - evt->kind == OS_EventKind_Scroll && + evt->kind == UI_EventKind_Scroll && evt->modifiers != OS_EventFlag_Ctrl && evt_mouse_in_bounds) { diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 57106585..3f664541 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -88,6 +88,7 @@ enum typedef enum UI_EventDeltaUnit { + UI_EventDeltaUnit_Null, UI_EventDeltaUnit_Char, UI_EventDeltaUnit_Word, UI_EventDeltaUnit_Line, @@ -149,78 +150,6 @@ struct UI_TxtOp TxtPt mark; }; -#if 0 -//////////////////////////////// -//~ rjf: Navigation Types - -typedef enum UI_NavDeltaUnit -{ - UI_NavDeltaUnit_Element, - UI_NavDeltaUnit_Chunk, - UI_NavDeltaUnit_Whole, - UI_NavDeltaUnit_EndPoint, - UI_NavDeltaUnit_COUNT, -} -UI_NavDeltaUnit; - -typedef U32 UI_NavActionFlags; -enum -{ - UI_NavActionFlag_KeepMark = (1<<0), - UI_NavActionFlag_Delete = (1<<1), - UI_NavActionFlag_Copy = (1<<2), - UI_NavActionFlag_Paste = (1<<3), - UI_NavActionFlag_ZeroDeltaOnSelect = (1<<4), - UI_NavActionFlag_PickSelectSide = (1<<5), - UI_NavActionFlag_CapAtLine = (1<<6), - UI_NavActionFlag_ExplicitDirectional = (1<<7), - UI_NavActionFlag_ReplaceAndCommit = (1<<8), -}; - -typedef struct UI_NavAction UI_NavAction; -struct UI_NavAction -{ - UI_NavActionFlags flags; - Vec2S32 delta; - UI_NavDeltaUnit delta_unit; - String8 insertion; -}; - -typedef struct UI_NavActionNode UI_NavActionNode; -struct UI_NavActionNode -{ - UI_NavActionNode *next; - UI_NavActionNode *prev; - UI_NavAction v; -}; - -typedef struct UI_NavActionList UI_NavActionList; -struct UI_NavActionList -{ - UI_NavActionNode *first; - UI_NavActionNode *last; - U64 count; -}; - -typedef U32 UI_NavTxtOpFlags; -enum -{ - UI_NavTxtOpFlag_Invalid = (1<<0), - UI_NavTxtOpFlag_Copy = (1<<1), -}; - -typedef struct UI_NavTxtOp UI_NavTxtOp; -struct UI_NavTxtOp -{ - UI_NavTxtOpFlags flags; - String8 replace; - String8 copy; - TxtRng range; - TxtPt cursor; - TxtPt mark; -}; -#endif - //////////////////////////////// //~ rjf: Keys @@ -636,13 +565,10 @@ internal UI_Key ui_key_from_stringf(UI_Key seed_key, char *fmt, ...); internal B32 ui_key_match(UI_Key a, UI_Key b); //////////////////////////////// -//~ rjf: Event Functions +//~ 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 B32 ui_key_press(UI_EventList *list, OS_EventFlags mods, OS_Key key); -internal B32 ui_key_release(UI_EventList *list, OS_EventFlags mods, OS_Key key); -internal B32 ui_text(UI_EventList *list, U32 character); //////////////////////////////// //~ rjf: Text Operation Functions @@ -652,26 +578,6 @@ internal S64 ui_scanned_column_from_column(String8 string, S64 start_column, Sid internal UI_TxtOp ui_single_line_txt_op_from_event(Arena *arena, UI_Event *event, String8 string, TxtPt cursor, TxtPt mark); internal String8 ui_push_string_replace_range(Arena *arena, String8 string, Rng1S64 range, String8 replace); -#if 0 -//////////////////////////////// -//~ rjf: Navigation Action List Building & Consumption Functions - -internal void ui_nav_action_list_push(Arena *arena, UI_NavActionList *list, UI_NavAction action); -internal void ui_nav_eat_action_node(UI_NavActionList *list, UI_NavActionNode *node); - -//////////////////////////////// -//~ rjf: High Level Navigation Action => Text Operations - -internal B32 ui_nav_char_is_scan_boundary(U8 c); -internal S64 ui_nav_scanned_column_from_column(String8 string, S64 start_column, Side side); -internal UI_NavTxtOp ui_nav_single_line_txt_op_from_action(Arena *arena, UI_NavAction action, String8 line, TxtPt cursor, TxtPt mark); - -//////////////////////////////// -//~ rjf: Single-Line String Modification - -internal String8 ui_nav_push_string_replace_range(Arena *arena, String8 string, Rng1S64 col_range, String8 replace); -#endif - //////////////////////////////// //~ rjf: Size Type Functions @@ -730,6 +636,11 @@ 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 consumption helpers +internal B32 ui_key_press(OS_EventFlags mods, OS_Key key); +internal B32 ui_key_release(OS_EventFlags mods, OS_Key key); +internal B32 ui_text(U32 character); + //- rjf: drag data internal Vec2F32 ui_drag_start_mouse(void); internal Vec2F32 ui_drag_delta(void);