mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
GScrollBar: Add the same hover highlight effect as GButton.
This commit is contained in:
parent
8bda69e32f
commit
6306cf5c27
Notes:
sideshowbarker
2024-07-19 14:48:19 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6306cf5c27c
@ -197,14 +197,14 @@ void GScrollBar::paint_event(GPaintEvent& event)
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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)
|
||||
@ -271,6 +271,19 @@ void GScrollBar::mouseup_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)
|
||||
return;
|
||||
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);
|
||||
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"; }
|
||||
|
||||
enum Component {
|
||||
Invalid,
|
||||
DecrementButton,
|
||||
IncrementButton,
|
||||
Gutter,
|
||||
Scrubber,
|
||||
};
|
||||
|
||||
private:
|
||||
virtual void paint_event(GPaintEvent&) override;
|
||||
virtual void mousedown_event(GMouseEvent&) override;
|
||||
virtual void mouseup_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(); }
|
||||
Rect up_button_rect() const;
|
||||
@ -52,4 +61,5 @@ private:
|
||||
Point m_scrub_origin;
|
||||
|
||||
Orientation m_orientation { Orientation::Vertical };
|
||||
Component m_hovered_component { Component::Invalid };
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user