@papercraftgames/estragon 0.1.0-beta.2 → 0.1.0-beta.20

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 (94) hide show
  1. package/CHANGELOG.md +7 -3
  2. package/README.md +11 -8
  3. package/addons/estragon/compiler/bindable.gd +3 -3
  4. package/addons/estragon/compiler/compiler.gd +8 -8
  5. package/addons/estragon/compiler/composition.gd +5 -4
  6. package/addons/estragon/compiler/emitter.gd +34 -8
  7. package/addons/estragon/compiler/frontend.gd +8 -8
  8. package/addons/estragon/compiler/lexer.gd +2 -2
  9. package/addons/estragon/compiler/model.gd +2 -0
  10. package/addons/estragon/compiler/native/resolver.gd +122 -29
  11. package/addons/estragon/compiler/parser.gd +3 -3
  12. package/addons/estragon/compiler/project_sources.gd +91 -0
  13. package/addons/estragon/compiler/project_sources.gd.uid +1 -0
  14. package/addons/estragon/compiler/script_validation.gd +3 -3
  15. package/addons/estragon/compiler/source.gd +19 -2
  16. package/addons/estragon/compiler/source_map.gd +3 -3
  17. package/addons/estragon/compiler/validator.gd +71 -10
  18. package/addons/estragon/editor/build_service.gd +91 -72
  19. package/addons/estragon/editor/color_property.gd +37 -0
  20. package/addons/estragon/editor/color_property.gd.uid +1 -0
  21. package/addons/estragon/editor/completion.gd +531 -0
  22. package/addons/estragon/editor/completion.gd.uid +1 -0
  23. package/addons/estragon/editor/completion_edit.gd +7 -0
  24. package/addons/estragon/editor/completion_edit.gd.uid +1 -0
  25. package/addons/estragon/editor/components.gd +20 -0
  26. package/addons/estragon/editor/components.gd.uid +1 -0
  27. package/addons/estragon/editor/creation_menu.gd.txt +14 -0
  28. package/addons/estragon/editor/generated_editors.gd +256 -0
  29. package/addons/estragon/editor/generated_editors.gd.uid +1 -0
  30. package/addons/estragon/editor/highlighter.gd +62 -103
  31. package/addons/estragon/editor/highlighter_association.gd +11 -2
  32. package/addons/estragon/editor/imports.gd +47 -0
  33. package/addons/estragon/editor/imports.gd.uid +1 -0
  34. package/addons/estragon/editor/language_services.gd +288 -0
  35. package/addons/estragon/editor/language_services.gd.uid +1 -0
  36. package/addons/estragon/editor/length_property.gd +22 -0
  37. package/addons/estragon/editor/length_property.gd.uid +1 -0
  38. package/addons/estragon/editor/lexical_context.gd +159 -0
  39. package/addons/estragon/editor/lexical_context.gd.uid +1 -0
  40. package/addons/estragon/editor/navigation.gd +30 -0
  41. package/addons/estragon/editor/navigation.gd.uid +1 -0
  42. package/addons/estragon/editor/new_script.gd +77 -0
  43. package/addons/estragon/editor/new_script.gd.uid +1 -0
  44. package/addons/estragon/editor/plugin.cfg +1 -1
  45. package/addons/estragon/editor/plugin.gd +113 -40
  46. package/addons/estragon/editor/scene_components.gd +267 -0
  47. package/addons/estragon/editor/scene_components.gd.uid +1 -0
  48. package/addons/estragon/editor/scene_inspector.gd +42 -0
  49. package/addons/estragon/editor/scene_inspector.gd.uid +1 -0
  50. package/addons/estragon/editor/script_dependencies.gd +5 -3
  51. package/addons/estragon/runtime/composition/binding.gd +1 -1
  52. package/addons/estragon/runtime/composition/computation.gd +134 -9
  53. package/addons/estragon/runtime/composition/element.gd +3 -1
  54. package/addons/estragon/runtime/composition/layout_host.gd +58 -0
  55. package/addons/estragon/runtime/composition/layout_host.gd.uid +1 -0
  56. package/addons/estragon/runtime/composition/profile.tres +1 -1
  57. package/addons/estragon/runtime/composition/projection.gd +32 -0
  58. package/addons/estragon/runtime/composition/projection.gd.uid +1 -0
  59. package/addons/estragon/runtime/composition/state.gd +13 -2
  60. package/addons/estragon/runtime/composition/state.tres +1 -1
  61. package/addons/estragon/runtime/node/box.gd +90 -0
  62. package/addons/estragon/runtime/node/box.gd.uid +1 -0
  63. package/addons/estragon/runtime/node/button.gd +8 -2
  64. package/addons/estragon/runtime/node/component_2d.gd +128 -24
  65. package/addons/estragon/runtime/node/component_3d.gd +54 -18
  66. package/addons/estragon/runtime/node/estragon_2d.gd +2 -11
  67. package/addons/estragon/runtime/node/estragon_3d.gd +1 -10
  68. package/addons/estragon/runtime/node/hbox.gd +4 -1
  69. package/addons/estragon/runtime/node/internal/composition_hosts.gd +159 -0
  70. package/addons/estragon/runtime/node/internal/composition_hosts.gd.uid +1 -0
  71. package/addons/estragon/runtime/node/internal/composition_hosts.tres +6 -0
  72. package/addons/estragon/runtime/node/internal/control_participant.gd +164 -0
  73. package/addons/estragon/runtime/node/internal/control_participant.gd.uid +1 -0
  74. package/addons/estragon/runtime/node/internal/coordinator.gd +79 -27
  75. package/addons/estragon/runtime/node/internal/grid_definition.gd +75 -0
  76. package/addons/estragon/runtime/node/internal/grid_definition.gd.uid +1 -0
  77. package/addons/estragon/runtime/node/internal/layout_core.gd +200 -22
  78. package/addons/estragon/runtime/node/internal/length.gd +93 -0
  79. package/addons/estragon/runtime/node/internal/length.gd.uid +1 -0
  80. package/addons/estragon/runtime/node/internal/stack_contract.gd +21 -0
  81. package/addons/estragon/runtime/node/internal/stack_contract.gd.uid +1 -0
  82. package/addons/estragon/runtime/node/internal/stack_policy.gd +59 -0
  83. package/addons/estragon/runtime/node/internal/stack_policy.gd.uid +1 -0
  84. package/addons/estragon/runtime/node/internal/visual_style_2d.gd +65 -0
  85. package/addons/estragon/runtime/node/internal/visual_style_2d.gd.uid +1 -0
  86. package/addons/estragon/runtime/node/native_2d.gd +5 -5
  87. package/addons/estragon/runtime/node/native_3d.gd +5 -5
  88. package/addons/estragon/runtime/node/rect.gd +2 -1
  89. package/addons/estragon/runtime/node/spacer.gd +4 -0
  90. package/addons/estragon/runtime/node/spacer.gd.uid +1 -0
  91. package/addons/estragon/runtime/node/text.gd +2 -1
  92. package/addons/estragon/runtime/node/toggle.gd +1 -1
  93. package/addons/estragon/runtime/node/vbox.gd +4 -1
  94. package/package.json +1 -1
