Request a desired route for an input chord (key + mods). Return true if the route is available this frame. - Routes and key ownership are attributed at the beginning of next frame based on best score and mod state. (Conceptually this does a "Submit for next frame" + "Test for current frame". As such, it could be called TrySetXXX or SubmitXXX, or the Submit and Test operations should be separate.)
| 9509 | // (Conceptually this does a "Submit for next frame" + "Test for current frame". |
| 9510 | // As such, it could be called TrySetXXX or SubmitXXX, or the Submit and Test operations should be separate.) |
| 9511 | bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiInputFlags flags, ImGuiID owner_id) |
| 9512 | { |
| 9513 | ImGuiContext& g = *GImGui; |
| 9514 | if ((flags & ImGuiInputFlags_RouteTypeMask_) == 0) |
| 9515 | flags |= ImGuiInputFlags_RouteGlobal | ImGuiInputFlags_RouteOverFocused | ImGuiInputFlags_RouteOverActive; // IMPORTANT: This is the default for SetShortcutRouting() but NOT Shortcut() |
| 9516 | else |
| 9517 | IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiInputFlags_RouteTypeMask_)); // Check that only 1 routing flag is used |
| 9518 | IM_ASSERT(owner_id != ImGuiKeyOwner_Any && owner_id != ImGuiKeyOwner_NoOwner); |
| 9519 | if (flags & (ImGuiInputFlags_RouteOverFocused | ImGuiInputFlags_RouteOverActive | ImGuiInputFlags_RouteUnlessBgFocused)) |
| 9520 | IM_ASSERT(flags & ImGuiInputFlags_RouteGlobal); |
| 9521 | |
| 9522 | // Add ImGuiMod_XXXX when a corresponding ImGuiKey_LeftXXX/ImGuiKey_RightXXX is specified. |
| 9523 | key_chord = FixupKeyChord(key_chord); |
| 9524 | |
| 9525 | // [DEBUG] Debug break requested by user |
| 9526 | if (g.DebugBreakInShortcutRouting == key_chord) |
| 9527 | IM_DEBUG_BREAK(); |
| 9528 | |
| 9529 | if (flags & ImGuiInputFlags_RouteUnlessBgFocused) |
| 9530 | if (g.NavWindow == NULL) |
| 9531 | return false; |
| 9532 | |
| 9533 | // Note how ImGuiInputFlags_RouteAlways won't set routing and thus won't set owner. May want to rework this? |
| 9534 | if (flags & ImGuiInputFlags_RouteAlways) |
| 9535 | { |
| 9536 | IMGUI_DEBUG_LOG_INPUTROUTING("SetShortcutRouting(%s, flags=%04X, owner_id=0x%08X) -> always, no register\n", GetKeyChordName(key_chord), flags, owner_id); |
| 9537 | return true; |
| 9538 | } |
| 9539 | |
| 9540 | // Specific culling when there's an active item. |
| 9541 | if (g.ActiveId != 0 && g.ActiveId != owner_id) |
| 9542 | { |
| 9543 | if (flags & ImGuiInputFlags_RouteActive) |
| 9544 | return false; |
| 9545 | |
| 9546 | // Cull shortcuts with no modifiers when it could generate a character. |
| 9547 | // e.g. Shortcut(ImGuiKey_G) also generates 'g' character, should not trigger when InputText() is active. |
| 9548 | // but Shortcut(Ctrl+G) should generally trigger when InputText() is active. |
| 9549 | // TL;DR: lettered shortcut with no mods or with only Alt mod will not trigger while an item reading text input is active. |
| 9550 | // (We cannot filter based on io.InputQueueCharacters[] contents because of trickling and key<>chars submission order are undefined) |
| 9551 | if (g.IO.WantTextInput && IsKeyChordPotentiallyCharInput(key_chord)) |
| 9552 | { |
| 9553 | IMGUI_DEBUG_LOG_INPUTROUTING("SetShortcutRouting(%s, flags=%04X, owner_id=0x%08X) -> filtered as potential char input\n", GetKeyChordName(key_chord), flags, owner_id); |
| 9554 | return false; |
| 9555 | } |
| 9556 | |
| 9557 | // ActiveIdUsingAllKeyboardKeys trumps all for ActiveId |
| 9558 | if ((flags & ImGuiInputFlags_RouteOverActive) == 0 && g.ActiveIdUsingAllKeyboardKeys) |
| 9559 | { |
| 9560 | ImGuiKey key = (ImGuiKey)(key_chord & ~ImGuiMod_Mask_); |
| 9561 | if (key == ImGuiKey_None) |
| 9562 | key = ConvertSingleModFlagToKey((ImGuiKey)(key_chord & ImGuiMod_Mask_)); |
| 9563 | if (key >= ImGuiKey_Keyboard_BEGIN && key < ImGuiKey_Keyboard_END) |
| 9564 | return false; |
| 9565 | } |
| 9566 | } |
| 9567 | |
| 9568 | // Where do we evaluate route for? |
nothing calls this directly
no test coverage detected