-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shortcut routing for an active item #7618
Comments
I am going to investigate this. Please note that I have just started making some of this public API, and before doing so I have pushed various breaking changes:
|
I realize it may be confusing but this is correct as you are using the I believe you would want to do: if (ImGui::IsItemActive() && ImGui::Shortcut(ImGuiKey_M, ImGuiInputFlags_RouteFocused, ImGui::GetItemID()))
... Which is effectively essentially what widget code are doing themselves. But I realize it could make sense to add a helper |
I added if (ImGui::Shortcut(ImGuiKey_M, ImGuiInputFlags_RouteGlobal))
IMGUI_DEBUG_LOG("Global\n");
....
static char buf[32];
ImGui::InputText("##Address", buf, 32);
if (ImGui::Shortcut(ImGuiKey_M, ImGuiInputFlags_RouteActiveItem, ImGui::GetItemID()))
IMGUI_DEBUG_LOG("InputText shortcut\n"); |
I believe the changes you posted will not help me. Here's the minimal reproducible example of my problem:
Here, the
In this case:
The last point happens because |
I didn't, it is because last week My point is this is incorrect (or at least not what you actually want): ImGui::InputText(...);
ImGui::Shortcut(ImGuiKey_M, ImGui::GetItemID(), ImGuiInputFlags_RouteFocused); This in latest works as expected: if (ImGui::Shortcut(ImGuiKey_M, ImGuiInputFlags_RouteGlobal))
IMGUI_DEBUG_LOG("Global\n");
ImGui::Begin("AAA");
static char buf[32];
ImGui::InputText("##Address", buf, 32);
if (ImGui::Shortcut(ImGuiKey_M, ImGuiInputFlags_RouteActive, ImGui::GetItemID()))
IMGUI_DEBUG_LOG("AAA\n");
ImGui::End();
ImGui::Begin("BBB");
if (ImGui::Shortcut(ImGuiKey_M))
IMGUI_DEBUG_LOG("BBB\n");
ImGui::End(); |
And in your older version, instead of: if (ImGui::Shortcut(ImGuiKey_M, ImGuiInputFlags_RouteGlobal))
IMGUI_DEBUG_LOG("Global\n"); You can write: if (ImGui::Shortcut(ImGuiKey_M, 0, ImGuiInputFlags_RouteGlobalLow))
IMGUI_DEBUG_LOG("Global\n"); And instead of: if (ImGui::Shortcut(ImGuiKey_M, ImGuiInputFlags_RouteActive, ImGui::GetItemID()))
IMGUI_DEBUG_LOG("AAA\n"); You can write: if (ImGui::IsItemActive() && ImGui::Shortcut(ImGuiKey_M, ImGui::GetItemID(), ImGuiInputFlags_RouteFocused))
IMGUI_DEBUG_LOG("AAA\n"); For the same effect. |
Thank you, @ocornut. Your suggested code works. The new changes (
but still looks strange - after all, when using an |
Not exactly: people want other shortcuts such as Ctrl+S to work. But here.... just realized there is bug, it shouldn't do it with M only, because key emitting characters should normally automatically be filtered out by the active |
Actually I think this debatable, here by passing Can you clarify what you actual use case is, with this |
The culling logic for keys that maps to characters only apply if you are NOT the active item: // Specific culling when there's an active item.
if (g.ActiveId != 0 && g.ActiveId != owner_id)
{
// Cull shortcuts with no modifiers when it could generate a character.
// e.g. Shortcut(ImGuiKey_G) also generates 'g' character, should not trigger when InputText() is active.
// but Shortcut(Ctrl+G) should generally trigger when InputText() is active.
// TL;DR: lettered shortcut with no mods or with only Alt mod will not trigger while an item reading text input is active.
// (We cannot filter based on io.InputQueueCharacters[] contents because of trickling and key<>chars submission order are undefined)
if ((flags & ImGuiInputFlags_RouteFocused) && g.IO.WantTextInput && IsKeyChordPotentiallyCharInput(key_chord))
{
IMGUI_DEBUG_LOG_INPUTROUTING("SetShortcutRouting(%s, flags=%04X, owner_id=0x%08X) -> filtered as potential char input\n", GetKeyChordName(key_chord), flags, owner_id);
return false;
} Which IMHO makes sense. I think sensible answer and design can only come if I understand what you are trying to achieve in the first place with this |
I have a list of global actions to perform - a dozen of tasks bound to different single letter keys (I'm porting a legacy app to The solution you posted kinda work, but requires to abbreviate all occurrences of |
Ah indeed the mixed key<>char filtering without mods should have been applied for global routes as well, my mistake: 7832e6a I'm writing new sets of tests right now. |
I have amended the When you have time could you update to latest and make sure everything works as expected? Thanks for your help and feedback! |
I updated to latest and everything works now - I don't need to |
I am curious however when/how you are using |
That's right, I tested it with |
Version/Branch of Dear ImGui:
Version 1.90.1, Branch: docking
Back-ends:
imgui_impl_glfw.cpp
Compiler, OS:
Ubuntu 20.04, imgui_impl_glfw
Full config/build information:
No response
Details:
In this scenario:
I want to achieve the following:
According to the docs, the routing is organized like this:
Following this logic I added to my
main.cpp
:And for the text input:
While preventing to fire a global shortcut during text input usage, it also intercepts the shortcut when the text not in focus, but the window where this text is a child is in focus. In other words, the line
ImGui::SetShortcutRouting(ImGuiKey_M, ImGui::GetID("##Address"), ImGuiInputFlags_RouteFocused)
returnstrue
even when the text input not focused, but the parent window is.The text was updated successfully, but these errors were encountered: