spin_button_double.vala 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2012-2018 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/dbartolini/crown/blob/master/LICENSE
  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. public bool _stop_emit;
  16. // Widgets
  17. public 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. _x.set_width_chars(1);
  43. add(_x);
  44. }
  45. private void on_value_changed()
  46. {
  47. if (!_stop_emit)
  48. value_changed();
  49. }
  50. private bool on_scroll(Gdk.EventScroll ev)
  51. {
  52. GLib.Signal.stop_emission_by_name(_x, "scroll-event");
  53. return false;
  54. }
  55. }
  56. }