From 3b0064d8cd23ef1fa648602150edc9e9a1213493 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Fri, 9 May 2025 10:34:00 -0700 Subject: [PATCH] multi-toggle-switch-toggle-in-single-press --- src/raddbg/raddbg_widgets.c | 35 ++++++++++++++++++++++++++++++++--- src/ui/ui_core.h | 2 +- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/raddbg/raddbg_widgets.c b/src/raddbg/raddbg_widgets.c index 9b47d471..9c8b872e 100644 --- a/src/raddbg/raddbg_widgets.c +++ b/src/raddbg/raddbg_widgets.c @@ -3492,6 +3492,7 @@ rd_cell(RD_CellParams *params, String8 string) UI_PrefHeight(ui_px(height_px, 1.f)) UI_CornerRadius(floor_f32(height_px/2.f - 1.f)) UI_TagF(is_toggled ? "good_pop" : "") + UI_GroupKey(ui_key_from_stringf(ui_key_zero(), "toggle_switch_group_key")) { UI_Box *switch_box = ui_build_box_from_stringf(UI_BoxFlag_DrawHotEffects|UI_BoxFlag_DrawBorder|UI_BoxFlag_DrawBackground|UI_BoxFlag_Clickable, "toggle_switch"); UI_Parent(switch_box) @@ -3512,15 +3513,43 @@ rd_cell(RD_CellParams *params, String8 string) UI_PrefHeight(ui_px(toggler_size_px, 1.f)) UI_CornerRadius(floor_f32(toggler_size_px/2.f - 1.f)) { - UI_Box *toggler = ui_build_box_from_key(UI_BoxFlag_DrawBackground|UI_BoxFlag_DrawDropShadow, ui_key_zero()); + ui_build_box_from_key(UI_BoxFlag_DrawBackground|UI_BoxFlag_DrawDropShadow, ui_key_zero()); } } ui_spacer(ui_pct(1.f-toggle_t, 0)); } UI_Signal switch_sig = ui_signal_from_box(switch_box); - if(ui_pressed(switch_sig)) + if(ui_dragging(switch_sig)) { - params->toggled_out[0] ^= 1; + // rjf: press -> toggle, & gather this key + if(ui_pressed(switch_sig)) + { + ui_store_drag_struct(&switch_box->key); + params->toggled_out[0] ^= 1; + } + + // rjf: dragging -> check if key is in batch of touched keys. if so, do nothing, otherwise, toggle. + // always store this new key if not in batch + String8 all_keys_data = ui_get_drag_data(sizeof(UI_Key)); + UI_Key *keys = (UI_Key *)all_keys_data.str; + U64 keys_count = all_keys_data.size / sizeof(UI_Key); + B32 key_is_touched = 0; + for EachIndex(idx, keys_count) + { + if(ui_key_match(keys[idx], switch_box->key)) + { + key_is_touched = 1; + break; + } + } + if(!key_is_touched) + { + params->toggled_out[0] ^= 1; + UI_Key *new_keys = push_array(scratch.arena, UI_Key, keys_count+1); + MemoryCopy(new_keys, keys, sizeof(UI_Key)*keys_count); + new_keys[keys_count] = switch_box->key; + ui_store_drag_data(str8((U8 *)new_keys, sizeof(UI_Key) * (keys_count+1))); + } } } if(ui_top_text_alignment() == UI_TextAlign_Center) diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 5cec6662..1c915ee5 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -827,7 +827,7 @@ internal UI_State *ui_get_selected_state(void); internal Arena * ui_build_arena(void); internal OS_Handle ui_window(void); internal Vec2F32 ui_mouse(void); -internal FNT_Tag ui_icon_font(void); +internal FNT_Tag ui_icon_font(void); internal String8 ui_icon_string_from_kind(UI_IconKind icon_kind); internal F32 ui_dt(void);