summaryrefslogtreecommitdiff
path: root/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-29 02:51:19 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-29 02:51:19 +0100
commitc77d369b75dd8e222efe0475a511066cf6211b02 (patch)
treec19dc9423a5874f850df21f39fd7270524747ac5 /LibGUI
parenta5135dbf011293519f8b75107cb91305a8d430a3 (diff)
downloadserenity-c77d369b75dd8e222efe0475a511066cf6211b02.zip
GScrollBar: Make the scrubber size proportional to the scrollable range.
Diffstat (limited to 'LibGUI')
-rw-r--r--LibGUI/GScrollBar.cpp17
-rw-r--r--LibGUI/GScrollBar.h1
2 files changed, 13 insertions, 5 deletions
diff --git a/LibGUI/GScrollBar.cpp b/LibGUI/GScrollBar.cpp
index 9f0c235726..f1d28de914 100644
--- a/LibGUI/GScrollBar.cpp
+++ b/LibGUI/GScrollBar.cpp
@@ -151,9 +151,9 @@ Rect GScrollBar::lower_gutter_rect() const
int GScrollBar::scrubbable_range_in_pixels() const
{
if (orientation() == Orientation::Vertical)
- return height() - button_size() * 3;
+ return height() - button_size() * 2 - scrubber_size();
else
- return width() - button_size() * 3;
+ return width() - button_size() * 2 - scrubber_size();
}
bool GScrollBar::has_scrubber() const
@@ -161,6 +161,13 @@ bool GScrollBar::has_scrubber() const
return m_max != m_min;
}
+int GScrollBar::scrubber_size() const
+{
+ int pixel_range = (orientation() == Orientation::Vertical ? height() : width()) - button_size() * 2;
+ int value_range = m_max - m_min;
+ return ::max(pixel_range - value_range, button_size());
+}
+
Rect GScrollBar::scrubber_rect() const
{
if (!has_scrubber())
@@ -169,7 +176,7 @@ Rect GScrollBar::scrubber_rect() const
if (m_value == m_min)
x_or_y = button_size();
else if (m_value == m_max)
- x_or_y = ((orientation() == Orientation::Vertical ? height() : width()) - (button_size() * 2)) + 1;
+ x_or_y = ((orientation() == Orientation::Vertical ? height() : width()) - button_size() - scrubber_size()) + 1;
else {
float range_size = m_max - m_min;
float available = scrubbable_range_in_pixels();
@@ -178,9 +185,9 @@ Rect GScrollBar::scrubber_rect() const
}
if (orientation() == Orientation::Vertical)
- return { 0, (int)x_or_y, button_size(), button_size() };
+ return { 0, (int)x_or_y, button_size(), scrubber_size() };
else
- return { (int)x_or_y, 0, button_size(), button_size() };
+ return { (int)x_or_y, 0, scrubber_size(), button_size() };
}
void GScrollBar::paint_event(GPaintEvent& event)
diff --git a/LibGUI/GScrollBar.h b/LibGUI/GScrollBar.h
index dca2c08475..b29e9f3811 100644
--- a/LibGUI/GScrollBar.h
+++ b/LibGUI/GScrollBar.h
@@ -38,6 +38,7 @@ private:
Rect upper_gutter_rect() const;
Rect lower_gutter_rect() const;
Rect scrubber_rect() const;
+ int scrubber_size() const;
int scrubbable_range_in_pixels() const;
int m_min { 0 };