61 std::unique_ptr<View> content) {
62 auto* content_raw = content.get();
64 if (!pages_.empty()) {
65 content_raw->set_visible(
false);
68 pages_.push_back({std::move(title), std::move(icon), content_raw});
69 if (pages_.size() == 1) {
80 return index < pages_.size() ? pages_[index].content :
nullptr;
83 return index < pages_.size() ? pages_[index].title : empty_string();
86 return index < pages_.size() ? pages_[index].icon : empty_string();
93 return (active_ >= 0 &&
static_cast<size_t>(active_) < pages_.size())
94 ? pages_[
static_cast<size_t>(active_)].title
100 if (index < 0 ||
static_cast<size_t>(index) >= pages_.size())
return;
101 if (index == active_)
return;
103 if (active_ >= 0 &&
static_cast<size_t>(active_) < pages_.size()) {
104 if (
auto*
v = pages_[
static_cast<size_t>(active_)].content)
v->set_visible(
false);
107 if (
auto*
v = pages_[
static_cast<size_t>(active_)].content)
v->set_visible(
true);
114 for (
size_t i = 0;
i < pages_.size(); ++
i) {
115 if (pages_[
i].title == title) {
135 if (
auto stored = props_->get_string(persistence_key_)) {
144 persistence_key_ = std::move(key);
153 void persist_active()
const {
155 if (active_ < 0 ||
static_cast<size_t>(active_) >= pages_.size())
return;
156 props_->set_string(persistence_key_, pages_[
static_cast<size_t>(active_)].title);
158 void notify_change() {
161 static const std::string& empty_string() {
162 static const std::string
s;
166 std::vector<Page> pages_;
169 std::string persistence_key_ =
"preferences.active_page";
JSON-backed persistent settings file.
Definition properties_file.hpp:16
void simulate_select(int index)
Test helper — mirrors what a sidebar click would do.
Definition preferences_panel.hpp:124
std::function< void(int active_index)> on_page_change
Definition preferences_panel.hpp:150
const std::string & page_icon(size_t index) const
Definition preferences_panel.hpp:85
std::string active_page_title() const
Definition preferences_panel.hpp:92
const std::string & page_title(size_t index) const
Definition preferences_panel.hpp:82
const std::string & persistence_key() const
Definition preferences_panel.hpp:146
int active_page() const
Definition preferences_panel.hpp:91
bool has_persistence() const
Definition preferences_panel.hpp:141
void set_persistence_key(std::string key)
Definition preferences_panel.hpp:143
void clear_persistence()
Detach from persistence without touching the store.
Definition preferences_panel.hpp:140
void set_active_page(int index)
Switch by index. No-op when out of range.
Definition preferences_panel.hpp:99
size_t page_count() const
Definition preferences_panel.hpp:75
bool set_active_page(std::string_view title)
Switch by title. Returns true if a matching page was found.
Definition preferences_panel.hpp:113
View * page_content(size_t index) const
Returns nullptr if index is out of range.
Definition preferences_panel.hpp:79
void add_page(std::string title, std::string icon, std::unique_ptr< View > content)
Register a new page.
Definition preferences_panel.hpp:59
PreferencesPanel()=default
void bind_persistence(pulp::state::PropertiesFile *props)
Bind to a JSON-backed PropertiesFile (typically ApplicationProperties::user_settings()).
Definition preferences_panel.hpp:132
std::unique_ptr< View > add_child(std::unique_ptr< View > child)
Attaches child and returns nullptr.
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ s
Definition input_events.hpp:41
@ i
Definition input_events.hpp:40
@ v
Definition input_events.hpp:41
Definition preferences_panel.hpp:43
View * content
Non-owning — actual ownership is in the View tree (children_), so the page entry just remembers the s...
Definition preferences_panel.hpp:46
std::string title
Definition preferences_panel.hpp:44
std::string icon
Icon glyph / asset id; opaque to the panel.
Definition preferences_panel.hpp:45