MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / FindBestWheelingWindow

Function FindBestWheelingWindow

imgui_tiny_app/imgui/imgui.cpp:10897–10934  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10895}
10896
10897static ImGuiWindow* FindBestWheelingWindow(const ImVec2& wheel)
10898{
10899 // For each axis, find window in the hierarchy that may want to use scrolling
10900 ImGuiContext& g = *GImGui;
10901 ImGuiWindow* windows[2] = { NULL, NULL };
10902 for (int axis = 0; axis < 2; axis++)
10903 if (wheel[axis] != 0.0f)
10904 for (ImGuiWindow* window = windows[axis] = g.HoveredWindow; window->Flags & ImGuiWindowFlags_ChildWindow; window = windows[axis] = window->ParentWindow)
10905 {
10906 // Bubble up into parent window if:
10907 // - a child window doesn't allow any scrolling.
10908 // - a child window has the ImGuiWindowFlags_NoScrollWithMouse flag.
10909 //// - a child window doesn't need scrolling because it is already at the edge for the direction we are going in (FIXME-WIP)
10910 const bool has_scrolling = (window->ScrollMax[axis] != 0.0f);
10911 const bool inputs_disabled = (window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs);
10912 //const bool scrolling_past_limits = (wheel_v < 0.0f) ? (window->Scroll[axis] <= 0.0f) : (window->Scroll[axis] >= window->ScrollMax[axis]);
10913 if (has_scrolling && !inputs_disabled) // && !scrolling_past_limits)
10914 break; // select this window
10915 }
10916 if (windows[0] == NULL && windows[1] == NULL)
10917 return NULL;
10918
10919 // If there's only one window or only one axis then there's no ambiguity
10920 if (windows[0] == windows[1] || windows[0] == NULL || windows[1] == NULL)
10921 return windows[1] ? windows[1] : windows[0];
10922
10923 // If candidate are different windows we need to decide which one to prioritize
10924 // - First frame: only find a winner if one axis is zero.
10925 // - Subsequent frames: only find a winner when one is more than the other.
10926 if (g.WheelingWindowStartFrame == -1)
10927 g.WheelingWindowStartFrame = g.FrameCount;
10928 if ((g.WheelingWindowStartFrame == g.FrameCount && wheel.x != 0.0f && wheel.y != 0.0f) || (g.WheelingAxisAvg.x == g.WheelingAxisAvg.y))
10929 {
10930 g.WheelingWindowWheelRemainder = wheel;
10931 return NULL;
10932 }
10933 return (g.WheelingAxisAvg.x > g.WheelingAxisAvg.y) ? windows[0] : windows[1];
10934}
10935
10936// Called by NewFrame()
10937void ImGui::UpdateMouseWheel()

Callers 1

UpdateMouseWheelMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected