spin_button_double.vala 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE-GPLv2
  4. */
  5. using Gtk;
  6. using Gdk;
  7. namespace Crown
  8. {
  9. /// <summary>
  10. /// Double spin button.
  11. /// </summary>
  12. public class SpinButtonDouble : Gtk.Bin
  13. {
  14. // Data
  15. private bool _stop_emit;
  16. // Widgets
  17. private Gtk.SpinButton _x;
  18. public double value
  19. {
  20. get
  21. {
  22. return _x.value;
  23. }
  24. set
  25. {
  26. _stop_emit = true;
  27. _x.value = value;
  28. _stop_emit = false;
  29. }
  30. }
  31. // Signals
  32. public signal void value_changed();
  33. public SpinButtonDouble(double x, double min, double max)
  34. {
  35. this.hexpand = true;
  36. // Data
  37. _stop_emit = false;
  38. // Widgets
  39. _x = new SpinButton(new Adjustment(x, min, max, 1.0, 10.0, 0.0), 1.0, 4);
  40. _x.value_changed.connect(on_value_changed);
  41. _x.scroll_event.connect(on_scroll);
  42. add(_x);
  43. }
  44. private void on_value_changed()
  45. {
  46. if (!_stop_emit)
  47. value_changed();
  48. }
  49. private bool on_scroll(Gdk.EventScroll ev)
  50. {
  51. GLib.Signal.stop_emission_by_name(_x, "scroll-event");
  52. return false;
  53. }
  54. }
  55. }