mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05:00
parent
9ca453d8c9
commit
070a2f8980
3 changed files with 11 additions and 7 deletions
|
@ -165,20 +165,20 @@ bool GScrollBar::has_scrubber() const
|
|||
|
||||
int GScrollBar::scrubber_size() const
|
||||
{
|
||||
int pixel_range = (orientation() == Orientation::Vertical ? height() : width()) - button_size() * 2;
|
||||
int pixel_range = length(orientation()) - 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())
|
||||
if (!has_scrubber() || length(orientation()) <= (button_size() * 2) + scrubber_size())
|
||||
return {};
|
||||
float x_or_y;
|
||||
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() - scrubber_size()) + 1;
|
||||
x_or_y = (length(orientation()) - button_size() - scrubber_size()) + 1;
|
||||
else {
|
||||
float range_size = m_max - m_min;
|
||||
float available = scrubbable_range_in_pixels();
|
||||
|
@ -200,10 +200,12 @@ void GScrollBar::paint_event(GPaintEvent& event)
|
|||
painter.fill_rect(rect(), Color::from_rgb(0xd6d2ce));
|
||||
|
||||
StylePainter::paint_button(painter, decrement_button_rect(), ButtonStyle::Normal, false, m_hovered_component == Component::DecrementButton);
|
||||
painter.draw_bitmap(decrement_button_rect().location().translated(3, 3), orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, has_scrubber() ? Color::Black : Color::MidGray);
|
||||
|
||||
StylePainter::paint_button(painter, increment_button_rect(), ButtonStyle::Normal, false, m_hovered_component == Component::IncrementButton);
|
||||
painter.draw_bitmap(increment_button_rect().location().translated(3, 3), orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, has_scrubber() ? Color::Black : Color::MidGray);
|
||||
|
||||
if (length(orientation()) > default_button_size()) {
|
||||
painter.draw_bitmap(decrement_button_rect().location().translated(3, 3), orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, has_scrubber() ? Color::Black : Color::MidGray);
|
||||
painter.draw_bitmap(increment_button_rect().location().translated(3, 3), orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, has_scrubber() ? Color::Black : Color::MidGray);
|
||||
}
|
||||
|
||||
if (has_scrubber())
|
||||
StylePainter::paint_button(painter, scrubber_rect(), ButtonStyle::Normal, false, m_hovered_component == Component::Scrubber);
|
||||
|
|
|
@ -45,7 +45,8 @@ private:
|
|||
virtual void leave_event(CEvent&) override;
|
||||
virtual void change_event(GEvent&) override;
|
||||
|
||||
int button_size() const { return 16; }
|
||||
int default_button_size() const { return 16; }
|
||||
int button_size() const { return length(orientation()) <= (default_button_size() * 2) ? length(orientation()) / 2 : default_button_size(); }
|
||||
int button_width() const { return orientation() == Orientation::Vertical ? width() : button_size(); }
|
||||
int button_height() const { return orientation() == Orientation::Horizontal ? height() : button_size(); }
|
||||
Rect decrement_button_rect() const;
|
||||
|
|
|
@ -94,6 +94,7 @@ public:
|
|||
int y() const { return m_relative_rect.y(); }
|
||||
int width() const { return m_relative_rect.width(); }
|
||||
int height() const { return m_relative_rect.height(); }
|
||||
int length(Orientation orientation) const { return orientation == Orientation::Vertical ? height() : width(); }
|
||||
|
||||
Rect rect() const { return { 0, 0, width(), height() }; }
|
||||
Size size() const { return m_relative_rect.size(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue