input_vector2.vala 1.7 KB

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