@@ -3,32 +3,113 @@ class_name EstragonComponent2D
3
3
  extends Node2D
4
4
  ## Native C1 participant. Needs a contiguous same-dimensional chain to an entry.
5
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:
6
+ const Coordinator = preload("internal/coordinator.gd")
7
+ const ESTRAGON_LENGTHS := true
8
+ const VisualStyle = preload("internal/visual_style_2d.gd")
9
+ var _visual_style = VisualStyle.new()
10
+ const Length = preload("internal/length.gd")
11
+ var lengths = Length.new()
12
+ const ESTRAGON_VISUAL_STYLE := true
13
+ var background_color: Variant = "transparent":
8
14
  set(value):
9
- if not valid_length(value) or width == value: return
15
+ if is_same(background_color,value) or not _style_supported() or not _visual_style.assign("background_color",value): return
16
+ background_color = value
17
+ _queue_style_redraw()
18
+ var border_color: Variant = "transparent":
19
+ set(value):
20
+ if is_same(border_color,value) or not _style_supported() or not _visual_style.assign("border_color",value): return
21
+ border_color = value
22
+ _queue_style_redraw()
23
+ var border_width: Variant = 0.0:
24
+ set(value):
25
+ if is_same(border_width,value) or not _style_supported() or not lengths.assign("border_width",value): return
26
+ border_width = value
27
+ _changed()
28
+ _queue_style_redraw()
29
+ var border_top_width: Variant = "auto":
30
+ set(value):
31
+ if is_same(border_top_width,value) or not _style_supported() or not lengths.assign("border_top_width",value): return
32
+ border_top_width = value
33
+ _changed()
34
+ _queue_style_redraw()
35
+ var border_right_width: Variant = "auto":
36
+ set(value):
37
+ if is_same(border_right_width,value) or not _style_supported() or not lengths.assign("border_right_width",value): return
38
+ border_right_width = value
39
+ _changed()
40
+ _queue_style_redraw()
41
+ var border_bottom_width: Variant = "auto":
42
+ set(value):
43
+ if is_same(border_bottom_width,value) or not _style_supported() or not lengths.assign("border_bottom_width",value): return
44
+ border_bottom_width = value
45
+ _changed()
46
+ _queue_style_redraw()
47
+ var border_left_width: Variant = "auto":
48
+ set(value):
49
+ if is_same(border_left_width,value) or not _style_supported() or not lengths.assign("border_left_width",value): return
50
+ border_left_width = value
51
+ _changed()
52
+ _queue_style_redraw()
53
+ var width: Variant = "auto":
54
+ set(value):
55
+ if is_same(width,value) or not lengths.assign("width",value): return
10
56
  width = value
