Horizon
preferences_row.hpp
1 #pragma once
2 #include <gtkmm.h>
3 #include "preferences/preferences.hpp"
4 
5 namespace horizon {
6 
7 class PreferencesRow : public Gtk::Box {
8 public:
9  PreferencesRow(const std::string &title, const std::string &subtitle, Preferences &prefs);
10  virtual void activate()
11  {
12  }
13 
14 protected:
15  Preferences &preferences;
16 };
17 
18 
20 public:
21  PreferencesRowBool(const std::string &title, const std::string &subtitle, Preferences &prefs, bool &v);
22  void activate() override;
23 
24 private:
25  Gtk::Switch *sw = nullptr;
26 };
27 
29 public:
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 
34 template <typename T> class PreferencesRowNumeric : public PreferencesRow {
35 public:
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 
59 private:
60  T &value;
61  Gtk::SpinButton *sp = nullptr;
62 };
63 
64 class PreferencesGroup : public Gtk::Box {
65 public:
66  PreferencesGroup(const std::string &title);
67  void add_row(PreferencesRow &row);
68 
69 private:
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