Horizon
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};
17
18
20public:
21 PreferencesRowBool(const std::string &title, const std::string &subtitle, Preferences &prefs, bool &v);
22 void activate() override;
23
24private:
25 Gtk::Switch *sw = nullptr;
26};
27
29public:
30 PreferencesRowBoolButton(const std::string &title, const std::string &subtitle, const std::string &label_true,
31 const std::string &label_false, Preferences &prefs, bool &v);
32};
33
34template <typename T> class PreferencesRowNumeric : public PreferencesRow {
35public:
36 PreferencesRowNumeric(const std::string &title, const std::string &subtitle, Preferences &prefs, T &v)
37 : PreferencesRow(title, subtitle, prefs), value(v)
38 {
39 sp = Gtk::manage(new Gtk::SpinButton);
40 sp->set_valign(Gtk::ALIGN_CENTER);
41 sp->show();
42 pack_start(*sp, false, false, 0);
43 }
44
45 Gtk::SpinButton &get_spinbutton()
46 {
47 return *sp;
48 }
49
50 void bind()
51 {
52 sp->set_value(value);
53 sp->signal_value_changed().connect([this] {
54 value = sp->get_value();
55 preferences.signal_changed().emit();
56 });
57 }
58
59private:
60 T &value;
61 Gtk::SpinButton *sp = nullptr;
62};
63
64class PreferencesGroup : public Gtk::Box {
65public:
66 PreferencesGroup(const std::string &title);
67 void add_row(PreferencesRow &row);
68
69private:
70 Gtk::ListBox *listbox = nullptr;
71};
72
73} // namespace horizon
Definition: preferences_row.hpp:64
Definition: preferences_row.hpp:28
Definition: preferences_row.hpp:19
Definition: preferences_row.hpp:34
Definition: preferences_row.hpp:7
Definition: preferences.hpp:147