MCPcopy Create free account
hub / github.com/cinder/Cinder / ScrollToRectEx

Method ScrollToRectEx

src/imgui/imgui.cpp:11624–11694  ·  view source on GitHub ↗

Scroll to keep newly navigated item fully into view

Source from the content-addressed store, hash-verified

11622
11623// Scroll to keep newly navigated item fully into view
11624ImVec2 ImGui::ScrollToRectEx(ImGuiWindow* window, const ImRect& item_rect, ImGuiScrollFlags flags)
11625{
11626 ImGuiContext& g = *GImGui;
11627 ImRect scroll_rect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1));
11628 scroll_rect.Min.x = ImMin(scroll_rect.Min.x + window->DecoInnerSizeX1, scroll_rect.Max.x);
11629 scroll_rect.Min.y = ImMin(scroll_rect.Min.y + window->DecoInnerSizeY1, scroll_rect.Max.y);
11630 //GetForegroundDrawList(window)->AddRect(item_rect.Min, item_rect.Max, IM_COL32(255,0,0,255), 0.0f, 0, 5.0f); // [DEBUG]
11631 //GetForegroundDrawList(window)->AddRect(scroll_rect.Min, scroll_rect.Max, IM_COL32_WHITE); // [DEBUG]
11632
11633 // Check that only one behavior is selected per axis
11634 IM_ASSERT((flags & ImGuiScrollFlags_MaskX_) == 0 || ImIsPowerOfTwo(flags & ImGuiScrollFlags_MaskX_));
11635 IM_ASSERT((flags & ImGuiScrollFlags_MaskY_) == 0 || ImIsPowerOfTwo(flags & ImGuiScrollFlags_MaskY_));
11636
11637 // Defaults
11638 ImGuiScrollFlags in_flags = flags;
11639 if ((flags & ImGuiScrollFlags_MaskX_) == 0 && window->ScrollbarX)
11640 flags |= ImGuiScrollFlags_KeepVisibleEdgeX;
11641 if ((flags & ImGuiScrollFlags_MaskY_) == 0)
11642 flags |= window->Appearing ? ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeY;
11643
11644 const bool fully_visible_x = item_rect.Min.x >= scroll_rect.Min.x && item_rect.Max.x <= scroll_rect.Max.x;
11645 const bool fully_visible_y = item_rect.Min.y >= scroll_rect.Min.y && item_rect.Max.y <= scroll_rect.Max.y;
11646 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;
11647 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;
11648
11649 if ((flags & ImGuiScrollFlags_KeepVisibleEdgeX) && !fully_visible_x)
11650 {
11651 if (item_rect.Min.x < scroll_rect.Min.x || !can_be_fully_visible_x)
11652 SetScrollFromPosX(window, item_rect.Min.x - g.Style.ItemSpacing.x - window->Pos.x, 0.0f);
11653 else if (item_rect.Max.x >= scroll_rect.Max.x)
11654 SetScrollFromPosX(window, item_rect.Max.x + g.Style.ItemSpacing.x - window->Pos.x, 1.0f);
11655 }
11656 else if (((flags & ImGuiScrollFlags_KeepVisibleCenterX) && !fully_visible_x) || (flags & ImGuiScrollFlags_AlwaysCenterX))
11657 {
11658 if (can_be_fully_visible_x)
11659 SetScrollFromPosX(window, ImTrunc((item_rect.Min.x + item_rect.Max.x) * 0.5f) - window->Pos.x, 0.5f);
11660 else
11661 SetScrollFromPosX(window, item_rect.Min.x - window->Pos.x, 0.0f);
11662 }
11663
11664 if ((flags & ImGuiScrollFlags_KeepVisibleEdgeY) && !fully_visible_y)
11665 {
11666 if (item_rect.Min.y < scroll_rect.Min.y || !can_be_fully_visible_y)
11667 SetScrollFromPosY(window, item_rect.Min.y - g.Style.ItemSpacing.y - window->Pos.y, 0.0f);
11668 else if (item_rect.Max.y >= scroll_rect.Max.y)
11669 SetScrollFromPosY(window, item_rect.Max.y + g.Style.ItemSpacing.y - window->Pos.y, 1.0f);
11670 }
11671 else if (((flags & ImGuiScrollFlags_KeepVisibleCenterY) && !fully_visible_y) || (flags & ImGuiScrollFlags_AlwaysCenterY))
11672 {
11673 if (can_be_fully_visible_y)
11674 SetScrollFromPosY(window, ImTrunc((item_rect.Min.y + item_rect.Max.y) * 0.5f) - window->Pos.y, 0.5f);
11675 else
11676 SetScrollFromPosY(window, item_rect.Min.y - window->Pos.y, 0.0f);
11677 }
11678
11679 ImVec2 next_scroll = CalcNextScrollFromScrollTargetAndClamp(window);
11680 ImVec2 delta_scroll = next_scroll - window->Scroll;
11681

Callers

nothing calls this directly

Calls 7

ImVec2Function · 0.85
ImMinFunction · 0.85
ImIsPowerOfTwoFunction · 0.85
ImTruncFunction · 0.85
GetHeightMethod · 0.80
ImRectFunction · 0.50

Tested by

no test coverage detected