@papercraftgames/estragon 0.0.0-stage → 0.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +20 -0
  3. package/README.md +28 -2
  4. package/addons/estragon/compiler/bindable.gd +213 -0
  5. package/addons/estragon/compiler/bindable.gd.uid +1 -0
  6. package/addons/estragon/compiler/compiler.gd +24 -0
  7. package/addons/estragon/compiler/compiler.gd.uid +1 -0
  8. package/addons/estragon/compiler/composition.gd +51 -0
  9. package/addons/estragon/compiler/composition.gd.uid +1 -0
  10. package/addons/estragon/compiler/diagnostic_capture.gd.txt +18 -0
  11. package/addons/estragon/compiler/emitter.gd +209 -0
  12. package/addons/estragon/compiler/emitter.gd.uid +1 -0
  13. package/addons/estragon/compiler/frontend.gd +22 -0
  14. package/addons/estragon/compiler/frontend.gd.uid +1 -0
  15. package/addons/estragon/compiler/lexer.gd +78 -0
  16. package/addons/estragon/compiler/lexer.gd.uid +1 -0
  17. package/addons/estragon/compiler/model.gd +87 -0
  18. package/addons/estragon/compiler/model.gd.uid +1 -0
  19. package/addons/estragon/compiler/native/resolver.gd +200 -0
  20. package/addons/estragon/compiler/native/resolver.gd.uid +1 -0
  21. package/addons/estragon/compiler/parser.gd +252 -0
  22. package/addons/estragon/compiler/parser.gd.uid +1 -0
  23. package/addons/estragon/compiler/script_validation.gd +80 -0
  24. package/addons/estragon/compiler/script_validation.gd.uid +1 -0
  25. package/addons/estragon/compiler/source.gd +65 -0
  26. package/addons/estragon/compiler/source.gd.uid +1 -0
  27. package/addons/estragon/compiler/source_map.gd +59 -0
  28. package/addons/estragon/compiler/source_map.gd.uid +1 -0
  29. package/addons/estragon/compiler/validator.gd +277 -0
  30. package/addons/estragon/compiler/validator.gd.uid +1 -0
  31. package/addons/estragon/editor/buffer_guard.gd +84 -0
  32. package/addons/estragon/editor/buffer_guard.gd.uid +1 -0
  33. package/addons/estragon/editor/build_service.gd +252 -0
  34. package/addons/estragon/editor/build_service.gd.uid +1 -0
  35. package/addons/estragon/editor/highlighter.gd +116 -0
  36. package/addons/estragon/editor/highlighter.gd.uid +1 -0
  37. package/addons/estragon/editor/highlighter_association.gd +80 -0
  38. package/addons/estragon/editor/highlighter_association.gd.uid +1 -0
  39. package/addons/estragon/editor/plugin.cfg +7 -0
  40. package/addons/estragon/editor/plugin.gd +225 -0
  41. package/addons/estragon/editor/plugin.gd.uid +1 -0
  42. package/addons/estragon/editor/script_dependencies.gd +45 -0
  43. package/addons/estragon/editor/script_dependencies.gd.uid +1 -0
  44. package/addons/estragon/runtime/composition/binding.gd +62 -0
  45. package/addons/estragon/runtime/composition/binding.gd.uid +1 -0
  46. package/addons/estragon/runtime/composition/computation.gd +477 -0
  47. package/addons/estragon/runtime/composition/computation.gd.uid +1 -0
  48. package/addons/estragon/runtime/composition/element.gd +23 -0
  49. package/addons/estragon/runtime/composition/element.gd.uid +1 -0
  50. package/addons/estragon/runtime/composition/profile.gd +21 -0
  51. package/addons/estragon/runtime/composition/profile.gd.uid +1 -0
  52. package/addons/estragon/runtime/composition/profile.tres +6 -0
  53. package/addons/estragon/runtime/composition/state.gd +65 -0
  54. package/addons/estragon/runtime/composition/state.gd.uid +1 -0
  55. package/addons/estragon/runtime/composition/state.tres +6 -0
  56. package/addons/estragon/runtime/node/button.gd +53 -0
  57. package/addons/estragon/runtime/node/button.gd.uid +1 -0
  58. package/addons/estragon/runtime/node/component_2d.gd +105 -0
  59. package/addons/estragon/runtime/node/component_2d.gd.uid +1 -0
  60. package/addons/estragon/runtime/node/component_3d.gd +91 -0
  61. package/addons/estragon/runtime/node/component_3d.gd.uid +1 -0
  62. package/addons/estragon/runtime/node/estragon_2d.gd +32 -0
  63. package/addons/estragon/runtime/node/estragon_2d.gd.uid +1 -0
  64. package/addons/estragon/runtime/node/estragon_3d.gd +15 -0
  65. package/addons/estragon/runtime/node/estragon_3d.gd.uid +1 -0
  66. package/addons/estragon/runtime/node/hbox.gd +6 -0
  67. package/addons/estragon/runtime/node/hbox.gd.uid +1 -0
  68. package/addons/estragon/runtime/node/internal/coordinator.gd +145 -0
  69. package/addons/estragon/runtime/node/internal/coordinator.gd.uid +1 -0
  70. package/addons/estragon/runtime/node/internal/layout_core.gd +115 -0
  71. package/addons/estragon/runtime/node/internal/layout_core.gd.uid +1 -0
  72. package/addons/estragon/runtime/node/internal/native_bounds.gd +103 -0
  73. package/addons/estragon/runtime/node/internal/native_bounds.gd.uid +1 -0
  74. package/addons/estragon/runtime/node/internal/pointer_2d.gd +70 -0
  75. package/addons/estragon/runtime/node/internal/pointer_2d.gd.uid +1 -0
  76. package/addons/estragon/runtime/node/native_2d.gd +40 -0
  77. package/addons/estragon/runtime/node/native_2d.gd.uid +1 -0
  78. package/addons/estragon/runtime/node/native_3d.gd +40 -0
  79. package/addons/estragon/runtime/node/native_3d.gd.uid +1 -0
  80. package/addons/estragon/runtime/node/rect.gd +15 -0
  81. package/addons/estragon/runtime/node/rect.gd.uid +1 -0
  82. package/addons/estragon/runtime/node/text.gd +66 -0
  83. package/addons/estragon/runtime/node/text.gd.uid +1 -0
  84. package/addons/estragon/runtime/node/toggle.gd +23 -0
  85. package/addons/estragon/runtime/node/toggle.gd.uid +1 -0
  86. package/addons/estragon/runtime/node/vbox.gd +6 -0
  87. package/addons/estragon/runtime/node/vbox.gd.uid +1 -0
  88. package/package.json +31 -4
