|
@@ -5742,7 +5742,7 @@ static void ShowDemoWindowInputs()
|
|
ImGui::Text("io.WantSetMousePos: %d", io.WantSetMousePos);
|
|
ImGui::Text("io.WantSetMousePos: %d", io.WantSetMousePos);
|
|
ImGui::Text("io.NavActive: %d, io.NavVisible: %d", io.NavActive, io.NavVisible);
|
|
ImGui::Text("io.NavActive: %d, io.NavVisible: %d", io.NavActive, io.NavVisible);
|
|
|
|
|
|
- IMGUI_DEMO_MARKER("Inputs & Focus/Outputs/Capture override");
|
|
|
|
|
|
+ IMGUI_DEMO_MARKER("Inputs & Focus/Outputs/WantCapture override");
|
|
if (ImGui::TreeNode("WantCapture override"))
|
|
if (ImGui::TreeNode("WantCapture override"))
|
|
{
|
|
{
|
|
HelpMarker(
|
|
HelpMarker(
|
|
@@ -5767,6 +5767,76 @@ static void ShowDemoWindowInputs()
|
|
ImGui::TreePop();
|
|
ImGui::TreePop();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Demonstrate using Shortcut() and Routing Policies.
|
|
|
|
+ // The general flow is:
|
|
|
|
+ // - Code interested in a chord (e.g. "Ctrl+A") declares their intent.
|
|
|
|
+ // - Multiple locations may be interested in same chord! Routing helps find a winner.
|
|
|
|
+ // - Every frame, we resolve all claims and assign one owner if the modifiers are matching.
|
|
|
|
+ // - The lower-level function is 'bool SetShortcutRouting()', returns true when caller got the route.
|
|
|
|
+ // - Most of the times, SetShortcutRouting() is not called directly. User mostly calls Shortcut() with routing flags.
|
|
|
|
+ // - If you call Shortcut() WITHOUT any routing option, it uses ImGuiInputFlags_RouteFocused.
|
|
|
|
+ // TL;DR: Most uses will simply be:
|
|
|
|
+ // - Shortcut(ImGuiMod_Ctrl | ImGuiKey_A); // Use ImGuiInputFlags_RouteFocused policy.
|
|
|
|
+ if (ImGui::TreeNode("Shortcut Routing"))
|
|
|
|
+ {
|
|
|
|
+ const float line_height = ImGui::GetTextLineHeightWithSpacing();
|
|
|
|
+ const ImGuiKeyChord key_chord = ImGuiMod_Ctrl | ImGuiKey_A;
|
|
|
|
+ static ImGuiInputFlags repeat_flags = ImGuiInputFlags_Repeat;
|
|
|
|
+ static ImGuiInputFlags routing_flags = ImGuiInputFlags_RouteFocused;
|
|
|
|
+ ImGui::CheckboxFlags("ImGuiInputFlags_Repeat", &repeat_flags, ImGuiInputFlags_Repeat);
|
|
|
|
+ ImGui::RadioButton("ImGuiInputFlags_RouteFocused (default)", &routing_flags, ImGuiInputFlags_RouteFocused);
|
|
|
|
+ ImGui::RadioButton("ImGuiInputFlags_RouteAlways", &routing_flags, ImGuiInputFlags_RouteAlways);
|
|
|
|
+ ImGui::RadioButton("ImGuiInputFlags_RouteGlobal", &routing_flags, ImGuiInputFlags_RouteGlobal);
|
|
|
|
+ ImGui::RadioButton("ImGuiInputFlags_RouteGlobalHigh", &routing_flags, ImGuiInputFlags_RouteGlobalHigh);
|
|
|
|
+ ImGui::RadioButton("ImGuiInputFlags_RouteGlobalLow", &routing_flags, ImGuiInputFlags_RouteGlobalLow);
|
|
|
|
+ const ImGuiInputFlags flags = repeat_flags | routing_flags; // Merged flags
|
|
|
|
+
|
|
|
|
+ ImGui::Text("IsWindowFocused: %d, Shortcut: %s", ImGui::IsWindowFocused(), ImGui::Shortcut(key_chord, 0, flags) ? "PRESSED" : "...");
|
|
|
|
+
|
|
|
|
+ ImGui::BeginChild("WindowA", ImVec2(-FLT_MIN, line_height * 18), true);
|
|
|
|
+ ImGui::Text("Press CTRL+A and see who receives it!");
|
|
|
|
+ ImGui::Separator();
|
|
|
|
+
|
|
|
|
+ // 1: Window polling for CTRL+A
|
|
|
|
+ ImGui::Text("(in WindowA)");
|
|
|
|
+ ImGui::Text("IsWindowFocused: %d, Shortcut: %s", ImGui::IsWindowFocused(), ImGui::Shortcut(key_chord, 0, flags) ? "PRESSED" : "...");
|
|
|
|
+
|
|
|
|
+ // 2: InputText also polling for CTRL+A: it always uses _RouteFocused internally (gets priority when active)
|
|
|
|
+ char str[16] = "Press CTRL+A";
|
|
|
|
+ ImGui::Spacing();
|
|
|
|
+ ImGui::InputText("InputTextB", str, IM_ARRAYSIZE(str), ImGuiInputTextFlags_ReadOnly);
|
|
|
|
+ ImGuiID item_id = ImGui::GetItemID();
|
|
|
|
+ ImGui::SameLine(); HelpMarker("Internal widgets always use _RouteFocused");
|
|
|
|
+ ImGui::Text("IsWindowFocused: %d, Shortcut: %s", ImGui::IsWindowFocused(), ImGui::Shortcut(key_chord, item_id, flags) ? "PRESSED" : "...");
|
|
|
|
+
|
|
|
|
+ // 3: Dummy child is not claiming the route: focusing them shouldn't steal route away from WindowA
|
|
|
|
+ ImGui::BeginChild("ChildD", ImVec2(-FLT_MIN, line_height * 4), true);
|
|
|
|
+ ImGui::Text("(in ChildD: not using same Shortcut)");
|
|
|
|
+ ImGui::Text("IsWindowFocused: %d", ImGui::IsWindowFocused());
|
|
|
|
+ ImGui::EndChild();
|
|
|
|
+
|
|
|
|
+ // 4: Child window polling for CTRL+A. It is deeper than WindowA and gets priority when focused.
|
|
|
|
+ ImGui::BeginChild("ChildE", ImVec2(-FLT_MIN, line_height * 4), true);
|
|
|
|
+ ImGui::Text("(in ChildE: using same Shortcut)");
|
|
|
|
+ ImGui::Text("IsWindowFocused: %d, Shortcut: %s", ImGui::IsWindowFocused(), ImGui::Shortcut(key_chord, 0, flags) ? "PRESSED" : "...");
|
|
|
|
+ ImGui::EndChild();
|
|
|
|
+
|
|
|
|
+ // 5: In a popup
|
|
|
|
+ if (ImGui::Button("Open Popup"))
|
|
|
|
+ ImGui::OpenPopup("PopupF");
|
|
|
|
+ if (ImGui::BeginPopup("PopupF"))
|
|
|
|
+ {
|
|
|
|
+ ImGui::Text("(in PopupF)");
|
|
|
|
+ ImGui::Text("IsWindowFocused: %d, Shortcut: %s", ImGui::IsWindowFocused(), ImGui::Shortcut(key_chord, 0, flags) ? "PRESSED" : "...");
|
|
|
|
+ ImGui::InputText("InputTextG", str, IM_ARRAYSIZE(str), ImGuiInputTextFlags_ReadOnly);
|
|
|
|
+ ImGui::Text("IsWindowFocused: %d, Shortcut: %s", ImGui::IsWindowFocused(), ImGui::Shortcut(key_chord, ImGui::GetItemID(), flags) ? "PRESSED" : "...");
|
|
|
|
+ ImGui::EndPopup();
|
|
|
|
+ }
|
|
|
|
+ ImGui::EndChild();
|
|
|
|
+
|
|
|
|
+ ImGui::TreePop();
|
|
|
|
+ }
|
|
|
|
+
|
|
// Display mouse cursors
|
|
// Display mouse cursors
|
|
IMGUI_DEMO_MARKER("Inputs & Focus/Mouse Cursors");
|
|
IMGUI_DEMO_MARKER("Inputs & Focus/Mouse Cursors");
|
|
if (ImGui::TreeNode("Mouse Cursors"))
|
|
if (ImGui::TreeNode("Mouse Cursors"))
|
|
@@ -7024,12 +7094,15 @@ static void ShowExampleAppLayout(bool* p_open)
|
|
{
|
|
{
|
|
if (ImGui::BeginMenu("File"))
|
|
if (ImGui::BeginMenu("File"))
|
|
{
|
|
{
|
|
- if (ImGui::MenuItem("Close")) *p_open = false;
|
|
|
|
|
|
+ if (ImGui::MenuItem("Close", "Ctrl+W")) { *p_open = false; }
|
|
ImGui::EndMenu();
|
|
ImGui::EndMenu();
|
|
}
|
|
}
|
|
ImGui::EndMenuBar();
|
|
ImGui::EndMenuBar();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (ImGui::Shortcut(ImGuiMod_Ctrl | ImGuiKey_W))
|
|
|
|
+ *p_open = false;
|
|
|
|
+
|
|
// Left
|
|
// Left
|
|
static int selected = 0;
|
|
static int selected = 0;
|
|
{
|
|
{
|
|
@@ -7737,11 +7810,14 @@ struct MyDocument
|
|
ImGui::PushStyleColor(ImGuiCol_Text, doc->Color);
|
|
ImGui::PushStyleColor(ImGuiCol_Text, doc->Color);
|
|
ImGui::TextWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
|
|
ImGui::TextWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
|
|
ImGui::PopStyleColor();
|
|
ImGui::PopStyleColor();
|
|
- if (ImGui::Button("Modify", ImVec2(100, 0)))
|
|
|
|
|
|
+ if (ImGui::Button("Modify (Ctrl+M)") || ImGui::Shortcut(ImGuiMod_Shortcut | ImGuiKey_M))
|
|
doc->Dirty = true;
|
|
doc->Dirty = true;
|
|
ImGui::SameLine();
|
|
ImGui::SameLine();
|
|
- if (ImGui::Button("Save", ImVec2(100, 0)))
|
|
|
|
|
|
+ if (ImGui::Button("Save (Ctrl+S)") || ImGui::Shortcut(ImGuiMod_Shortcut | ImGuiKey_S))
|
|
doc->DoSave();
|
|
doc->DoSave();
|
|
|
|
+ ImGui::SameLine();
|
|
|
|
+ if (ImGui::Button("Close (Ctrl+W)") || ImGui::Shortcut(ImGuiMod_Shortcut | ImGuiKey_W))
|
|
|
|
+ doc->DoQueueClose();
|
|
ImGui::ColorEdit3("color", &doc->Color.x); // Useful to test drag and drop and hold-dragged-to-open-tab behavior.
|
|
ImGui::ColorEdit3("color", &doc->Color.x); // Useful to test drag and drop and hold-dragged-to-open-tab behavior.
|
|
ImGui::PopID();
|
|
ImGui::PopID();
|
|
}
|
|
}
|
|
@@ -7754,9 +7830,9 @@ struct MyDocument
|
|
|
|
|
|
char buf[256];
|
|
char buf[256];
|
|
sprintf(buf, "Save %s", doc->Name);
|
|
sprintf(buf, "Save %s", doc->Name);
|
|
- if (ImGui::MenuItem(buf, "CTRL+S", false, doc->Open))
|
|
|
|
|
|
+ if (ImGui::MenuItem(buf, "Ctrl+S", false, doc->Open))
|
|
doc->DoSave();
|
|
doc->DoSave();
|
|
- if (ImGui::MenuItem("Close", "CTRL+W", false, doc->Open))
|
|
|
|
|
|
+ if (ImGui::MenuItem("Close", "Ctrl+W", false, doc->Open))
|
|
doc->DoQueueClose();
|
|
doc->DoQueueClose();
|
|
ImGui::EndPopup();
|
|
ImGui::EndPopup();
|
|
}
|
|
}
|
|
@@ -7834,7 +7910,7 @@ void ShowExampleAppDocuments(bool* p_open)
|
|
if (ImGui::MenuItem("Close All Documents", NULL, false, open_count > 0))
|
|
if (ImGui::MenuItem("Close All Documents", NULL, false, open_count > 0))
|
|
for (int doc_n = 0; doc_n < app.Documents.Size; doc_n++)
|
|
for (int doc_n = 0; doc_n < app.Documents.Size; doc_n++)
|
|
app.Documents[doc_n].DoQueueClose();
|
|
app.Documents[doc_n].DoQueueClose();
|
|
- if (ImGui::MenuItem("Exit", "Ctrl+F4") && p_open)
|
|
|
|
|
|
+ if (ImGui::MenuItem("Exit") && p_open)
|
|
*p_open = false;
|
|
*p_open = false;
|
|
ImGui::EndMenu();
|
|
ImGui::EndMenu();
|
|
}
|
|
}
|