11
57
  _changed()
12
- @export var height: float = -1.0:
58
+ var height: Variant = "auto":
13
59
  set(value):
14
- if not valid_length(value) or height == value: return
60
+ if is_same(height,value) or not lengths.assign("height",value): return
15
61
  height = value
16
62
  _changed()
17
- @export var fill_width: bool = false:
63
+ var x: Variant = 0.0:
18
64
  set(value):
19
- if fill_width == value: return
20
- fill_width = value
65
+ if is_same(x,value) or not lengths.assign("x",value): return
66
+ x = value
21
67
  _changed()
22
- @export var fill_height: bool = false:
68
+ var y: Variant = 0.0:
23
69
  set(value):
24
- if fill_height == value: return
25
- fill_height = value
70
+ if is_same(y,value) or not lengths.assign("y",value): return
71
+ y = value
26
72
  _changed()
27
- @export var gap: float = 0.0:
73
+ var gap: Variant = 0.0:
28
74
  set(value):
29
- if not is_finite(value) or value < 0 or value == gap: return
75
+ if is_same(gap,value) or not lengths.assign("gap",value): return
30
76
  gap = value
31
77
  _changed()
78
+ var margin: Variant = 0.0:
79
+ set(value):
80
+ if is_same(margin,value) or not lengths.assign("margin",value): return
81
+ margin = value
82
+ _changed()
83
+ var margin_top: Variant = "auto":
84
+ set(value):
85
+ if is_same(margin_top,value) or not lengths.assign("margin_top",value): return
86
+ margin_top = value
87
+ _changed()
88
+ var margin_right: Variant = "auto":
89
+ set(value):
90
+ if is_same(margin_right,value) or not lengths.assign("margin_right",value): return
91
+ margin_right = value
92
+ _changed()
93
+ var margin_bottom: Variant = "auto":
94
+ set(value):
95
+ if is_same(margin_bottom,value) or not lengths.assign("margin_bottom",value): return
96
+ margin_bottom = value
97
+ _changed()
98
+ var margin_left: Variant = "auto":
99
+ set(value):
100
+ if is_same(margin_left,value) or not lengths.assign("margin_left",value): return
101
+ margin_left = value
102
+ _changed()
103
+ @export var grow: float = 0.0:
104
+ set(value):
105
+ if not is_finite(value) or value<0 or value==grow: return
106
+ grow = value
107
+ _changed()
108
+ @export_enum("Natural", "Stretch") var stretch: int = 0:
109
+ set(value):
110
+ if value not in [0,1] or value==stretch: return
111
+ stretch = value
112
+ _changed()
32
113
  @export var center: bool = false:
