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

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 (95) 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 +125 -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 +74 -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 +141 -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 +57 -0
  62. package/addons/estragon/runtime/node/box.gd.uid +1 -0
  63. package/addons/estragon/runtime/node/button.gd +44 -15
  64. package/addons/estragon/runtime/node/component_2d.gd +167 -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/component_2d_icon.tres +4 -0
  70. package/addons/estragon/runtime/node/internal/composition_hosts.gd +159 -0
  71. package/addons/estragon/runtime/node/internal/composition_hosts.gd.uid +1 -0
  72. package/addons/estragon/runtime/node/internal/composition_hosts.tres +6 -0
  73. package/addons/estragon/runtime/node/internal/control_participant.gd +164 -0
  74. package/addons/estragon/runtime/node/internal/control_participant.gd.uid +1 -0
  75. package/addons/estragon/runtime/node/internal/coordinator.gd +79 -27
  76. package/addons/estragon/runtime/node/internal/grid_definition.gd +75 -0
  77. package/addons/estragon/runtime/node/internal/grid_definition.gd.uid +1 -0
  78. package/addons/estragon/runtime/node/internal/layout_core.gd +205 -22
  79. package/addons/estragon/runtime/node/internal/length.gd +94 -0
  80. package/addons/estragon/runtime/node/internal/length.gd.uid +1 -0
  81. package/addons/estragon/runtime/node/internal/stack_contract.gd +21 -0
  82. package/addons/estragon/runtime/node/internal/stack_contract.gd.uid +1 -0
  83. package/addons/estragon/runtime/node/internal/stack_policy.gd +59 -0
  84. package/addons/estragon/runtime/node/internal/stack_policy.gd.uid +1 -0
  85. package/addons/estragon/runtime/node/internal/visual_style_2d.gd +75 -0
  86. package/addons/estragon/runtime/node/internal/visual_style_2d.gd.uid +1 -0
  87. package/addons/estragon/runtime/node/native_2d.gd +5 -5
  88. package/addons/estragon/runtime/node/native_3d.gd +5 -5
  89. package/addons/estragon/runtime/node/rect.gd +13 -13
  90. package/addons/estragon/runtime/node/spacer.gd +4 -0
  91. package/addons/estragon/runtime/node/spacer.gd.uid +1 -0
  92. package/addons/estragon/runtime/node/text.gd +5 -3
  93. package/addons/estragon/runtime/node/toggle.gd +18 -5
  94. package/addons/estragon/runtime/node/vbox.gd +4 -1
  95. package/package.json +1 -1
