Current score encoding - 0: Never route - 1: ImGuiInputFlags_RouteGlobal (lower priority) - 100..199: ImGuiInputFlags_RouteFocused (if window in focus-stack) 200: ImGuiInputFlags_RouteGlobal | ImGuiInputFlags_RouteOverFocused 300: ImGuiInputFlags_RouteActive or ImGuiInputFlags_RouteFocused (if item active) 400: ImGuiInputFlags_RouteGlobal | ImGuiInputFlags_RouteOverActive - 50
| 10246 | // - 500..599: ImGuiInputFlags_RouteFocused | ImGuiInputFlags_RouteOverActive (if window in focus-stack) (higher priority) |
| 10247 | // 'flags' should include an explicit routing policy |
| 10248 | static int CalcRoutingScore(ImGuiID focus_scope_id, ImGuiID owner_id, ImGuiInputFlags flags) |
| 10249 | { |
| 10250 | ImGuiContext& g = *GImGui; |
| 10251 | if (flags & ImGuiInputFlags_RouteFocused) |
| 10252 | { |
| 10253 | // ActiveID gets high priority |
| 10254 | // (we don't check g.ActiveIdUsingAllKeys here. Routing is applied but if input ownership is tested later it may discard it) |
| 10255 | if (owner_id != 0 && g.ActiveId == owner_id) |
| 10256 | return 300; |
| 10257 | |
| 10258 | // Score based on distance to focused window (lower is better) |
| 10259 | // Assuming both windows are submitting a routing request, |
| 10260 | // - When Window....... is focused -> Window scores 3 (best), Window/ChildB scores 255 (no match) |
| 10261 | // - When Window/ChildB is focused -> Window scores 4, Window/ChildB scores 3 (best) |
| 10262 | // Assuming only WindowA is submitting a routing request, |
| 10263 | // - When Window/ChildB is focused -> Window scores 4 (best), Window/ChildB doesn't have a score. |
| 10264 | // This essentially follow the window->ParentWindowForFocusRoute chain. |
| 10265 | if (focus_scope_id == 0) |
| 10266 | return 0; |
| 10267 | for (int index_in_focus_path = 0; index_in_focus_path < g.NavFocusRoute.Size; index_in_focus_path++) |
| 10268 | if (g.NavFocusRoute.Data[index_in_focus_path].ID == focus_scope_id) |
| 10269 | { |
| 10270 | if (flags & ImGuiInputFlags_RouteOverActive) // && g.ActiveId != 0 && g.ActiveId != owner_id) |
| 10271 | return 599 - index_in_focus_path; |
| 10272 | else |
| 10273 | return 199 - index_in_focus_path; |
| 10274 | } |
| 10275 | return 0; |
| 10276 | } |
| 10277 | else if (flags & ImGuiInputFlags_RouteActive) |
| 10278 | { |
| 10279 | if (owner_id != 0 && g.ActiveId == owner_id) |
| 10280 | return 300; |
| 10281 | return 0; |
| 10282 | } |
| 10283 | else if (flags & ImGuiInputFlags_RouteGlobal) |
| 10284 | { |
| 10285 | if (flags & ImGuiInputFlags_RouteOverActive) |
| 10286 | return 400; |
| 10287 | if (owner_id != 0 && g.ActiveId == owner_id) |
| 10288 | return 300; |
| 10289 | if (flags & ImGuiInputFlags_RouteOverFocused) |
| 10290 | return 200; |
| 10291 | return 1; |
| 10292 | } |
| 10293 | IM_ASSERT(0); |
| 10294 | return 0; |
| 10295 | } |
| 10296 | |
| 10297 | // - We need this to filter some Shortcut() routes when an item e.g. an InputText() is active |
| 10298 | // e.g. ImGuiKey_G won't be considered a shortcut when item is active, but ImGuiMod|ImGuiKey_G can be. |