1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-28 09:30:56 +01:00

Internal: Scrollbar: Further sane simplification (using InnerMainRect instead of duplicating calculations).

This commit is contained in:
omar 2019-05-09 19:30:13 +02:00
parent 37174c85e2
commit 39eeda0227
2 changed files with 17 additions and 25 deletions

View File

@ -39,6 +39,7 @@ Other Changes:
- Columns: Fixed Selectable with SpanAllColumns flag from creating an extraneous draw command. (#125) - Columns: Fixed Selectable with SpanAllColumns flag from creating an extraneous draw command. (#125)
- Separator: Revert 1.70 "Declare its thickness (1.0f) to the layout" change. It's not incorrect - Separator: Revert 1.70 "Declare its thickness (1.0f) to the layout" change. It's not incorrect
but it breaks existing some layout patterns. Will return back to it when we expose Separator flags. but it breaks existing some layout patterns. Will return back to it when we expose Separator flags.
- Scrollbar: Very minor bounding box adjustment to cope with various border size.
----------------------------------------------------------------------- -----------------------------------------------------------------------

View File

@ -875,36 +875,27 @@ void ImGui::Scrollbar(ImGuiAxis axis)
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow; ImGuiWindow* window = g.CurrentWindow;
const bool horizontal = (axis == ImGuiAxis_X);
const ImGuiStyle& style = g.Style;
const ImGuiID id = GetScrollbarID(window, axis); const ImGuiID id = GetScrollbarID(window, axis);
KeepAliveID(id); KeepAliveID(id);
// Calculate our bounding box (FIXME: This is messy, should be made simpler using e.g. InnerRect/WorkRect data). // Calculate scrollbar bounding box
const ImRect outer_rect = window->Rect();
const float other_scrollbar_size = window->ScrollbarSizes[axis]; const float other_scrollbar_size = window->ScrollbarSizes[axis];
const ImRect win_rect = window->Rect(); ImDrawCornerFlags rounding_corners = (other_scrollbar_size <= 0.0f) ? ImDrawCornerFlags_BotRight : 0;
const float border_size = window->WindowBorderSize; ImRect bb;
ImRect bb = horizontal if (axis == ImGuiAxis_X)
? ImRect(win_rect.Min.x + border_size, win_rect.Max.y - style.ScrollbarSize, win_rect.Max.x - other_scrollbar_size - border_size, win_rect.Max.y - border_size) {
: ImRect(win_rect.Max.x - style.ScrollbarSize, win_rect.Min.y + border_size, win_rect.Max.x - border_size, win_rect.Max.y - other_scrollbar_size - border_size); bb.Min = ImVec2(window->InnerMainRect.Min.x, window->InnerMainRect.Max.y);
bb.Min.x = ImMax(win_rect.Min.x, bb.Min.x); // Handle case where the host rectangle is smaller than the scrollbar bb.Max = ImVec2(window->InnerMainRect.Max.x, outer_rect.Max.y - window->WindowBorderSize);
bb.Min.y = ImMax(win_rect.Min.y, bb.Min.y); rounding_corners |= ImDrawCornerFlags_BotLeft;
if (!horizontal) }
bb.Min.y += window->TitleBarHeight() + ((window->Flags & ImGuiWindowFlags_MenuBar) ? window->MenuBarHeight() : 0.0f); // FIXME: InnerRect?
// Select rounding
ImDrawCornerFlags rounding_corners;
if (horizontal)
rounding_corners = ImDrawCornerFlags_BotLeft;
else else
rounding_corners = ((window->Flags & ImGuiWindowFlags_NoTitleBar) && !(window->Flags & ImGuiWindowFlags_MenuBar)) ? ImDrawCornerFlags_TopRight : 0; {
if (other_scrollbar_size <= 0.0f) bb.Min = ImVec2(window->InnerMainRect.Max.x, window->InnerMainRect.Min.y);
rounding_corners |= ImDrawCornerFlags_BotRight; bb.Max = ImVec2(outer_rect.Max.x - window->WindowBorderSize, window->InnerMainRect.Max.y);
rounding_corners |= ((window->Flags & ImGuiWindowFlags_NoTitleBar) && !(window->Flags & ImGuiWindowFlags_MenuBar)) ? ImDrawCornerFlags_TopRight : 0;
if (horizontal) }
ScrollbarEx(bb, id, axis, &window->Scroll.x, window->SizeFull.x - other_scrollbar_size, window->SizeContents.x, rounding_corners); ScrollbarEx(bb, id, axis, &window->Scroll[axis], window->SizeFull[axis] - other_scrollbar_size, window->SizeContents[axis], rounding_corners);
else
ScrollbarEx(bb, id, axis, &window->Scroll.y, window->SizeFull.y - other_scrollbar_size, window->SizeContents.y, rounding_corners);
} }
void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col) void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col)