@@ -0,0 +1,164 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Native Control minimum/outer-rect bridge. Container internals remain opaque.
4
+ const Hosts = preload("composition_hosts.tres")
5
+ var host: WeakRef
6
+ var coordinator: WeakRef
7
+ var original: Rect2
8
+ var native_parent: WeakRef
9
+ var assigned: Rect2
10
+ var allocated := false
11
+ var active := false
12
+ var queued := false
13
+ var writing := false
14
+ var reason := ""
15
+ var minimum_reads := 0
16
+ var refreshes := 0
17
+ var native_writes := 0
18
+ var subscribed := false
19
+ var included := false
20
+
21
+ func _init(node: Control, layout: RefCounted) -> void:
22
+ host = weakref(node)
23
+ coordinator = weakref(layout)
24
+ original = Rect2(node.position,node.size)
25
+ assigned = original
26
+
27
+ func start() -> void:
28
+ active = true
29
+ var node = host.get_ref()
30
+ for event in ["minimum_size_changed","theme_changed","size_flags_changed","visibility_changed"]:
31
+ node.connect(event,changed)
32
+ node.resized.connect(rect_changed)
33
+ node.item_rect_changed.connect(rect_changed)
34
+ node.tree_exiting.connect(exiting)
35
+ subscribed = true
36
+ refresh()
37
+
38
+ func stop() -> void:
39
+ if not active: return
40
+ active = false
41
+ var node = host.get_ref()
42
+ if node == null: return
43
+ for event in ["minimum_size_changed","theme_changed","size_flags_changed","visibility_changed"]:
44
+ if node.is_connected(event,changed): node.disconnect(event,changed)
45
+ for event in ["resized","item_rect_changed"]:
46
+ if node.is_connected(event,rect_changed): node.disconnect(event,rect_changed)
47
+ if node.tree_exiting.is_connected(exiting): node.tree_exiting.disconnect(exiting)
48
+ subscribed = false
49
+ restore()
50
+
51
+ func exiting() -> void:
52
+ var node = host.get_ref()
53
+ var layout = coordinator.get_ref()
54
+ var parent = layout.parent_coordinator() if layout != null else null
55
+ if node != null:
56
+ Hosts.block_control(node)
57
+ Hosts.release_control(node)
58
+ # Native child_exiting_tree can precede actual removal. Reconcile the core
59
+ # after that removal, never reacquire an exiting Control in its callback.
60
+ if parent != null: parent._sync.call_deferred()
61
+
62
+ func changed() -> void:
63
+ if not active or queued: return
64
+ queued = true
65
+ refresh.call_deferred()
66
+
67
+ func rect_changed() -> void:
68
+ if writing or not active: return
69
+ var node = host.get_ref()
70
+ if node == null: return
71
+ if not allocated or limitation() != reason or not node.position.is_equal_approx(assigned.position) or not node.size.is_equal_approx(assigned.size): changed()
72
+
73
+ func logical_parent() -> Node:
74
+ var node = host.get_ref()
75
+ if node == null: return null
76
+ var projected = Hosts.projected_parent(node)
77
+ return projected if projected != null else node.get_parent()
78
+
79
+ func limitation() -> String:
80
+ var node = host.get_ref()
81
+ var parent = logical_parent()
82
+ if node == null or not node.is_inside_tree(): return "outside the native tree"
83
+ if node.get_parent() is Container: return "native Container owns its direct children's rectangles"
84
+ if node.is_set_as_top_level(): return "top_level Control uses independent native coordinates"
85
+ if node.anchor_left != 0 or node.anchor_top != 0 or node.anchor_right != 0 or node.anchor_bottom != 0: return "nonzero anchors compete with Box allocation"
86
+ if not is_zero_approx(node.rotation) or not node.scale.is_equal_approx(Vector2.ONE) or not node.pivot_offset.is_zero_approx(): return "local rotation/scale/pivot requires explicit positioning"
87
+ if not parent is CanvasItem: return "no compatible CanvasItem layout parent"
88
+ if parent.get_viewport() != node.get_viewport() or parent.get_canvas() != node.get_canvas(): return "different native viewport/CanvasLayer"
89
+ # CanvasItem's native parent-item getter is not a public Script API.
90
+ # The local/global matrices expose the same parent basis without traversal.
91
+ var basis: Transform2D = node.get_global_transform()*node.get_transform().affine_inverse()
92
+ if is_zero_approx(basis.x.cross(basis.y)): return "singular native parent transform"
93
+ var relative: Transform2D = basis.affine_inverse()*parent.get_global_transform()
94
+ if not relative.x.is_equal_approx(Vector2.RIGHT) or not relative.y.is_equal_approx(Vector2.DOWN): return "borrowed logical/native parent bases differ"
95
+ return ""
96
+
97
+ func participates() -> bool:
98
+ var node = host.get_ref()
99
+ return active and node != null and node.is_visible_in_tree() and limitation().is_empty()
100
+
101
+ func refresh() -> void:
102
+ queued = false
103
+ if not active: return
104
+ var node = host.get_ref()
105
+ var layout = coordinator.get_ref()
106
+ if node == null or layout == null: return
107
+ refreshes += 1
108
+ var next := limitation()
109
+ if next != reason and not next.is_empty(): push_warning("Estragon native Control layout skipped: "+str(node.get_path())+": "+next)
110
+ reason = next
111
+ var next_included := participates()
112
+ var inclusion_changed := included != next_included
113
+ included = next_included
114
+ minimum_reads += 1
115
+ var minimum: Vector2 = node.get_combined_minimum_size()
116
+ var fills := Vector3(1 if node.size_flags_horizontal == Control.SIZE_EXPAND_FILL else 0,1 if node.size_flags_vertical == Control.SIZE_EXPAND_FILL else 0,0)
117
+ layout.model.allocation_minimum = Vector3(minimum.x,minimum.y,0)
118
+ layout.model.configure(Vector3(-1,-1,0),0,false,0,fills,Vector3(minimum.x,minimum.y,0))
119
+ if inclusion_changed: layout.model.invalidate()
120
+ if not participates(): restore()
121
+ elif allocated and (not node.position.is_equal_approx(assigned.position) or not node.size.is_equal_approx(assigned.size)): layout.model.invalidate()
122
+ var parent = layout.parent_coordinator()
123
+ if parent != null: parent._sync()
124
+
125
+ func restore() -> void:
126
+ if not allocated: return
127
+ var node = host.get_ref()
128
+ if node != null and native_parent != null and node.get_parent() == native_parent.get_ref():
129
+ writing = true
130
+ node.position = original.position
131
+ node.size = original.size
132
+ writing = false
133
+ allocated = false
134
+
135
+ func place(offset: Vector3) -> void:
136
+ if not participates(): return
137
+ var node = host.get_ref()
138
+ if not allocated:
139
+ # Capture after native add/reparent/theme initialization completes, not
140
+ # inside child_entered_tree halfway through that native transaction.
141
+ original = Rect2(node.position,node.size)
142
+ native_parent = weakref(node.get_parent())
143
+ var parent: CanvasItem = logical_parent()
144
+ var point: Vector2 = parent.get_global_transform()*Vector2(offset.x,offset.y)
145
+ writing = true
146
+ if not node.global_position.is_equal_approx(point):
147
+ node.global_position = point
148
+ native_writes += 1
149
+ assigned.position = node.position
150
+ writing = false
151
+ allocated = true
152
+
153
+ func arrange(size: Vector3) -> void:
154
+ if not participates(): return
155
+ var layout = coordinator.get_ref()
156
+ place(layout.model.offset)
157
+ var node = host.get_ref()
158
+ var wanted := Vector2(size.x,size.y)
159
+ writing = true
160
+ if not node.size.is_equal_approx(wanted):
161
+ node.size = wanted
162
+ native_writes += 1
163
+ assigned.size = node.size
164
+ writing = false
@@ -0,0 +1 @@
1
+ uid://d10lmffp0yjv1
@@ -1,10 +1,13 @@
1
1
  @tool