33
114
  set(value):
34
115
  if center == value: return
@@ -37,11 +118,13 @@ const Coordinator = preload("res://addons/estragon/runtime/node/internal/coordin
37
118
  var layout_size: Vector2:
38
119
  get: return _layout_size
39
120
  var _layout_size := Vector2.ZERO
40
- # Internal bridge, deliberately not the public authoring API.
41
121
  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)
122
+ func _get_property_list() -> Array[Dictionary]:
123
+ var properties := Length.properties(["width","height","x","y","gap","margin","margin_top","margin_right","margin_bottom","margin_left"])
124
+ if VisualStyle.supported(get_script()): properties.append_array(Length.properties(["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width","background_color","border_color"]))
125
+ return properties
126
+ static func valid_length(value) -> bool:
127
+ return Length.valid(value,"extent")
45
128
 
46
129
  func set_extent(value: Vector2) -> Error:
47
130
  for axis in range(2):
@@ -51,7 +134,7 @@ func set_extent(value: Vector2) -> Error:
51
134
  return OK
52
135
 
53
136
  func requested_extent() -> Vector3:
54
- return Vector3(width, height, 0.0)
137
+ return layout.model.requested
55
138
 
56
139
  func _layout_axis() -> int:
57
140
  return 0
@@ -61,14 +144,11 @@ func _measure_native() -> Vector2:
61
144
 
62
145
  func _layout_options() -> Dictionary:
63
146
  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)}
147
+ return {"axis":_layout_axis(),"fill":Vector3.ZERO,"intrinsic":Vector3(natural.x,natural.y,0)}
65
148
 
66
149
  func _is_layout_entry() -> bool:
67
150
  return false
68
151
 
69
- func _layout_viewport_scale() -> float:
70
- return 0.0
71
-
72
152
  func _changed() -> void:
73
153
  if layout != null: layout.changed()
74
154
 
@@ -77,10 +157,15 @@ func _notification(what: int) -> void:
77
157
  if what == 12 and layout != null: layout.order_moved()
78
158
 
79
159
  func _enter_tree() -> void:
160
+ # Native draw signal precedes script _draw, so derived Box foreground hooks
161
+ # cannot accidentally bypass the shared style. Legacy widget painters
162
+ # explicitly opt out of S01 styles and remain untouched until S02.
163
+ if VisualStyle.supported(get_script()) and not draw.is_connected(_paint_visual_style): draw.connect(_paint_visual_style)
80
164
  layout.changed()
81
165
  layout.start()
82
166
 
83
167
  func _exit_tree() -> void:
168
+ if draw.is_connected(_paint_visual_style): draw.disconnect(_paint_visual_style)
84
169
  layout.stop()
85
170
 
86
171
  func invalidate_layout() -> void:
@@ -99,7 +184,26 @@ func apply_layout_position(offset: Vector3) -> void:
99
184
  position = Vector2(offset.x, offset.y)
100
185
 
101
186
  func apply_layout_size(size: Vector3) -> void:
102
- _layout_size = Vector2(size.x, size.y)
187
+ var next := Vector2(size.x,size.y)
188
+ if next!=_layout_size: _queue_style_redraw()
189
+ _layout_size = next
103
190
  # Explicit invalidation also restores a native position edited externally.
104
- if layout.parent_coordinator() != null: apply_layout_position(layout.model.offset)
191
+ if layout.parent_coordinator() != null: layout._place(layout.model.offset)
105
192
  layout_applied.emit(_layout_size)
