@@ -3001,6 +3001,98 @@ static void ShowDemoWindowMisc()
3001
3001
ImGui::TreePop ();
3002
3002
}
3003
3003
3004
+ if (ImGui::TreeNode (" Untranslated Key Input" ))
3005
+ {
3006
+ static bool use_untranslated_keys = true ;
3007
+
3008
+ ImGui::Text (" HasUntranslatedKeys: %d" , (io.BackendFlags & ImGuiBackednFlags_HasUntranslatedKeys) ? 1 : 0 );
3009
+
3010
+ ImGui::Checkbox (" Use untranslated keys" , &use_untranslated_keys);
3011
+
3012
+ static const ImVec2 key_size = ImVec2 (35 .0f , 35 .0f );
3013
+ static const float key_rounding = 3 .0f ;
3014
+ static const ImVec2 key_face_size = ImVec2 (25 .0f , 25 .0f );
3015
+ static const ImVec2 key_face_pos = ImVec2 (5 .0f , 3 .0f );
3016
+ static const float key_face_rounding = 2 .0f ;
3017
+ static const ImVec2 key_label_pos = ImVec2 (7 .0f , 4 .0f );
3018
+ static const ImVec2 key_advance = ImVec2 (key_size.x - 1 .0f , key_size.y - 1 .0f );
3019
+ static const float key_row_offset = 9 .0f ;
3020
+
3021
+ struct Funcs
3022
+ {
3023
+ static void DrawKey (const ImVec2& pos, const char * label, int key)
3024
+ {
3025
+ ImDrawList* draw_list = ImGui::GetWindowDrawList ();
3026
+ ImVec2 key_min = pos;
3027
+ ImVec2 key_max = ImVec2 (key_min.x + key_size.x , key_min.y + key_size.y );
3028
+ draw_list->AddRectFilled (key_min, key_max, IM_COL32 (204 , 204 , 204 , 255 ), key_rounding);
3029
+ draw_list->AddRect (key_min, key_max, IM_COL32 (24 , 24 , 24 , 255 ), key_rounding);
3030
+ ImVec2 face_min = ImVec2 (key_min.x + key_face_pos.x , key_min.y + key_face_pos.y );
3031
+ ImVec2 face_max = ImVec2 (face_min.x + key_face_size.x , face_min.y + key_face_size.y );
3032
+ draw_list->AddRect (face_min, face_max, IM_COL32 (193 , 193 , 193 , 255 ), key_face_rounding, ImDrawCornerFlags_All, 2 .0f );
3033
+ draw_list->AddRectFilled (face_min, face_max, IM_COL32 (252 , 252 , 252 , 255 ), key_face_rounding);
3034
+ ImVec2 label_min = ImVec2 (key_min.x + key_label_pos.x , key_min.y + key_label_pos.y );
3035
+ draw_list->AddText (label_min, IM_COL32 (64 , 64 , 64 , 255 ), label);
3036
+ if (key >= 0 )
3037
+ {
3038
+ int key_index = use_untranslated_keys ? ImGui::GetUntranslatedKeyIndex (key) : ImGui::GetKeyIndex (key);
3039
+ if (ImGui::IsKeyDown (key_index))
3040
+ draw_list->AddRectFilled (key_min, key_max, IM_COL32 (255 , 0 , 0 , 128 ), key_rounding);
3041
+ }
3042
+ }
3043
+ };
3044
+
3045
+ ImVec2 cursor_pos = ImGui::GetCursorScreenPos ();
3046
+ ImVec2 board_min = cursor_pos;
3047
+ ImVec2 board_max = ImVec2 (cursor_pos.x + 3 * key_advance.x + 2 * key_row_offset + 10 .0f , cursor_pos.y + 3 * key_advance.y + 10 .0f );
3048
+ ImVec2 start_pos = ImVec2 (board_min.x + 5 .0f , board_min.y );
3049
+
3050
+ ImDrawList* draw_list = ImGui::GetWindowDrawList ();
3051
+ draw_list->PushClipRect (board_min, board_max, true );
3052
+
3053
+ ImVec2 key_pos = start_pos;
3054
+ key_pos.x -= key_advance.x ;
3055
+ Funcs::DrawKey (key_pos, " " , ImGuiKey_Tab);
3056
+ key_pos.x += key_advance.x ;
3057
+ Funcs::DrawKey (key_pos, " Q" , ImGuiKey_Q);
3058
+ key_pos.x += key_advance.x ;
3059
+ Funcs::DrawKey (key_pos, " W" , ImGuiKey_W);
3060
+ key_pos.x += key_advance.x ;
3061
+ Funcs::DrawKey (key_pos, " E" , ImGuiKey_E);
3062
+ key_pos.x += key_advance.x ;
3063
+ Funcs::DrawKey (key_pos, " R" , ImGuiKey_R);
3064
+ key_pos.x = start_pos.x + key_row_offset;
3065
+ key_pos.y += key_advance.y ;
3066
+ key_pos.x -= key_advance.x ;
3067
+ Funcs::DrawKey (key_pos, " " , -1 );
3068
+ key_pos.x += key_advance.x ;
3069
+ Funcs::DrawKey (key_pos, " A" , ImGuiKey_A);
3070
+ key_pos.x += key_advance.x ;
3071
+ Funcs::DrawKey (key_pos, " S" , ImGuiKey_S);
3072
+ key_pos.x += key_advance.x ;
3073
+ Funcs::DrawKey (key_pos, " D" , ImGuiKey_D);
3074
+ key_pos.x += key_advance.x ;
3075
+ Funcs::DrawKey (key_pos, " F" , ImGuiKey_F);
3076
+ key_pos.x = start_pos.x + key_row_offset * 2 ;
3077
+ key_pos.y += key_advance.y ;
3078
+ key_pos.x -= key_advance.x ;
3079
+ Funcs::DrawKey (key_pos, " " , -1 );
3080
+ key_pos.x += key_advance.x ;
3081
+ Funcs::DrawKey (key_pos, " Z" , ImGuiKey_Z);
3082
+ key_pos.x += key_advance.x ;
3083
+ Funcs::DrawKey (key_pos, " X" , ImGuiKey_X);
3084
+ key_pos.x += key_advance.x ;
3085
+ Funcs::DrawKey (key_pos, " C" , ImGuiKey_C);
3086
+ key_pos.x += key_advance.x ;
3087
+ Funcs::DrawKey (key_pos, " V" , ImGuiKey_V);
3088
+
3089
+ draw_list->PopClipRect ();
3090
+
3091
+ ImGui::Dummy (ImVec2 (board_max.x - board_min.x , board_max.y - board_min.y ));
3092
+
3093
+ ImGui::TreePop ();
3094
+ }
3095
+
3004
3096
if (ImGui::TreeNode (" Tabbing" ))
3005
3097
{
3006
3098
ImGui::Text (" Use TAB/SHIFT+TAB to cycle through keyboard editable fields." );
0 commit comments