Horizon
Loading...
Searching...
No Matches
preferences_row.hpp
1#pragma once
2#include <gtkmm.h>
3#include "preferences/preferences.hpp"
4
5namespace horizon {
6
7class PreferencesRow : public Gtk::Box {
8public:
9 PreferencesRow(const std::string &title, const std::string &subtitle, Preferences &prefs);
10 virtual void activate()
11 {
12 }
13
14protected:
15 Preferences &preferences;
16 void set_title(const std::string &t);
17 void set_subtitle(const std::string &t);
18
19private:
20 Gtk::Label *label_title = nullptr;
21 Gtk::Label *label_subtitle = nullptr;
22};
23
24
26public:
27 PreferencesRowBool(const std::string &title, const std::string &subtitle, Preferences &prefs, bool &v);
28 void activate() override;
29
30private:
31 Gtk::Switch *sw = nullptr;
32};
33
35public:
36 PreferencesRowBoolButton(const std::string &title, const std::string &subtitle, const std::string &label_true,
37 const std::string &label_false, Preferences &prefs, bool &v);
38};
39
40template <typename T> class PreferencesRowNumeric : public PreferencesRow {
41public:
42 PreferencesRowNumeric(const std::string &title, const std::string &subtitle, Preferences &prefs, T &v)
43 : PreferencesRow(title, subtitle, prefs), value(v)
44 {
45 sp = Gtk::manage(new Gtk::SpinButton);
46 sp->set_valign(Gtk::ALIGN_CENTER);
47 sp->show();
48 pack_start(*sp, false, false, 0);
49 }
50
51 Gtk::SpinButton &get_spinbutton()
52 {
53 return *sp;
54 }
55
56 void bind()
57 {
58 sp->set_value(value);
59 sp->signal_value_changed().connect([this] {
60 value = sp->get_value();
61 preferences.signal_changed().emit();
62 });
63 }
64
65private:
66 T &value;
67 Gtk::SpinButton *sp = nullptr;
68};
69
70template <typename T> class PreferencesRowEnum : public PreferencesRow {
71public:
72 PreferencesRowEnum(const std::string &title, const std::string &subtitle, Preferences &prefs, T &v,
73 const std::vector<std::pair<T, std::string>> &names)
74 : PreferencesRow(title, subtitle, prefs), value(v)
75 {
76 combo = Gtk::manage(new Gtk::ComboBoxText);
77 for (const auto &[key, enum_value] : names) {
78 combo->append(std::to_string(static_cast<int>(key)), enum_value);
79 }
80 combo->set_valign(Gtk::ALIGN_CENTER);
81 combo->show();
82 pack_start(*combo, false, false, 0);
83 }
84
85 void bind()
86 {
87 combo->set_active_id(std::to_string(static_cast<int>(value)));
88 combo->signal_changed().connect([this] {
89 value = static_cast<T>(std::stoi(combo->get_active_id()));
90 preferences.signal_changed().emit();
91 });
92 }
93
94private:
95 T &value;
96 Gtk::ComboBoxText *combo = nullptr;
97};
98
99class PreferencesGroup : public Gtk::Box {
100public:
101 PreferencesGroup(const std::string &title);
102 void add_row(PreferencesRow &row);
103
104 void set_placeholder(Gtk::Widget &w);
105
106private:
107 Gtk::ListBox *listbox = nullptr;
108};
109
110} // namespace horizon
Definition preferences_row.hpp:99
Definition preferences_row.hpp:34
Definition preferences_row.hpp:25
Definition preferences_row.hpp:70
Definition preferences_row.hpp:40
Definition preferences_row.hpp:7
Definition preferences.hpp:167