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