From fc568ea13a86b59b5a0c011fb4c74d1fefe563b5 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 8 Jul 2020 22:12:24 -0600 Subject: LibGUI: Make scrollbar thumb size relative to content size In order to calculate a thumb size that is a representation of the visible portion (page) of the content, that information needs to be taken into account. --- Libraries/LibGUI/ScrollBar.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'Libraries/LibGUI/ScrollBar.cpp') diff --git a/Libraries/LibGUI/ScrollBar.cpp b/Libraries/LibGUI/ScrollBar.cpp index c5a56e373d..a5fbdd367e 100644 --- a/Libraries/LibGUI/ScrollBar.cpp +++ b/Libraries/LibGUI/ScrollBar.cpp @@ -115,14 +115,17 @@ ScrollBar::~ScrollBar() { } -void ScrollBar::set_range(int min, int max) +void ScrollBar::set_range(int min, int max, int page) { ASSERT(min <= max); - if (m_min == min && m_max == max) + if (page < 0) + page = 0; + if (m_min == min && m_max == max && m_page == page) return; m_min = min; m_max = max; + m_page = page; int old_value = m_value; m_value = clamp(m_value, m_min, m_max); @@ -190,7 +193,14 @@ int ScrollBar::scrubber_size() const { int pixel_range = length(orientation()) - button_size() * 2; int value_range = m_max - m_min; - return ::max(pixel_range - value_range, button_size()); + + int scrubber_size = 0; + if (value_range > 0) { + // Scrubber size should be proportional to the visible portion + // (page) in relation to the content (value range + page) + scrubber_size = (m_page * pixel_range) / (value_range + m_page); + } + return ::max(scrubber_size, button_size()); } Gfx::IntRect ScrollBar::scrubber_rect() const -- cgit v1.2.3