193
+
194
+ func _margin_insets() -> Vector4:
195
+ layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
196
+ return layout.model.margin
197
+
198
+ func _queue_style_redraw() -> void:
199
+ _visual_style.redraw_count += 1
200
+ queue_redraw()
201
+ func _paint_visual_style() -> void:
202
+ _visual_style.paint(self,layout_size,layout.model.border)
203
+ func get_visual_style_stats() -> Dictionary:
204
+ return {"parse":_visual_style.parse_count,"draw":_visual_style.draw_count,"commands":_visual_style.command_count,"redraw":_visual_style.redraw_count}
205
+
206
+ func _style_supported() -> bool:
207
+ if VisualStyle.supported(get_script()): return true
208
+ push_error("Estragon style: Text/Rect/Button painters retain their local API until S02")
209
+ return false
@@ -3,27 +3,60 @@ class_name EstragonComponent3D
3
3
  extends Node3D
4
4
  ## Native C1 participant. Needs a contiguous same-dimensional chain to an entry.
5
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:
6
+ const Coordinator = preload("internal/coordinator.gd")
7
+ const ESTRAGON_LENGTHS := true
8
+ const Length = preload("internal/length.gd")
9
+ var lengths = Length.new()
10
+ var width: Variant = "auto":
8
11
  set(value):
9
- if not valid_length(value) or width == value: return
12
+ if is_same(width,value) or not lengths.assign("width",value): return
10
13
  width = value
11
14
  _changed()
12
- @export var height: float = -1.0:
15
+ var height: Variant = "auto":
13
16
  set(value):
14
- if not valid_length(value) or height == value: return
17
+ if is_same(height,value) or not lengths.assign("height",value): return
15
18
  height = value
16
19
  _changed()
17
- @export var depth: float = -1.0:
20
+ var depth: Variant = "auto":
18
21
  set(value):
19
- if not valid_length(value) or depth == value: return
22
+ if is_same(depth,value) or not lengths.assign("depth",value): return
20
23
  depth = value
21
24
  _changed()
22
- @export var gap: float = 0.0:
25
+ var x: Variant = 0.0:
23
26
  set(value):
24
- if not is_finite(value) or value < 0 or value == gap: return
27
+ if is_same(x,value) or not lengths.assign("x",value): return
28
+ x = value
29
+ _changed()
30
+ var y: Variant = 0.0:
31
+ set(value):
32
+ if is_same(y,value) or not lengths.assign("y",value): return
33
+ y = value
34
+ _changed()
35
+ var z: Variant = 0.0:
36
+ set(value):
37
+ if is_same(z,value) or not lengths.assign("z",value): return
38
+ z = value
39
+ _changed()
40
+ var gap: Variant = 0.0:
41
+ set(value):
42
+ if is_same(gap,value) or not lengths.assign("gap",value): return
25
43
  gap = value
26
44
  _changed()
45
+ @export var grow: float = 0.0:
46
+ set(value):
47
+ if not is_finite(value) or value<0 or value==grow: return
48
+ grow = value
49
+ _changed()
50
+ @export_enum("Natural", "Stretch") var stretch: int = 0:
51
+ set(value):
52
+ if value not in [0,1] or value==stretch: return
53
+ stretch = value
54
+ _changed()
55
+ @export var pixels_per_unit: float = 100.0:
56
+ set(value):
57
+ if not is_finite(value) or value<=0 or pixels_per_unit==value: return
58
+ pixels_per_unit = value
59
+ _changed()
27
60
  @export var center: bool = false:
28
61
  set(value):
29
62
  if center == value: return
@@ -32,11 +65,11 @@ const Coordinator = preload("res://addons/estragon/runtime/node/internal/coordin
32
65
  var layout_size: Vector3:
33
66
  get: return _layout_size
34
67
  var _layout_size := Vector3.ZERO
35
- # Internal bridge, deliberately not the public authoring API.
36
68
  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)
