Skip to content

Commit 16990fe

Browse files
committed
GScrollBar: Improve appearance for curiously-shaped scrollbars.
1 parent 07a9b2c commit 16990fe

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

LibGUI/GScrollBar.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,40 +120,40 @@ void GScrollBar::set_value(int value)
120120

121121
Rect GScrollBar::up_button_rect() const
122122
{
123-
return { 0, 0, button_size(), button_size() };
123+
return { 0, 0, button_width(), button_height() };
124124
}
125125

126126
Rect GScrollBar::down_button_rect() const
127127
{
128128
if (orientation() == Orientation::Vertical)
129-
return { 0, height() - button_size(), button_size(), button_size() };
129+
return { 0, height() - button_height(), button_width(), button_height() };
130130
else
131-
return { width() - button_size(), 0, button_size(), button_size() };
131+
return { width() - button_width(), 0, button_width(), button_height() };
132132
}
133133

134134
Rect GScrollBar::upper_gutter_rect() const
135135
{
136136
if (orientation() == Orientation::Vertical)
137-
return { 0, button_size(), button_size(), scrubber_rect().top() - button_size() };
137+
return { 0, button_height(), button_width(), scrubber_rect().top() - button_height() };
138138
else
139-
return { button_size(), 0, scrubber_rect().x() - button_size(), button_size() };
139+
return { button_width(), 0, scrubber_rect().x() - button_width(), button_height() };
140140
}
141141

142142
Rect GScrollBar::lower_gutter_rect() const
143143
{
144144
auto scrubber_rect = this->scrubber_rect();
145145
if (orientation() == Orientation::Vertical)
146-
return { 0, scrubber_rect.bottom() + 1, button_size(), height() - button_size() - scrubber_rect.bottom() - 1};
146+
return { 0, scrubber_rect.bottom() + 1, button_width(), height() - button_height() - scrubber_rect.bottom() - 1};
147147
else
148-
return { scrubber_rect.right() + 1, 0, width() - button_size() - scrubber_rect.right() - 1, button_size() };
148+
return { scrubber_rect.right() + 1, 0, width() - button_width() - scrubber_rect.right() - 1, button_width() };
149149
}
150150

151151
int GScrollBar::scrubbable_range_in_pixels() const
152152
{
153153
if (orientation() == Orientation::Vertical)
154-
return height() - button_size() * 2 - scrubber_size();
154+
return height() - button_height() * 2 - scrubber_size();
155155
else
156-
return width() - button_size() * 2 - scrubber_size();
156+
return width() - button_width() * 2 - scrubber_size();
157157
}
158158

159159
bool GScrollBar::has_scrubber() const
@@ -185,9 +185,9 @@ Rect GScrollBar::scrubber_rect() const
185185
}
186186

187187
if (orientation() == Orientation::Vertical)
188-
return { 0, (int)x_or_y, button_size(), scrubber_size() };
188+
return { 0, (int)x_or_y, button_width(), scrubber_size() };
189189
else
190-
return { (int)x_or_y, 0, scrubber_size(), button_size() };
190+
return { (int)x_or_y, 0, scrubber_size(), button_height() };
191191
}
192192

193193
void GScrollBar::paint_event(GPaintEvent& event)
@@ -241,8 +241,8 @@ void GScrollBar::mousedown_event(GMouseEvent& event)
241241
float range_size = m_max - m_min;
242242
float available = scrubbable_range_in_pixels();
243243

244-
float x = ::max(0, event.position().x() - button_size() - button_size() / 2);
245-
float y = ::max(0, event.position().y() - button_size() - button_size() / 2);
244+
float x = ::max(0, event.position().x() - button_width() - button_width() / 2);
245+
float y = ::max(0, event.position().y() - button_height() - button_height() / 2);
246246

247247
float rel_x = x / available;
248248
float rel_y = y / available;

LibGUI/GScrollBar.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ class GScrollBar final : public GWidget {
4141
virtual void mousemove_event(GMouseEvent&) override;
4242
virtual void leave_event(CEvent&) override;
4343

44-
int button_size() const { return orientation() == Orientation::Vertical ? width() : height(); }
44+
int button_size() const { return 16; }
45+
int button_width() const { return orientation() == Orientation::Vertical ? width() : button_size(); }
46+
int button_height() const { return orientation() == Orientation::Horizontal ? height() : button_size(); }
4547
Rect up_button_rect() const;
4648
Rect down_button_rect() const;
4749
Rect upper_gutter_rect() const;

0 commit comments

Comments
 (0)