entry_vector2.vala 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2012-2020 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/dbartolini/crown/blob/master/LICENSE
  4. */
  5. using Gtk;
  6. namespace Crown
  7. {
  8. public class EntryVector2 : Gtk.Box
  9. {
  10. // Data
  11. public bool _stop_emit;
  12. // Widgets
  13. public EntryDouble _x;
  14. public EntryDouble _y;
  15. public Vector2 value
  16. {
  17. get
  18. {
  19. return Vector2(_x.value, _y.value);
  20. }
  21. set
  22. {
  23. _stop_emit = true;
  24. Vector2 val = (Vector2)value;
  25. _x.value = val.x;
  26. _y.value = val.y;
  27. _stop_emit = false;
  28. }
  29. }
  30. // Signals
  31. public signal void value_changed();
  32. public EntryVector2(Vector2 xyz, Vector2 min, Vector2 max)
  33. {
  34. Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 0);
  35. // Data
  36. _stop_emit = false;
  37. // Widgets
  38. _x = new EntryDouble(xyz.x, min.x, max.x);
  39. _y = new EntryDouble(xyz.y, min.y, max.y);
  40. _x.value_changed.connect(on_value_changed);
  41. _y.value_changed.connect(on_value_changed);
  42. this.pack_start(_x, true, true);
  43. this.pack_start(_y, true, true);
  44. }
  45. private void on_value_changed()
  46. {
  47. if (!_stop_emit)
  48. value_changed();
  49. }
  50. }
  51. }