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.)
| 8115 | // - Using 'owner_id == ImGuiKeyOwner_Any/0': auto-assign an owner based on current focus scope (each window has its focus scope by default) |
| 8116 | // - Using 'owner_id == ImGuiKeyOwner_None': allows disabling/locking a shortcut. |
| 8117 | bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags) |
| 8118 | { |
| 8119 | ImGuiContext& g = *GImGui; |
| 8120 | if ((flags & ImGuiInputFlags_RouteMask_) == 0) |
| 8121 | flags |= ImGuiInputFlags_RouteGlobalHigh; // IMPORTANT: This is the default for SetShortcutRouting() but NOT Shortcut() |
| 8122 | else |
| 8123 | IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiInputFlags_RouteMask_)); // Check that only 1 routing flag is used |
| 8124 | |
| 8125 | if (flags & ImGuiInputFlags_RouteUnlessBgFocused) |
| 8126 | if (g.NavWindow == NULL) |
| 8127 | return false; |
| 8128 | if (flags & ImGuiInputFlags_RouteAlways) |
| 8129 | return true; |
| 8130 | |
| 8131 | const int score = CalcRoutingScore(g.CurrentWindow, owner_id, flags); |
| 8132 | if (score == 255) |
| 8133 | return false; |
| 8134 | |
| 8135 | // Submit routing for NEXT frame (assuming score is sufficient) |
| 8136 | // FIXME: Could expose a way to use a "serve last" policy for same score resolution (using <= instead of <). |
| 8137 | ImGuiKeyRoutingData* routing_data = GetShortcutRoutingData(key_chord); |
| 8138 | const ImGuiID routing_id = GetRoutingIdFromOwnerId(owner_id); |
| 8139 | //const bool set_route = (flags & ImGuiInputFlags_ServeLast) ? (score <= routing_data->RoutingNextScore) : (score < routing_data->RoutingNextScore); |
| 8140 | if (score < routing_data->RoutingNextScore) |
| 8141 | { |
| 8142 | routing_data->RoutingNext = routing_id; |
| 8143 | routing_data->RoutingNextScore = (ImU8)score; |
| 8144 | } |
| 8145 | |
| 8146 | // Return routing state for CURRENT frame |
| 8147 | return routing_data->RoutingCurr == routing_id; |
| 8148 | } |
| 8149 | |
| 8150 | // Currently unused by core (but used by tests) |
| 8151 | // Note: this cannot be turned into GetShortcutRouting() because we do the owner_id->routing_id translation, name would be more misleading. |
nothing calls this directly
no test coverage detected