|
@@ -5686,146 +5686,59 @@ namespace ImGui { extern ImGuiKeyData* GetKeyData(ImGuiKey key); }
|
|
|
|
|
|
static void ShowDemoWindowInputs()
|
|
|
{
|
|
|
- IMGUI_DEMO_MARKER("Inputs, Navigation & Focus");
|
|
|
- if (ImGui::CollapsingHeader("Inputs, Navigation & Focus"))
|
|
|
+ IMGUI_DEMO_MARKER("Inputs & Focus");
|
|
|
+ if (ImGui::CollapsingHeader("Inputs & Focus"))
|
|
|
{
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
|
- // Display ImGuiIO output flags
|
|
|
- IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Output");
|
|
|
+ // Display inputs submitted to ImGuiIO
|
|
|
+ IMGUI_DEMO_MARKER("Inputs & Focus/Inputs");
|
|
|
ImGui::SetNextItemOpen(true, ImGuiCond_Once);
|
|
|
- if (ImGui::TreeNode("Output"))
|
|
|
- {
|
|
|
- ImGui::Text("io.WantCaptureMouse: %d", io.WantCaptureMouse);
|
|
|
- ImGui::Text("io.WantCaptureMouseUnlessPopupClose: %d", io.WantCaptureMouseUnlessPopupClose);
|
|
|
- ImGui::Text("io.WantCaptureKeyboard: %d", io.WantCaptureKeyboard);
|
|
|
- ImGui::Text("io.WantTextInput: %d", io.WantTextInput);
|
|
|
- ImGui::Text("io.WantSetMousePos: %d", io.WantSetMousePos);
|
|
|
- ImGui::Text("io.NavActive: %d, io.NavVisible: %d", io.NavActive, io.NavVisible);
|
|
|
- ImGui::TreePop();
|
|
|
- }
|
|
|
-
|
|
|
- // Display Mouse state
|
|
|
- IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Mouse State");
|
|
|
- if (ImGui::TreeNode("Mouse State"))
|
|
|
+ if (ImGui::TreeNode("Inputs"))
|
|
|
{
|
|
|
+ HelpMarker(
|
|
|
+ "This is a simplified view. See more detailed input state:\n"
|
|
|
+ "- in 'Tools->Metrics/Debugger->Inputs'.\n"
|
|
|
+ "- in 'Tools->Debug Log->IO'.");
|
|
|
if (ImGui::IsMousePosValid())
|
|
|
ImGui::Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y);
|
|
|
else
|
|
|
ImGui::Text("Mouse pos: <INVALID>");
|
|
|
ImGui::Text("Mouse delta: (%g, %g)", io.MouseDelta.x, io.MouseDelta.y);
|
|
|
-
|
|
|
- int count = IM_ARRAYSIZE(io.MouseDown);
|
|
|
- ImGui::Text("Mouse down:"); for (int i = 0; i < count; i++) if (ImGui::IsMouseDown(i)) { ImGui::SameLine(); ImGui::Text("b%d (%.02f secs)", i, io.MouseDownDuration[i]); }
|
|
|
- ImGui::Text("Mouse clicked:"); for (int i = 0; i < count; i++) if (ImGui::IsMouseClicked(i)) { ImGui::SameLine(); ImGui::Text("b%d (%d)", i, ImGui::GetMouseClickedCount(i)); }
|
|
|
- ImGui::Text("Mouse released:"); for (int i = 0; i < count; i++) if (ImGui::IsMouseReleased(i)) { ImGui::SameLine(); ImGui::Text("b%d", i); }
|
|
|
+ ImGui::Text("Mouse down:");
|
|
|
+ for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseDown(i)) { ImGui::SameLine(); ImGui::Text("b%d (%.02f secs)", i, io.MouseDownDuration[i]); }
|
|
|
ImGui::Text("Mouse wheel: %.1f", io.MouseWheel);
|
|
|
- ImGui::Text("Pen Pressure: %.1f", io.PenPressure); // Note: currently unused
|
|
|
- ImGui::TreePop();
|
|
|
- }
|
|
|
-
|
|
|
- // Display mouse cursors
|
|
|
- IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Mouse Cursors");
|
|
|
- if (ImGui::TreeNode("Mouse Cursors"))
|
|
|
- {
|
|
|
- const char* mouse_cursors_names[] = { "Arrow", "TextInput", "ResizeAll", "ResizeNS", "ResizeEW", "ResizeNESW", "ResizeNWSE", "Hand", "NotAllowed" };
|
|
|
- IM_ASSERT(IM_ARRAYSIZE(mouse_cursors_names) == ImGuiMouseCursor_COUNT);
|
|
|
-
|
|
|
- ImGuiMouseCursor current = ImGui::GetMouseCursor();
|
|
|
- ImGui::Text("Current mouse cursor = %d: %s", current, mouse_cursors_names[current]);
|
|
|
- ImGui::BeginDisabled(true);
|
|
|
- ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", &io.BackendFlags, ImGuiBackendFlags_HasMouseCursors);
|
|
|
- ImGui::EndDisabled();
|
|
|
|
|
|
- ImGui::Text("Hover to see mouse cursors:");
|
|
|
- ImGui::SameLine(); HelpMarker(
|
|
|
- "Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. "
|
|
|
- "If software cursor rendering (io.MouseDrawCursor) is set ImGui will draw the right cursor for you, "
|
|
|
- "otherwise your backend needs to handle it.");
|
|
|
- for (int i = 0; i < ImGuiMouseCursor_COUNT; i++)
|
|
|
- {
|
|
|
- char label[32];
|
|
|
- sprintf(label, "Mouse cursor %d: %s", i, mouse_cursors_names[i]);
|
|
|
- ImGui::Bullet(); ImGui::Selectable(label, false);
|
|
|
- if (ImGui::IsItemHovered())
|
|
|
- ImGui::SetMouseCursor(i);
|
|
|
- }
|
|
|
- ImGui::TreePop();
|
|
|
- }
|
|
|
-
|
|
|
- // Display Keyboard/Mouse state
|
|
|
- IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Keyboard, Gamepad & Navigation State");
|
|
|
- if (ImGui::TreeNode("Keyboard, Gamepad & Navigation State"))
|
|
|
- {
|
|
|
// We iterate both legacy native range and named ImGuiKey ranges, which is a little odd but this allows displaying the data for old/new backends.
|
|
|
// User code should never have to go through such hoops: old code may use native keycodes, new code may use ImGuiKey codes.
|
|
|
#ifdef IMGUI_DISABLE_OBSOLETE_KEYIO
|
|
|
struct funcs { static bool IsLegacyNativeDupe(ImGuiKey) { return false; } };
|
|
|
- const ImGuiKey key_first = (ImGuiKey)ImGuiKey_NamedKey_BEGIN;
|
|
|
#else
|
|
|
struct funcs { static bool IsLegacyNativeDupe(ImGuiKey key) { return key < 512 && ImGui::GetIO().KeyMap[key] != -1; } }; // Hide Native<>ImGuiKey duplicates when both exists in the array
|
|
|
- const ImGuiKey key_first = (ImGuiKey)0;
|
|
|
- //ImGui::Text("Legacy raw:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key++) { if (io.KeysDown[key]) { ImGui::SameLine(); ImGui::Text("\"%s\" %d", ImGui::GetKeyName(key), key); } }
|
|
|
#endif
|
|
|
- ImGui::Text("Keys down:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key = (ImGuiKey)(key + 1)) { if (funcs::IsLegacyNativeDupe(key)) continue; if (ImGui::IsKeyDown(key)) { ImGui::SameLine(); ImGui::Text("\"%s\" %d (%.02f)", ImGui::GetKeyName(key), key, ImGui::GetKeyData(key)->DownDuration); } }
|
|
|
- ImGui::Text("Keys pressed:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key = (ImGuiKey)(key + 1)) { if (funcs::IsLegacyNativeDupe(key)) continue; if (ImGui::IsKeyPressed(key)) { ImGui::SameLine(); ImGui::Text("\"%s\" %d", ImGui::GetKeyName(key), key); } }
|
|
|
- ImGui::Text("Keys released:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key = (ImGuiKey)(key + 1)) { if (funcs::IsLegacyNativeDupe(key)) continue; if (ImGui::IsKeyReleased(key)) { ImGui::SameLine(); ImGui::Text("\"%s\" %d", ImGui::GetKeyName(key), key); } }
|
|
|
+ ImGui::Text("Keys down:"); for (ImGuiKey key = ImGuiKey_KeysData_OFFSET; key < ImGuiKey_COUNT; key = (ImGuiKey)(key + 1)) { if (funcs::IsLegacyNativeDupe(key) || !ImGui::IsKeyDown(key)) continue; ImGui::SameLine(); ImGui::Text((key < ImGuiKey_NamedKey_BEGIN) ? "\"%s\"" : "\"%s\" %d", ImGui::GetKeyName(key), key); ImGui::SameLine(); ImGui::Text("(%.02f)", ImGui::GetKeyData(key)->DownDuration); }
|
|
|
ImGui::Text("Keys mods: %s%s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "", io.KeySuper ? "SUPER " : "");
|
|
|
- ImGui::Text("Chars queue:"); for (int i = 0; i < io.InputQueueCharacters.Size; i++) { ImWchar c = io.InputQueueCharacters[i]; ImGui::SameLine(); ImGui::Text("\'%c\' (0x%04X)", (c > ' ' && c <= 255) ? (char)c : '?', c); } // FIXME: We should convert 'c' to UTF-8 here but the functions are not public.
|
|
|
-
|
|
|
- // Draw an arbitrary US keyboard layout to visualize translated keys
|
|
|
- {
|
|
|
- const ImVec2 key_size = ImVec2(35.0f, 35.0f);
|
|
|
- const float key_rounding = 3.0f;
|
|
|
- const ImVec2 key_face_size = ImVec2(25.0f, 25.0f);
|
|
|
- const ImVec2 key_face_pos = ImVec2(5.0f, 3.0f);
|
|
|
- const float key_face_rounding = 2.0f;
|
|
|
- const ImVec2 key_label_pos = ImVec2(7.0f, 4.0f);
|
|
|
- const ImVec2 key_step = ImVec2(key_size.x - 1.0f, key_size.y - 1.0f);
|
|
|
- const float key_row_offset = 9.0f;
|
|
|
+ ImGui::Text("Chars queue:"); for (int i = 0; i < io.InputQueueCharacters.Size; i++) { ImWchar c = io.InputQueueCharacters[i]; ImGui::SameLine(); ImGui::Text("\'%c\' (0x%04X)", (c > ' ' && c <= 255) ? (char)c : '?', c); } // FIXME: We should convert 'c' to UTF-8 here but the functions are not public.
|
|
|
|
|
|
- ImVec2 board_min = ImGui::GetCursorScreenPos();
|
|
|
- ImVec2 board_max = ImVec2(board_min.x + 3 * key_step.x + 2 * key_row_offset + 10.0f, board_min.y + 3 * key_step.y + 10.0f);
|
|
|
- ImVec2 start_pos = ImVec2(board_min.x + 5.0f - key_step.x, board_min.y);
|
|
|
+ ImGui::TreePop();
|
|
|
+ }
|
|
|
|
|
|
- struct KeyLayoutData { int Row, Col; const char* Label; ImGuiKey Key; };
|
|
|
- const KeyLayoutData keys_to_display[] =
|
|
|
- {
|
|
|
- { 0, 0, "", ImGuiKey_Tab }, { 0, 1, "Q", ImGuiKey_Q }, { 0, 2, "W", ImGuiKey_W }, { 0, 3, "E", ImGuiKey_E }, { 0, 4, "R", ImGuiKey_R },
|
|
|
- { 1, 0, "", ImGuiKey_CapsLock }, { 1, 1, "A", ImGuiKey_A }, { 1, 2, "S", ImGuiKey_S }, { 1, 3, "D", ImGuiKey_D }, { 1, 4, "F", ImGuiKey_F },
|
|
|
- { 2, 0, "", ImGuiKey_LeftShift },{ 2, 1, "Z", ImGuiKey_Z }, { 2, 2, "X", ImGuiKey_X }, { 2, 3, "C", ImGuiKey_C }, { 2, 4, "V", ImGuiKey_V }
|
|
|
- };
|
|
|
-
|
|
|
- // Elements rendered manually via ImDrawList API are not clipped automatically.
|
|
|
- // While not strictly necessary, here IsItemVisible() is used to avoid rendering these shapes when they are out of view.
|
|
|
- ImGui::Dummy(ImVec2(board_max.x - board_min.x, board_max.y - board_min.y));
|
|
|
- if (ImGui::IsItemVisible())
|
|
|
- {
|
|
|
- ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
|
|
- draw_list->PushClipRect(board_min, board_max, true);
|
|
|
- for (int n = 0; n < IM_ARRAYSIZE(keys_to_display); n++)
|
|
|
- {
|
|
|
- const KeyLayoutData* key_data = &keys_to_display[n];
|
|
|
- ImVec2 key_min = ImVec2(start_pos.x + key_data->Col * key_step.x + key_data->Row * key_row_offset, start_pos.y + key_data->Row * key_step.y);
|
|
|
- ImVec2 key_max = ImVec2(key_min.x + key_size.x, key_min.y + key_size.y);
|
|
|
- draw_list->AddRectFilled(key_min, key_max, IM_COL32(204, 204, 204, 255), key_rounding);
|
|
|
- draw_list->AddRect(key_min, key_max, IM_COL32(24, 24, 24, 255), key_rounding);
|
|
|
- ImVec2 face_min = ImVec2(key_min.x + key_face_pos.x, key_min.y + key_face_pos.y);
|
|
|
- ImVec2 face_max = ImVec2(face_min.x + key_face_size.x, face_min.y + key_face_size.y);
|
|
|
- draw_list->AddRect(face_min, face_max, IM_COL32(193, 193, 193, 255), key_face_rounding, ImDrawFlags_None, 2.0f);
|
|
|
- draw_list->AddRectFilled(face_min, face_max, IM_COL32(252, 252, 252, 255), key_face_rounding);
|
|
|
- ImVec2 label_min = ImVec2(key_min.x + key_label_pos.x, key_min.y + key_label_pos.y);
|
|
|
- draw_list->AddText(label_min, IM_COL32(64, 64, 64, 255), key_data->Label);
|
|
|
- if (ImGui::IsKeyDown(key_data->Key))
|
|
|
- draw_list->AddRectFilled(key_min, key_max, IM_COL32(255, 0, 0, 128), key_rounding);
|
|
|
- }
|
|
|
- draw_list->PopClipRect();
|
|
|
- }
|
|
|
- }
|
|
|
+ // Display ImGuiIO output flags
|
|
|
+ IMGUI_DEMO_MARKER("Inputs & Focus/Outputs");
|
|
|
+ ImGui::SetNextItemOpen(true, ImGuiCond_Once);
|
|
|
+ if (ImGui::TreeNode("Outputs"))
|
|
|
+ {
|
|
|
+ ImGui::Text("io.WantCaptureMouse: %d", io.WantCaptureMouse);
|
|
|
+ ImGui::Text("io.WantCaptureMouseUnlessPopupClose: %d", io.WantCaptureMouseUnlessPopupClose);
|
|
|
+ ImGui::Text("io.WantCaptureKeyboard: %d", io.WantCaptureKeyboard);
|
|
|
+ ImGui::Text("io.WantTextInput: %d", io.WantTextInput);
|
|
|
+ ImGui::Text("io.WantSetMousePos: %d", io.WantSetMousePos);
|
|
|
+ ImGui::Text("io.NavActive: %d, io.NavVisible: %d", io.NavActive, io.NavVisible);
|
|
|
ImGui::TreePop();
|
|
|
}
|
|
|
|
|
|
- if (ImGui::TreeNode("Capture override"))
|
|
|
+ IMGUI_DEMO_MARKER("Inputs & Focus/IO Output: Capture override");
|
|
|
+ if (ImGui::TreeNode("IO Output: Capture override"))
|
|
|
{
|
|
|
HelpMarker(
|
|
|
"The value of io.WantCaptureMouse and io.WantCaptureKeyboard are normally set by Dear ImGui "
|
|
@@ -5859,7 +5772,36 @@ static void ShowDemoWindowInputs()
|
|
|
ImGui::TreePop();
|
|
|
}
|
|
|
|
|
|
- IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Tabbing");
|
|
|
+ // Display mouse cursors
|
|
|
+ IMGUI_DEMO_MARKER("Inputs & Focus/Mouse Cursors");
|
|
|
+ if (ImGui::TreeNode("Mouse Cursors"))
|
|
|
+ {
|
|
|
+ const char* mouse_cursors_names[] = { "Arrow", "TextInput", "ResizeAll", "ResizeNS", "ResizeEW", "ResizeNESW", "ResizeNWSE", "Hand", "NotAllowed" };
|
|
|
+ IM_ASSERT(IM_ARRAYSIZE(mouse_cursors_names) == ImGuiMouseCursor_COUNT);
|
|
|
+
|
|
|
+ ImGuiMouseCursor current = ImGui::GetMouseCursor();
|
|
|
+ ImGui::Text("Current mouse cursor = %d: %s", current, mouse_cursors_names[current]);
|
|
|
+ ImGui::BeginDisabled(true);
|
|
|
+ ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", &io.BackendFlags, ImGuiBackendFlags_HasMouseCursors);
|
|
|
+ ImGui::EndDisabled();
|
|
|
+
|
|
|
+ ImGui::Text("Hover to see mouse cursors:");
|
|
|
+ ImGui::SameLine(); HelpMarker(
|
|
|
+ "Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. "
|
|
|
+ "If software cursor rendering (io.MouseDrawCursor) is set ImGui will draw the right cursor for you, "
|
|
|
+ "otherwise your backend needs to handle it.");
|
|
|
+ for (int i = 0; i < ImGuiMouseCursor_COUNT; i++)
|
|
|
+ {
|
|
|
+ char label[32];
|
|
|
+ sprintf(label, "Mouse cursor %d: %s", i, mouse_cursors_names[i]);
|
|
|
+ ImGui::Bullet(); ImGui::Selectable(label, false);
|
|
|
+ if (ImGui::IsItemHovered())
|
|
|
+ ImGui::SetMouseCursor(i);
|
|
|
+ }
|
|
|
+ ImGui::TreePop();
|
|
|
+ }
|
|
|
+
|
|
|
+ IMGUI_DEMO_MARKER("Inputs & Focus/Tabbing");
|
|
|
if (ImGui::TreeNode("Tabbing"))
|
|
|
{
|
|
|
ImGui::Text("Use TAB/SHIFT+TAB to cycle through keyboard editable fields.");
|
|
@@ -5875,7 +5817,7 @@ static void ShowDemoWindowInputs()
|
|
|
ImGui::TreePop();
|
|
|
}
|
|
|
|
|
|
- IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Focus from code");
|
|
|
+ IMGUI_DEMO_MARKER("Inputs & Focus/Focus from code");
|
|
|
if (ImGui::TreeNode("Focus from code"))
|
|
|
{
|
|
|
bool focus_1 = ImGui::Button("Focus on 1"); ImGui::SameLine();
|
|
@@ -5917,7 +5859,7 @@ static void ShowDemoWindowInputs()
|
|
|
ImGui::TreePop();
|
|
|
}
|
|
|
|
|
|
- IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Dragging");
|
|
|
+ IMGUI_DEMO_MARKER("Inputs & Focus/Dragging");
|
|
|
if (ImGui::TreeNode("Dragging"))
|
|
|
{
|
|
|
ImGui::TextWrapped("You can use ImGui::GetMouseDragDelta(0) to query for the dragged amount on any widget.");
|