light_on_list.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <string>
  2. #include <functional>
  3. #include <gtkmm/box.h>
  4. #include <gtkmm/label.h>
  5. #include <gtkmm/frame.h>
  6. #include <gtkmm/button.h>
  7. #include <gtkmm/orientable.h>
  8. #include "light_on_list.hpp"
  9. namespace cx_light {
  10. light_on_list::light_on_list(light target) {
  11. this->target = target.copy();
  12. this->show_callback = [] (light *target) {};
  13. this->edit_callback = [] (light *target) {};
  14. this->center = new Gtk::Box();
  15. this->center->set_margin(5);
  16. this->center->set_spacing(10);
  17. this->center->set_orientation(Gtk::Orientation::HORIZONTAL);
  18. this->center->set_homogeneous();
  19. this->set_margin_bottom(5);
  20. this->set_child(*this->center);
  21. this->title = new Gtk::Label(this->target->get_name());
  22. this->center->append(*this->title);
  23. this->show = new Gtk::Button("Show");
  24. this->center->append(*this->show);
  25. this->show->signal_clicked().connect([&] () {
  26. this->show_callback(this->target);
  27. });
  28. this->edit = new Gtk::Button("Edit");
  29. this->center->append(*this->edit);
  30. this->edit->signal_clicked().connect([&] () {
  31. this->edit_callback(this->target);
  32. });
  33. }
  34. light_on_list::~light_on_list() {
  35. delete this->center;
  36. delete this->title;
  37. delete this->show;
  38. delete this->edit;
  39. delete this->target;
  40. }
  41. int light_on_list::width() {
  42. return 200;
  43. }
  44. int light_on_list::height() {
  45. return 40;
  46. }
  47. void light_on_list::set_edit_callback(std::function<void(light *)> target) {
  48. this->edit_callback = target;
  49. }
  50. void light_on_list::set_show_callback(std::function<void(light *)> target) {
  51. this->show_callback = target;
  52. }
  53. }