69
+ func _get_property_list() -> Array[Dictionary]:
70
+ return Length.properties(["width","height","depth","x","y","z","gap"])
71
+ static func valid_length(value) -> bool:
72
+ return Length.valid(value,"extent")
40
73
 
41
74
  func set_extent(value: Vector3) -> Error:
42
75
  for axis in range(3):
@@ -47,14 +80,17 @@ func set_extent(value: Vector3) -> Error:
47
80
  return OK
48
81
 
49
82
  func requested_extent() -> Vector3:
50
- return Vector3(width, height, depth)
83
+ return layout.model.requested
84
+
85
+ func _measure_native() -> Vector3:
86
+ return Vector3.ZERO
87
+
88
+ func _layout_options() -> Dictionary:
89
+ return {"axis":0,"fill":Vector3.ZERO,"intrinsic":_measure_native()}
51
90
 
52
91
  func _is_layout_entry() -> bool:
53
92
  return false
54
93
 
55
- func _layout_viewport_scale() -> float:
56
- return 0.0
57
-
58
94
  func _changed() -> void:
59
95
  if layout != null: layout.changed()
60
96
 
@@ -87,5 +123,5 @@ func apply_layout_position(offset: Vector3) -> void:
87
123
  func apply_layout_size(size: Vector3) -> void:
88
124
  _layout_size = size
89
125
  # Explicit invalidation also restores a native position edited externally.
90
- if layout.parent_coordinator() != null: apply_layout_position(layout.model.offset)
126
+ if layout.parent_coordinator() != null: layout._place(layout.model.offset)
91
127
  layout_applied.emit(_layout_size)
@@ -1,20 +1,11 @@
1
1
  @tool
2
2
  class_name Estragon2D
3
- extends "res://addons/estragon/runtime/node/component_2d.gd"
3
+ extends "box.gd"
4
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
5
  func _is_layout_entry() -> bool:
12
6
  return true
13
7
 
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")
8
+ const Pointer = preload("internal/pointer_2d.gd")
18
9
  var _pointer = Pointer.new(self)
19
10
 
20
11
  func _get_pointer_router():
@@ -1,15 +1,6 @@
1
1
  @tool
2
2
  class_name Estragon3D
3
- extends "res://addons/estragon/runtime/node/component_3d.gd"
3
+ extends "component_3d.gd"
4
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
5
  func _is_layout_entry() -> bool:
12
6
  return true
13
-
14
- func _layout_viewport_scale() -> float:
15
- return viewport_width_scale
@@ -1,6 +1,9 @@
1
1
  @tool
2
2
  class_name EstragonHBox
3
- extends "res://addons/estragon/runtime/node/component_2d.gd"
3
+ extends "box.gd"
4
+ const STACK_DIRECTION := "row"
5
+ func _init() -> void:
6
+ direction = "row"
4
7
  ## Native stack participant using the shared composed layout algorithm.
5
8
  func _layout_axis() -> int:
6
9
  return 0
