scales.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef _UI_SCALES_H_
  2. #define _UI_SCALES_H_
  3. #include <gtkmm.h>
  4. namespace ui
  5. {
  6. class ScaleWidget: public Gtk::Scale
  7. {
  8. void (*on_change)(double) = nullptr;
  9. public:
  10. ScaleWidget(Gtk::Orientation orientation,
  11. double min,
  12. double max,
  13. void (*on_change_fn)(double)):
  14. Gtk::Scale(orientation),
  15. on_change(on_change_fn)
  16. {
  17. set_range(min, max);
  18. signal_value_changed().connect([=]() {
  19. this->on_change(this->get_value());
  20. });
  21. }
  22. };
  23. Gtk::Scale & HScale(double min, double max, void (*on_change_fn)(double))
  24. {
  25. auto scale = Gtk::manage(new ScaleWidget(
  26. Gtk::Orientation::HORIZONTAL, min, max, on_change_fn));
  27. scale->set_hexpand(true);
  28. return *scale;
  29. }
  30. Gtk::Scale & VScale(double min, double max, void (*on_change_fn)(double))
  31. {
  32. auto scale = Gtk::manage(new ScaleWidget(
  33. Gtk::Orientation::VERTICAL, min, max, on_change_fn));
  34. scale->set_vexpand(true);
  35. return *scale;
  36. }
  37. }
  38. #endif