MCPcopy Create free account
hub / github.com/RenderKit/embree / CalcRoutingScore

Function CalcRoutingScore

tutorials/common/imgui/imgui.cpp:8071–8108  ·  view source on GitHub ↗

Current score encoding (lower is highest priority): - 0: ImGuiInputFlags_RouteGlobalHigh - 1: ImGuiInputFlags_RouteFocused (if item active) - 2: ImGuiInputFlags_RouteGlobal - 3+: ImGuiInputFlags_RouteFocused (if window in focus-stack) - 254: ImGuiInputFlags_RouteGlobalLow - 255: never route 'flags' should include an explicit routing policy

Source from the content-addressed store, hash-verified

8069// - 255: never route
8070// 'flags' should include an explicit routing policy
8071static int CalcRoutingScore(ImGuiWindow* location, ImGuiID owner_id, ImGuiInputFlags flags)
8072{
8073 if (flags & ImGuiInputFlags_RouteFocused)
8074 {
8075 ImGuiContext& g = *GImGui;
8076 ImGuiWindow* focused = g.NavWindow;
8077
8078 // ActiveID gets top priority
8079 // (we don't check g.ActiveIdUsingAllKeys here. Routing is applied but if input ownership is tested later it may discard it)
8080 if (owner_id != 0 && g.ActiveId == owner_id)
8081 return 1;
8082
8083 // Score based on distance to focused window (lower is better)
8084 // Assuming both windows are submitting a routing request,
8085 // - When Window....... is focused -> Window scores 3 (best), Window/ChildB scores 255 (no match)
8086 // - When Window/ChildB is focused -> Window scores 4, Window/ChildB scores 3 (best)
8087 // Assuming only WindowA is submitting a routing request,
8088 // - When Window/ChildB is focused -> Window scores 4 (best), Window/ChildB doesn't have a score.
8089 if (focused != NULL && focused->RootWindow == location->RootWindow)
8090 for (int next_score = 3; focused != NULL; next_score++)
8091 {
8092 if (focused == location)
8093 {
8094 IM_ASSERT(next_score < 255);
8095 return next_score;
8096 }
8097 focused = (focused->RootWindow != focused) ? focused->ParentWindow : NULL; // FIXME: This could be later abstracted as a focus path
8098 }
8099 return 255;
8100 }
8101
8102 // ImGuiInputFlags_RouteGlobalHigh is default, so calls without flags are not conditional
8103 if (flags & ImGuiInputFlags_RouteGlobal)
8104 return 2;
8105 if (flags & ImGuiInputFlags_RouteGlobalLow)
8106 return 254;
8107 return 0;
8108}
8109
8110// Request a desired route for an input chord (key + mods).
8111// Return true if the route is available this frame.

Callers 1

SetShortcutRoutingMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected