entry_vector2.vala 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2012-2025 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  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 Gtk.Label _x_label;
  16. public Gtk.Label _y_label;
  17. public Gtk.Box _x_box;
  18. public Gtk.Box _y_box;
  19. public Vector2 value
  20. {
  21. get
  22. {
  23. return Vector2(_x.value, _y.value);
  24. }
  25. set
  26. {
  27. _stop_emit = true;
  28. Vector2 val = (Vector2)value;
  29. _x.value = val.x;
  30. _y.value = val.y;
  31. _stop_emit = false;
  32. }
  33. }
  34. // Signals
  35. public signal void value_changed();
  36. public EntryVector2(Vector2 xyz, Vector2 min, Vector2 max, string preview_fmt = "%.4g")
  37. {
  38. Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 4);
  39. // Data
  40. _stop_emit = false;
  41. // Widgets
  42. _x = new EntryDouble(xyz.x, min.x, max.x, preview_fmt);
  43. _y = new EntryDouble(xyz.y, min.y, max.y, preview_fmt);
  44. _x.value_changed.connect(on_value_changed);
  45. _y.value_changed.connect(on_value_changed);
  46. _x_label = new Gtk.Label("X");
  47. _x_label.get_style_context().add_class("axis");
  48. _x_label.get_style_context().add_class("x");
  49. _y_label = new Gtk.Label("Y");
  50. _y_label.get_style_context().add_class("axis");
  51. _y_label.get_style_context().add_class("y");
  52. _x_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  53. _x_box.pack_start(_x_label, false);
  54. _x_box.pack_start(_x, true);
  55. _y_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
  56. _y_box.pack_start(_y_label, false);
  57. _y_box.pack_start(_y, true);
  58. this.pack_start(_x_box, true);
  59. this.pack_start(_y_box, true);
  60. }
  61. private void on_value_changed()
  62. {
  63. if (!_stop_emit)
  64. value_changed();
  65. }
  66. }
  67. } /* namespace Crown */