mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-18 06:06:35 +00:00
Scrollbar: Comments. Fixed potential div-by-zero error which I can repro now, so added an assert to notify us if it's actually ever useful or not.
This commit is contained in:
parent
1065a7b95b
commit
fd394e1e95
@ -4490,15 +4490,17 @@ static void Scrollbar(ImGuiWindow* window, bool horizontal)
|
||||
window->DrawList->AddRectFilled(bb.Min, bb.Max, ImGui::GetColorU32(ImGuiCol_ScrollbarBg), window_rounding, window_rounding_corners);
|
||||
bb.Reduce(ImVec2(ImClamp((float)(int)((bb.Max.x - bb.Min.x - 2.0f) * 0.5f), 0.0f, 3.0f), ImClamp((float)(int)((bb.Max.y - bb.Min.y - 2.0f) * 0.5f), 0.0f, 3.0f)));
|
||||
|
||||
// V denote the main axis of the scrollbar
|
||||
// V denote the main, longer axis of the scrollbar (= height for a vertical scrollbar)
|
||||
float scrollbar_size_v = horizontal ? bb.GetWidth() : bb.GetHeight();
|
||||
float scroll_v = horizontal ? window->Scroll.x : window->Scroll.y;
|
||||
float win_size_avail_v = (horizontal ? window->SizeFull.x : window->SizeFull.y) - other_scrollbar_size_w;
|
||||
float win_size_contents_v = horizontal ? window->SizeContents.x : window->SizeContents.y;
|
||||
|
||||
// The grabbable box size generally represent the amount visible (vs the total scrollable amount)
|
||||
// Calculate the height of our grabbable box. It generally represent the amount visible (vs the total scrollable amount)
|
||||
// But we maintain a minimum size in pixel to allow for the user to still aim inside.
|
||||
const float grab_h_pixels = ImMin(ImMax(scrollbar_size_v * ImSaturate(win_size_avail_v / ImMax(win_size_contents_v, win_size_avail_v)), style.GrabMinSize), scrollbar_size_v);
|
||||
IM_ASSERT(ImMax(win_size_contents_v, win_size_avail_v) > 0.0f); // Adding this assert to check if the ImMax(XXX,1.0f) is still needed. PLEASE CONTACT ME if this triggers.
|
||||
const float win_size_v = ImMax(ImMax(win_size_contents_v, win_size_avail_v), 1.0f);
|
||||
const float grab_h_pixels = ImClamp(scrollbar_size_v * (win_size_avail_v / win_size_v), style.GrabMinSize, scrollbar_size_v);
|
||||
const float grab_h_norm = grab_h_pixels / scrollbar_size_v;
|
||||
|
||||
// Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar().
|
||||
|
Loading…
Reference in New Issue
Block a user