2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-02-09 08:19:38 -02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2020-12-30 11:20:02 -03:00
|
|
|
#include <LibGUI/AbstractSlider.h>
|
2019-02-09 08:19:38 -02:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
namespace GUI {
|
|
|
|
|
|
2021-04-13 11:18:20 -03:00
|
|
|
class Scrollbar : public AbstractSlider {
|
|
|
|
|
C_OBJECT(Scrollbar);
|
2020-12-30 11:20:02 -03:00
|
|
|
|
2019-02-09 08:19:38 -02:00
|
|
|
public:
|
2021-04-13 11:18:20 -03:00
|
|
|
virtual ~Scrollbar() override;
|
2019-02-09 08:19:38 -02:00
|
|
|
|
2019-08-20 15:10:02 -03:00
|
|
|
bool is_scrollable() const { return max() != min(); }
|
|
|
|
|
|
2019-02-10 04:11:01 -02:00
|
|
|
bool has_scrubber() const;
|
2019-02-09 08:19:38 -02:00
|
|
|
|
2019-06-07 12:13:23 -03:00
|
|
|
enum Component {
|
2020-08-25 13:54:40 -03:00
|
|
|
None,
|
2019-04-06 08:55:56 -03:00
|
|
|
DecrementButton,
|
|
|
|
|
IncrementButton,
|
|
|
|
|
Gutter,
|
|
|
|
|
Scrubber,
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-20 20:19:52 -03:00
|
|
|
protected:
|
2021-04-13 11:18:20 -03:00
|
|
|
explicit Scrollbar(Gfx::Orientation = Gfx::Orientation::Vertical);
|
2020-02-02 11:07:41 -03:00
|
|
|
|
|
|
|
|
virtual void paint_event(PaintEvent&) override;
|
|
|
|
|
virtual void mousedown_event(MouseEvent&) override;
|
|
|
|
|
virtual void mouseup_event(MouseEvent&) override;
|
|
|
|
|
virtual void mousemove_event(MouseEvent&) override;
|
|
|
|
|
virtual void mousewheel_event(MouseEvent&) override;
|
2020-02-02 08:34:39 -03:00
|
|
|
virtual void leave_event(Core::Event&) override;
|
2020-02-02 11:07:41 -03:00
|
|
|
virtual void change_event(Event&) override;
|
2019-02-09 08:19:38 -02:00
|
|
|
|
2021-02-20 20:19:52 -03:00
|
|
|
private:
|
2019-07-01 04:46:36 -03:00
|
|
|
int default_button_size() const { return 16; }
|
|
|
|
|
int button_size() const { return length(orientation()) <= (default_button_size() * 2) ? length(orientation()) / 2 : default_button_size(); }
|
2019-04-11 08:16:43 -03:00
|
|
|
int button_width() const { return orientation() == Orientation::Vertical ? width() : button_size(); }
|
|
|
|
|
int button_height() const { return orientation() == Orientation::Horizontal ? height() : button_size(); }
|
2020-06-10 05:57:59 -03:00
|
|
|
Gfx::IntRect decrement_button_rect() const;
|
|
|
|
|
Gfx::IntRect increment_button_rect() const;
|
|
|
|
|
Gfx::IntRect scrubber_rect() const;
|
2020-08-11 22:35:15 -03:00
|
|
|
int unclamped_scrubber_size() const;
|
2020-08-11 22:32:40 -03:00
|
|
|
int visible_scrubber_size() const;
|
2019-02-10 03:51:01 -02:00
|
|
|
int scrubbable_range_in_pixels() const;
|
2019-06-07 05:43:10 -03:00
|
|
|
void on_automatic_scrolling_timer_fired();
|
2020-08-25 13:54:40 -03:00
|
|
|
void set_automatic_scrolling_active(bool, Component);
|
2019-02-09 08:19:38 -02:00
|
|
|
|
2020-08-11 21:56:52 -03:00
|
|
|
void scroll_to_position(const Gfx::IntPoint&);
|
2020-08-11 22:35:15 -03:00
|
|
|
void scroll_by_page(const Gfx::IntPoint&);
|
2020-08-11 21:56:52 -03:00
|
|
|
|
2020-08-25 11:31:20 -03:00
|
|
|
Component component_at_position(const Gfx::IntPoint&);
|
|
|
|
|
|
2019-02-10 03:51:01 -02:00
|
|
|
int m_scrub_start_value { 0 };
|
2020-06-10 05:57:59 -03:00
|
|
|
Gfx::IntPoint m_scrub_origin;
|
2019-02-10 08:57:19 -02:00
|
|
|
|
2020-08-25 13:54:40 -03:00
|
|
|
Component m_hovered_component { Component::None };
|
|
|
|
|
Component m_pressed_component { Component::None };
|
2020-08-25 12:04:53 -03:00
|
|
|
Gfx::IntPoint m_last_mouse_position;
|
2019-06-07 05:43:10 -03:00
|
|
|
|
2020-02-02 08:34:39 -03:00
|
|
|
RefPtr<Core::Timer> m_automatic_scrolling_timer;
|
2019-02-10 03:51:01 -02:00
|
|
|
};
|
2020-02-02 11:07:41 -03:00
|
|
|
|
|
|
|
|
}
|