2
2
  extends RefCounted
3
- const Profile = preload("res://addons/estragon/runtime/composition/profile.tres")
3
+ const Profile = preload("../../composition/profile.tres")
4
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")
5
+ const Core = preload("layout_core.gd")
6
+ const CompositionHosts = preload("composition_hosts.tres")
6
7
  const META := "_estragon_b2_coordinator"
7
- enum Mode { PROOF, PARTICIPANT, ENTRY }
8
+ enum Mode { PROOF, PARTICIPANT, ENTRY, COMPOSITION, CONTROL }
9
+ var control_adapter
10
+ var managed_root: WeakRef
8
11
  var _mode: int
9
12
  var model := Core.new()
10
13
  var active: bool = false
@@ -13,6 +16,7 @@ var _host: WeakRef
13
16
  var _dimension: int
14
17
  var _queued: bool = false
15
18
  var _viewport: Viewport
19
+ var _root_offset := Vector3.ZERO
16
20
 
17
21
  func _init(host: Node, dimension: int, mode: int = Mode.PROOF) -> void:
18
22
  _mode = mode
@@ -26,18 +30,23 @@ func _init(host: Node, dimension: int, mode: int = Mode.PROOF) -> void:
26
30
  func parent_coordinator():
27
31
  var host = _host.get_ref()
28
32
  if host == null or _mode == Mode.ENTRY: return null
29
- return participant(host.get_parent())
33
+ var projected = CompositionHosts.projected_parent(host)
34
+ return participant(projected if projected != null else host.get_parent())
30
35
 
31
- func participant(node: Node):
36
+ func participant(node: Node, acquire_control := false):
32
37
  if node == null: return null
38
+ if node is Control and CompositionHosts.control_exiting(node): return null
33
39
  var found
34
40
  if _mode == Mode.PROOF:
35
41
  if not node.has_meta(META): return null
36
42
  found = node.get_meta(META).get_ref()
37
43
  else:
38
44
  # 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()
45
+ found = node._get_layout_coordinator() if node.has_method("_get_layout_coordinator") else CompositionHosts.find(node)
46
+ if found == null and acquire_control and _dimension == 2 and node is Control and node.is_inside_tree():
47
+ found = get_script().new(node,2,Mode.CONTROL)
48
+ CompositionHosts.add_control(node,found)
49
+ found.start()
41
50
  return found if found != null and found.active and found._dimension == _dimension else null
42
51
 
43
52
  func scope_root():
@@ -54,19 +63,20 @@ func root_host() -> Node:
54
63
  var found = scope_root()
