MCPcopy Create free account
hub / github.com/Wemino/EchoPatch / ScrollToRectEx

Method ScrollToRectEx

include/imgui/imgui.cpp:11804–11874  ·  view source on GitHub ↗

Scroll to keep newly navigated item fully into view

Source from the content-addressed store, hash-verified

11802
11803// Scroll to keep newly navigated item fully into view
11804ImVec2 ImGui::ScrollToRectEx(ImGuiWindow* window, const ImRect& item_rect, ImGuiScrollFlags flags)
11805{
11806 ImGuiContext& g = *GImGui;
11807 ImRect scroll_rect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1));
11808 scroll_rect.Min.x = ImMin(scroll_rect.Min.x + window->DecoInnerSizeX1, scroll_rect.Max.x);
11809 scroll_rect.Min.y = ImMin(scroll_rect.Min.y + window->DecoInnerSizeY1, scroll_rect.Max.y);
11810 //GetForegroundDrawList(window)->AddRect(item_rect.Min, item_rect.Max, IM_COL32(255,0,0,255), 0.0f, 0, 5.0f); // [DEBUG]
11811 //GetForegroundDrawList(window)->AddRect(scroll_rect.Min, scroll_rect.Max, IM_COL32_WHITE); // [DEBUG]
11812
11813 // Check that only one behavior is selected per axis
11814 IM_ASSERT((flags & ImGuiScrollFlags_MaskX_) == 0 || ImIsPowerOfTwo(flags & ImGuiScrollFlags_MaskX_));
11815 IM_ASSERT((flags & ImGuiScrollFlags_MaskY_) == 0 || ImIsPowerOfTwo(flags & ImGuiScrollFlags_MaskY_));
11816
11817 // Defaults
11818 ImGuiScrollFlags in_flags = flags;
11819 if ((flags & ImGuiScrollFlags_MaskX_) == 0 && window->ScrollbarX)
11820 flags |= ImGuiScrollFlags_KeepVisibleEdgeX;
11821 if ((flags & ImGuiScrollFlags_MaskY_) == 0)
11822 flags |= window->Appearing ? ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeY;
11823
11824 const bool fully_visible_x = item_rect.Min.x >= scroll_rect.Min.x && item_rect.Max.x <= scroll_rect.Max.x;
11825 const bool fully_visible_y = item_rect.Min.y >= scroll_rect.Min.y && item_rect.Max.y <= scroll_rect.Max.y;
11826 const bool can_be_fully_visible_x = (item_rect.GetWidth() + g.Style.ItemSpacing.x * 2.0f) <= scroll_rect.GetWidth() || (window->AutoFitFramesX > 0) || (window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0;
11827 const bool can_be_fully_visible_y = (item_rect.GetHeight() + g.Style.ItemSpacing.y * 2.0f) <= scroll_rect.GetHeight() || (window->AutoFitFramesY > 0) || (window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0;
11828
11829 if ((flags & ImGuiScrollFlags_KeepVisibleEdgeX) && !fully_visible_x)
11830 {
11831 if (item_rect.Min.x < scroll_rect.Min.x || !can_be_fully_visible_x)
11832 SetScrollFromPosX(window, item_rect.Min.x - g.Style.ItemSpacing.x - window->Pos.x, 0.0f);
11833 else if (item_rect.Max.x >= scroll_rect.Max.x)
11834 SetScrollFromPosX(window, item_rect.Max.x + g.Style.ItemSpacing.x - window->Pos.x, 1.0f);
11835 }
11836 else if (((flags & ImGuiScrollFlags_KeepVisibleCenterX) && !fully_visible_x) || (flags & ImGuiScrollFlags_AlwaysCenterX))
11837 {
11838 if (can_be_fully_visible_x)
11839 SetScrollFromPosX(window, ImTrunc((item_rect.Min.x + item_rect.Max.x) * 0.5f) - window->Pos.x, 0.5f);
11840 else
11841 SetScrollFromPosX(window, item_rect.Min.x - window->Pos.x, 0.0f);
11842 }
11843
11844 if ((flags & ImGuiScrollFlags_KeepVisibleEdgeY) && !fully_visible_y)
11845 {
11846 if (item_rect.Min.y < scroll_rect.Min.y || !can_be_fully_visible_y)
11847 SetScrollFromPosY(window, item_rect.Min.y - g.Style.ItemSpacing.y - window->Pos.y, 0.0f);
11848 else if (item_rect.Max.y >= scroll_rect.Max.y)
11849 SetScrollFromPosY(window, item_rect.Max.y + g.Style.ItemSpacing.y - window->Pos.y, 1.0f);
11850 }
11851 else if (((flags & ImGuiScrollFlags_KeepVisibleCenterY) && !fully_visible_y) || (flags & ImGuiScrollFlags_AlwaysCenterY))
11852 {
11853 if (can_be_fully_visible_y)
11854 SetScrollFromPosY(window, ImTrunc((item_rect.Min.y + item_rect.Max.y) * 0.5f) - window->Pos.y, 0.5f);
11855 else
11856 SetScrollFromPosY(window, item_rect.Min.y - window->Pos.y, 0.0f);
11857 }
11858
11859 ImVec2 next_scroll = CalcNextScrollFromScrollTargetAndClamp(window);
11860 ImVec2 delta_scroll = next_scroll - window->Scroll;
11861

Callers

nothing calls this directly

Calls 6

ImVec2Function · 0.85
ImMinFunction · 0.85
ImIsPowerOfTwoFunction · 0.85
ImTruncFunction · 0.85
ImRectFunction · 0.70

Tested by

no test coverage detected