@@ -0,0 +1,159 @@
1
+ @tool
2
+ extends Resource
3
+ ## External weak lookup only. Never serialized onto authored Nodes/Resources.
4
+ var hosts: Dictionary = {}
5
+ # Strong bridge records, weak native hosts. Native exit/projection release owns
6
+ # teardown; no adapter lifetime or coordinator is stored on application Nodes.
7
+ var controls: Dictionary = {}
8
+ var exiting_controls: Dictionary = {}
9
+ func block_control(node: Control) -> void:
10
+ var id := node.get_instance_id()
11
+ if exiting_controls.has(id): return
12
+ var reference: WeakRef = weakref(node)
13
+ exiting_controls[id] = reference
14
+ _unblock_control.call_deferred(id,reference)
15
+ func enter_control(node: Control) -> void:
16
+ exiting_controls.erase(node.get_instance_id())
17
+ func control_exiting(node: Control) -> bool:
18
+ var reference = exiting_controls.get(node.get_instance_id())
19
+ return reference != null and reference.get_ref() == node
20
+ func _unblock_control(id: int, reference: WeakRef) -> void:
21
+ if exiting_controls.get(id) != reference: return
22
+ exiting_controls.erase(id)
23
+ var node = reference.get_ref()
24
+ if node != null and node.is_inside_tree():
25
+ var parent = projected_parent(node)
26
+ if parent == null: parent = node.get_parent()
27
+ var layout = _coordinator(parent)
28
+ if layout != null: layout._sync()
29
+ func add_control(node: Control, coordinator: RefCounted) -> void:
30
+ controls[node.get_instance_id()] = coordinator
31
+ add(node,coordinator)
32
+ func release_control(node: Control) -> void:
33
+ var id := node.get_instance_id()
34
+ var coordinator = controls.get(id)
35
+ if coordinator == null: return
36
+ coordinator.stop()
37
+ remove(node,coordinator)
38
+ controls.erase(id)
39
+ func find(node: Node):
40
+ if node == null: return null
41
+ var reference = hosts.get(node.get_instance_id())
42
+ return reference.get_ref() if reference != null else null
43
+ func add(node: Node, coordinator: RefCounted) -> void:
44
+ hosts[node.get_instance_id()] = weakref(coordinator)
45
+ func remove(node: Node, coordinator: RefCounted) -> void:
46
+ if find(node) == coordinator: hosts.erase(node.get_instance_id())
47
+
48
+ # E08 borrowed scene references. All ownership/order bookkeeping lives here,
49
+ # never on authored objects. Native parents, owners and sibling order stay put.
50
+ var projections: Dictionary = {}
51
+ var orders: Dictionary = {}
52
+ var order_owners: Dictionary = {}
53
+ func projected_parent(node: Node) -> Node:
54
+ var entry = projections.get(node.get_instance_id())
55
+ return entry.parent.get_ref() if entry != null else null
56
+ func children(parent: Node, native_children: Array) -> Array:
57
+ var result: Array = []
58
+ for reference in orders.get(parent.get_instance_id(),[]):
59
+ var node = reference.get_ref()
60
+ if node != null:
61
+ var logical = projected_parent(node)
62
+ if logical == null or logical == parent: result.append(node)
63
+ for node in native_children:
64
+ var logical = projected_parent(node)
65
+ if not result.has(node) and (logical == null or logical == parent): result.append(node)
66
+ return result
67
+ func _coordinator(node: Node):
68
+ if node == null: return null
69
+ return node._get_layout_coordinator() if node.has_method("_get_layout_coordinator") else find(node)
70
+ func _placement(node: Node, parent: Node):
71
+ var coordinator = _coordinator(node)
72
+ if coordinator == null or coordinator._mode == coordinator.Mode.ENTRY or coordinator.participant(parent) == null: return null
73
+ return coordinator
74
+ func _same_projection(owner: RefCounted, next: Dictionary, next_orders: Dictionary) -> bool:
75
+ var count := 0
76
+ for id in projections:
77
+ var item: Dictionary = projections[id]
78
+ if item.claim.get_ref() != owner: continue
79
+ count += 1
80
+ if not next.has(id) or item.node.get_ref() != next[id][0] or item.parent.get_ref() != next[id][1] or item.native_parent.get_ref() != next[id][0].get_parent(): return false
81
+ if count != next.size(): return false
82
+ count = 0
83
+ for id in order_owners:
84
+ if order_owners[id].get_ref() != owner: continue
85
+ count += 1
86
+ if not next_orders.has(id) or orders[id].size() != next_orders[id].size(): return false
87
+ for index in range(orders[id].size()):
88
+ if orders[id][index].get_ref() != next_orders[id][index].get_ref(): return false
89
+ return count == next_orders.size()
90
+ func replace_projection(owner: RefCounted, next: Dictionary, next_orders: Dictionary) -> void:
91
+ if _same_projection(owner,next,next_orders):
92
+ for item in next.values():
93
+ var coordinator = _placement(item[0],item[1])
94
+ if coordinator != null and coordinator.scope_root() != null: coordinator._place(coordinator.model.offset)
95
+ return
96
+ var affected: Array = []
97
+ var refresh: Array = []
98
+ # Detach changed model edges before adopting into another model. Core remains
99
+ # the sole authority for one-parent/cycle validation and layout arithmetic.
100
+ for id in projections:
101
+ var item: Dictionary = projections[id]
102
+ if item.claim.get_ref() != owner: continue
103
+ for reference in [item.parent,item.native_parent]:
104
+ var node = reference.get_ref()
105
+ if node != null and not affected.has(node): affected.append(node)
106
+ for id in next:
107
+ var prior = projections.get(id)
108
+ if prior != null and prior.parent.get_ref() != null and not affected.has(prior.parent.get_ref()): affected.append(prior.parent.get_ref())
109
+ var item: Array = next[id]
110
+ for node in [item[0].get_parent(),item[1]]:
111
+ if node != null and not affected.has(node): affected.append(node)
112
+ for node in affected:
113
+ var coordinator = _coordinator(node)
114
+ if coordinator != null and coordinator.active: coordinator.model.set_children([])
115
+ for id in projections.keys():
116
+ var item: Dictionary = projections[id]
117
+ if item.claim.get_ref() != owner: continue
118
+ var node = item.node.get_ref()
119
+ if not next.has(id):
120
+ projections.erase(id)
121
+ if node != null:
122
+ if node is Control: release_control(node)
123
+ if node.get_parent() == item.native_parent.get_ref() and item.position != null: node.position = item.position
124
+ refresh.append(node)
125
+ for id in next:
126
+ var node: Node = next[id][0]
127
+ var parent: Node = next[id][1]
128
+ if not projections.has(id) or projections[id].claim.get_ref() != owner:
129
+ var coordinator = _placement(node,parent)
130
+ projections[id] = {"node":weakref(node),"native_parent":weakref(node.get_parent()),"position":node.position if coordinator != null and (node is Node2D or node is Node3D) else null,"claim":weakref(owner),"parent":weakref(parent)}
131
+ else:
132
+ var item: Dictionary = projections[id]
133
+ if _placement(node,parent) == null and item.position != null:
134
+ if node.get_parent() == item.native_parent.get_ref(): node.position = item.position
135
+ item.position = null
136
+ elif _placement(node,parent) != null and item.position == null and (node is Node2D or node is Node3D): item.position = node.position
137
+ item.parent = weakref(parent)
138
+ refresh.append(node)
139
+ for id in order_owners.keys():
140
+ if order_owners[id].get_ref() == owner:
141
+ orders.erase(id)
142
+ order_owners.erase(id)
143
+ for id in next_orders:
144
+ orders[id] = next_orders[id]
145
+ order_owners[id] = weakref(owner)
146
+ for node in affected:
147
+ var coordinator = _coordinator(node)
148
+ if coordinator != null: coordinator._sync()
149
+ for node in refresh: _refresh_scope(node)
150
+ func _refresh_scope(node: Node) -> void:
151
+ if node.has_method("_layout_scope_changed"): node._layout_scope_changed()
152
+ for child in node.get_children(): _refresh_scope(child)
153
+ func refresh_positions(root: RefCounted) -> void:
154
+ # Called after event-driven arrange, never per frame. A logical ancestor may
155
+ # move without changing this child's model offset, so refresh its translation.
156
+ for item in projections.values():
157
+ var node = item.node.get_ref()
158
+ var coordinator = _coordinator(node)
159
+ if coordinator != null and coordinator._mode != coordinator.Mode.ENTRY and coordinator.scope_root() == root: coordinator._place(coordinator.model.offset)
@@ -0,0 +1 @@
1
+ uid://6o74mb6n662t
@@ -0,0 +1,6 @@
1
+ [gd_resource type="Resource" load_steps=2 format=3]
2
+
3
+ [ext_resource type="Script" path="composition_hosts.gd" id="1"]
4
+
5
+ [resource]
6
+ script = ExtResource("1")