55
64
  return found._host.get_ref() if found != null else null
56
65
 
57
- func _viewport_scale(host: Node) -> float:
58
- return host.viewport_width_scale if _mode == Mode.PROOF else host._layout_viewport_scale()
59
-
60
66
  func start() -> void:
61
67
  active = true
62
68
  var host: Node = _host.get_ref()
69
+ if _mode == Mode.CONTROL:
70
+ control_adapter = preload("control_participant.gd").new(host,self)
71
+ control_adapter.start()
72
+ return
63
73
  # PackedScene restores metadata after construction. Refresh the proof-only
64
74
  # weak registry at entry; C1 resolves the live script field instead.
65
75
  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)
76
+ host.child_entered_tree.connect(_child_entered)
77
+ host.child_exiting_tree.connect(_child_exiting)
68
78
  if host.has_signal("child_order_changed"): host.connect("child_order_changed", _sync)
69
- if _mode != Mode.PARTICIPANT:
79
+ if _mode in [Mode.PROOF,Mode.ENTRY]:
70
80
  _viewport = host.get_viewport()
71
81
  _viewport.size_changed.connect(_viewport_changed)
72
82
  _sync()
@@ -77,8 +87,12 @@ func start() -> void:
77
87
  func stop() -> void:
78
88
  active = false
79
89
  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)
90
+ if _mode == Mode.CONTROL:
91
+ if control_adapter != null: control_adapter.stop()
92
+ model.set_children([])
93
+ return
94
+ if host.child_entered_tree.is_connected(_child_entered): host.child_entered_tree.disconnect(_child_entered)
95
+ if host.child_exiting_tree.is_connected(_child_exiting): host.child_exiting_tree.disconnect(_child_exiting)
82
96
  if host.has_signal("child_order_changed") and host.is_connected("child_order_changed", _sync): host.disconnect("child_order_changed", _sync)
83
97
  if _viewport != null and _viewport.size_changed.is_connected(_viewport_changed): _viewport.size_changed.disconnect(_viewport_changed)
84
98
  _viewport = null
@@ -86,7 +100,12 @@ func stop() -> void:
86
100
  var parent = parent_coordinator()
87
101
  if parent != null: parent._sync()
88
102
 
89
- func _child_changed(_child: Node) -> void:
103
+ func _child_entered(child: Node) -> void:
104
+ if child is Control: CompositionHosts.enter_control(child)
105
+ _sync()
106
+
107
+ func _child_exiting(child: Node) -> void:
108
+ if child is Control: CompositionHosts.block_control(child)
90
109
  _sync()
91
110
 
92
111
  func order_moved() -> void:
@@ -94,12 +113,17 @@ func order_moved() -> void:
94
113
  if parent != null: parent._sync()
95
114
 
96
115
  func _sync() -> void:
97
- if not active: return
116
+ if not active or _mode == Mode.CONTROL: return
98
117
  var values: Array = []
99
118
  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)
119
+ var children: Array = host.get_children() if _mode != Mode.COMPOSITION else []
120
+ if _mode == Mode.COMPOSITION and managed_root != null and managed_root.get_ref() != null: children.append(managed_root.get_ref())
121
+ children = CompositionHosts.children(host,children)
122
+ for child in children:
123
+ var found = participant(child,true)
124
+ if found != null and found._mode != Mode.ENTRY:
125
+ if found._mode == Mode.CONTROL and not found.control_adapter.participates(): continue
126
+ values.append(found.model)
103
127
  var error := model.set_children(values)
104
128
  if error != OK: push_error("Estragon layout model ownership: " + error_string(error))
105
129
 
@@ -108,38 +132,66 @@ func changed() -> void:
108
132
  if host == null: return
109
133
  if host.has_method("_layout_options"):
110
134
  var options: Dictionary = host._layout_options()
111
- model.configure(host.requested_extent(),host.gap,host.center,options.axis,options.fill,options.intrinsic)
135
+ model.set_policy(options.get("alignment",["start","start","start"]))
136
+ if "lengths" in host:
137
+ for property in host._get_property_list():
138
+ if not Core.Length.domain(property.name).is_empty() and not host.lengths.specs.has(property.name): host.lengths.assign(property.name,host.get(property.name),Core.Length.domain(property.name,host.get_script()))
139
+ model.set_lengths(host.lengths.specs,host.grow,host.stretch,host.pixels_per_unit if _dimension==3 else 1.0,options.axis,host._default_padding() if host.has_method("_default_padding") else Vector4.ZERO)
140
+ model.configure(host.requested_extent(),model.gap,host.center,options.axis,options.fill,options.intrinsic,model.padding if "lengths" in host else options.get("padding",Vector4.ZERO),model.margin if "lengths" in host else options.get("margin",Vector4.ZERO))
112
141
  else: model.configure(host.requested_extent(), host.gap, host.center)
