Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
theme_editor.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pulp/view/view.hpp>
5#include <functional>
6
7namespace pulp::view {
8
14class ThemeEditor : public View {
15public:
17
20 editing_theme_ = std::move(theme);
21 build_swatches();
22 }
23
25 const Theme& editing_theme() const { return editing_theme_; }
26
28 std::function<void(const std::string& token, Color new_color)> on_color_changed;
29
31 std::function<void(const Theme& theme)> on_export;
32
34 std::string export_json() const { return editing_theme_.to_json(); }
35
37 std::vector<std::string> token_names() const {
38 std::vector<std::string> names;
39 names.reserve(editing_theme_.colors.size());
40 for (auto& [k, _] : editing_theme_.colors)
41 names.push_back(k);
42 return names;
43 }
44
46 void select_token(const std::string& name) {
47 selected_token_ = name;
48 auto it = editing_theme_.colors.find(name);
49 if (it != editing_theme_.colors.end()) {
50 picker_color_ = it->second;
51 }
52 }
53
54 const std::string& selected_token() const { return selected_token_; }
55
56protected:
57 void paint(canvas::Canvas& canvas) override;
58
59private:
60 void build_swatches();
61
62 Theme editing_theme_;
63 std::string selected_token_;
64 Color picker_color_;
65 float swatch_size_ = 24.0f;
66 float swatch_gap_ = 4.0f;
67};
68
69} // namespace pulp::view
Definition canvas.hpp:240
void paint(canvas::Canvas &canvas) override
const Theme & editing_theme() const
Get the current edited theme.
Definition theme_editor.hpp:25
void select_token(const std::string &name)
Set the currently selected token (opens ColorPicker for it).
Definition theme_editor.hpp:46
std::string export_json() const
Export the current theme as JSON.
Definition theme_editor.hpp:34
std::function< void(const std::string &token, Color new_color)> on_color_changed
Callback when any color token is changed.
Definition theme_editor.hpp:28
std::vector< std::string > token_names() const
Get the list of color token names in the theme.
Definition theme_editor.hpp:37
std::function< void(const Theme &theme)> on_export
Callback when the entire theme is exported (e.g., save button).
Definition theme_editor.hpp:31
const std::string & selected_token() const
Definition theme_editor.hpp:54
void set_theme(Theme theme)
Set the theme to edit. Changes are applied in real-time.
Definition theme_editor.hpp:19
const Theme & theme() const
Definition view.hpp:213
Definition affine_transform.hpp:24
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
canvas::Color Color
Definition theme.hpp:12
@ k
Definition input_events.hpp:40
Definition theme.hpp:32