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