Skip to content

Commit c77d369

Browse files
committed
GScrollBar: Make the scrubber size proportional to the scrollable range.
1 parent a5135db commit c77d369

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

LibGUI/GScrollBar.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,23 @@ Rect GScrollBar::lower_gutter_rect() const
151151
int GScrollBar::scrubbable_range_in_pixels() const
152152
{
153153
if (orientation() == Orientation::Vertical)
154-
return height() - button_size() * 3;
154+
return height() - button_size() * 2 - scrubber_size();
155155
else
156-
return width() - button_size() * 3;
156+
return width() - button_size() * 2 - scrubber_size();
157157
}
158158

159159
bool GScrollBar::has_scrubber() const
160160
{
161161
return m_max != m_min;
162162
}
163163

164+
int GScrollBar::scrubber_size() const
165+
{
166+
int pixel_range = (orientation() == Orientation::Vertical ? height() : width()) - button_size() * 2;
167+
int value_range = m_max - m_min;
168+
return ::max(pixel_range - value_range, button_size());
169+
}
170+
164171
Rect GScrollBar::scrubber_rect() const
165172
{
166173
if (!has_scrubber())
@@ -169,7 +176,7 @@ Rect GScrollBar::scrubber_rect() const
169176
if (m_value == m_min)
170177
x_or_y = button_size();
171178
else if (m_value == m_max)
172-
x_or_y = ((orientation() == Orientation::Vertical ? height() : width()) - (button_size() * 2)) + 1;
179+
x_or_y = ((orientation() == Orientation::Vertical ? height() : width()) - button_size() - scrubber_size()) + 1;
173180
else {
174181
float range_size = m_max - m_min;
175182
float available = scrubbable_range_in_pixels();
@@ -178,9 +185,9 @@ Rect GScrollBar::scrubber_rect() const
178185
}
179186

180187
if (orientation() == Orientation::Vertical)
181-
return { 0, (int)x_or_y, button_size(), button_size() };
188+
return { 0, (int)x_or_y, button_size(), scrubber_size() };
182189
else
183-
return { (int)x_or_y, 0, button_size(), button_size() };
190+
return { (int)x_or_y, 0, scrubber_size(), button_size() };
184191
}
185192

186193
void GScrollBar::paint_event(GPaintEvent& event)

LibGUI/GScrollBar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class GScrollBar final : public GWidget {
3838
Rect upper_gutter_rect() const;
3939
Rect lower_gutter_rect() const;
4040
Rect scrubber_rect() const;
41+
int scrubber_size() const;
4142
int scrubbable_range_in_pixels() const;
4243

4344
int m_min { 0 };

0 commit comments

Comments
 (0)