@@ -0,0 +1,105 @@
1
+ @tool
2
+ class_name EstragonComponent2D
3
+ extends Node2D
4
+ ## Native C1 participant. Needs a contiguous same-dimensional chain to an entry.
5
+ signal layout_applied(size: Vector2)
6
+ const Coordinator = preload("res://addons/estragon/runtime/node/internal/coordinator.gd")
7
+ @export var width: float = -1.0:
8
+ set(value):
9
+ if not valid_length(value) or width == value: return
10
+ width = value
11
+ _changed()
12
+ @export var height: float = -1.0:
13
+ set(value):
14
+ if not valid_length(value) or height == value: return
15
+ height = value
16
+ _changed()
17
+ @export var fill_width: bool = false:
18
+ set(value):
19
+ if fill_width == value: return
20
+ fill_width = value
21
+ _changed()
22
+ @export var fill_height: bool = false:
23
+ set(value):
24
+ if fill_height == value: return
25
+ fill_height = value
26
+ _changed()
27
+ @export var gap: float = 0.0:
28
+ set(value):
29
+ if not is_finite(value) or value < 0 or value == gap: return
30
+ gap = value
31
+ _changed()
32
+ @export var center: bool = false:
33
+ set(value):
34
+ if center == value: return
35
+ center = value
36
+ _changed()
37
+ var layout_size: Vector2:
38
+ get: return _layout_size
39
+ var _layout_size := Vector2.ZERO
40
+ # Internal bridge, deliberately not the public authoring API.
41
+ var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
42
+
43
+ static func valid_length(value: float) -> bool:
44
+ return is_finite(value) and (value >= 0 or value == -1)
45
+
46
+ func set_extent(value: Vector2) -> Error:
47
+ for axis in range(2):
48
+ if not valid_length(value[axis]): return ERR_INVALID_PARAMETER
49
+ width = value[0]
50
+ height = value[1]
51
+ return OK
52
+
53
+ func requested_extent() -> Vector3:
54
+ return Vector3(width, height, 0.0)
55
+
56
+ func _layout_axis() -> int:
57
+ return 0
58
+
59
+ func _measure_native() -> Vector2:
60
+ return Vector2.ZERO
61
+
62
+ func _layout_options() -> Dictionary:
63
+ var natural := _measure_native()
64
+ return {"axis":_layout_axis(),"fill":Vector3(1 if fill_width else 0,1 if fill_height else 0,0),"intrinsic":Vector3(natural.x,natural.y,0)}
65
+
66
+ func _is_layout_entry() -> bool:
67
+ return false
68
+
69
+ func _layout_viewport_scale() -> float:
70
+ return 0.0
71
+
72
+ func _changed() -> void:
73
+ if layout != null: layout.changed()
74
+
75
+ func _notification(what: int) -> void:
76
+ # 4.0 MOVED_IN_PARENT; newer engines use child_order_changed.
77
+ if what == 12 and layout != null: layout.order_moved()
78
+
79
+ func _enter_tree() -> void:
80
+ layout.changed()
81
+ layout.start()
82
+
83
+ func _exit_tree() -> void:
84
+ layout.stop()
85
+
86
+ func invalidate_layout() -> void:
87
+ layout.model.invalidate()
88
+
89
+ func _get_layout_coordinator():
90
+ return layout
91
+
92
+ func get_layout_root() -> Node:
93
+ return layout.root_host()
94
+
95
+ func get_layout_stats() -> Dictionary:
96
+ return {"measure": layout.model.measure_count, "arrange": layout.model.arrange_count, "flush": layout.flush_count, "active": get_layout_root() != null}
97
+
98
+ func apply_layout_position(offset: Vector3) -> void:
99
+ position = Vector2(offset.x, offset.y)
100
+
101
+ func apply_layout_size(size: Vector3) -> void:
102
+ _layout_size = Vector2(size.x, size.y)
103
+ # Explicit invalidation also restores a native position edited externally.
104
+ if layout.parent_coordinator() != null: apply_layout_position(layout.model.offset)
105
+ layout_applied.emit(_layout_size)
@@ -0,0 +1 @@
1
+ uid://b6ucicu50s6qb
@@ -0,0 +1,91 @@
1
+ @tool
2
+ class_name EstragonComponent3D
3
+ extends Node3D
4
+ ## Native C1 participant. Needs a contiguous same-dimensional chain to an entry.
5
+ signal layout_applied(size: Vector3)
6
+ const Coordinator = preload("res://addons/estragon/runtime/node/internal/coordinator.gd")
7
+ @export var width: float = -1.0:
8
+ set(value):
9
+ if not valid_length(value) or width == value: return
10
+ width = value
11
+ _changed()
12
+ @export var height: float = -1.0:
13
+ set(value):
14
+ if not valid_length(value) or height == value: return
15
+ height = value
16
+ _changed()
17
+ @export var depth: float = -1.0:
18
+ set(value):
19
+ if not valid_length(value) or depth == value: return
20
+ depth = value
21
+ _changed()
22
+ @export var gap: float = 0.0:
23
+ set(value):
24
+ if not is_finite(value) or value < 0 or value == gap: return
25
+ gap = value
26
+ _changed()
27
+ @export var center: bool = false:
28
+ set(value):
29
+ if center == value: return
30
+ center = value
31
+ _changed()
32
+ var layout_size: Vector3:
33
+ get: return _layout_size
34
+ var _layout_size := Vector3.ZERO
35
+ # Internal bridge, deliberately not the public authoring API.
36
+ var layout = Coordinator.new(self, 3, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
37
+
38
+ static func valid_length(value: float) -> bool:
39
+ return is_finite(value) and (value >= 0 or value == -1)
40
+
41
+ func set_extent(value: Vector3) -> Error:
42
+ for axis in range(3):
43
+ if not valid_length(value[axis]): return ERR_INVALID_PARAMETER
44
+ width = value[0]
45
+ height = value[1]
46
+ depth = value[2]
47
+ return OK
48
+
49
+ func requested_extent() -> Vector3:
50
+ return Vector3(width, height, depth)
51
+
52
+ func _is_layout_entry() -> bool:
53
+ return false
54
+
55
+ func _layout_viewport_scale() -> float:
56
+ return 0.0
57
+
58
+ func _changed() -> void:
59
+ if layout != null: layout.changed()
60
+
61
+ func _notification(what: int) -> void:
62
+ # 4.0 MOVED_IN_PARENT; newer engines use child_order_changed.
63
+ if what == 12 and layout != null: layout.order_moved()
64
+
65
+ func _enter_tree() -> void:
66
+ layout.changed()
67
+ layout.start()
68
+
69
+ func _exit_tree() -> void:
70
+ layout.stop()
71
+
72
+ func invalidate_layout() -> void:
73
+ layout.model.invalidate()
74
+
75
+ func _get_layout_coordinator():
76
+ return layout
77
+
78
+ func get_layout_root() -> Node:
79
+ return layout.root_host()
80
+
81
+ func get_layout_stats() -> Dictionary:
82
+ return {"measure": layout.model.measure_count, "arrange": layout.model.arrange_count, "flush": layout.flush_count, "active": get_layout_root() != null}
83
+
84
+ func apply_layout_position(offset: Vector3) -> void:
85
+ position = offset
86
+
87
+ func apply_layout_size(size: Vector3) -> void:
88
+ _layout_size = size
89
+ # Explicit invalidation also restores a native position edited externally.
90
+ if layout.parent_coordinator() != null: apply_layout_position(layout.model.offset)
91
+ layout_applied.emit(_layout_size)
@@ -0,0 +1 @@
1
+ uid://c0lpeeb1sekft
@@ -0,0 +1,32 @@
1
+ @tool
2
+ class_name Estragon2D
3
+ extends "res://addons/estragon/runtime/node/component_2d.gd"
4
+ ## Explicit independent layout scope; does not assign native scene owner.
5
+ @export var viewport_width_scale: float = 0.0:
6
+ set(value):
7
+ if not is_finite(value) or value < 0 or viewport_width_scale == value: return
8
+ viewport_width_scale = value
9
+ if layout != null: layout._invalidated()
10
+
11
+ func _is_layout_entry() -> bool:
12
+ return true
13
+
14
+ func _layout_viewport_scale() -> float:
15
+ return viewport_width_scale
16
+
17
+ const Pointer = preload("res://addons/estragon/runtime/node/internal/pointer_2d.gd")
18
+ var _pointer = Pointer.new(self)
19
+
20
+ func _get_pointer_router():
21
+ return _pointer
22
+
23
+ func _enter_tree() -> void:
24
+ _pointer.start()
25
+ super._enter_tree()
26
+
27
+ func _exit_tree() -> void:
28
+ _pointer.stop()
29
+ super._exit_tree()
30
+
31
+ func _input(event: InputEvent) -> void:
32
+ if _pointer.input(event): get_viewport().set_input_as_handled()
@@ -0,0 +1 @@
1
+ uid://bmj6hsf3muwpe
@@ -0,0 +1,15 @@
1
+ @tool
2
+ class_name Estragon3D
3
+ extends "res://addons/estragon/runtime/node/component_3d.gd"
4
+ ## Explicit independent layout scope; does not assign native scene owner.
5
+ @export var viewport_width_scale: float = 0.0:
6
+ set(value):
7
+ if not is_finite(value) or value < 0 or viewport_width_scale == value: return
8
+ viewport_width_scale = value
9
+ if layout != null: layout._invalidated()
10
+
11
+ func _is_layout_entry() -> bool:
12
+ return true
13
+
14
+ func _layout_viewport_scale() -> float:
15
+ return viewport_width_scale
@@ -0,0 +1 @@
1
+ uid://by00wy3kqo7bw
@@ -0,0 +1,6 @@
1
+ @tool
2
+ class_name EstragonHBox
3
+ extends "res://addons/estragon/runtime/node/component_2d.gd"
4
+ ## Native stack participant using the shared composed layout algorithm.
5
+ func _layout_axis() -> int:
6
+ return 0
@@ -0,0 +1 @@
1
+ uid://cls1tdwjvep3a
@@ -0,0 +1,145 @@
1
+ @tool
2
+ extends RefCounted
3
+ const Profile = preload("res://addons/estragon/runtime/composition/profile.tres")
4
+ ## Native event/lifetime adapter shared by both spatial branches. No layout math.
5
+ const Core = preload("res://addons/estragon/runtime/node/internal/layout_core.gd")
6
+ const META := "_estragon_b2_coordinator"
7
+ enum Mode { PROOF, PARTICIPANT, ENTRY }
8
+ var _mode: int
9
+ var model := Core.new()
10
+ var active: bool = false
11
+ var flush_count: int = 0
12
+ var _host: WeakRef
13
+ var _dimension: int
14
+ var _queued: bool = false
15
+ var _viewport: Viewport
16
+
17
+ func _init(host: Node, dimension: int, mode: int = Mode.PROOF) -> void:
18
+ _mode = mode
19
+ _host = weakref(host)
20
+ _dimension = dimension
21
+ if _mode == Mode.PROOF: host.set_meta(META, weakref(self))
22
+ model.invalidated.connect(_invalidated)
23
+ model.placed.connect(_place)
24
+ model.arranged.connect(_arranged)
25
+
26
+ func parent_coordinator():
27
+ var host = _host.get_ref()
28
+ if host == null or _mode == Mode.ENTRY: return null
29
+ return participant(host.get_parent())
30
+
31
+ func participant(node: Node):
32
+ if node == null: return null
33
+ var found
34
+ if _mode == Mode.PROOF:
35
+ if not node.has_meta(META): return null
36
+ found = node.get_meta(META).get_ref()
37
+ else:
38
+ # Runtime references must never be serialized as Node metadata.
39
+ if not node.has_method("_get_layout_coordinator"): return null
40
+ found = node._get_layout_coordinator()
41
+ return found if found != null and found.active and found._dimension == _dimension else null
42
+
43
+ func scope_root():
44
+ if not active: return null
45
+ var current = self
46
+ while current != null:
47
+ if current._mode == Mode.ENTRY: return current
48
+ var parent = current.parent_coordinator()
49
+ if current._mode == Mode.PROOF and parent == null: return current
50
+ current = parent
51
+ return null
52
+
53
+ func root_host() -> Node:
54
+ var found = scope_root()
55
+ return found._host.get_ref() if found != null else null
56
+
57
+ func _viewport_scale(host: Node) -> float:
58
+ return host.viewport_width_scale if _mode == Mode.PROOF else host._layout_viewport_scale()
59
+
60
+ func start() -> void:
61
+ active = true
62
+ var host: Node = _host.get_ref()
63
+ # PackedScene restores metadata after construction. Refresh the proof-only
64
+ # weak registry at entry; C1 resolves the live script field instead.
65
+ if _mode == Mode.PROOF: host.set_meta(META, weakref(self))
66
+ host.child_entered_tree.connect(_child_changed)
67
+ host.child_exiting_tree.connect(_child_changed)
68
+ if host.has_signal("child_order_changed"): host.connect("child_order_changed", _sync)
69
+ if _mode != Mode.PARTICIPANT:
70
+ _viewport = host.get_viewport()
71
+ _viewport.size_changed.connect(_viewport_changed)
72
+ _sync()
73
+ var parent = parent_coordinator()
74
+ if parent != null: parent._sync()
75
+ _invalidated()
76
+
77
+ func stop() -> void:
78
+ active = false
79
+ var host: Node = _host.get_ref()
80
+ if host.child_entered_tree.is_connected(_child_changed): host.child_entered_tree.disconnect(_child_changed)
81
+ if host.child_exiting_tree.is_connected(_child_changed): host.child_exiting_tree.disconnect(_child_changed)
82
+ if host.has_signal("child_order_changed") and host.is_connected("child_order_changed", _sync): host.disconnect("child_order_changed", _sync)
83
+ if _viewport != null and _viewport.size_changed.is_connected(_viewport_changed): _viewport.size_changed.disconnect(_viewport_changed)
84
+ _viewport = null
85
+ model.set_children([])
86
+ var parent = parent_coordinator()
87
+ if parent != null: parent._sync()
88
+
89
+ func _child_changed(_child: Node) -> void:
90
+ _sync()
91
+
92
+ func order_moved() -> void:
93
+ var parent = parent_coordinator()
94
+ if parent != null: parent._sync()
95
+
96
+ func _sync() -> void:
97
+ if not active: return
98
+ var values: Array = []
99
+ var host: Node = _host.get_ref()
100
+ for child in host.get_children():
101
+ var found = participant(child)
102
+ if found != null and found._mode != Mode.ENTRY: values.append(found.model)
103
+ var error := model.set_children(values)
104
+ if error != OK: push_error("Estragon layout model ownership: " + error_string(error))
105
+
106
+ func changed() -> void:
107
+ var host = _host.get_ref()
108
+ if host == null: return
109
+ if host.has_method("_layout_options"):
110
+ var options: Dictionary = host._layout_options()
111
+ model.configure(host.requested_extent(),host.gap,host.center,options.axis,options.fill,options.intrinsic)
112
+ else: model.configure(host.requested_extent(), host.gap, host.center)
113
+
114
+ func _viewport_changed() -> void:
115
+ var host = _host.get_ref()
116
+ if host != null and parent_coordinator() == null and _viewport_scale(host) > 0: _invalidated()
117
+
118
+ func _invalidated() -> void:
119
+ if Profile.is_enabled(): Profile.add("layout_invalidations")
120
+ if not active or _queued or parent_coordinator() != null or _mode == Mode.PARTICIPANT: return
121
+ _queued = true
122
+ call_deferred("_flush")
123
+
124
+ func _flush() -> void:
125
+ _queued = false
126
+ if not active or parent_coordinator() != null or _mode == Mode.PARTICIPANT: return
127
+ var host = _host.get_ref()
128
+ if host == null or host.is_queued_for_deletion(): return
129
+ flush_count += 1
130
+ if Profile.is_enabled(): Profile.add("layout_flushes")
131
+ var available: Vector3 = model.measure()
132
+ if _viewport_scale(host) > 0 and _viewport != null:
133
+ available.x = _viewport.get_visible_rect().size.x * _viewport_scale(host)
134
+ model.arrange(available)
135
+
136
+ func _place(offset: Vector3) -> void:
137
+ var host = _host.get_ref()
138
+ if host == null: return
139
+ if host.has_method("apply_layout_position"): host.apply_layout_position(offset)
140
+ elif _dimension == 2: host.position = Vector2(offset.x, offset.y)
141
+ else: host.position = offset
142
+
143
+ func _arranged(size: Vector3) -> void:
144
+ var host = _host.get_ref()
145
+ if host != null: host.apply_layout_size(size)
@@ -0,0 +1 @@
1
+ uid://dtbrerokp7n7d
@@ -0,0 +1,115 @@
1
+ @tool
2
+ extends RefCounted
3
+ const Profile = preload("res://addons/estragon/runtime/composition/profile.tres")
4
+ ## Shared B2/C1 mathematical row layout. No Nodes, rendering or SceneTree dependencies.
5
+ signal invalidated
6
+ signal placed(offset)
7
+ signal arranged(size)
8
+ var requested := Vector3(-1, -1, -1)
9
+ var gap: float = 0.0
10
+ var center: bool = false
11
+ var axis: int = 0
12
+ var fill := Vector3.ZERO
13
+ var intrinsic := Vector3.ZERO
14
+ var children: Array = []
15
+ var measured := Vector3.ZERO
16
+ var size := Vector3.ZERO
17
+ var offset := Vector3.ZERO
18
+ var measure_count: int = 0
19
+ var arrange_count: int = 0
20
+ var _measure_dirty: bool = true
21
+ var _arrange_dirty: bool = true
22
+ var _parent: WeakRef
23
+
24
+ static func valid_extent(value: Vector3) -> bool:
25
+ for axis in range(3):
26
+ if not is_finite(value[axis]) or value[axis] < 0 and value[axis] != -1: return false
27
+ return true
28
+
29
+ func configure(extent: Vector3, spacing: float, centered: bool, stack_axis: int = 0, fills: Vector3 = Vector3.ZERO, content: Vector3 = Vector3.ZERO) -> Error:
30
+ if not valid_extent(extent) or not is_finite(spacing) or spacing < 0 or stack_axis < 0 or stack_axis > 2: return ERR_INVALID_PARAMETER
31
+ for index in range(3):
32
+ if fills[index] not in [0.0,1.0] or not is_finite(content[index]) or content[index] < 0: return ERR_INVALID_PARAMETER
33
+ if requested == extent and gap == spacing and center == centered and axis == stack_axis and fill == fills and intrinsic == content: return OK
34
+ axis = stack_axis
35
+ fill = fills
36
+ intrinsic = content
37
+ requested = extent
38
+ gap = spacing
39
+ center = centered
40
+ invalidate()
41
+ return OK
42
+
43
+ func set_children(values: Array) -> Error:
44
+ var seen: Array = []
45
+ for child in values:
46
+ if child == null or child == self or seen.has(child): return ERR_INVALID_PARAMETER
47
+ var ancestor = self
48
+ while ancestor != null:
49
+ if child == ancestor: return ERR_INVALID_PARAMETER
50
+ ancestor = ancestor._parent.get_ref() if ancestor._parent != null else null
51
+ if child._parent != null and child._parent.get_ref() != null and child._parent.get_ref() != self: return ERR_ALREADY_IN_USE
52
+ seen.append(child)
53
+ if children == values: return OK
54
+ for child in children:
55
+ if not values.has(child): child._parent = null
56
+ children = values.duplicate()
57
+ for child in children: child._parent = weakref(self)
58
+ invalidate()
59
+ return OK
60
+
61
+ func invalidate() -> void:
62
+ _measure_dirty = true
63
+ _arrange_dirty = true
64
+ var parent = _parent.get_ref() if _parent != null else null
65
+ if parent != null: parent.invalidate()
66
+ invalidated.emit()
67
+
68
+ func measure() -> Vector3:
69
+ if not _measure_dirty: return measured
70
+ measure_count += 1
71
+ if Profile.is_enabled(): Profile.add("layout_measures")
72
+ var natural := Vector3.ZERO
73
+ for child in children:
74
+ var child_size: Vector3 = child.measure()
75
+ for index in range(3):
76
+ if index == axis: natural[index] += child_size[index]
77
+ else: natural[index] = maxf(natural[index],child_size[index])
78
+ if children.size() > 1: natural[axis] += gap * (children.size() - 1)
79
+ for index in range(3): natural[index] = maxf(natural[index],intrinsic[index])
80
+ measured = natural
81
+ for axis in range(3):
82
+ if requested[axis] >= 0: measured[axis] = requested[axis]
83
+ _measure_dirty = false
84
+ return measured
85
+
86
+ func arrange(available: Vector3) -> void:
87
+ if not _arrange_dirty and size == available: return
88
+ measure()
89
+ arrange_count += 1
90
+ if Profile.is_enabled(): Profile.add("layout_arranges")
91
+ size = available
92
+ # Clear before callbacks so a signal-triggered change queues a genuine
93
+ # follow-up instead of being overwritten when this pass finishes.
94
+ _arrange_dirty = false
95
+ var fixed: float = gap * maxi(0, children.size() - 1)
96
+ var flexible: int = 0
97
+ for child in children:
98
+ if child.fill[axis] > 0 and child.requested[axis] < 0: flexible += 1
99
+ else: fixed += child.measured[axis]
100
+ var share: float = maxf(0,available[axis] - fixed) / maxi(1,flexible)
101
+ var row_extent: float = fixed + share * flexible
102
+ var cursor: float = (available[axis] - row_extent) * 0.5 if center else 0.0
103
+ for child in children:
104
+ var allocation: Vector3 = child.measured
105
+ for index in range(3):
106
+ if child.fill[index] > 0 and child.requested[index] < 0:
107
+ allocation[index] = share if index == axis else available[index]
108
+ var next := Vector3.ZERO
109
+ next[axis] = cursor
110
+ if child.offset != next or child.arrange_count == 0:
111
+ child.offset = next
112
+ child.placed.emit(next)
113
+ child.arrange(allocation)
114
+ cursor += allocation[axis] + gap
115
+ arranged.emit(size)
@@ -0,0 +1 @@
1
+ uid://40d6qyioc4ye
@@ -0,0 +1,103 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Shared B3/C1 snapshot/subscription bridge. Geometry stays native-owned; no polling.
4
+ var origin := Vector3.ZERO
5
+ var extent := Vector3.ZERO
6
+ var snapshots: int = 0
7
+ var notifications: int = 0
8
+ var status: Error = ERR_UNCONFIGURED
9
+ var _host: WeakRef
10
+ var _dimension: int
11
+ var _active: bool = false
12
+ var _queued: bool = false
13
+ var _source: Object
14
+ var _signal: StringName
15
+
16
+ func _init(host: Node, dimension: int) -> void:
17
+ _host = weakref(host)
18
+ _dimension = dimension
19
+
20
+ func start() -> void:
21
+ _active = true
22
+ var host: Node = _host.get_ref()
23
+ host.child_entered_tree.connect(_child_changed)
24
+ host.child_exiting_tree.connect(_child_changed)
25
+ invalidate()
26
+
27
+ func stop() -> void:
28
+ _active = false
29
+ _disconnect()
30
+ var host: Node = _host.get_ref()
31
+ if host.child_entered_tree.is_connected(_child_changed): host.child_entered_tree.disconnect(_child_changed)
32
+ if host.child_exiting_tree.is_connected(_child_changed): host.child_exiting_tree.disconnect(_child_changed)
33
+
34
+ func _child_changed(_child: Node) -> void:
35
+ invalidate()
36
+
37
+ func _disconnect() -> void:
38
+ if is_instance_valid(_source) and _source.is_connected(_signal, _native_changed):
39
+ _source.disconnect(_signal, _native_changed)
40
+ _source = null
41
+
42
+ func _native_changed() -> void:
43
+ notifications += 1
44
+ invalidate()
45
+
46
+ func invalidate() -> void:
47
+ if not _active or _queued: return
48
+ _queued = true
49
+ call_deferred("_refresh")
50
+
51
+ func _refresh() -> void:
52
+ _queued = false
53
+ if not _active: return
54
+ _disconnect()
55
+ snapshots += 1
56
+ origin = Vector3.ZERO
57
+ extent = Vector3.ZERO
58
+ var host = _host.get_ref()
59
+ status = ERR_INVALID_PARAMETER
60
+ if host == null or host.get_child_count() != 1:
61
+ _publish(host)
62
+ return
63
+ var child: Node = host.get_child(0)
64
+ var points: Array[Vector3] = []
65
+ if _dimension == 2 and child is Polygon2D:
66
+ var basis: Transform2D = host.transform
67
+ basis.origin = Vector2.ZERO
68
+ var transform: Transform2D = basis * child.transform
69
+ for point in child.polygon:
70
+ var transformed: Vector2 = transform * (point + child.offset)
71
+ points.append(Vector3(transformed.x, transformed.y, 0))
72
+ if host.observe_native:
73
+ _source = child
74
+ _signal = &"item_rect_changed"
75
+ elif _dimension == 3 and child is MeshInstance3D and child.mesh != null:
76
+ var box: AABB = child.mesh.get_aabb()
77
+ var transform: Transform3D = Transform3D(host.basis, Vector3.ZERO) * child.transform
78
+ for index in range(8): points.append(transform * box.get_endpoint(index))
79
+ if host.observe_native:
80
+ _source = child.mesh
81
+ _signal = &"changed"
82
+ if points.is_empty():
83
+ _publish(host)
84
+ return
85
+ var minimum: Vector3 = points[0]
86
+ var maximum: Vector3 = minimum
87
+ for point in points:
88
+ if not is_finite(point.x) or not is_finite(point.y) or not is_finite(point.z):
89
+ _publish(host)
90
+ return
91
+ minimum = Vector3(minf(minimum.x,point.x),minf(minimum.y,point.y),minf(minimum.z,point.z))
92
+ maximum = Vector3(maxf(maximum.x,point.x),maxf(maximum.y,point.y),maxf(maximum.z,point.z))
93
+ origin = minimum
94
+ extent = maximum - minimum
95
+ status = OK
96
+ if _source != null: _source.connect(_signal, _native_changed)
97
+ _publish(host)
98
+
99
+ func _publish(host: Node) -> void:
100
+ if host != null:
101
+ host.layout.changed()
102
+ # A changed minimum with identical size still requires placement.
103
+ host.layout.model.invalidate()
@@ -0,0 +1 @@
1
+ uid://c7mj7krrd3pov