2019-02-09 13:19:38 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <LibGUI/GWidget.h>
|
2019-02-09 13:19:38 +03:00
|
|
|
|
|
|
|
class GScrollBar final : public GWidget {
|
|
|
|
public:
|
2019-02-10 13:57:19 +03:00
|
|
|
explicit GScrollBar(Orientation, GWidget* parent);
|
2019-02-09 13:19:38 +03:00
|
|
|
virtual ~GScrollBar() override;
|
|
|
|
|
2019-02-10 13:57:19 +03:00
|
|
|
Orientation orientation() const { return m_orientation; }
|
|
|
|
|
2019-02-09 13:19:38 +03:00
|
|
|
int value() const { return m_value; }
|
|
|
|
int min() const { return m_min; }
|
|
|
|
int max() const { return m_max; }
|
|
|
|
int step() const { return m_step; }
|
|
|
|
int big_step() const { return m_big_step; }
|
|
|
|
|
2019-04-19 02:05:59 +03:00
|
|
|
void set_min(int min) { set_range(min, max()); }
|
|
|
|
void set_max(int max) { set_range(min(), max); }
|
2019-02-09 13:19:38 +03:00
|
|
|
void set_range(int min, int max);
|
|
|
|
void set_value(int value);
|
|
|
|
void set_step(int step) { m_step = step; }
|
|
|
|
void set_big_step(int big_step) { m_big_step = big_step; }
|
2019-02-10 09:11:01 +03:00
|
|
|
bool has_scrubber() const;
|
2019-02-09 13:19:38 +03:00
|
|
|
|
|
|
|
Function<void(int)> on_change;
|
|
|
|
|
2019-03-16 14:57:04 +03:00
|
|
|
virtual const char* class_name() const override { return "GScrollBar"; }
|
|
|
|
|
2019-05-28 12:53:16 +03:00
|
|
|
enum Component
|
|
|
|
{
|
2019-04-06 14:55:56 +03:00
|
|
|
Invalid,
|
|
|
|
DecrementButton,
|
|
|
|
IncrementButton,
|
|
|
|
Gutter,
|
|
|
|
Scrubber,
|
|
|
|
};
|
|
|
|
|
2019-02-09 13:19:38 +03:00
|
|
|
private:
|
|
|
|
virtual void paint_event(GPaintEvent&) override;
|
|
|
|
virtual void mousedown_event(GMouseEvent&) override;
|
2019-02-10 08:51:01 +03:00
|
|
|
virtual void mouseup_event(GMouseEvent&) override;
|
|
|
|
virtual void mousemove_event(GMouseEvent&) override;
|
2019-04-10 17:56:55 +03:00
|
|
|
virtual void leave_event(CEvent&) override;
|
2019-05-25 14:40:57 +03:00
|
|
|
virtual void change_event(GEvent&) override;
|
2019-02-09 13:19:38 +03:00
|
|
|
|
2019-04-11 14:16:43 +03:00
|
|
|
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(); }
|
2019-02-09 13:19:38 +03:00
|
|
|
Rect up_button_rect() const;
|
|
|
|
Rect down_button_rect() const;
|
2019-02-10 08:51:01 +03:00
|
|
|
Rect upper_gutter_rect() const;
|
|
|
|
Rect lower_gutter_rect() const;
|
2019-02-09 13:19:38 +03:00
|
|
|
Rect scrubber_rect() const;
|
2019-03-29 04:51:19 +03:00
|
|
|
int scrubber_size() const;
|
2019-02-10 08:51:01 +03:00
|
|
|
int scrubbable_range_in_pixels() const;
|
2019-02-09 13:19:38 +03:00
|
|
|
|
|
|
|
int m_min { 0 };
|
|
|
|
int m_max { 0 };
|
|
|
|
int m_value { 0 };
|
|
|
|
int m_step { 1 };
|
|
|
|
int m_big_step { 5 };
|
|
|
|
|
2019-02-10 08:51:01 +03:00
|
|
|
bool m_scrubbing { false };
|
|
|
|
int m_scrub_start_value { 0 };
|
|
|
|
Point m_scrub_origin;
|
2019-02-10 13:57:19 +03:00
|
|
|
|
|
|
|
Orientation m_orientation { Orientation::Vertical };
|
2019-04-06 14:55:56 +03:00
|
|
|
Component m_hovered_component { Component::Invalid };
|
2019-02-10 08:51:01 +03:00
|
|
|
};
|