From ddd7ff4bbb03958e3619924a155252ed1154e05b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 19 Oct 2023 14:27:22 -0700 Subject: [PATCH] apprt/gtk: use shared key => imgui key helper --- src/apprt/gtk/ImguiWidget.zig | 133 +--------------------------------- 1 file changed, 1 insertion(+), 132 deletions(-) diff --git a/src/apprt/gtk/ImguiWidget.zig b/src/apprt/gtk/ImguiWidget.zig index 68a62f12c..8e47c87b2 100644 --- a/src/apprt/gtk/ImguiWidget.zig +++ b/src/apprt/gtk/ImguiWidget.zig @@ -367,7 +367,7 @@ fn keyEvent( // If our keyval has a key, then we send that key event if (key.keyFromKeyval(keyval)) |inputkey| { - if (translateKey(inputkey)) |imgui_key| { + if (inputkey.imguiKey()) |imgui_key| { cimgui.c.ImGuiIO_AddKeyEvent(io, imgui_key, action == .press); } } @@ -378,134 +378,3 @@ fn keyEvent( return true; } - -fn translateKey(v: input.Key) ?c_uint { - return switch (v) { - .a => cimgui.c.ImGuiKey_A, - .b => cimgui.c.ImGuiKey_B, - .c => cimgui.c.ImGuiKey_C, - .d => cimgui.c.ImGuiKey_D, - .e => cimgui.c.ImGuiKey_E, - .f => cimgui.c.ImGuiKey_F, - .g => cimgui.c.ImGuiKey_G, - .h => cimgui.c.ImGuiKey_H, - .i => cimgui.c.ImGuiKey_I, - .j => cimgui.c.ImGuiKey_J, - .k => cimgui.c.ImGuiKey_K, - .l => cimgui.c.ImGuiKey_L, - .m => cimgui.c.ImGuiKey_M, - .n => cimgui.c.ImGuiKey_N, - .o => cimgui.c.ImGuiKey_O, - .p => cimgui.c.ImGuiKey_P, - .q => cimgui.c.ImGuiKey_Q, - .r => cimgui.c.ImGuiKey_R, - .s => cimgui.c.ImGuiKey_S, - .t => cimgui.c.ImGuiKey_T, - .u => cimgui.c.ImGuiKey_U, - .v => cimgui.c.ImGuiKey_V, - .w => cimgui.c.ImGuiKey_W, - .x => cimgui.c.ImGuiKey_X, - .y => cimgui.c.ImGuiKey_Y, - .z => cimgui.c.ImGuiKey_Z, - - .zero => cimgui.c.ImGuiKey_0, - .one => cimgui.c.ImGuiKey_1, - .two => cimgui.c.ImGuiKey_2, - .three => cimgui.c.ImGuiKey_3, - .four => cimgui.c.ImGuiKey_4, - .five => cimgui.c.ImGuiKey_5, - .six => cimgui.c.ImGuiKey_6, - .seven => cimgui.c.ImGuiKey_7, - .eight => cimgui.c.ImGuiKey_8, - .nine => cimgui.c.ImGuiKey_9, - - .semicolon => cimgui.c.ImGuiKey_Semicolon, - .space => cimgui.c.ImGuiKey_Space, - .apostrophe => cimgui.c.ImGuiKey_Apostrophe, - .comma => cimgui.c.ImGuiKey_Comma, - .grave_accent => cimgui.c.ImGuiKey_GraveAccent, - .period => cimgui.c.ImGuiKey_Period, - .slash => cimgui.c.ImGuiKey_Slash, - .minus => cimgui.c.ImGuiKey_Minus, - .equal => cimgui.c.ImGuiKey_Equal, - .left_bracket => cimgui.c.ImGuiKey_LeftBracket, - .right_bracket => cimgui.c.ImGuiKey_RightBracket, - .backslash => cimgui.c.ImGuiKey_Backslash, - - .up => cimgui.c.ImGuiKey_UpArrow, - .down => cimgui.c.ImGuiKey_DownArrow, - .left => cimgui.c.ImGuiKey_LeftArrow, - .right => cimgui.c.ImGuiKey_RightArrow, - .home => cimgui.c.ImGuiKey_Home, - .end => cimgui.c.ImGuiKey_End, - .insert => cimgui.c.ImGuiKey_Insert, - .delete => cimgui.c.ImGuiKey_Delete, - .caps_lock => cimgui.c.ImGuiKey_CapsLock, - .scroll_lock => cimgui.c.ImGuiKey_ScrollLock, - .num_lock => cimgui.c.ImGuiKey_NumLock, - .page_up => cimgui.c.ImGuiKey_PageUp, - .page_down => cimgui.c.ImGuiKey_PageDown, - .escape => cimgui.c.ImGuiKey_Escape, - .enter => cimgui.c.ImGuiKey_Enter, - .tab => cimgui.c.ImGuiKey_Tab, - .backspace => cimgui.c.ImGuiKey_Backspace, - .print_screen => cimgui.c.ImGuiKey_PrintScreen, - .pause => cimgui.c.ImGuiKey_Pause, - - .f1 => cimgui.c.ImGuiKey_F1, - .f2 => cimgui.c.ImGuiKey_F2, - .f3 => cimgui.c.ImGuiKey_F3, - .f4 => cimgui.c.ImGuiKey_F4, - .f5 => cimgui.c.ImGuiKey_F5, - .f6 => cimgui.c.ImGuiKey_F6, - .f7 => cimgui.c.ImGuiKey_F7, - .f8 => cimgui.c.ImGuiKey_F8, - .f9 => cimgui.c.ImGuiKey_F9, - .f10 => cimgui.c.ImGuiKey_F10, - .f11 => cimgui.c.ImGuiKey_F11, - .f12 => cimgui.c.ImGuiKey_F12, - - .kp_0 => cimgui.c.ImGuiKey_Keypad0, - .kp_1 => cimgui.c.ImGuiKey_Keypad1, - .kp_2 => cimgui.c.ImGuiKey_Keypad2, - .kp_3 => cimgui.c.ImGuiKey_Keypad3, - .kp_4 => cimgui.c.ImGuiKey_Keypad4, - .kp_5 => cimgui.c.ImGuiKey_Keypad5, - .kp_6 => cimgui.c.ImGuiKey_Keypad6, - .kp_7 => cimgui.c.ImGuiKey_Keypad7, - .kp_8 => cimgui.c.ImGuiKey_Keypad8, - .kp_9 => cimgui.c.ImGuiKey_Keypad9, - .kp_decimal => cimgui.c.ImGuiKey_KeypadDecimal, - .kp_divide => cimgui.c.ImGuiKey_KeypadDivide, - .kp_multiply => cimgui.c.ImGuiKey_KeypadMultiply, - .kp_subtract => cimgui.c.ImGuiKey_KeypadSubtract, - .kp_add => cimgui.c.ImGuiKey_KeypadAdd, - .kp_enter => cimgui.c.ImGuiKey_KeypadEnter, - .kp_equal => cimgui.c.ImGuiKey_KeypadEqual, - - .left_shift => cimgui.c.ImGuiKey_LeftShift, - .left_control => cimgui.c.ImGuiKey_LeftCtrl, - .left_alt => cimgui.c.ImGuiKey_LeftAlt, - .left_super => cimgui.c.ImGuiKey_LeftSuper, - .right_shift => cimgui.c.ImGuiKey_RightShift, - .right_control => cimgui.c.ImGuiKey_RightCtrl, - .right_alt => cimgui.c.ImGuiKey_RightAlt, - .right_super => cimgui.c.ImGuiKey_RightSuper, - - .invalid, - .f13, - .f14, - .f15, - .f16, - .f17, - .f18, - .f19, - .f20, - .f21, - .f22, - .f23, - .f24, - .f25, - => null, - }; -}