Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
property_list.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pulp/view/view.hpp>
4#include <functional>
5#include <string>
6#include <variant>
7#include <vector>
8
9namespace pulp::view {
10
11// ── PropertyList ────────────────────────────────────────────────────────────
12// Key-value property editor for inspector panels.
13
14class PropertyList : public View {
15public:
17 using PropertyValue = std::variant<std::string, float, int, bool, Color>;
18
19 struct Property {
20 std::string key;
21 std::string label; // Display name
23 bool read_only = false;
24 std::string category; // Optional grouping category
25 };
26
28
30 void set_properties(std::vector<Property> props);
31 const std::vector<Property>& properties() const { return properties_; }
32
34 void set_value(const std::string& key, PropertyValue value);
35
37 const Property* find_property(const std::string& key) const;
38
40 std::function<void(const std::string& key, PropertyValue new_value)> on_change;
41
43 void set_row_height(float h) { row_height_ = h; }
44 float row_height() const { return row_height_; }
45
46 void set_label_width_fraction(float f) { label_width_ = f; }
47 float label_width_fraction() const { return label_width_; }
48
49 void set_show_categories(bool show) { show_categories_ = show; }
50 bool show_categories() const { return show_categories_; }
51
52 void paint(canvas::Canvas& canvas) override;
53 void on_mouse_down(Point pos) override;
54 bool wants_mouse_input() const override { return true; }
55
56 float intrinsic_height() const override;
57
58private:
59 std::vector<Property> properties_;
60 float row_height_ = 28.0f;
61 float label_width_ = 0.4f;
62 bool show_categories_ = true;
63 int editing_index_ = -1;
64};
65
66} // namespace pulp::view
Definition canvas.hpp:240
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 property_list.hpp:54
bool show_categories() const
Definition property_list.hpp:50
const std::vector< Property > & properties() const
Definition property_list.hpp:31
std::variant< std::string, float, int, bool, Color > PropertyValue
Property value types.
Definition property_list.hpp:17
float label_width_fraction() const
Definition property_list.hpp:47
void set_properties(std::vector< Property > props)
Set the list of properties.
void paint(canvas::Canvas &canvas) override
void set_value(const std::string &key, PropertyValue value)
Update a single property value by key.
float intrinsic_height() const override
void set_label_width_fraction(float f)
Definition property_list.hpp:46
void on_mouse_down(Point pos) override
std::function< void(const std::string &key, PropertyValue new_value)> on_change
Callback when a property value changes.
Definition property_list.hpp:40
void set_row_height(float h)
Display options.
Definition property_list.hpp:43
void set_show_categories(bool show)
Definition property_list.hpp:49
float row_height() const
Definition property_list.hpp:44
const Property * find_property(const std::string &key) const
Get a property value by key. Returns nullptr if not found.
Definition affine_transform.hpp:24
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ value
the widget's primary value (Knob, Fader, RangeSlider, Toggle, ProgressBar)
Definition binding_diagnostics.hpp:19
@ h
Definition input_events.hpp:39
@ f
Definition input_events.hpp:39
Definition geometry.hpp:20
Definition property_list.hpp:19
std::string label
Definition property_list.hpp:21
PropertyValue value
Definition property_list.hpp:22
bool read_only
Definition property_list.hpp:23
std::string key
Definition property_list.hpp:20
std::string category
Definition property_list.hpp:24