mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:38:11 +00:00
GScrollBar: Add the same hover highlight effect as GButton.
This commit is contained in:
parent
8bda69e32f
commit
6306cf5c27
2 changed files with 31 additions and 3 deletions
|
@ -197,14 +197,14 @@ void GScrollBar::paint_event(GPaintEvent& event)
|
||||||
|
|
||||||
painter.fill_rect(rect(), Color::from_rgb(0xd6d2ce));
|
painter.fill_rect(rect(), Color::from_rgb(0xd6d2ce));
|
||||||
|
|
||||||
StylePainter::paint_button(painter, up_button_rect(), ButtonStyle::Normal, false);
|
StylePainter::paint_button(painter, up_button_rect(), ButtonStyle::Normal, false, m_hovered_component == Component::DecrementButton);
|
||||||
painter.draw_bitmap(up_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(up_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, down_button_rect(), ButtonStyle::Normal, false);
|
StylePainter::paint_button(painter, down_button_rect(), ButtonStyle::Normal, false, m_hovered_component == Component::IncrementButton);
|
||||||
painter.draw_bitmap(down_button_rect().location().translated(3, 3), orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, has_scrubber() ? Color::Black : Color::MidGray);
|
painter.draw_bitmap(down_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())
|
if (has_scrubber())
|
||||||
StylePainter::paint_button(painter, scrubber_rect(), ButtonStyle::Normal, false);
|
StylePainter::paint_button(painter, scrubber_rect(), ButtonStyle::Normal, false, m_hovered_component == Component::Scrubber);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GScrollBar::mousedown_event(GMouseEvent& event)
|
void GScrollBar::mousedown_event(GMouseEvent& event)
|
||||||
|
@ -271,6 +271,19 @@ void GScrollBar::mouseup_event(GMouseEvent& event)
|
||||||
|
|
||||||
void GScrollBar::mousemove_event(GMouseEvent& event)
|
void GScrollBar::mousemove_event(GMouseEvent& event)
|
||||||
{
|
{
|
||||||
|
auto old_hovered_component = m_hovered_component;
|
||||||
|
if (scrubber_rect().contains(event.position()))
|
||||||
|
m_hovered_component = Component::Scrubber;
|
||||||
|
else if (up_button_rect().contains(event.position()))
|
||||||
|
m_hovered_component = Component::DecrementButton;
|
||||||
|
else if (down_button_rect().contains(event.position()))
|
||||||
|
m_hovered_component = Component::IncrementButton;
|
||||||
|
else if (rect().contains(event.position()))
|
||||||
|
m_hovered_component = Component::Gutter;
|
||||||
|
else
|
||||||
|
m_hovered_component = Component::Invalid;
|
||||||
|
if (old_hovered_component != m_hovered_component)
|
||||||
|
update();
|
||||||
if (!m_scrubbing)
|
if (!m_scrubbing)
|
||||||
return;
|
return;
|
||||||
float delta = orientation() == Orientation::Vertical ? (event.y() - m_scrub_origin.y()) : (event.x() - m_scrub_origin.x());
|
float delta = orientation() == Orientation::Vertical ? (event.y() - m_scrub_origin.y()) : (event.x() - m_scrub_origin.x());
|
||||||
|
@ -279,3 +292,8 @@ void GScrollBar::mousemove_event(GMouseEvent& event)
|
||||||
float new_value = m_scrub_start_value + (value_steps_per_scrubbed_pixel * delta);
|
float new_value = m_scrub_start_value + (value_steps_per_scrubbed_pixel * delta);
|
||||||
set_value(new_value);
|
set_value(new_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GScrollBar::leave_event(GEvent&)
|
||||||
|
{
|
||||||
|
m_hovered_component = Component::Invalid;
|
||||||
|
}
|
||||||
|
|
|
@ -26,11 +26,20 @@ public:
|
||||||
|
|
||||||
virtual const char* class_name() const override { return "GScrollBar"; }
|
virtual const char* class_name() const override { return "GScrollBar"; }
|
||||||
|
|
||||||
|
enum Component {
|
||||||
|
Invalid,
|
||||||
|
DecrementButton,
|
||||||
|
IncrementButton,
|
||||||
|
Gutter,
|
||||||
|
Scrubber,
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void paint_event(GPaintEvent&) override;
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
virtual void mousedown_event(GMouseEvent&) override;
|
virtual void mousedown_event(GMouseEvent&) override;
|
||||||
virtual void mouseup_event(GMouseEvent&) override;
|
virtual void mouseup_event(GMouseEvent&) override;
|
||||||
virtual void mousemove_event(GMouseEvent&) override;
|
virtual void mousemove_event(GMouseEvent&) override;
|
||||||
|
virtual void leave_event(GEvent&) override;
|
||||||
|
|
||||||
int button_size() const { return orientation() == Orientation::Vertical ? width() : height(); }
|
int button_size() const { return orientation() == Orientation::Vertical ? width() : height(); }
|
||||||
Rect up_button_rect() const;
|
Rect up_button_rect() const;
|
||||||
|
@ -52,4 +61,5 @@ private:
|
||||||
Point m_scrub_origin;
|
Point m_scrub_origin;
|
||||||
|
|
||||||
Orientation m_orientation { Orientation::Vertical };
|
Orientation m_orientation { Orientation::Vertical };
|
||||||
|
Component m_hovered_component { Component::Invalid };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue