Scroll to keep newly navigated item fully into view
| 11878 | |
| 11879 | // Scroll to keep newly navigated item fully into view |
| 11880 | ImVec2 ImGui::ScrollToRectEx(ImGuiWindow* window, const ImRect& item_rect, ImGuiScrollFlags flags) |
| 11881 | { |
| 11882 | ImGuiContext& g = *GImGui; |
| 11883 | ImRect scroll_rect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1)); |
| 11884 | scroll_rect.Min.x = ImMin(scroll_rect.Min.x + window->DecoInnerSizeX1, scroll_rect.Max.x); |
| 11885 | scroll_rect.Min.y = ImMin(scroll_rect.Min.y + window->DecoInnerSizeY1, scroll_rect.Max.y); |
| 11886 | //GetForegroundDrawList(window)->AddRect(item_rect.Min, item_rect.Max, IM_COL32(255,0,0,255), 0.0f, 0, 5.0f); // [DEBUG] |
| 11887 | //GetForegroundDrawList(window)->AddRect(scroll_rect.Min, scroll_rect.Max, IM_COL32_WHITE); // [DEBUG] |
| 11888 | |
| 11889 | // Check that only one behavior is selected per axis |
| 11890 | IM_ASSERT((flags & ImGuiScrollFlags_MaskX_) == 0 || ImIsPowerOfTwo(flags & ImGuiScrollFlags_MaskX_)); |
| 11891 | IM_ASSERT((flags & ImGuiScrollFlags_MaskY_) == 0 || ImIsPowerOfTwo(flags & ImGuiScrollFlags_MaskY_)); |
| 11892 | |
| 11893 | // Defaults |
| 11894 | ImGuiScrollFlags in_flags = flags; |
| 11895 | if ((flags & ImGuiScrollFlags_MaskX_) == 0 && window->ScrollbarX) |
| 11896 | flags |= ImGuiScrollFlags_KeepVisibleEdgeX; |
| 11897 | if ((flags & ImGuiScrollFlags_MaskY_) == 0) |
| 11898 | flags |= window->Appearing ? ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeY; |
| 11899 | |
| 11900 | const bool fully_visible_x = item_rect.Min.x >= scroll_rect.Min.x && item_rect.Max.x <= scroll_rect.Max.x; |
| 11901 | const bool fully_visible_y = item_rect.Min.y >= scroll_rect.Min.y && item_rect.Max.y <= scroll_rect.Max.y; |
| 11902 | 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; |
| 11903 | 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; |
| 11904 | |
| 11905 | if ((flags & ImGuiScrollFlags_KeepVisibleEdgeX) && !fully_visible_x) |
| 11906 | { |
| 11907 | if (item_rect.Min.x < scroll_rect.Min.x || !can_be_fully_visible_x) |
| 11908 | SetScrollFromPosX(window, item_rect.Min.x - g.Style.ItemSpacing.x - window->Pos.x, 0.0f); |
| 11909 | else if (item_rect.Max.x >= scroll_rect.Max.x) |
| 11910 | SetScrollFromPosX(window, item_rect.Max.x + g.Style.ItemSpacing.x - window->Pos.x, 1.0f); |
| 11911 | } |
| 11912 | else if (((flags & ImGuiScrollFlags_KeepVisibleCenterX) && !fully_visible_x) || (flags & ImGuiScrollFlags_AlwaysCenterX)) |
| 11913 | { |
| 11914 | if (can_be_fully_visible_x) |
| 11915 | SetScrollFromPosX(window, ImTrunc((item_rect.Min.x + item_rect.Max.x) * 0.5f) - window->Pos.x, 0.5f); |
| 11916 | else |
| 11917 | SetScrollFromPosX(window, item_rect.Min.x - window->Pos.x, 0.0f); |
| 11918 | } |
| 11919 | |
| 11920 | if ((flags & ImGuiScrollFlags_KeepVisibleEdgeY) && !fully_visible_y) |
| 11921 | { |
| 11922 | if (item_rect.Min.y < scroll_rect.Min.y || !can_be_fully_visible_y) |
| 11923 | SetScrollFromPosY(window, item_rect.Min.y - g.Style.ItemSpacing.y - window->Pos.y, 0.0f); |
| 11924 | else if (item_rect.Max.y >= scroll_rect.Max.y) |
| 11925 | SetScrollFromPosY(window, item_rect.Max.y + g.Style.ItemSpacing.y - window->Pos.y, 1.0f); |
| 11926 | } |
| 11927 | else if (((flags & ImGuiScrollFlags_KeepVisibleCenterY) && !fully_visible_y) || (flags & ImGuiScrollFlags_AlwaysCenterY)) |
| 11928 | { |
| 11929 | if (can_be_fully_visible_y) |
| 11930 | SetScrollFromPosY(window, ImTrunc((item_rect.Min.y + item_rect.Max.y) * 0.5f) - window->Pos.y, 0.5f); |
| 11931 | else |
| 11932 | SetScrollFromPosY(window, item_rect.Min.y - window->Pos.y, 0.0f); |
| 11933 | } |
| 11934 | |
| 11935 | ImVec2 next_scroll = CalcNextScrollFromScrollTargetAndClamp(window); |
| 11936 | ImVec2 delta_scroll = next_scroll - window->Scroll; |
| 11937 |
nothing calls this directly
no test coverage detected