Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
side_panel.hpp
Go to the documentation of this file.
1#pragma once
2
24
25#include <algorithm>
26#include <functional>
28#include <pulp/view/view.hpp>
29
30namespace pulp::view {
31
32class SidePanel : public View {
33public:
34 enum class Edge { left, right, top, bottom };
35 enum class State { closed, opening, open, closing };
36
37 SidePanel() = default;
38
39 void set_edge(Edge e) { edge_ = e; }
40 Edge edge() const { return edge_; }
41
44 void set_extent(float px) { extent_ = std::max(0.0f, px); }
45 float extent() const { return extent_; }
46
49 void set_animation_duration(float seconds) {
50 animation_duration_ = std::max(0.0f, seconds);
51 }
52 float animation_duration() const { return animation_duration_; }
53
54 void set_easing(EasingFunction ef) { easing_ = ef; }
55
58 void open() {
59 if (state_ == State::opening || state_ == State::open) return;
60 tween_ = Tween{progress_, 1.0f, animation_duration_, easing_};
61 state_ = State::opening;
62 set_visible(true);
64 }
65
67 void close() {
68 if (state_ == State::closing || state_ == State::closed) return;
69 tween_ = Tween{progress_, 0.0f, animation_duration_, easing_};
70 state_ = State::closing;
72 }
73
74 void toggle() {
75 if (state_ == State::open || state_ == State::opening) close();
76 else open();
77 }
78
79 State state() const { return state_; }
80 bool is_open() const { return state_ == State::open; }
81 bool is_open_or_opening() const {
82 return state_ == State::open || state_ == State::opening;
83 }
84 bool is_animating() const {
85 return state_ == State::opening || state_ == State::closing;
86 }
87
89 float progress() const { return progress_; }
90
93 float slide_offset() const { return progress_ * extent_; }
94
99 void advance_animations(float dt) override {
100 if (!is_animating()) return;
101 progress_ = tween_.advance(dt);
102 if (tween_.finished()) {
103 if (state_ == State::opening) {
104 state_ = State::open;
105 progress_ = 1.0f;
106 } else {
107 state_ = State::closed;
108 progress_ = 0.0f;
109 set_visible(false);
110 }
111 if (on_state_change) on_state_change(state_);
112 }
113 }
114
117 std::function<void(State)> on_state_change;
118
119private:
120 Edge edge_ = Edge::right;
121 float extent_ = 240.0f;
122 float animation_duration_ = 0.25f;
124
125 State state_ = State::closed;
126 float progress_ = 0.0f; // 0 = closed, 1 = open
127 Tween tween_;
128};
129
137
138} // namespace pulp::view
Definition side_panel.hpp:32
Edge
Definition side_panel.hpp:34
@ right
Definition side_panel.hpp:34
bool is_open() const
Definition side_panel.hpp:80
void close()
Slide-out tween. Idempotent.
Definition side_panel.hpp:67
Edge edge() const
Definition side_panel.hpp:40
float extent() const
Definition side_panel.hpp:45
State state() const
Definition side_panel.hpp:79
float slide_offset() const
Pixel distance the panel is slid in from the edge (0 → fully hidden, extent → fully visible).
Definition side_panel.hpp:93
State
Definition side_panel.hpp:35
@ closed
Definition side_panel.hpp:35
@ closing
Definition side_panel.hpp:35
@ open
Definition side_panel.hpp:35
@ opening
Definition side_panel.hpp:35
void open()
Slide-in tween.
Definition side_panel.hpp:58
bool is_open_or_opening() const
Definition side_panel.hpp:81
void set_animation_duration(float seconds)
Tween duration in seconds.
Definition side_panel.hpp:49
float animation_duration() const
Definition side_panel.hpp:52
bool is_animating() const
Definition side_panel.hpp:84
void set_easing(EasingFunction ef)
Definition side_panel.hpp:54
void toggle()
Definition side_panel.hpp:74
void advance_animations(float dt) override
Step the slide animation.
Definition side_panel.hpp:99
void set_edge(Edge e)
Definition side_panel.hpp:39
std::function< void(State)> on_state_change
Fires on every State transition (closed→opening, opening→open, open→closing, closing→closed).
Definition side_panel.hpp:117
float progress() const
0 = fully off-screen (closed), 1 = fully on-screen (open).
Definition side_panel.hpp:89
void set_extent(float px)
Pixel extent perpendicular to the edge.
Definition side_panel.hpp:44
Definition animation.hpp:72
void set_visible(bool v)
Show or hide this view.
Definition view.hpp:343
float bottom() const
Definition view.hpp:1800
float top() const
Definition view.hpp:1798
float right() const
Definition view.hpp:1799
float left() const
Definition view.hpp:1801
float ease_out_cubic(float t)
Definition animation.hpp:33
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ px
Absolute pixels.
Definition geometry.hpp:393
@ e
Definition input_events.hpp:39
SidePanel Sidebar
Design-system alias.
Definition side_panel.hpp:136
float(*)(float) EasingFunction
Definition animation.hpp:51