From 275ffcf143a44bb8d71ff56f88f53ff7def2f2aa Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sun, 19 May 2024 11:06:09 -0400 Subject: [PATCH] Got the first 'input box' to work. Did some changes to keyboard input Renamed KeyboardKey to KeyCode, redid the encoding layout (preemtively getting ready for SDL later as well) I got the input box working but it has no constraints and needs to be lifted. The scroll box construction does as well. --- code/sectr/app/screen.odin | 15 +- code/sectr/engine/client_api.odin | 4 +- code/sectr/grime/grime.odin | 10 +- code/sectr/grime/string_interning.odin | 5 +- code/sectr/input/input.odin | 334 ++++++----------- code/sectr/input/input_raylib.odin | 496 +++++++++++++------------ code/sectr/input/input_sdl.odin | 0 code/sectr/input/keyboard_qwerty.odin | 239 ++++++++++++ code/sectr/input/keycode.odin | 154 ++++++++ code/sectr/ui/core/Readme.md | 2 +- code/sectr/ui/core/box.odin | 2 + code/sectr/ui/core/signal.odin | 6 +- code/sectr/ui/core/state.odin | 15 - 13 files changed, 782 insertions(+), 500 deletions(-) create mode 100644 code/sectr/input/input_sdl.odin create mode 100644 code/sectr/input/keyboard_qwerty.odin create mode 100644 code/sectr/input/keycode.odin diff --git a/code/sectr/app/screen.odin b/code/sectr/app/screen.odin index b8ef33d..cfeb7d4 100644 --- a/code/sectr/app/screen.odin +++ b/code/sectr/app/screen.odin @@ -266,18 +266,23 @@ ui_screen_settings_menu :: proc( captures : rawptr = nil ) -> ( should_raise : b style.corner_radii[0] = 0.35 } @static value_str : Array(rune) - if value_str.data == nil { + if value_str.header == nil { error : AllocatorError value_str, error = array_init_reserve(rune, persistent_slab_allocator(), Kilo) - ensure(error != AllocatorError.None, "Failed to allocate array for value_str of input_box") - array_append( & value_str, rune('_')) + ensure(error == AllocatorError.None, "Failed to allocate array for value_str of input_box") + } + if input_box.pressed { + array_clear( value_str ) } if input_box.active { array_append( & value_str, input.keyboard_events.chars_pressed ) array_clear( input.keyboard_events.chars_pressed ) } else if input_box.was_active { - + value, success := parse_uint(to_string(array_to_slice(value_str))) + if success { + config.engine_refresh_hz = value + } } else { array_clear( value_str) @@ -286,7 +291,7 @@ ui_screen_settings_menu :: proc( captures : rawptr = nil ) -> ( should_raise : b // input_box { ui_parent(input_box) - value_txt := ui_text("settings_menu.engine_refresh.refresh_value", to_str_runes_pair(value_str)) + value_txt := ui_text("settings_menu.engine_refresh.refresh_value", to_str_runes_pair(array_to_slice(value_str))) value_txt.layout.text_alignment = vec2(1, 0.5) } diff --git a/code/sectr/engine/client_api.odin b/code/sectr/engine/client_api.odin index 2dc6ee0..82ee63d 100644 --- a/code/sectr/engine/client_api.odin +++ b/code/sectr/engine/client_api.odin @@ -103,7 +103,7 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem for & input in input_data { using input error : AllocatorError - keyboard_events.keys_pressed, error = array_init_reserve(KeyboardKey, persistent_slab_allocator(), Kilo) + keyboard_events.keys_pressed, error = array_init_reserve(KeyCode, persistent_slab_allocator(), Kilo) ensure(error == AllocatorError.None, "Failed to allocate input.keyboard_events.keys_pressed array") keyboard_events.chars_pressed, error = array_init_reserve(rune, persistent_slab_allocator(), Kilo) ensure(error == AllocatorError.None, "Failed to allocate input.keyboard_events.chars_pressed array") @@ -346,7 +346,7 @@ tick :: proc( host_delta_time : f64, host_delta_ns : Duration ) -> b32 // Timing { // profile("Client tick timing processing") - config.engine_refresh_hz = uint(monitor_refresh_hz) + // config.engine_refresh_hz = uint(monitor_refresh_hz) // config.engine_refresh_hz = 6 frametime_target_ms = 1.0 / f64(config.engine_refresh_hz) * S_To_MS sub_ms_granularity_required := frametime_target_ms <= Frametime_High_Perf_Threshold_MS diff --git a/code/sectr/grime/grime.odin b/code/sectr/grime/grime.odin index ab19b01..dd2d703 100644 --- a/code/sectr/grime/grime.odin +++ b/code/sectr/grime/grime.odin @@ -75,6 +75,10 @@ import "core:os" file_write :: os.write import "core:path/filepath" file_name_from_path :: filepath.short_stem +import "core:strconv" + parse_f32 :: strconv.parse_f32 + parse_u64 :: strconv.parse_u64 + parse_uint :: strconv.parse_uint import str "core:strings" StringBuilder :: str.Builder str_builder_from_bytes :: str.builder_from_bytes @@ -261,6 +265,11 @@ to_string :: proc { str_builder_to_string, } +to_str_runes_pair :: proc { + to_str_runes_pair_via_runes, + to_str_runes_pair_via_string, +} + vec3 :: proc { vec3_via_f32s, bivec3_to_vec3, @@ -283,7 +292,6 @@ to_ui_layout_side :: proc { } ui_compute_layout :: proc { - ui_core_compute_layout, ui_box_compute_layout, } diff --git a/code/sectr/grime/string_interning.odin b/code/sectr/grime/string_interning.odin index 7bfda89..ec8732b 100644 --- a/code/sectr/grime/string_interning.odin +++ b/code/sectr/grime/string_interning.odin @@ -23,9 +23,8 @@ StrRunesPair :: struct { str : string, runes : []rune, } -to_str_runes_pair :: proc ( content : string ) -> StrRunesPair { - return { content, to_runes(content) } -} +to_str_runes_pair_via_string :: #force_inline proc ( content : string ) -> StrRunesPair { return { content, to_runes(content) } } +to_str_runes_pair_via_runes :: #force_inline proc ( content : []rune ) -> StrRunesPair { return { to_string(content), content } } StringCache :: struct { slab : Slab, diff --git a/code/sectr/input/input.odin b/code/sectr/input/input.odin index 9d72bef..84b547f 100644 --- a/code/sectr/input/input.odin +++ b/code/sectr/input/input.odin @@ -21,233 +21,6 @@ btn_released :: proc ( btn : DigitalBtn ) -> b32 { return btn.ended_down == false && btn.half_transitions > 0 } -MaxKeyboardKeys :: 256 -KeyboardKey :: enum u32 { - null = 0x00, - - enter = 0x01, - tab = 0x02, - space = 0x03, - bracket_open = 0x04, - bracket_close = 0x05, - semicolon = 0x06, - apostrophe = 0x07, - comma = 0x08, - period = 0x09, - - // 0x0A - // 0x0B - // 0x0C - // 0x0D - // 0x0E - // 0x0F - - caps_lock = 0x10, - scroll_lock = 0x11, - num_lock = 0x12, - left_alt = 0x13, - left_shit = 0x14, - left_control = 0x15, - right_alt = 0x16, - right_shift = 0x17, - right_control = 0x18, - - // 0x19 - // 0x1A - // 0x1B - // 0x1C - // 0x1D - // 0x1C - // 0x1D - - escape = 0x1F, - F1 = 0x20, - F2 = 0x21, - F3 = 0x22, - F4 = 0x23, - F5 = 0x24, - F6 = 0x25, - F7 = 0x26, - F8 = 0x27, - F9 = 0x28, - F10 = 0x29, - F11 = 0x2A, - F12 = 0x2B, - - print_screen = 0x2C, - pause = 0x2D, - // = 0x2E, - - backtick = 0x2F, - nrow_0 = 0x30, - nrow_1 = 0x31, - nrow_2 = 0x32, - nrow_3 = 0x33, - nrow_4 = 0x34, - nrow_5 = 0x35, - nrow_6 = 0x36, - nrow_7 = 0x37, - nrow_8 = 0x38, - nrow_9 = 0x39, - hyphen = 0x3A, - equals = 0x3B, - backspace = 0x3C, - - backslash = 0x3D, - slash = 0x3E, - // = 0x3F, - // = 0x40, - - A = 0x41, - B = 0x42, - C = 0x43, - D = 0x44, - E = 0x45, - F = 0x46, - G = 0x47, - H = 0x48, - I = 0x49, - J = 0x4A, - K = 0x4B, - L = 0x4C, - M = 0x4D, - N = 0x4E, - O = 0x4F, - P = 0x50, - Q = 0x51, - R = 0x52, - S = 0x53, - T = 0x54, - U = 0x55, - V = 0x56, - W = 0x57, - X = 0x58, - Y = 0x59, - Z = 0x5A, - - insert = 0x5B, - delete = 0x5C, - home = 0x5D, - end = 0x5E, - page_up = 0x5F, - page_down = 0x60, - - npad_0 = 0x61, - npad_1 = 0x62, - npad_2 = 0x63, - npad_3 = 0x64, - npad_4 = 0x65, - npad_5 = 0x66, - npad_6 = 0x67, - npad_7 = 0x68, - npad_8 = 0x69, - npad_9 = 0x6A, - npad_decimal = 0x6B, - npad_equals = 0x6C, - npad_plus = 0x6D, - npad_minus = 0x6E, - npad_multiply = 0x6F, - npad_divide = 0x70, - npad_enter = 0x71, - - count = 0x72 -} - -KeyboardState :: struct #raw_union { - keys : [MaxKeyboardKeys] DigitalBtn, - using individual : struct { - enter, - tab, - space, - bracket_open, - bracket_close, - semicolon, - apostrophe, - comma, - period : DigitalBtn, - - __0x0A_0x0F_Unassigned__ : [ 6 * size_of( DigitalBtn )] u8, - - caps_lock, - scroll_lock, - num_lock, - left_alt, - left_shift, - left_control, - right_alt, - right_shift, - right_control : DigitalBtn, - - __0x19_0x1D_Unassigned__ : [ 6 * size_of( DigitalBtn )] u8, - - escape, - F1, - F2, - F3, - F4, - F5, - F6, - F7, - F8, - F9, - F10, - F11, - F12 : DigitalBtn, - - print_screen, - pause : DigitalBtn, - - __0x2E_Unassigned__ : [size_of(DigitalBtn)] u8, - - backtick, - nrow_0, - nrow_1, - nrow_2, - nrow_3, - nrow_4, - nrow_5, - nrow_6, - nrow_7, - nrow_8, - nrow_9, - hyphen, - equals, - backspace : DigitalBtn, - - backslash, - slash : DigitalBtn, - - __0x3F_0x40_Unassigned__ : [ 2 * size_of(DigitalBtn)] u8, - - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z : DigitalBtn, - - insert, - delete, - home, - end, - page_up, - page_down : DigitalBtn, - - npad_0, - npad_1, - npad_2, - npad_3, - npad_4, - npad_5, - npad_6, - npad_7, - npad_8, - npad_9, - npad_decimal, - npad_equals, - npad_plus, - npad_minus, - npad_multiply, - npad_divide, - npad_enter : DigitalBtn - } -} - MaxMouseBtns :: 16 MouseBtn :: enum u32 { Left = 0x0, @@ -261,6 +34,111 @@ MouseBtn :: enum u32 { count } +KeyboardState :: struct #raw_union { + keys : [KeyCode.count] DigitalBtn, + using individual : struct { + + ignored : DigitalBtn, + + __0x02_0x07_Unassigned__ : [ 6 * size_of( DigitalBtn)] u8, + + tab, backspace : DigitalBtn, + + right, left, up, down : DigitalBtn, + + enter : DigitalBtn, + + __0x0F_Unassigned__ : [ 1 * size_of( DigitalBtn)] u8, + + caps_lock, + scroll_lock, + num_lock : DigitalBtn, + + left_alt, + left_shift, + left_control, + right_alt, + right_shift, + right_control : DigitalBtn, + + __0x19_Unassigned__ : [ 1 * size_of( DigitalBtn )] u8, + + pause, + escape, + home, + end, + page_up, + page_down, + space : DigitalBtn, + + exlamation, + quote_dbl, + hash, + dollar, + percent, + ampersand, + quote, + paren_open, + paren_close, + asterisk, + plus, + comma, + minus, + period, + slash : DigitalBtn, + + nrow_0, + nrow_1, + nrow_2, + nrow_3, + nrow_4, + nrow_5, + nrow_6, + nrow_7, + nrow_8, + nrow_9, + + __0x3A_Unassigned__ : [ 1 * size_of(DigitalBtn)] u8, + + semicolon, + less, + equals, + greater, + question, + at : DigitalBtn, + + A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z : DigitalBtn, + + bracket_open, + backslash, + bracket_close, + underscore, + backtick : DigitalBtn, + + kpad_0, + kpad_1, + kpad_2, + kpad_3, + kpad_4, + kpad_5, + kpad_6, + kpad_7, + kpad_8, + kpad_9, + kpad_decimal, + kpad_equals, + kpad_plus, + kpad_minus, + kpad_multiply, + kpad_divide, + kpad_enter : DigitalBtn, + + F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12 : DigitalBtn, + + insert, delete : DigitalBtn, + } +} + MouseState :: struct { using _ : struct #raw_union { btns : [16] DigitalBtn, @@ -288,6 +166,6 @@ InputState :: struct { // TODO(Ed): Whats the lifetime of these events? (So far we're picking per full-frame) KeyboardEvents :: struct { - keys_pressed : Array(KeyboardKey), + keys_pressed : Array(KeyCode), chars_pressed : Array(rune), } diff --git a/code/sectr/input/input_raylib.odin b/code/sectr/input/input_raylib.odin index c03f093..735f2de 100644 --- a/code/sectr/input/input_raylib.odin +++ b/code/sectr/input/input_raylib.odin @@ -31,22 +31,21 @@ poll_input :: proc( old, new : ^ InputState ) entry_old := & old.keyboard.keys[id - 1] entry_new := & new.keyboard.keys[id - 1] - key_id := cast(KeyboardKey) id + key_id := cast(KeyCode) id is_down := cast(b32) rl.IsKeyDown( to_raylib_key(id) ) input_process_digital_btn( entry_old, entry_new, is_down ) } } - DeadBound_1 :: 0x0A - DeadBound_2 :: 0x2E + DeadBound_1 :: 0x02 + DeadBound_2 :: 0x0F DeadBound_3 :: 0x19 - DeadBound_4 :: 0x3F - check_range( old, new, cast(i32) KeyboardKey.enter, DeadBound_1 ) - check_range( old, new, cast(i32) KeyboardKey.caps_lock, DeadBound_2 ) - check_range( old, new, cast(i32) KeyboardKey.escape, DeadBound_3 ) - check_range( old, new, cast(i32) KeyboardKey.backtick, DeadBound_4 ) - check_range( old, new, cast(i32) KeyboardKey.A, cast(i32) KeyboardKey.count ) + DeadBound_4 :: 0x3A + check_range( old, new, cast(i32) KeyCode.backspace, DeadBound_2 ) + check_range( old, new, cast(i32) KeyCode.caps_lock, DeadBound_3 ) + check_range( old, new, cast(i32) KeyCode.pause, DeadBound_4 ) + check_range( old, new, cast(i32) KeyCode.semicolon, cast(i32) KeyCode.count ) swap( & old.keyboard_events.keys_pressed, & new.keyboard_events.keys_pressed ) swap( & old.keyboard_events.chars_pressed, & new.keyboard_events.chars_pressed ) @@ -98,242 +97,157 @@ play_input :: proc( replay_file : os.Handle, input : ^ InputState ) { } } -to_key_from_raylib :: proc( key : rl.KeyboardKey ) -> KeyboardKey { - @static lookup_table := [?] KeyboardKey { - KeyboardKey.null, - KeyboardKey.enter, - KeyboardKey.tab, - KeyboardKey.space, - KeyboardKey.bracket_open, - KeyboardKey.bracket_close, - KeyboardKey.semicolon, - KeyboardKey.apostrophe, - KeyboardKey.comma, - KeyboardKey.period, - cast(KeyboardKey) 0, // 0x0A - cast(KeyboardKey) 0, // 0x0B - cast(KeyboardKey) 0, // 0x0C - cast(KeyboardKey) 0, // 0x0D - cast(KeyboardKey) 0, // 0x0E - cast(KeyboardKey) 0, // 0x0F - KeyboardKey.caps_lock, - KeyboardKey.scroll_lock, - KeyboardKey.num_lock, - KeyboardKey.left_alt, - KeyboardKey.left_shit, - KeyboardKey.left_control, - KeyboardKey.right_alt, - KeyboardKey.right_shift, - KeyboardKey.right_control, - cast(KeyboardKey) 0, // 0x0F - cast(KeyboardKey) 0, // 0x0F - cast(KeyboardKey) 0, // 0x0F - cast(KeyboardKey) 0, // 0x0F - cast(KeyboardKey) 0, // 0x0F - cast(KeyboardKey) 0, // 0x0F - cast(KeyboardKey) 0, // 0x0F - KeyboardKey.escape, - KeyboardKey.F1, - KeyboardKey.F2, - KeyboardKey.F3, - KeyboardKey.F4, - KeyboardKey.F5, - KeyboardKey.F7, - KeyboardKey.F8, - KeyboardKey.F9, - KeyboardKey.F10, - KeyboardKey.F11, - KeyboardKey.F12, - KeyboardKey.print_screen, - KeyboardKey.pause, - cast(KeyboardKey) 0, // 0x2E - KeyboardKey.backtick, - KeyboardKey.nrow_0, - KeyboardKey.nrow_1, - KeyboardKey.nrow_2, - KeyboardKey.nrow_3, - KeyboardKey.nrow_4, - KeyboardKey.nrow_5, - KeyboardKey.nrow_6, - KeyboardKey.nrow_7, - KeyboardKey.nrow_8, - KeyboardKey.nrow_9, - KeyboardKey.hyphen, - KeyboardKey.equals, - KeyboardKey.backspace, - KeyboardKey.backslash, - KeyboardKey.slash, - cast(KeyboardKey) 0, // 0x3F - cast(KeyboardKey) 0, // 0x40 - KeyboardKey.A, - KeyboardKey.B, - KeyboardKey.C, - KeyboardKey.D, - KeyboardKey.E, - KeyboardKey.F, - KeyboardKey.G, - KeyboardKey.H, - KeyboardKey.I, - KeyboardKey.J, - KeyboardKey.K, - KeyboardKey.L, - KeyboardKey.M, - KeyboardKey.N, - KeyboardKey.O, - KeyboardKey.P, - KeyboardKey.Q, - KeyboardKey.R, - KeyboardKey.S, - KeyboardKey.T, - KeyboardKey.U, - KeyboardKey.V, - KeyboardKey.W, - KeyboardKey.X, - KeyboardKey.Y, - KeyboardKey.Z, - KeyboardKey.insert, - KeyboardKey.delete, - KeyboardKey.home, - KeyboardKey.end, - KeyboardKey.page_up, - KeyboardKey.page_down, - KeyboardKey.npad_0, - KeyboardKey.npad_1, - KeyboardKey.npad_2, - KeyboardKey.npad_3, - KeyboardKey.npad_4, - KeyboardKey.npad_5, - KeyboardKey.npad_6, - KeyboardKey.npad_7, - KeyboardKey.npad_8, - KeyboardKey.npad_9, - KeyboardKey.npad_decimal, - KeyboardKey.npad_equals, - KeyboardKey.npad_plus, - KeyboardKey.npad_minus, - KeyboardKey.npad_multiply, - KeyboardKey.npad_divide, - KeyboardKey.npad_enter, } - return lookup_table[key] -} - to_raylib_key :: proc( key : i32 ) -> rl.KeyboardKey { - @static raylib_key_lookup_table := [?] rl.KeyboardKey { - rl.KeyboardKey.KEY_NULL, - rl.KeyboardKey.ENTER, - rl.KeyboardKey.TAB, - rl.KeyboardKey.SPACE, - rl.KeyboardKey.LEFT_BRACKET, - rl.KeyboardKey.RIGHT_BRACKET, - rl.KeyboardKey.SEMICOLON, - rl.KeyboardKey.APOSTROPHE, - rl.KeyboardKey.COMMA, - rl.KeyboardKey.PERIOD, - cast(rl.KeyboardKey) 0, // 0x0A - cast(rl.KeyboardKey) 0, // 0x0B - cast(rl.KeyboardKey) 0, // 0x0C - cast(rl.KeyboardKey) 0, // 0x0D - cast(rl.KeyboardKey) 0, // 0x0E - cast(rl.KeyboardKey) 0, // 0x0F - rl.KeyboardKey.CAPS_LOCK, - rl.KeyboardKey.SCROLL_LOCK, - rl.KeyboardKey.NUM_LOCK, - rl.KeyboardKey.LEFT_ALT, - rl.KeyboardKey.LEFT_SHIFT, - rl.KeyboardKey.LEFT_CONTROL, - rl.KeyboardKey.RIGHT_ALT, - rl.KeyboardKey.RIGHT_SHIFT, - rl.KeyboardKey.RIGHT_CONTROL, - cast(rl.KeyboardKey) 0, // 0x0F - cast(rl.KeyboardKey) 0, // 0x0F - cast(rl.KeyboardKey) 0, // 0x0F - cast(rl.KeyboardKey) 0, // 0x0F - cast(rl.KeyboardKey) 0, // 0x0F - cast(rl.KeyboardKey) 0, // 0x0F - cast(rl.KeyboardKey) 0, // 0x0F - rl.KeyboardKey.ESCAPE, - rl.KeyboardKey.F1, - rl.KeyboardKey.F2, - rl.KeyboardKey.F3, - rl.KeyboardKey.F4, - rl.KeyboardKey.F5, - rl.KeyboardKey.F7, - rl.KeyboardKey.F8, - rl.KeyboardKey.F9, - rl.KeyboardKey.F10, - rl.KeyboardKey.F11, - rl.KeyboardKey.F12, - rl.KeyboardKey.PRINT_SCREEN, - rl.KeyboardKey.PAUSE, - cast(rl.KeyboardKey) 0, // 0x2E - rl.KeyboardKey.GRAVE, - cast(rl.KeyboardKey) '0', - cast(rl.KeyboardKey) '1', - cast(rl.KeyboardKey) '2', - cast(rl.KeyboardKey) '3', - cast(rl.KeyboardKey) '4', - cast(rl.KeyboardKey) '5', - cast(rl.KeyboardKey) '6', - cast(rl.KeyboardKey) '7', - cast(rl.KeyboardKey) '8', - cast(rl.KeyboardKey) '9', - rl.KeyboardKey.MINUS, - rl.KeyboardKey.EQUAL, - rl.KeyboardKey.BACKSPACE, - rl.KeyboardKey.BACKSLASH, - rl.KeyboardKey.SLASH, - cast(rl.KeyboardKey) 0, // 0x3F - cast(rl.KeyboardKey) 0, // 0x40 - rl.KeyboardKey.A, - rl.KeyboardKey.B, - rl.KeyboardKey.C, - rl.KeyboardKey.D, - rl.KeyboardKey.E, - rl.KeyboardKey.F, - rl.KeyboardKey.G, - rl.KeyboardKey.H, - rl.KeyboardKey.I, - rl.KeyboardKey.J, - rl.KeyboardKey.K, - rl.KeyboardKey.L, - rl.KeyboardKey.M, - rl.KeyboardKey.N, - rl.KeyboardKey.O, - rl.KeyboardKey.P, - rl.KeyboardKey.Q, - rl.KeyboardKey.R, - rl.KeyboardKey.S, - rl.KeyboardKey.T, - rl.KeyboardKey.U, - rl.KeyboardKey.V, - rl.KeyboardKey.W, - rl.KeyboardKey.X, - rl.KeyboardKey.Y, - rl.KeyboardKey.Z, - rl.KeyboardKey.INSERT, - rl.KeyboardKey.DELETE, - rl.KeyboardKey.HOME, - rl.KeyboardKey.END, - rl.KeyboardKey.PAGE_UP, - rl.KeyboardKey.PAGE_DOWN, - rl.KeyboardKey.KP_0, - rl.KeyboardKey.KP_1, - rl.KeyboardKey.KP_2, - rl.KeyboardKey.KP_3, - rl.KeyboardKey.KP_4, - rl.KeyboardKey.KP_5, - rl.KeyboardKey.KP_6, - rl.KeyboardKey.KP_7, - rl.KeyboardKey.KP_8, - rl.KeyboardKey.KP_9, - rl.KeyboardKey.KP_DECIMAL, - rl.KeyboardKey.KP_EQUAL, - rl.KeyboardKey.KP_ADD, - rl.KeyboardKey.KP_SUBTRACT, - rl.KeyboardKey.KP_MULTIPLY, - rl.KeyboardKey.KP_DIVIDE, - rl.KeyboardKey.KP_ENTER, } + @static raylib_key_lookup_table := [KeyCode.count] rl.KeyboardKey { + rl.KeyboardKey.KEY_NULL, // 0x00 + + cast(rl.KeyboardKey) 0, // 0x01 + + cast(rl.KeyboardKey) 0, // 0x02 + cast(rl.KeyboardKey) 0, // 0x03 + cast(rl.KeyboardKey) 0, // 0x04 + cast(rl.KeyboardKey) 0, // 0x05 + cast(rl.KeyboardKey) 0, // 0x06 + cast(rl.KeyboardKey) 0, // 0x07 + + rl.KeyboardKey.BACKSPACE, // 0x08 + rl.KeyboardKey.TAB, // 0x09 + + rl.KeyboardKey.RIGHT, // 0x0A + rl.KeyboardKey.LEFT, // 0x0B + rl.KeyboardKey.DOWN, // 0x0C + rl.KeyboardKey.UP, // 0x0D + + rl.KeyboardKey.ENTER, // 0x0E + + cast(rl.KeyboardKey) 0, // 0x0F + + rl.KeyboardKey.CAPS_LOCK, // 0x10 + rl.KeyboardKey.SCROLL_LOCK, // 0x11 + rl.KeyboardKey.NUM_LOCK, // 0x12 + + rl.KeyboardKey.LEFT_ALT, // 0x13 + rl.KeyboardKey.LEFT_SHIFT, // 0x14 + rl.KeyboardKey.LEFT_CONTROL, // 0x15 + rl.KeyboardKey.RIGHT_ALT, // 0x16 + rl.KeyboardKey.RIGHT_SHIFT, // 0x17 + rl.KeyboardKey.RIGHT_CONTROL, // 0x18 + + cast(rl.KeyboardKey) 0, // 0x19 + + rl.KeyboardKey.PAUSE, // 0x1A + rl.KeyboardKey.ESCAPE, // 0x1B + rl.KeyboardKey.HOME, // 0x1C + rl.KeyboardKey.END, // 0x1D + rl.KeyboardKey.PAGE_UP, // 0x1E + rl.KeyboardKey.PAGE_DOWN, // 0x1F + rl.KeyboardKey.SPACE, // 0x20 + + cast(rl.KeyboardKey) '!', // 0x21 + cast(rl.KeyboardKey) '"', // 0x22 + cast(rl.KeyboardKey) '#', // 0x23 + cast(rl.KeyboardKey) '$', // 0x24 + cast(rl.KeyboardKey) '%', // 0x25 + cast(rl.KeyboardKey) '&', // 0x26 + cast(rl.KeyboardKey) '\'', // 0x27 + cast(rl.KeyboardKey) '(', // 0x28 + cast(rl.KeyboardKey) ')', // 0x29 + cast(rl.KeyboardKey) '*', // 0x2A + cast(rl.KeyboardKey) '+', // 0x2B + cast(rl.KeyboardKey) ',', // 0x2C + cast(rl.KeyboardKey) '-', // 0x2D + cast(rl.KeyboardKey) '.', // 0x2E + cast(rl.KeyboardKey) '/', // 0x2F + + cast(rl.KeyboardKey) '0', // 0x30 + cast(rl.KeyboardKey) '1', // 0x31 + cast(rl.KeyboardKey) '2', // 0x32 + cast(rl.KeyboardKey) '3', // 0x33 + cast(rl.KeyboardKey) '4', // 0x34 + cast(rl.KeyboardKey) '5', // 0x35 + cast(rl.KeyboardKey) '6', // 0x36 + cast(rl.KeyboardKey) '7', // 0x37 + cast(rl.KeyboardKey) '8', // 0x38 + cast(rl.KeyboardKey) '9', // 0x39 + + cast(rl.KeyboardKey) 0, // 0x3A + + cast(rl.KeyboardKey) ';', // 0x3B + cast(rl.KeyboardKey) '<', // 0x3C + cast(rl.KeyboardKey) '=', // 0x3D + cast(rl.KeyboardKey) '>', // 0x3E + cast(rl.KeyboardKey) '?', // 0x3F + cast(rl.KeyboardKey) '@', // 0x40 + + rl.KeyboardKey.A, // 0x41 + rl.KeyboardKey.B, // 0x42 + rl.KeyboardKey.C, // 0x43 + rl.KeyboardKey.D, // 0x44 + rl.KeyboardKey.E, // 0x45 + rl.KeyboardKey.F, // 0x46 + rl.KeyboardKey.G, // 0x47 + rl.KeyboardKey.H, // 0x48 + rl.KeyboardKey.I, // 0x49 + rl.KeyboardKey.J, // 0x4A + rl.KeyboardKey.K, // 0x4B + rl.KeyboardKey.L, // 0x4C + rl.KeyboardKey.M, // 0x4D + rl.KeyboardKey.N, // 0x4E + rl.KeyboardKey.O, // 0x4F + rl.KeyboardKey.P, // 0x50 + rl.KeyboardKey.Q, // 0x51 + rl.KeyboardKey.R, // 0x52 + rl.KeyboardKey.S, // 0x53 + rl.KeyboardKey.T, // 0x54 + rl.KeyboardKey.U, // 0x55 + rl.KeyboardKey.V, // 0x56 + rl.KeyboardKey.W, // 0x57 + rl.KeyboardKey.X, // 0x58 + rl.KeyboardKey.Y, // 0x59 + rl.KeyboardKey.Z, // 0x5A + + rl.KeyboardKey.LEFT_BRACKET, // 0x5B + rl.KeyboardKey.BACKSLASH, // 0x5C + rl.KeyboardKey.RIGHT_BRACKET, // 0x5D + cast(rl.KeyboardKey) '^', // 0x5E + rl.KeyboardKey.GRAVE, // 0x5F + cast(rl.KeyboardKey) '`', // 0x60 + + rl.KeyboardKey.KP_0, // 0x61 + rl.KeyboardKey.KP_1, // 0x62 + rl.KeyboardKey.KP_2, // 0x63 + rl.KeyboardKey.KP_3, // 0x64 + rl.KeyboardKey.KP_4, // 0x65 + rl.KeyboardKey.KP_5, // 0x66 + rl.KeyboardKey.KP_6, // 0x67 + rl.KeyboardKey.KP_7, // 0x68 + rl.KeyboardKey.KP_8, // 0x69 + rl.KeyboardKey.KP_9, // 0x6A + rl.KeyboardKey.KP_DECIMAL, // 0x6B + rl.KeyboardKey.KP_EQUAL, // 0x6C + rl.KeyboardKey.KP_ADD, // 0x6D + rl.KeyboardKey.KP_SUBTRACT, // 0x6E + rl.KeyboardKey.KP_MULTIPLY, // 0x6F + rl.KeyboardKey.KP_DIVIDE, // 0x70 + rl.KeyboardKey.KP_ENTER, // 0x71 + + rl.KeyboardKey.F1, // 0x72 + rl.KeyboardKey.F2, // 0x73 + rl.KeyboardKey.F3, // 0x74 + rl.KeyboardKey.F4, // 0x75 + rl.KeyboardKey.F5, // 0x76 + rl.KeyboardKey.F6, // 0x77 + rl.KeyboardKey.F7, // 0x78 + rl.KeyboardKey.F8, // 0x79 + rl.KeyboardKey.F9, // 0x7A + rl.KeyboardKey.F10, // 0x7B + rl.KeyboardKey.F11, // 0x7C + rl.KeyboardKey.F12, // 0x7D + + rl.KeyboardKey.INSERT, // 0x7E + rl.KeyboardKey.DELETE, // 0x7F + } return raylib_key_lookup_table[ key ] } @@ -348,3 +262,99 @@ to_raylib_mouse_btn :: proc( btn : i32 ) -> rl.MouseButton { rl.MouseButton.EXTRA, } return raylib_mouse_btn_lookup_table[ btn ] } + +to_key_from_raylib :: proc( ray_key : rl.KeyboardKey ) -> (key : KeyCode) { + + switch (ray_key) { + case .KEY_NULL : key = cast(KeyCode) ray_key + + case .SPACE, + cast(rl.KeyboardKey) '!', + cast(rl.KeyboardKey) '"', + cast(rl.KeyboardKey) '#', + cast(rl.KeyboardKey) '$', + cast(rl.KeyboardKey) '%', + cast(rl.KeyboardKey) '&', + .APOSTROPHE, + cast(rl.KeyboardKey) '(', + cast(rl.KeyboardKey) ')', + cast(rl.KeyboardKey) '*', + cast(rl.KeyboardKey) '+', + .COMMA, .MINUS, .PERIOD, .SLASH, + .ZERO, .ONE, .TWO, .THREE, .FOUR, .FIVE, .SIX, .SEVEN, .EIGHT, .NINE, + .SEMICOLON,.EQUAL, + .A, .B, .C, .D, .E, .F, .G, .H, .I, .J, .K, .L, .M, .N, .O, .P, .Q, .R, .S, .T, .U, .V, .W, .X, .Y, .Z, + .LEFT_BRACKET, .BACKSLASH, .RIGHT_BRACKET, cast(rl.KeyboardKey) '_', .GRAVE : + key = cast(KeyCode) ray_key + + case .ESCAPE : key = KeyCode.escape + case .ENTER : key = KeyCode.enter + case .TAB : key = KeyCode.tab + case .BACKSPACE : key = KeyCode.backspace + + case .INSERT : key = KeyCode.insert + case .DELETE : key = KeyCode.delete + + case .RIGHT : key = KeyCode.right + case .LEFT : key = KeyCode.left + case .UP : key = KeyCode.up + case .DOWN : key = KeyCode.down + + case .PAGE_UP : key = KeyCode.page_up + case .PAGE_DOWN : key = KeyCode.page_down + case .HOME : key = KeyCode.home + case .END : key = KeyCode.end + case .CAPS_LOCK : key = KeyCode.caps_lock + case .SCROLL_LOCK : key = KeyCode.scroll_lock + case .NUM_LOCK : key = KeyCode.num_lock + case .PRINT_SCREEN : key = KeyCode.ignored + case .PAUSE : key = KeyCode.pause + + case .F1 : key = KeyCode.F1 + case .F2 : key = KeyCode.F2 + case .F3 : key = KeyCode.F3 + case .F4 : key = KeyCode.F4 + case .F5 : key = KeyCode.F5 + case .F6 : key = KeyCode.F6 + case .F7 : key = KeyCode.F7 + case .F8 : key = KeyCode.F8 + case .F9 : key = KeyCode.F9 + case .F10 : key = KeyCode.F10 + case .F11 : key = KeyCode.F11 + case .F12 : key = KeyCode.F12 + + case .LEFT_SHIFT : key = KeyCode.left_shift + case .LEFT_CONTROL : key = KeyCode.left_control + case .LEFT_ALT : key = KeyCode.left_alt + case .LEFT_SUPER : key = KeyCode.ignored + case .RIGHT_SHIFT : key = KeyCode.right_shift + case .RIGHT_CONTROL : key = KeyCode.right_control + case .RIGHT_ALT : key = KeyCode.right_alt + case .RIGHT_SUPER : key = KeyCode.ignored + case .KB_MENU : key = KeyCode.ignored + + case .KP_0 : key = KeyCode.kpad_0 + case .KP_1 : key = KeyCode.kpad_1 + case .KP_2 : key = KeyCode.kpad_2 + case .KP_3 : key = KeyCode.kpad_3 + case .KP_4 : key = KeyCode.kpad_4 + case .KP_5 : key = KeyCode.kpad_5 + case .KP_6 : key = KeyCode.kpad_6 + case .KP_7 : key = KeyCode.kpad_7 + case .KP_8 : key = KeyCode.kpad_8 + case .KP_9 : key = KeyCode.kpad_9 + + case .KP_DECIMAL : key = KeyCode.kpad_decimal + case .KP_DIVIDE : key = KeyCode.kpad_divide + case .KP_MULTIPLY : key = KeyCode.kpad_multiply + case .KP_SUBTRACT : key = KeyCode.kpad_minus + case .KP_ADD : key = KeyCode.kpad_plus + case .KP_ENTER : key = KeyCode.kpad_enter + case .KP_EQUAL : key = KeyCode.kpad_equals + + case .BACK : key = KeyCode.ignored + case .VOLUME_UP : key = KeyCode.ignored + case .VOLUME_DOWN : key = KeyCode.ignored + } + return +} diff --git a/code/sectr/input/input_sdl.odin b/code/sectr/input/input_sdl.odin new file mode 100644 index 0000000..e69de29 diff --git a/code/sectr/input/keyboard_qwerty.odin b/code/sectr/input/keyboard_qwerty.odin new file mode 100644 index 0000000..c4bf0ee --- /dev/null +++ b/code/sectr/input/keyboard_qwerty.odin @@ -0,0 +1,239 @@ +package sectr + +// Based off of SDL2's Scancode; which is based off of: +// https://usb.org/sites/default/files/hut1_12.pdf +// I gutted values I would never use +QeurtyCode :: enum u32 { + unknown = 0, + + A = 4, + B = 5, + C = 6, + D = 7, + E = 8, + F = 9, + G = 10, + H = 11, + I = 12, + J = 13, + K = 14, + L = 15, + M = 16, + N = 17, + O = 18, + P = 19, + Q = 20, + R = 21, + S = 22, + T = 23, + U = 24, + V = 25, + W = 26, + X = 27, + Y = 28, + Z = 29, + + nrow_1 = 30, + nrow_2 = 31, + nrow_3 = 32, + nrow_4 = 33, + nrow_5 = 34, + nrow_6 = 35, + nrow_7 = 36, + nrow_8 = 37, + nrow_9 = 38, + nrow_0 = 39, + + enter = 40, + escape = 41, + backspace = 42, + tab = 43, + space = 44, + + minus = 45, + equals = 46, + bracket_open = 47, + bracket_close = 48, + backslash = 49, + NONUSHASH = 50, + semicolon = 51, + apostrophe = 52, + grave = 53, + comma = 54, + period = 55, + slash = 56, + + capslock = 57, + + F1 = 58, + F2 = 59, + F3 = 60, + F4 = 61, + F5 = 62, + F6 = 63, + F7 = 64, + F8 = 65, + F9 = 66, + F10 = 67, + F11 = 68, + F12 = 69, + + // print_screen = 70, + // scroll_lock = 71, + pause = 72, + insert = 73, + home = 74, + page_up = 75, + delete = 76, + end = 77, + page_down = 78, + right = 79, + left = 80, + down = 81, + up = 82, + + numlock_clear = 83, + kpad_divide = 84, + kpad_multiply = 85, + kpad_minus = 86, + kpad_plus = 87, + kpad_enter = 88, + kpad_1 = 89, + kpad_2 = 90, + kpad_3 = 91, + kpad_4 = 92, + kpad_5 = 93, + kpad_6 = 94, + kpad_7 = 95, + kpad_8 = 96, + kpad_9 = 97, + kpad_0 = 98, + kpad_period = 99, + + // NONUSBACKSLASH = 100, + // OS_Compose = 101, + // power = 102, + kpad_equals = 103, + + // F13 = 104, + // F14 = 105, + // F15 = 106, + // F16 = 107, + // F17 = 108, + // F18 = 109, + // F19 = 110, + // F20 = 111, + // F21 = 112, + // F22 = 113, + // F23 = 114, + // F24 = 115, + + // execute = 116, + // help = 117, + // menu = 118, + // select = 119, + // stop = 120, + // again = 121, + // undo = 122, + // cut = 123, + // copy = 124, + // paste = 125, + // find = 126, + // mute = 127, + // volume_up = 128, + // volume_down = 129, + /* LOCKINGCAPSLOCK = 130, */ + /* LOCKINGNUMLOCK = 131, */ + /* LOCKINGSCROLLLOCK = 132, */ + // kpad_comma = 133, + // kpad_equals_AS400 = 134, + + // international_1 = 135, + // international_2 = 136, + // international_3 = 137, + // international_4 = 138, + // international_5 = 139, + // international_6 = 140, + // international_7 = 141, + // international_8 = 142, + // international_9 = 143, + // lang_1 = 144, + // lang_2 = 145, + // lang_3 = 146, + // lang_4 = 147, + // lang_5 = 148, + // lang_6 = 149, + // lang_7 = 150, + // lang_8 = 151, + // lang_9 = 152, + + // alt_erase = 153, + // sysreq = 154, + // cancel = 155, + // clear = 156, + // prior = 157, + // return_2 = 158, + // separator = 159, + // out = 160, + // OPER = 161, + // clear_again = 162, + // CRSEL = 163, + // EXSEL = 164, + + // KP_00 = 176, + // KP_000 = 177, + // THOUSANDSSEPARATOR = 178, + // DECIMALSEPARATOR = 179, + // CURRENCYUNIT = 180, + // CURRENCYSUBUNIT = 181, + // KP_LEFTPAREN = 182, + // KP_RIGHTPAREN = 183, + // KP_LEFTBRACE = 184, + // KP_RIGHTBRACE = 185, + // KP_TAB = 186, + // KP_BACKSPACE = 187, + // KP_A = 188, + // KP_B = 189, + // KP_C = 190, + // KP_D = 191, + // KP_E = 192, + // KP_F = 193, + // KP_XOR = 194, + // KP_POWER = 195, + // KP_PERCENT = 196, + // KP_LESS = 197, + // KP_GREATER = 198, + // KP_AMPERSAND = 199, + // KP_DBLAMPERSAND = 200, + // KP_VERTICALBAR = 201, + // KP_DBLVERTICALBAR = 202, + // KP_COLON = 203, + // KP_HASH = 204, + // KP_SPACE = 205, + // KP_AT = 206, + // KP_EXCLAM = 207, + // KP_MEMSTORE = 208, + // KP_MEMRECALL = 209, + // KP_MEMCLEAR = 210, + // KP_MEMADD = 211, + // KP_MEMSUBTRACT = 212, + // KP_MEMMULTIPLY = 213, + // KP_MEMDIVIDE = 214, + // KP_PLUSMINUS = 215, + // KP_CLEAR = 216, + // KP_CLEARENTRY = 217, + // KP_BINARY = 218, + // KP_OCTAL = 219, + // KP_DECIMAL = 220, + // KP_HEXADECIMAL = 221, + + left_control = 224, + left_shift = 225, + left_alt = 226, + // LGUI = 227, + right_control = 228, + right_shift = 229, + right_alt = 230, + + count = 512, +} diff --git a/code/sectr/input/keycode.odin b/code/sectr/input/keycode.odin new file mode 100644 index 0000000..1d95be9 --- /dev/null +++ b/code/sectr/input/keycode.odin @@ -0,0 +1,154 @@ +package sectr + +MaxKeyboardKeys :: 512 + +KeyCode :: enum u32 { + null = 0x00, + + ignored = 0x01, + // 0x02 + // 0x03 + // 0x04 + // 0x05 + // 0x06 + // 0x07 + + backspace = '\b', // 0x08 + tab = '\t', // 0x09 + + right = 0x0A, + left = 0x0B, + down = 0x0C, + up = 0x0D, + + enter = '\r', // 0x0E + + // 0x0F + + caps_lock = 0x10, + scroll_lock = 0x11, + num_lock = 0x12, + + left_alt = 0x13, + left_shift = 0x14, + left_control = 0x15, + right_alt = 0x16, + right_shift = 0x17, + right_control = 0x18, + + // 0x19 + + pause = 0x1A, + escape = '\x1B', // 0x1B + home = 0x1C, + end = 0x1D, + page_up = 0x1E, + page_down = 0x1F, + space = ' ', // 0x20 + + exclamation = '!', // 0x21 + quote_dbl = '"', // 0x22 + hash = '#', // 0x23 + dollar = '$', // 0x24 + percent = '%', // 0x25 + ampersand = '&', // 0x26 + quote = '\'', // 0x27 + paren_open = '(', // 0x28 + paren_close = ')', // 0x29 + asterisk = '*', // 0x2A + plus = '+', // 0x2B + comma = ',', // 0x2C + minus = '-', // 0x2D + period = '.', // 0x2E + slash = '/', // 0x2F + + nrow_0 = '0', // 0x30 + nrow_1 = '1', // 0x31 + nrow_2 = '2', // 0x32 + nrow_3 = '3', // 0x33 + nrow_4 = '4', // 0x34 + nrow_5 = '5', // 0x35 + nrow_6 = '6', // 0x36 + nrow_7 = '7', // 0x37 + nrow_8 = '8', // 0x38 + nrow_9 = '9', // 0x39 + + // 0x3A + + semicolon = ';', // 0x3B + less = '<', // 0x3C + equals = '=', // 0x3D + greater = '>', // 0x3E + question = '?', // 0x3F + at = '@', // 0x40 + + A = 'A', // 0x41 + B = 'B', // 0x42 + C = 'C', // 0x43 + D = 'D', // 0x44 + E = 'E', // 0x45 + F = 'F', // 0x46 + G = 'G', // 0x47 + H = 'H', // 0x48 + I = 'I', // 0x49 + J = 'J', // 0x4A + K = 'K', // 0x4B + L = 'L', // 0x4C + M = 'M', // 0x4D + N = 'N', // 0x4E + O = 'O', // 0x4F + P = 'P', // 0x50 + Q = 'Q', // 0x51 + R = 'R', // 0x52 + S = 'S', // 0x53 + T = 'T', // 0x54 + U = 'U', // 0x55 + V = 'V', // 0x56 + W = 'W', // 0x57 + X = 'X', // 0x58 + Y = 'Y', // 0x59 + Z = 'Z', // 0x5A + + bracket_open = '[', // 0x5B + backslash = '\\', // 0x5C + bracket_close = ']', // 0x5D + caret = '^', // 0x5E + underscore = '_', // 0x5F + backtick = '`', // 0x60 + + kpad_0 = 0x61, + kpad_1 = 0x62, + kpad_2 = 0x63, + kpad_3 = 0x64, + kpad_4 = 0x65, + kpad_5 = 0x66, + kpad_6 = 0x67, + kpad_7 = 0x68, + kpad_8 = 0x69, + kpad_9 = 0x6A, + kpad_decimal = 0x6B, + kpad_equals = 0x6C, + kpad_plus = 0x6D, + kpad_minus = 0x6E, + kpad_multiply = 0x6F, + kpad_divide = 0x70, + kpad_enter = 0x71, + + F1 = 0x72, + F2 = 0x73, + F3 = 0x74, + F4 = 0x75, + F5 = 0x76, + F6 = 0x77, + F7 = 0x78, + F8 = 0x79, + F9 = 0x7A, + F10 = 0x7B, + F11 = 0x7C, + F12 = 0x7D, + + insert = 0x7E, + delete = 0x7F, + + count = 0x80, +} diff --git a/code/sectr/ui/core/Readme.md b/code/sectr/ui/core/Readme.md index 454e1d0..33da0f9 100644 --- a/code/sectr/ui/core/Readme.md +++ b/code/sectr/ui/core/Readme.md @@ -3,5 +3,5 @@ Eventually want to generalize this core UI as its own library. This will keep track of here whats needed for it to work wihtout the rest of this codebase. -* Provide UI input state in its own data stucture at the beginning of `ui_build_graph`: +* Provide UI input state or "events" in its own data stucture at the beginning of `ui_build_graph`: * \ No newline at end of file diff --git a/code/sectr/ui/core/box.odin b/code/sectr/ui/core/box.odin index 65cbd95..a4bde3a 100644 --- a/code/sectr/ui/core/box.odin +++ b/code/sectr/ui/core/box.odin @@ -128,6 +128,8 @@ ui_box_make :: proc( flags : UI_BoxFlags, label : string ) -> (^ UI_Box) return curr_box } +ui_prev_cached_box :: #force_inline proc( box : ^UI_Box ) -> ^UI_Box { return zpl_hmap_get( ui_context().prev_cache, cast(u64) box.key ) } + ui_box_tranverse_next :: proc "contextless" ( box : ^ UI_Box ) -> (^ UI_Box) { using state := get_state() diff --git a/code/sectr/ui/core/signal.odin b/code/sectr/ui/core/signal.odin index a216cee..95d919f 100644 --- a/code/sectr/ui/core/signal.odin +++ b/code/sectr/ui/core/signal.odin @@ -36,6 +36,8 @@ ui_signal_from_box :: proc ( box : ^ UI_Box, update_style := true, update_deltas frame_delta := frametime_delta32() + prev_box := ui_prev_cached_box(box) + signal := UI_Signal {} // Cursor Collision @@ -72,8 +74,8 @@ ui_signal_from_box :: proc ( box : ^ UI_Box, update_style := true, update_deltas keyboard_clickable := UI_BoxFlag.Keyboard_Clickable in box.flags is_focusable := .Focusable in box.flags - was_active := (ui.active == box.key) && (box.active_delta > 0) - was_hot := (box.hot_delta > 0) + was_active := box.active_delta > 0 + was_hot := box.hot_delta > 0 was_disabled := box.disabled_delta > 0 is_focused_locked := is_focusable ? was_active : false diff --git a/code/sectr/ui/core/state.odin b/code/sectr/ui/core/state.odin index 3ce5b85..b904792 100644 --- a/code/sectr/ui/core/state.odin +++ b/code/sectr/ui/core/state.odin @@ -206,17 +206,6 @@ ui_graph_build_begin :: proc( ui : ^ UI_State, bounds : Vec2 = {} ) ui_parent_push(root) } -ui_core_compute_layout :: proc( ui : ^UI_State ) -{ - profile(#procedure) - state := get_state() - - - - -} - - ui_graph_build_end :: proc( ui : ^UI_State ) { profile(#procedure) @@ -239,8 +228,6 @@ ui_graph_build_end :: proc( ui : ^UI_State ) } for current := root.first; current != nil; current = ui_box_tranverse_next( current ) { - - if ! current.computed.fresh { ui_box_compute_layout( current ) } @@ -290,8 +277,6 @@ ui_parent_pop :: #force_inline proc() { stack_pop( & get_state( @(deferred_none = ui_parent_pop) ui_parent :: #force_inline proc( ui : ^UI_Box) { ui_parent_push( ui ) } -ui_prev_cached_box :: #force_inline proc( box : ^UI_Box ) -> ^UI_Box { return zpl_hmap_get( ui_context().prev_cache, cast(u64) box.key ) } - // Topmost ancestor that is not the root ui_top_ancestor :: #force_inline proc "contextless" ( box : ^UI_Box ) -> (^UI_Box) { using ui := get_state().ui_context