Horizon
gtk_util.hpp
1 #pragma once
2 #include <gtkmm.h>
3 #include <stdint.h>
4 namespace horizon {
5 void bind_widget(class SpinButtonDim *sp, int64_t &v);
6 void bind_widget(class SpinButtonDim *sp, uint64_t &v);
7 
8 void bind_widget(Gtk::Switch *sw, bool &v);
9 void bind_widget(Gtk::CheckButton *sw, bool &v);
10 void bind_widget(Gtk::SpinButton *sp, int &v);
11 void bind_widget(Gtk::Scale *sc, float &v);
12 void bind_widget(Gtk::Entry *en, std::string &v, std::function<void(std::string &v)> extra_cb = nullptr);
13 template <typename T>
14 void bind_widget(std::map<T, Gtk::RadioButton *> &widgets, T &v, std::function<void(T)> extra_cb = nullptr)
15 {
16  widgets[v]->set_active(true);
17  for (auto &it : widgets) {
18  T key = it.first;
19  Gtk::RadioButton *w = it.second;
20  it.second->signal_toggled().connect([key, w, &v, extra_cb] {
21  if (w->get_active()) {
22  v = key;
23  if (extra_cb)
24  extra_cb(key);
25  }
26  });
27  }
28 }
29 
30 template <typename T>
31 void bind_widget(Gtk::ComboBoxText *combo, const std::map<T, std::string> &lut, T &v,
32  std::function<void(T)> extra_cb = nullptr)
33 {
34  for (const auto &it : lut) {
35  combo->append(std::to_string(static_cast<int>(it.first)), it.second);
36  }
37  combo->set_active_id(std::to_string(static_cast<int>(v)));
38  combo->signal_changed().connect([combo, &v, extra_cb] {
39  v = static_cast<T>(std::stoi(combo->get_active_id()));
40  if (extra_cb)
41  extra_cb(v);
42  });
43 }
44 
45 Gtk::Label *grid_attach_label_and_widget(Gtk::Grid *gr, const std::string &label, Gtk::Widget *w, int &top);
46 
47 void tree_view_scroll_to_selection(Gtk::TreeView *view);
48 void entry_set_warning(Gtk::Entry *e, const std::string &text);
49 
50 void header_func_separator(Gtk::ListBoxRow *row, Gtk::ListBoxRow *before);
51 } // namespace horizon
Definition: block.cpp:9