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  void set_title(const std::string &t);
17  void set_subtitle(const std::string &t);
18 
19 private:
20  Gtk::Label *label_title = nullptr;
21  Gtk::Label *label_subtitle = nullptr;
22 };
23 
24 
26 public:
27  PreferencesRowBool(const std::string &title, const std::string &subtitle, Preferences &prefs, bool &v);
28  void activate() override;
29 
30 private:
31  Gtk::Switch *sw = nullptr;
32 };
33 
35 public:
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 
40 template <typename T> class PreferencesRowNumeric : public PreferencesRow {
41 public:
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 
65 private:
66  T &value;
67  Gtk::SpinButton *sp = nullptr;
68 };
69 
70 class PreferencesGroup : public Gtk::Box {
71 public:
72  PreferencesGroup(const std::string &title);
73  void add_row(PreferencesRow &row);
74 
75  void set_placeholder(Gtk::Widget &w);
76 
77 private:
78  Gtk::ListBox *listbox = nullptr;
79 };
80 
81 } // namespace horizon
Definition: preferences_row.hpp:70
Definition: preferences_row.hpp:34
Definition: preferences_row.hpp:25
Definition: preferences_row.hpp:40
Definition: preferences_row.hpp:7
Definition: preferences.hpp:164