Scroll to keep newly navigated item fully into view
| 12490 | |
| 12491 | // Scroll to keep newly navigated item fully into view |
| 12492 | ImVec2 ImGui::ScrollToRectEx(ImGuiWindow* window, const ImRect& item_rect, ImGuiScrollFlags flags) |
| 12493 | { |
| 12494 | ImGuiContext& g = *GImGui; |
| 12495 | ImRect scroll_rect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1)); |
| 12496 | scroll_rect.Min.x = ImMin(scroll_rect.Min.x + window->DecoInnerSizeX1, scroll_rect.Max.x); |
| 12497 | scroll_rect.Min.y = ImMin(scroll_rect.Min.y + window->DecoInnerSizeY1, scroll_rect.Max.y); |
| 12498 | //GetForegroundDrawList(window)->AddRect(item_rect.Min, item_rect.Max, IM_COL32(255,0,0,255), 0.0f, 0, 5.0f); // [DEBUG] |
| 12499 | //GetForegroundDrawList(window)->AddRect(scroll_rect.Min, scroll_rect.Max, IM_COL32_WHITE); // [DEBUG] |
| 12500 | |
| 12501 | // Check that only one behavior is selected per axis |
| 12502 | IM_ASSERT((flags & ImGuiScrollFlags_MaskX_) == 0 || ImIsPowerOfTwo(flags & ImGuiScrollFlags_MaskX_)); |
| 12503 | IM_ASSERT((flags & ImGuiScrollFlags_MaskY_) == 0 || ImIsPowerOfTwo(flags & ImGuiScrollFlags_MaskY_)); |
| 12504 | |
| 12505 | // Defaults |
| 12506 | ImGuiScrollFlags in_flags = flags; |
| 12507 | if ((flags & ImGuiScrollFlags_MaskX_) == 0 && window->ScrollbarX) |
| 12508 | flags |= ImGuiScrollFlags_KeepVisibleEdgeX; |
| 12509 | if ((flags & ImGuiScrollFlags_MaskY_) == 0) |
| 12510 | flags |= window->Appearing ? ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeY; |
| 12511 | |
| 12512 | const bool fully_visible_x = item_rect.Min.x >= scroll_rect.Min.x && item_rect.Max.x <= scroll_rect.Max.x; |
| 12513 | const bool fully_visible_y = item_rect.Min.y >= scroll_rect.Min.y && item_rect.Max.y <= scroll_rect.Max.y; |
| 12514 | 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; |
| 12515 | 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; |
| 12516 | |
| 12517 | if ((flags & ImGuiScrollFlags_KeepVisibleEdgeX) && !fully_visible_x) |
| 12518 | { |
| 12519 | if (item_rect.Min.x < scroll_rect.Min.x || !can_be_fully_visible_x) |
| 12520 | SetScrollFromPosX(window, item_rect.Min.x - g.Style.ItemSpacing.x - window->Pos.x, 0.0f); |
| 12521 | else if (item_rect.Max.x >= scroll_rect.Max.x) |
| 12522 | SetScrollFromPosX(window, item_rect.Max.x + g.Style.ItemSpacing.x - window->Pos.x, 1.0f); |
| 12523 | } |
| 12524 | else if (((flags & ImGuiScrollFlags_KeepVisibleCenterX) && !fully_visible_x) || (flags & ImGuiScrollFlags_AlwaysCenterX)) |
| 12525 | { |
| 12526 | if (can_be_fully_visible_x) |
| 12527 | SetScrollFromPosX(window, ImTrunc((item_rect.Min.x + item_rect.Max.x) * 0.5f) - window->Pos.x, 0.5f); |
| 12528 | else |
| 12529 | SetScrollFromPosX(window, item_rect.Min.x - window->Pos.x, 0.0f); |
| 12530 | } |
| 12531 | |
| 12532 | if ((flags & ImGuiScrollFlags_KeepVisibleEdgeY) && !fully_visible_y) |
| 12533 | { |
| 12534 | if (item_rect.Min.y < scroll_rect.Min.y || !can_be_fully_visible_y) |
| 12535 | SetScrollFromPosY(window, item_rect.Min.y - g.Style.ItemSpacing.y - window->Pos.y, 0.0f); |
| 12536 | else if (item_rect.Max.y >= scroll_rect.Max.y) |
| 12537 | SetScrollFromPosY(window, item_rect.Max.y + g.Style.ItemSpacing.y - window->Pos.y, 1.0f); |
| 12538 | } |
| 12539 | else if (((flags & ImGuiScrollFlags_KeepVisibleCenterY) && !fully_visible_y) || (flags & ImGuiScrollFlags_AlwaysCenterY)) |
| 12540 | { |
| 12541 | if (can_be_fully_visible_y) |
| 12542 | SetScrollFromPosY(window, ImTrunc((item_rect.Min.y + item_rect.Max.y) * 0.5f) - window->Pos.y, 0.5f); |
| 12543 | else |
| 12544 | SetScrollFromPosY(window, item_rect.Min.y - window->Pos.y, 0.0f); |
| 12545 | } |
| 12546 | |
| 12547 | ImVec2 next_scroll = CalcNextScrollFromScrollTargetAndClamp(window); |
| 12548 | ImVec2 delta_scroll = next_scroll - window->Scroll; |
| 12549 |
nothing calls this directly
no test coverage detected