Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
concertina_panel.hpp
Go to the documentation of this file.
1#pragma once
2
3// ConcertinaPanel — accordion-style collapsible panel stack.
4// Each section has a header that can be clicked to expand/collapse.
5
6#include <pulp/view/view.hpp>
7#include <string>
8#include <vector>
9#include <memory>
10#include <functional>
11
12namespace pulp::view {
13
14class ConcertinaPanel : public View {
15public:
16 ConcertinaPanel() = default;
17
20 void add_section(std::string title, std::unique_ptr<View> content,
21 bool initially_expanded = false);
22
24 void expand(int index);
25
27 void collapse(int index);
28
30 void toggle(int index);
31
33 bool is_expanded(int index) const;
34
36 int section_count() const { return static_cast<int>(sections_.size()); }
37
39 void set_header_height(float h) { header_height_ = h; }
40 float header_height() const { return header_height_; }
41
43 void set_exclusive(bool e) { exclusive_ = e; }
44 bool is_exclusive() const { return exclusive_; }
45
46 void paint(canvas::Canvas& canvas) override;
47 void on_mouse_down(Point pos) override;
48 bool wants_mouse_input() const override { return true; }
49
52
53private:
54 struct Section {
55 std::string title;
56 std::unique_ptr<View> content;
57 bool expanded = false;
58 };
59
60 std::vector<Section> sections_;
61 float header_height_ = 30.0f;
62 bool exclusive_ = false;
63};
64
65} // namespace pulp::view
Definition canvas.hpp:240
void on_mouse_down(Point pos) override
void set_exclusive(bool e)
Whether only one section can be open at a time (default: false).
Definition concertina_panel.hpp:43
float header_height() const
Definition concertina_panel.hpp:40
void expand(int index)
Expand a section by index.
void toggle(int index)
Toggle a section.
int section_count() const
Number of sections.
Definition concertina_panel.hpp:36
void paint(canvas::Canvas &canvas) override
bool is_expanded(int index) const
Whether a section is expanded.
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 concertina_panel.hpp:48
void layout_sections()
Layout the sections vertically. Call after adding/toggling sections.
void collapse(int index)
Collapse a section by index.
bool is_exclusive() const
Definition concertina_panel.hpp:44
void set_header_height(float h)
Header height for each section.
Definition concertina_panel.hpp:39
void add_section(std::string title, std::unique_ptr< View > content, bool initially_expanded=false)
Add a section with a title and content view.
Definition affine_transform.hpp:24
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ h
Definition input_events.hpp:39
@ e
Definition input_events.hpp:39
Definition geometry.hpp:20