113
142
 
114
143
  func _viewport_changed() -> void:
115
144
  var host = _host.get_ref()
116
- if host != null and parent_coordinator() == null and _viewport_scale(host) > 0: _invalidated()
145
+ if host == null or parent_coordinator() != null: return
146
+ model.invalidate()
117
147
 
118
148
  func _invalidated() -> void:
119
149
  if Profile.is_enabled(): Profile.add("layout_invalidations")
120
- if not active or _queued or parent_coordinator() != null or _mode == Mode.PARTICIPANT: return
150
+ if not active or _queued or parent_coordinator() != null or _mode in [Mode.PARTICIPANT,Mode.COMPOSITION,Mode.CONTROL]: return
121
151
  _queued = true
122
152
  call_deferred("_flush")
123
153
 
124
154
  func _flush() -> void:
125
155
  _queued = false
126
- if not active or parent_coordinator() != null or _mode == Mode.PARTICIPANT: return
156
+ if not active or parent_coordinator() != null or _mode in [Mode.PARTICIPANT,Mode.COMPOSITION,Mode.CONTROL]: return
127
157
  var host = _host.get_ref()
128
158
  if host == null or host.is_queued_for_deletion(): return
129
159
  flush_count += 1
130
160
  if Profile.is_enabled(): Profile.add("layout_flushes")
161
+ var visible := _viewport.get_visible_rect().size if _viewport!=null else Vector2.ZERO
162
+ # An independent 2D Entry has a native containing rectangle even without
163
+ # an Estragon parent. Use the visible logical viewport for every eligible
164
+ # root percentage, including insets/gap/offsets; child preparation remains
165
+ # exclusively the core's immediate-content responsibility. No 3D Z inference.
166
+ var reference := Vector3(visible.x,visible.y,-1) if _mode==Mode.ENTRY and _dimension==2 else Vector3(-1,-1,-1)
167
+ model.prepare(reference,visible)
131
168
  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
169
  model.arrange(available)
170
+ if host is Node2D:
171
+ host.position += Vector2(model.length_offset.x-_root_offset.x,model.length_offset.y-_root_offset.y)
172
+ elif host is Node3D: host.position += model.length_offset-_root_offset
173
+ _root_offset = model.length_offset
174
+ CompositionHosts.refresh_positions(self)
135
175
 
136
176
  func _place(offset: Vector3) -> void:
177
+ if _mode == Mode.CONTROL:
178
+ control_adapter.place(offset)
179
+ return
137
180
  var host = _host.get_ref()
138
181
  if host == null: return
139
182
  if host.has_method("apply_layout_position"): host.apply_layout_position(offset)
140
183
  elif _dimension == 2: host.position = Vector2(offset.x, offset.y)
141
184
  else: host.position = offset
185
+ var projected = CompositionHosts.projected_parent(host)
186
+ if projected != null:
187
+ # Apply the participant/adapter's own origin policy first, then convert
188
+ # its logical position using Godot transforms (including top_level).
189
+ if host is Node2D and projected is Node2D: host.global_position = projected.to_global(host.position)
190
+ elif host is Node3D and projected is Node3D: host.global_position = projected.to_global(host.position)
142
191
 
143
192
  func _arranged(size: Vector3) -> void:
193
+ if _mode == Mode.CONTROL:
194
+ control_adapter.arrange(size)
195
+ return
144
196
  var host = _host.get_ref()
