Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
scroll_bar.hpp
Go to the documentation of this file.
1#pragma once
2
23
24#include <algorithm>
25#include <functional>
27#include <pulp/view/view.hpp>
28
29namespace pulp::view {
30
37public:
39
40 // ── AccessibilityValueInterface ──────────────────────────────────────
41 double get_current_value() const override { return value_; }
42 void set_current_value(double v) override { set_value(static_cast<float>(v)); }
43 double get_minimum_value() const override { return min_; }
44 double get_maximum_value() const override { return max_; }
45 double get_step_size() const override {
46 return arrow_step_ > 0.0f
47 ? arrow_step_
49 }
50
52 // Every platform has a first-class scrollbar role (UIA ScrollBar,
53 // AT-SPI SCROLL_BAR, NSAccessibilityScrollBarRole); it keeps the
54 // value-bearing range contract of a slider but announces correctly.
56 set_focusable(true);
57 }
58
59 void set_orientation(Orientation o) { orientation_ = o; }
60 Orientation orientation() const { return orientation_; }
61
62 void set_range(float min_v, float max_v) {
63 min_ = min_v;
64 max_ = std::max(min_v, max_v);
65 clamp_value();
66 }
67 float min_value() const { return min_; }
68 float max_value() const { return max_; }
69
73 void set_page_size(float page) { page_size_ = std::max(0.0f, page); }
74 float page_size() const { return page_size_; }
75
76 void set_arrow_step(float s) { arrow_step_ = std::max(0.0f, s); }
77 float arrow_step() const { return arrow_step_; }
78
79 void set_page_step(float s) { page_step_ = std::max(0.0f, s); }
80 float page_step() const { return page_step_; }
81
85 bool set_value(float v) {
86 float clamped = std::clamp(v, min_, max_);
87 if (clamped == value_) return false;
88 value_ = clamped;
89 if (on_change) on_change(value_);
90 return true;
91 }
92 float value() const { return value_; }
93
98 std::function<void(float)> on_change;
99
100 // ── Input ────────────────────────────────────────────────────────────
101
102 void on_mouse_event(const MouseEvent& event) override;
103 void on_mouse_drag(Point pos) override;
104 bool on_key_event(const KeyEvent& event) override;
105 bool wants_mouse_input() const override { return true; }
106
107 // ── Paint ────────────────────────────────────────────────────────────
108
109 void paint(canvas::Canvas& canvas) override;
110
111 // ── Test hooks (headless) ────────────────────────────────────────────
112
116 float thumb_pixel_length() const;
117
120 float thumb_pixel_offset() const;
121
122private:
123 void clamp_value() { value_ = std::clamp(value_, min_, max_); }
124 float primary_axis_length() const;
125 void apply_track_click(Point local);
126 void apply_drag(Point local);
127 bool point_in_thumb(Point local) const;
128
129 Orientation orientation_ = Orientation::vertical;
130 float min_ = 0.0f;
131 float max_ = 1.0f;
132 float value_ = 0.0f;
133 float page_size_ = 0.1f;
134 float arrow_step_ = 0.05f;
135 float page_step_ = 0.2f;
136
137 bool dragging_ = false;
138 float drag_grab_offset_ = 0.0f; // distance from thumb leading edge to grab point
139};
140
141} // namespace pulp::view
Definition canvas.hpp:240
Interface for accessible values (sliders, knobs, progress bars).
Definition accessibility.hpp:16
virtual double get_step_size() const
Step increment for keyboard navigation.
Definition accessibility.hpp:36
double get_minimum_value() const override
Minimum value.
Definition scroll_bar.hpp:43
float value() const
Definition scroll_bar.hpp:92
void set_arrow_step(float s)
Definition scroll_bar.hpp:76
bool wants_mouse_input() const override
True if this widget handles mouse down/drag through virtual methods even when it does not expose JS p...
Definition scroll_bar.hpp:105
float page_size() const
Definition scroll_bar.hpp:74
void paint(canvas::Canvas &canvas) override
float page_step() const
Definition scroll_bar.hpp:80
void set_range(float min_v, float max_v)
Definition scroll_bar.hpp:62
void on_mouse_event(const MouseEvent &event) override
Mouse down with full event context.
double get_maximum_value() const override
Maximum value.
Definition scroll_bar.hpp:44
bool on_key_event(const KeyEvent &event) override
Key event with modifiers and up/down state.
void set_page_step(float s)
Definition scroll_bar.hpp:79
bool set_value(float v)
Set the scroll value, clamped to [min, max].
Definition scroll_bar.hpp:85
double get_current_value() const override
Current value as a number.
Definition scroll_bar.hpp:41
Orientation orientation() const
Definition scroll_bar.hpp:60
double get_step_size() const override
Step increment for keyboard navigation.
Definition scroll_bar.hpp:45
std::function< void(float)> on_change
Called whenever the value changes (user or programmatic).
Definition scroll_bar.hpp:98
float thumb_pixel_offset() const
Thumb's leading-edge position along the primary axis, in pixels (excluding arrow-button reservations)...
float arrow_step() const
Definition scroll_bar.hpp:77
ScrollBar()
Definition scroll_bar.hpp:51
float min_value() const
Definition scroll_bar.hpp:67
void on_mouse_drag(Point pos) override
float thumb_pixel_length() const
Thumb extent along the bar's primary axis, in pixels.
void set_current_value(double v) override
Set the value (if editable).
Definition scroll_bar.hpp:42
void set_orientation(Orientation o)
Definition scroll_bar.hpp:59
float max_value() const
Definition scroll_bar.hpp:68
Orientation
Definition scroll_bar.hpp:38
@ horizontal
Definition scroll_bar.hpp:38
@ vertical
Definition scroll_bar.hpp:38
void set_page_size(float page)
Length of the visible window in value units (caller's coords).
Definition scroll_bar.hpp:73
@ scroll_bar
Definition view.hpp:992
void set_access_role(AccessRole role)
Definition view.hpp:995
void set_focusable(bool f)
Definition view.hpp:669
Definition affine_transform.hpp:24
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ s
Definition input_events.hpp:41
@ v
Definition input_events.hpp:41
@ o
Definition input_events.hpp:40
Rich key event with key code, modifiers, and repeat state.
Definition input_events.hpp:193
Rich mouse/pointer event with position, modifiers, button state, pointer ID, and stylus properties.
Definition input_events.hpp:104
Definition geometry.hpp:20