From 16990fece3d632d1133f3578e3642adb48cb94e6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 11 Apr 2019 13:16:43 +0200 Subject: [PATCH] GScrollBar: Improve appearance for curiously-shaped scrollbars. --- LibGUI/GScrollBar.cpp | 26 +++++++++++++------------- LibGUI/GScrollBar.h | 4 +++- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/LibGUI/GScrollBar.cpp b/LibGUI/GScrollBar.cpp index 2f356bfa451..acad0ecdb9f 100644 --- a/LibGUI/GScrollBar.cpp +++ b/LibGUI/GScrollBar.cpp @@ -120,40 +120,40 @@ void GScrollBar::set_value(int value) Rect GScrollBar::up_button_rect() const { - return { 0, 0, button_size(), button_size() }; + return { 0, 0, button_width(), button_height() }; } Rect GScrollBar::down_button_rect() const { if (orientation() == Orientation::Vertical) - return { 0, height() - button_size(), button_size(), button_size() }; + return { 0, height() - button_height(), button_width(), button_height() }; else - return { width() - button_size(), 0, button_size(), button_size() }; + return { width() - button_width(), 0, button_width(), button_height() }; } Rect GScrollBar::upper_gutter_rect() const { if (orientation() == Orientation::Vertical) - return { 0, button_size(), button_size(), scrubber_rect().top() - button_size() }; + return { 0, button_height(), button_width(), scrubber_rect().top() - button_height() }; else - return { button_size(), 0, scrubber_rect().x() - button_size(), button_size() }; + return { button_width(), 0, scrubber_rect().x() - button_width(), button_height() }; } Rect GScrollBar::lower_gutter_rect() const { auto scrubber_rect = this->scrubber_rect(); if (orientation() == Orientation::Vertical) - return { 0, scrubber_rect.bottom() + 1, button_size(), height() - button_size() - scrubber_rect.bottom() - 1}; + return { 0, scrubber_rect.bottom() + 1, button_width(), height() - button_height() - scrubber_rect.bottom() - 1}; else - return { scrubber_rect.right() + 1, 0, width() - button_size() - scrubber_rect.right() - 1, button_size() }; + return { scrubber_rect.right() + 1, 0, width() - button_width() - scrubber_rect.right() - 1, button_width() }; } int GScrollBar::scrubbable_range_in_pixels() const { if (orientation() == Orientation::Vertical) - return height() - button_size() * 2 - scrubber_size(); + return height() - button_height() * 2 - scrubber_size(); else - return width() - button_size() * 2 - scrubber_size(); + return width() - button_width() * 2 - scrubber_size(); } bool GScrollBar::has_scrubber() const @@ -185,9 +185,9 @@ Rect GScrollBar::scrubber_rect() const } if (orientation() == Orientation::Vertical) - return { 0, (int)x_or_y, button_size(), scrubber_size() }; + return { 0, (int)x_or_y, button_width(), scrubber_size() }; else - return { (int)x_or_y, 0, scrubber_size(), button_size() }; + return { (int)x_or_y, 0, scrubber_size(), button_height() }; } void GScrollBar::paint_event(GPaintEvent& event) @@ -241,8 +241,8 @@ void GScrollBar::mousedown_event(GMouseEvent& event) float range_size = m_max - m_min; float available = scrubbable_range_in_pixels(); - float x = ::max(0, event.position().x() - button_size() - button_size() / 2); - float y = ::max(0, event.position().y() - button_size() - button_size() / 2); + float x = ::max(0, event.position().x() - button_width() - button_width() / 2); + float y = ::max(0, event.position().y() - button_height() - button_height() / 2); float rel_x = x / available; float rel_y = y / available; diff --git a/LibGUI/GScrollBar.h b/LibGUI/GScrollBar.h index 6a5d2f2b7e1..4d13af190de 100644 --- a/LibGUI/GScrollBar.h +++ b/LibGUI/GScrollBar.h @@ -41,7 +41,9 @@ private: virtual void mousemove_event(GMouseEvent&) override; virtual void leave_event(CEvent&) override; - int button_size() const { return orientation() == Orientation::Vertical ? width() : height(); } + int button_size() const { return 16; } + int button_width() const { return orientation() == Orientation::Vertical ? width() : button_size(); } + int button_height() const { return orientation() == Orientation::Horizontal ? height() : button_size(); } Rect up_button_rect() const; Rect down_button_rect() const; Rect upper_gutter_rect() const;