@papercraftgames/estragon 0.1.0-beta.11 → 0.1.0-beta.13
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.
- package/addons/estragon/compiler/validator.gd +2 -2
- package/addons/estragon/editor/completion.gd +157 -36
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/runtime/composition/computation.gd +87 -4
- package/addons/estragon/runtime/composition/element.gd +2 -0
- package/addons/estragon/runtime/composition/layout_host.gd +58 -0
- package/addons/estragon/runtime/composition/layout_host.gd.uid +1 -0
- package/addons/estragon/runtime/composition/projection.gd +32 -0
- package/addons/estragon/runtime/composition/projection.gd.uid +1 -0
- package/addons/estragon/runtime/composition/state.gd +11 -0
- package/addons/estragon/runtime/node/button.gd +7 -1
- package/addons/estragon/runtime/node/component_2d.gd +1 -1
- package/addons/estragon/runtime/node/component_3d.gd +1 -1
- package/addons/estragon/runtime/node/internal/composition_hosts.gd +159 -0
- package/addons/estragon/runtime/node/internal/composition_hosts.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/composition_hosts.tres +6 -0
- package/addons/estragon/runtime/node/internal/control_participant.gd +164 -0
- package/addons/estragon/runtime/node/internal/control_participant.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/coordinator.gd +57 -18
- package/addons/estragon/runtime/node/internal/layout_core.gd +24 -5
- package/addons/estragon/runtime/node/native_2d.gd +1 -1
- package/addons/estragon/runtime/node/native_3d.gd +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
extends RefCounted
|
|
2
|
+
## Tree observation is scoped to computations that actually read native children.
|
|
3
|
+
var computation: WeakRef
|
|
4
|
+
var host: WeakRef
|
|
5
|
+
var watching := false
|
|
6
|
+
func _init(record: RefCounted, owner: Node) -> void:
|
|
7
|
+
computation = weakref(record)
|
|
8
|
+
host = weakref(owner)
|
|
9
|
+
func start() -> void:
|
|
10
|
+
if watching: return
|
|
11
|
+
var node = host.get_ref()
|
|
12
|
+
if node == null: return
|
|
13
|
+
watching = true
|
|
14
|
+
node.child_entered_tree.connect(changed)
|
|
15
|
+
node.child_exiting_tree.connect(changed)
|
|
16
|
+
if node.has_signal("child_order_changed"): node.connect("child_order_changed",ordered)
|
|
17
|
+
func stop() -> void:
|
|
18
|
+
if not watching: return
|
|
19
|
+
watching = false
|
|
20
|
+
var node = host.get_ref()
|
|
21
|
+
if node == null: return
|
|
22
|
+
if node.child_entered_tree.is_connected(changed): node.child_entered_tree.disconnect(changed)
|
|
23
|
+
if node.child_exiting_tree.is_connected(changed): node.child_exiting_tree.disconnect(changed)
|
|
24
|
+
if node.has_signal("child_order_changed") and node.is_connected("child_order_changed",ordered): node.disconnect("child_order_changed",ordered)
|
|
25
|
+
func changed(child: Node) -> void:
|
|
26
|
+
var record = computation.get_ref()
|
|
27
|
+
if record == null: return
|
|
28
|
+
var manager = record.state.get_ref()
|
|
29
|
+
if manager != null and not manager.is_managed(child): record.schedule()
|
|
30
|
+
func ordered() -> void:
|
|
31
|
+
var record = computation.get_ref()
|
|
32
|
+
if watching and record != null and not record._rendering: record.schedule()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://bfpksrcqadncu
|
|
@@ -4,9 +4,14 @@ const Profile = preload("profile.tres")
|
|
|
4
4
|
## Framework-owned shared scope stack; never stored on application objects.
|
|
5
5
|
var scopes: Array = []
|
|
6
6
|
var records: Dictionary = {}
|
|
7
|
+
var managed: Dictionary = {}
|
|
7
8
|
var dirty: Array = []
|
|
8
9
|
var pending := false
|
|
9
10
|
var flushing := false
|
|
11
|
+
func is_managed(node: Node) -> bool:
|
|
12
|
+
var reference = managed.get(node.get_instance_id())
|
|
13
|
+
return reference != null and reference.get_ref() == node
|
|
14
|
+
|
|
10
15
|
func enqueue(record) -> void:
|
|
11
16
|
if not dirty.has(record): dirty.append(record)
|
|
12
17
|
if not pending and not flushing:
|
|
@@ -55,6 +60,12 @@ func lifecycle(host: Node, what: int) -> void:
|
|
|
55
60
|
records[id].resume()
|
|
56
61
|
elif what == Node.NOTIFICATION_EXIT_TREE and records.has(id):
|
|
57
62
|
records[id].suspend()
|
|
63
|
+
elif what == 24 and records.has(id): # Public CHILD_ORDER_CHANGED, including 4.0
|
|
64
|
+
records[id].projection.ordered()
|
|
65
|
+
elif what == 12 and records.has(id): # 4.0 NOTIFICATION_MOVED_IN_PARENT
|
|
66
|
+
records[id].layout_host.order_moved()
|
|
67
|
+
var parent = host.get_parent()
|
|
68
|
+
if parent != null and records.has(parent.get_instance_id()): records[parent.get_instance_id()].projection.ordered()
|
|
58
69
|
elif what == NOTIFICATION_PREDELETE and records.has(id):
|
|
59
70
|
records[id].dispose(false)
|
|
60
71
|
records.erase(id)
|
|
@@ -15,11 +15,17 @@ var _hovered: bool = false
|
|
|
15
15
|
var _held: bool = false
|
|
16
16
|
func _enter_tree() -> void:
|
|
17
17
|
super._enter_tree()
|
|
18
|
+
_layout_scope_changed()
|
|
19
|
+
visibility_changed.connect(_cancel_pointer)
|
|
20
|
+
func _layout_scope_changed() -> void:
|
|
18
21
|
var entry = get_layout_root()
|
|
22
|
+
var next = entry._get_pointer_router() if entry != null and entry.has_method("_get_pointer_router") else null
|
|
23
|
+
if _router != null and _router.get_ref() == next: return
|
|
24
|
+
if _router != null and _router.get_ref() != null: _router.get_ref().unregister_button(self)
|
|
25
|
+
_router = null
|
|
19
26
|
if entry != null and entry.has_method("_get_pointer_router"):
|
|
20
27
|
_router = weakref(entry._get_pointer_router())
|
|
21
28
|
_router.get_ref().register_button(self)
|
|
22
|
-
visibility_changed.connect(_cancel_pointer)
|
|
23
29
|
func _exit_tree() -> void:
|
|
24
30
|
if _router != null and _router.get_ref() != null: _router.get_ref().unregister_button(self)
|
|
25
31
|
_router = null
|
|
@@ -101,5 +101,5 @@ func apply_layout_position(offset: Vector3) -> void:
|
|
|
101
101
|
func apply_layout_size(size: Vector3) -> void:
|
|
102
102
|
_layout_size = Vector2(size.x, size.y)
|
|
103
103
|
# Explicit invalidation also restores a native position edited externally.
|
|
104
|
-
if layout.parent_coordinator() != null:
|
|
104
|
+
if layout.parent_coordinator() != null: layout._place(layout.model.offset)
|
|
105
105
|
layout_applied.emit(_layout_size)
|
|
@@ -87,5 +87,5 @@ func apply_layout_position(offset: Vector3) -> void:
|
|
|
87
87
|
func apply_layout_size(size: Vector3) -> void:
|
|
88
88
|
_layout_size = size
|
|
89
89
|
# Explicit invalidation also restores a native position edited externally.
|
|
90
|
-
if layout.parent_coordinator() != null:
|
|
90
|
+
if layout.parent_coordinator() != null: layout._place(layout.model.offset)
|
|
91
91
|
layout_applied.emit(_layout_size)
|
|
@@ -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,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
|
|
@@ -3,8 +3,11 @@ extends RefCounted
|
|
|
3
3
|
const Profile = preload("../../composition/profile.tres")
|
|
4
4
|
## Native event/lifetime adapter shared by both spatial branches. No layout math.
|
|
5
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
|
|
@@ -26,18 +29,23 @@ func _init(host: Node, dimension: int, mode: int = Mode.PROOF) -> void:
|
|
|
26
29
|
func parent_coordinator():
|
|
27
30
|
var host = _host.get_ref()
|
|
28
31
|
if host == null or _mode == Mode.ENTRY: return null
|
|
29
|
-
|
|
32
|
+
var projected = CompositionHosts.projected_parent(host)
|
|
33
|
+
return participant(projected if projected != null else host.get_parent())
|
|
30
34
|
|
|
31
|
-
func participant(node: Node):
|
|
35
|
+
func participant(node: Node, acquire_control := false):
|
|
32
36
|
if node == null: return null
|
|
37
|
+
if node is Control and CompositionHosts.control_exiting(node): return null
|
|
33
38
|
var found
|
|
34
39
|
if _mode == Mode.PROOF:
|
|
35
40
|
if not node.has_meta(META): return null
|
|
36
41
|
found = node.get_meta(META).get_ref()
|
|
37
42
|
else:
|
|
38
43
|
# Runtime references must never be serialized as Node metadata.
|
|
39
|
-
|
|
40
|
-
found
|
|
44
|
+
found = node._get_layout_coordinator() if node.has_method("_get_layout_coordinator") else CompositionHosts.find(node)
|
|
45
|
+
if found == null and acquire_control and _dimension == 2 and node is Control and node.is_inside_tree():
|
|
46
|
+
found = get_script().new(node,2,Mode.CONTROL)
|
|
47
|
+
CompositionHosts.add_control(node,found)
|
|
48
|
+
found.start()
|
|
41
49
|
return found if found != null and found.active and found._dimension == _dimension else null
|
|
42
50
|
|
|
43
51
|
func scope_root():
|
|
@@ -60,13 +68,17 @@ func _viewport_scale(host: Node) -> float:
|
|
|
60
68
|
func start() -> void:
|
|
61
69
|
active = true
|
|
62
70
|
var host: Node = _host.get_ref()
|
|
71
|
+
if _mode == Mode.CONTROL:
|
|
72
|
+
control_adapter = preload("control_participant.gd").new(host,self)
|
|
73
|
+
control_adapter.start()
|
|
74
|
+
return
|
|
63
75
|
# PackedScene restores metadata after construction. Refresh the proof-only
|
|
64
76
|
# weak registry at entry; C1 resolves the live script field instead.
|
|
65
77
|
if _mode == Mode.PROOF: host.set_meta(META, weakref(self))
|
|
66
|
-
host.child_entered_tree.connect(
|
|
67
|
-
host.child_exiting_tree.connect(
|
|
78
|
+
host.child_entered_tree.connect(_child_entered)
|
|
79
|
+
host.child_exiting_tree.connect(_child_exiting)
|
|
68
80
|
if host.has_signal("child_order_changed"): host.connect("child_order_changed", _sync)
|
|
69
|
-
if _mode
|
|
81
|
+
if _mode in [Mode.PROOF,Mode.ENTRY]:
|
|
70
82
|
_viewport = host.get_viewport()
|
|
71
83
|
_viewport.size_changed.connect(_viewport_changed)
|
|
72
84
|
_sync()
|
|
@@ -77,8 +89,12 @@ func start() -> void:
|
|
|
77
89
|
func stop() -> void:
|
|
78
90
|
active = false
|
|
79
91
|
var host: Node = _host.get_ref()
|
|
80
|
-
if
|
|
81
|
-
|
|
92
|
+
if _mode == Mode.CONTROL:
|
|
93
|
+
if control_adapter != null: control_adapter.stop()
|
|
94
|
+
model.set_children([])
|
|
95
|
+
return
|
|
96
|
+
if host.child_entered_tree.is_connected(_child_entered): host.child_entered_tree.disconnect(_child_entered)
|
|
97
|
+
if host.child_exiting_tree.is_connected(_child_exiting): host.child_exiting_tree.disconnect(_child_exiting)
|
|
82
98
|
if host.has_signal("child_order_changed") and host.is_connected("child_order_changed", _sync): host.disconnect("child_order_changed", _sync)
|
|
83
99
|
if _viewport != null and _viewport.size_changed.is_connected(_viewport_changed): _viewport.size_changed.disconnect(_viewport_changed)
|
|
84
100
|
_viewport = null
|
|
@@ -86,7 +102,12 @@ func stop() -> void:
|
|
|
86
102
|
var parent = parent_coordinator()
|
|
87
103
|
if parent != null: parent._sync()
|
|
88
104
|
|
|
89
|
-
func
|
|
105
|
+
func _child_entered(child: Node) -> void:
|
|
106
|
+
if child is Control: CompositionHosts.enter_control(child)
|
|
107
|
+
_sync()
|
|
108
|
+
|
|
109
|
+
func _child_exiting(child: Node) -> void:
|
|
110
|
+
if child is Control: CompositionHosts.block_control(child)
|
|
90
111
|
_sync()
|
|
91
112
|
|
|
92
113
|
func order_moved() -> void:
|
|
@@ -94,12 +115,17 @@ func order_moved() -> void:
|
|
|
94
115
|
if parent != null: parent._sync()
|
|
95
116
|
|
|
96
117
|
func _sync() -> void:
|
|
97
|
-
if not active: return
|
|
118
|
+
if not active or _mode == Mode.CONTROL: return
|
|
98
119
|
var values: Array = []
|
|
99
120
|
var host: Node = _host.get_ref()
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
121
|
+
var children: Array = host.get_children() if _mode != Mode.COMPOSITION else []
|
|
122
|
+
if _mode == Mode.COMPOSITION and managed_root != null and managed_root.get_ref() != null: children.append(managed_root.get_ref())
|
|
123
|
+
children = CompositionHosts.children(host,children)
|
|
124
|
+
for child in children:
|
|
125
|
+
var found = participant(child,true)
|
|
126
|
+
if found != null and found._mode != Mode.ENTRY:
|
|
127
|
+
if found._mode == Mode.CONTROL and not found.control_adapter.participates(): continue
|
|
128
|
+
values.append(found.model)
|
|
103
129
|
var error := model.set_children(values)
|
|
104
130
|
if error != OK: push_error("Estragon layout model ownership: " + error_string(error))
|
|
105
131
|
|
|
@@ -117,13 +143,13 @@ func _viewport_changed() -> void:
|
|
|
117
143
|
|
|
118
144
|
func _invalidated() -> void:
|
|
119
145
|
if Profile.is_enabled(): Profile.add("layout_invalidations")
|
|
120
|
-
if not active or _queued or parent_coordinator() != null or _mode
|
|
146
|
+
if not active or _queued or parent_coordinator() != null or _mode in [Mode.PARTICIPANT,Mode.COMPOSITION,Mode.CONTROL]: return
|
|
121
147
|
_queued = true
|
|
122
148
|
call_deferred("_flush")
|
|
123
149
|
|
|
124
150
|
func _flush() -> void:
|
|
125
151
|
_queued = false
|
|
126
|
-
if not active or parent_coordinator() != null or _mode
|
|
152
|
+
if not active or parent_coordinator() != null or _mode in [Mode.PARTICIPANT,Mode.COMPOSITION,Mode.CONTROL]: return
|
|
127
153
|
var host = _host.get_ref()
|
|
128
154
|
if host == null or host.is_queued_for_deletion(): return
|
|
129
155
|
flush_count += 1
|
|
@@ -132,14 +158,27 @@ func _flush() -> void:
|
|
|
132
158
|
if _viewport_scale(host) > 0 and _viewport != null:
|
|
133
159
|
available.x = _viewport.get_visible_rect().size.x * _viewport_scale(host)
|
|
134
160
|
model.arrange(available)
|
|
161
|
+
CompositionHosts.refresh_positions(self)
|
|
135
162
|
|
|
136
163
|
func _place(offset: Vector3) -> void:
|
|
164
|
+
if _mode == Mode.CONTROL:
|
|
165
|
+
control_adapter.place(offset)
|
|
166
|
+
return
|
|
137
167
|
var host = _host.get_ref()
|
|
138
168
|
if host == null: return
|
|
139
169
|
if host.has_method("apply_layout_position"): host.apply_layout_position(offset)
|
|
140
170
|
elif _dimension == 2: host.position = Vector2(offset.x, offset.y)
|
|
141
171
|
else: host.position = offset
|
|
172
|
+
var projected = CompositionHosts.projected_parent(host)
|
|
173
|
+
if projected != null:
|
|
174
|
+
# Apply the participant/adapter's own origin policy first, then convert
|
|
175
|
+
# its logical position using Godot transforms (including top_level).
|
|
176
|
+
if host is Node2D and projected is Node2D: host.global_position = projected.to_global(host.position)
|
|
177
|
+
elif host is Node3D and projected is Node3D: host.global_position = projected.to_global(host.position)
|
|
142
178
|
|
|
143
179
|
func _arranged(size: Vector3) -> void:
|
|
180
|
+
if _mode == Mode.CONTROL:
|
|
181
|
+
control_adapter.arrange(size)
|
|
182
|
+
return
|
|
144
183
|
var host = _host.get_ref()
|
|
145
|
-
if host != null: host.apply_layout_size(size)
|
|
184
|
+
if host != null and _mode != Mode.COMPOSITION: host.apply_layout_size(size)
|
|
@@ -11,6 +11,8 @@ var center: bool = false
|
|
|
11
11
|
var axis: int = 0
|
|
12
12
|
var fill := Vector3.ZERO
|
|
13
13
|
var intrinsic := Vector3.ZERO
|
|
14
|
+
# Native Control minimums constrain assigned slots, never read back from size.
|
|
15
|
+
var allocation_minimum := Vector3.ZERO
|
|
14
16
|
var children: Array = []
|
|
15
17
|
var measured := Vector3.ZERO
|
|
16
18
|
var size := Vector3.ZERO
|
|
@@ -93,18 +95,35 @@ func arrange(available: Vector3) -> void:
|
|
|
93
95
|
# follow-up instead of being overwritten when this pass finishes.
|
|
94
96
|
_arrange_dirty = false
|
|
95
97
|
var fixed: float = gap * maxi(0, children.size() - 1)
|
|
96
|
-
var flexible:
|
|
98
|
+
var flexible: Array = []
|
|
97
99
|
for child in children:
|
|
98
|
-
if child.fill[axis] > 0 and child.requested[axis] < 0: flexible
|
|
100
|
+
if child.fill[axis] > 0 and child.requested[axis] < 0: flexible.append(child)
|
|
99
101
|
else: fixed += child.measured[axis]
|
|
100
|
-
var
|
|
101
|
-
var
|
|
102
|
+
var remaining: float = maxf(0,available[axis] - fixed)
|
|
103
|
+
var shares: Dictionary = {}
|
|
104
|
+
# Reserve constrained native minimums, then share the remaining space.
|
|
105
|
+
# Zero floors preserve the existing equal-share Box behavior.
|
|
106
|
+
while not flexible.is_empty():
|
|
107
|
+
var share: float = remaining / flexible.size()
|
|
108
|
+
var constrained := false
|
|
109
|
+
for child in flexible.duplicate():
|
|
110
|
+
if child.allocation_minimum[axis] > share:
|
|
111
|
+
shares[child] = child.allocation_minimum[axis]
|
|
112
|
+
remaining = maxf(0,remaining-child.allocation_minimum[axis])
|
|
113
|
+
flexible.erase(child)
|
|
114
|
+
constrained = true
|
|
115
|
+
if not constrained:
|
|
116
|
+
for child in flexible: shares[child] = share
|
|
117
|
+
break
|
|
118
|
+
var row_extent: float = fixed
|
|
119
|
+
for share in shares.values(): row_extent += share
|
|
102
120
|
var cursor: float = (available[axis] - row_extent) * 0.5 if center else 0.0
|
|
103
121
|
for child in children:
|
|
104
122
|
var allocation: Vector3 = child.measured
|
|
105
123
|
for index in range(3):
|
|
106
124
|
if child.fill[index] > 0 and child.requested[index] < 0:
|
|
107
|
-
allocation[index] =
|
|
125
|
+
allocation[index] = shares[child] if index == axis else available[index]
|
|
126
|
+
allocation[index] = maxf(allocation[index],child.allocation_minimum[index])
|
|
108
127
|
var next := Vector3.ZERO
|
|
109
128
|
next[axis] = cursor
|
|
110
129
|
if child.offset != next or child.arrange_count == 0:
|
|
@@ -30,7 +30,7 @@ func apply_layout_position(offset: Vector3) -> void:
|
|
|
30
30
|
|
|
31
31
|
func apply_layout_size(size: Vector3) -> void:
|
|
32
32
|
_layout_size = Vector2(size.x, size.y)
|
|
33
|
-
if layout.parent_coordinator() != null:
|
|
33
|
+
if layout.parent_coordinator() != null: layout._place(layout.model.offset)
|
|
34
34
|
layout_applied.emit(_layout_size)
|
|
35
35
|
|
|
36
36
|
func get_native_bounds() -> Rect2:
|
|
@@ -30,7 +30,7 @@ func apply_layout_position(offset: Vector3) -> void:
|
|
|
30
30
|
|
|
31
31
|
func apply_layout_size(size: Vector3) -> void:
|
|
32
32
|
_layout_size = size
|
|
33
|
-
if layout.parent_coordinator() != null:
|
|
33
|
+
if layout.parent_coordinator() != null: layout._place(layout.model.offset)
|
|
34
34
|
layout_applied.emit(_layout_size)
|
|
35
35
|
|
|
36
36
|
func get_native_bounds() -> AABB:
|