145
- if host != null: host.apply_layout_size(size)
197
+ if host != null and _mode != Mode.COMPOSITION: host.apply_layout_size(size)
@@ -0,0 +1,75 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Pure future Grid input normalization, not an executable layout component.
4
+ ## Serializable dictionaries only. Track fractions never enter Length dimensions.
5
+ const Length = preload("length.gd")
6
+ static func tracks(values) -> Dictionary:
7
+ if values is int:
8
+ if values<1 or values>256: return {"error":"track count must be 1..256"}
9
+ var result: Array = []
10
+ for index in range(values): result.append({"unit":"fr","value":1.0})
11
+ return {"tracks":result}
12
+ if not values is Array or values.is_empty() or values.size()>256: return {"error":"tracks require a nonempty array or count (maximum 256)"}
13
+ var result: Array = []
14
+ for value in values:
15
+ if value is String and value.ends_with("fr"):
16
+ var number: String = value.trim_suffix("fr")
17
+ if not number.is_valid_float() or not is_finite(float(number)) or float(number)<=0 or float(number)>Length.LIMIT: return {"error":"fr track weight must be finite and positive"}
18
+ result.append({"unit":"fr","value":float(number)})
19
+ else:
20
+ var spec := Length.parse(value,"extent")
21
+ if spec.has("error"): return {"error":"invalid track: "+spec.error}
22
+ result.append(spec)
23
+ return {"tracks":result}
24
+ static func normalize(columns, rows, areas: Array = [], placements: Array = []) -> Dictionary:
25
+ var cols := tracks(columns)
26
+ if cols.has("error"): return cols
27
+ var lines := tracks(rows)
28
+ if lines.has("error"): return lines
29
+ var matrix: Array = []
30
+ var bounds := {}
31
+ if not areas.is_empty() and areas.size()!=lines.tracks.size(): return {"error":"area row count must match row tracks"}
32
+ for row in range(areas.size()):
33
+ if not areas[row] is String: return {"error":"each area row must be a space-separated string"}
34
+ var cells: Array = []
35
+ for cell in areas[row].replace("\t"," ").split(" ",false): cells.append(cell)
36
+ if cells.size()!=cols.tracks.size(): return {"error":"uneven area row or column track count mismatch"}
37
+ matrix.append(cells)
38
+ for col in range(cells.size()):
39
+ var name: String = cells[col]
40
+ if name==".": continue
41
+ if not name.is_valid_identifier(): return {"error":"area names must be identifiers or ."}
42
+ if not bounds.has(name): bounds[name] = {"row":row,"column":col,"row_span":1,"column_span":1}
43
+ var rect: Dictionary = bounds[name]
44
+ rect.row_span = row-rect.row+1
45
+ var end: int = maxi(rect.column+rect.column_span,col+1)
46
+ rect.column = mini(rect.column,col)
47
+ rect.column_span = end-rect.column
48
+ for name in bounds:
49
+ var rect: Dictionary = bounds[name]
50
+ for row in range(rect.row,rect.row+rect.row_span):
51
+ for col in range(rect.column,rect.column+rect.column_span):
52
+ if matrix[row][col]!=name: return {"error":"area '"+name+"' must form one rectangle"}
53
+ var normalized: Array = []
54
+ var occupied := {}
55
+ for placement in placements:
56
+ if not placement is Dictionary: return {"error":"placement must be a dictionary"}
57
+ var rect: Dictionary
58
+ if placement.has("area"):
59
+ if placement.size()!=1: return {"error":"area conflicts with explicit row/column placement"}
60
+ if not bounds.has(placement.area): return {"error":"unknown placement area: "+str(placement.area)}
61
+ rect = bounds[placement.area].duplicate()
62
+ else:
63
+ for key in placement:
64
+ if key not in ["row","column","row_span","column_span"]: return {"error":"unknown placement field: "+str(key)}
65
+ rect = {"row":placement.get("row",0),"column":placement.get("column",0),"row_span":placement.get("row_span",1),"column_span":placement.get("column_span",1)}
66
+ for key in rect:
67
+ if not rect[key] is int or rect[key]<(1 if key.ends_with("span") else 0): return {"error":"placement indices must be nonnegative integers and spans positive"}
68
+ if rect.row+rect.row_span>lines.tracks.size() or rect.column+rect.column_span>cols.tracks.size(): return {"error":"placement exceeds track bounds"}
69
+ for row in range(rect.row,rect.row+rect.row_span):
70
+ for col in range(rect.column,rect.column+rect.column_span):
71
+ var key := str(row)+":"+str(col)
72
+ if occupied.has(key): return {"error":"duplicate/conflicting child placement at "+key}
73
+ occupied[key] = true
74
+ normalized.append(rect)
75
+ return {"columns":cols.tracks,"rows":lines.tracks,"areas":matrix,"bounds":bounds,"placements":normalized}
@@ -0,0 +1 @@
1
+ uid://6f643551992c