@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
@@ -1,10 +1,16 @@
1
1
  extends RefCounted
2
- const Profile = preload("res://addons/estragon/runtime/composition/profile.tres")
2
+ const StackContract = preload("../node/internal/stack_contract.gd")
3
+ const VisualStyle = preload("../node/internal/visual_style_2d.gd")
4
+ const Length = preload("../node/internal/length.gd")
5
+ const Profile = preload("profile.tres")
3
6
  ## F01 computation and retained static-shape records external to native objects.
4
- const Binding = preload("res://addons/estragon/runtime/composition/binding.gd")
5
- const Element = preload("res://addons/estragon/runtime/composition/element.gd")
7
+ const Binding = preload("binding.gd")
8
+ const Element = preload("element.gd")
9
+ const Hosts = preload("../node/internal/composition_hosts.tres")
6
10
  class Mounted extends RefCounted:
7
11
  var node: WeakRef
12
+ var id: int
13
+ var borrowed: WeakRef
8
14
  var type: Variant
9
15
  var key: Variant
10
16
  var keyed := false
@@ -14,6 +20,10 @@ class Mounted extends RefCounted:
14
20
  var bindings: Dictionary = {}
15
21
  var children: Array = []
16
22
  var host: WeakRef
23
+ var projection
24
+ var _borrow_seen: Dictionary = {}
25
+ var _observes_children := false
26
+ var layout_host
17
27
  var state: WeakRef
18
28
  var parent_computation: WeakRef
19
29
  var mounted: Mounted
@@ -29,9 +39,12 @@ var moves := 0
29
39
  var _rendering := false
30
40
  var _again := false
31
41
  var _consecutive := 0
42
+ var validation_error := ""
32
43
  func _init(owner: Node, manager: Resource) -> void:
33
44
  host = weakref(owner)
34
45
  state = weakref(manager)
46
+ projection = preload("projection.gd").new(self,owner)
47
+ layout_host = preload("layout_host.gd").new(owner)
35
48
  var ancestor := owner.get_parent()
36
49
  while ancestor != null:
37
50
  if manager.records.has(ancestor.get_instance_id()):
@@ -58,10 +71,14 @@ func depth() -> int:
58
71
  return result
59
72
  func suspend() -> void:
60
73
  active = false
74
+ projection.stop()
75
+ Hosts.replace_projection(self,{}, {})
76
+ layout_host.stop()
61
77
  _disconnect_bindings(mounted)
62
78
  _disconnect()
63
79
  func resume() -> void:
64
80
  active = true
81
+ layout_host.start()
65
82
  schedule()
66
83
  func _disconnect() -> void:
67
84
  for pair in subscriptions.values():
@@ -100,16 +117,28 @@ func _flush() -> void:
100
117
  var desired = owner.call("build_view")
101
118
  var reads: Dictionary = manager.finish()
102
119
  if Profile.is_enabled(): Profile.elapsed("view",started)
120
+ _borrow_seen.clear()
121
+ _observes_children = false
122
+ validation_error = ""
103
123
  desired = _normalize(desired)
104
124
  _rendering = false
105
125
  if not desired is Element or not _valid(desired,mounted) or not _preflight(desired,mounted,owner) or not _rescue_clear(desired,mounted,owner):
106
- push_error("Invalid composition output or foreign boundary conflict; previous tree retained")
126
+ push_error(validation_error if not validation_error.is_empty() else "Invalid composition output or foreign boundary conflict; previous tree retained")
107
127
  return
128
+ # A nested array may be an empty get_children() result. Observe native
129
+ # changes without inspecting the expression source or polling the tree.
130
+ if _observes_children: projection.start()
131
+ else: projection.stop()
108
132
  _subscribe(reads)
109
133
  # Catch mutation after a read during first composition/commit as a later
110
134
  # pass. Source-side effects are unsupported, but never recurse into SceneTree.
111
135
  _rendering = true
112
136
  mounted = _reconcile(desired,mounted,owner,owner)
137
+ var projected := {}
138
+ var ordering := {}
139
+ _projection_tree(mounted,projected,ordering)
140
+ Hosts.replace_projection(self,projected,ordering)
141
+ layout_host.update(mounted.node.get_ref() if mounted != null else null)
113
142
  _rendering = false
114
143
  runs += 1
115
144
  if Profile.is_enabled(): Profile.elapsed("computation",started)
@@ -141,8 +170,26 @@ func _flatten(values: Array, path: Array, output: Array, ancestors: Array, level
141
170
  slot.append(index)
142
171
  var value = values[index]
143
172
  if value is Array:
173
+ _observes_children = true
144
174
  if not _flatten(value,slot,output,ancestors,level+1): return false
145
175
  elif value==null: output.append(null)
176
+ elif value is Node:
177
+ _observes_children = true
178
+ var manager = state.get_ref()
179
+ if manager.is_managed(value): continue
180
+ if value.get_parent() != host.get_ref():
181
+ var label: String = str(value.get_path()) if value.is_inside_tree() else str(value.name)
182
+ push_error(ancestors.back().source+": GGX borrowed children must be persistent direct children of the rendering host: "+label)
183
+ return false
184
+ if value.owner == null: continue # Foreign runtime actors remain native.
185
+ if _borrow_seen.has(value.get_instance_id()):
186
+ push_error(ancestors.back().source+": GGX scene child referenced more than once: "+str(value.get_path()))
187
+ return false
188
+ _borrow_seen[value.get_instance_id()] = true
189
+ var child := Element.new()
190
+ child.borrowed = weakref(value)
191
+ child.slot = slot
192
+ output.append(child)
146
193
  else:
147
194
  var child = _normalize(value,ancestors,level+1)
148
195
  if child==null: return false
@@ -151,6 +198,7 @@ func _flatten(values: Array, path: Array, output: Array, ancestors: Array, level
151
198
  return true
152
199
  # Exact key type participates in identity (bool/float never alias int).
153
200
  func _identity(value, index: int) -> String:
201
+ if value.borrowed != null: return "n:"+str(value.borrowed.get_ref().get_instance_id()) if value.borrowed.get_ref() != null else "expired"
154
202
  if value.keyed: return "k:"+str(typeof(value.key))+":"+str(value.key)
155
203
  return "p:"+str(value.slot if not value.slot.is_empty() else [index])
156
204
  func _matches(desired: Array, previous: Array) -> Array:
@@ -163,6 +211,7 @@ func _matches(desired: Array, previous: Array) -> Array:
163
211
  return result
164
212
  func _valid(desired: Element, previous: Mounted) -> bool:
165
213
  if Profile.is_enabled(): Profile.add("validations")
214
+ if desired.borrowed != null: return desired.borrowed.get_ref() != null
166
215
  if desired.type == null: return false
167
216
  if desired.type is String:
168
217
  if not ClassDB.class_exists(desired.type) or not ClassDB.is_parent_class(desired.type,"Node") or not ClassDB.can_instantiate(desired.type): return false
@@ -189,7 +238,7 @@ func _valid(desired: Element, previous: Mounted) -> bool:
189
238
  names[name] = true
190
239
  return true
191
240
  func _collect_foreign(record, result: Array) -> void:
192
- if record==null: return
241
+ if record==null or record.borrowed != null: return
193
242
  var node = record.node.get_ref()
194
243
  if node==null: return
195
244
  var known: Array = []
@@ -238,10 +287,16 @@ func _boundary_clear(desired: Element, parent: Node) -> bool:
238
287
  return true
239
288
  func _mount(desired: Element, parent: Node, owner: Node) -> Mounted:
240
289
  var record := Mounted.new()
290
+ if desired.borrowed != null:
291
+ record.borrowed = desired.borrowed
292
+ record.node = desired.borrowed
293
+ return record
241
294
  var node: Node = ClassDB.instantiate(desired.type) if desired.type is String else desired.type.new()
295
+ state.get_ref().managed[node.get_instance_id()] = weakref(node)
242
296
  allocations += 1
243
297
  if Profile.is_enabled(): Profile.add("nodes_created")
244
298
  record.node = weakref(node)
299
+ record.id = node.get_instance_id()
245
300
  record.type = desired.type
246
301
  record.key = desired.key
247
302
  record.keyed = desired.keyed
@@ -267,9 +322,19 @@ func _apply(desired: Element, record: Mounted) -> void:
267
322
  writes += 1
268
323
  if Profile.is_enabled(): Profile.add("property_writes")
269
324
  binding.attach(node,self)
325
+ var stack := StackContract.registered(desired.type)
326
+ if stack: node._apply_stack_policy(desired.properties)
327
+ # An omitted previously declared border side removes that local override;
328
+ # do not turn omission into permanent native state or change other props.
329
+ if VisualStyle.supported(desired.type):
330
+ for key in record.properties:
331
+ if key in Length.BORDER_EDGES and not desired.properties.has(key):
332
+ node.set(key,"auto")
333
+ writes += 1
334
+ if Profile.is_enabled(): Profile.add("property_writes")
270
335
  for key in desired.properties:
271
336
  if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
272
- node.set(key,desired.properties[key])
337
+ if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
273
338
  writes += 1
274
339
  if Profile.is_enabled(): Profile.add("property_writes")
275
340
  for event in record.handlers:
@@ -284,6 +349,9 @@ func _apply(desired: Element, record: Mounted) -> void:
284
349
  record.properties = desired.properties.duplicate()
285
350
  record.handlers = desired.handlers.duplicate()
286
351
  func _compatible(desired: Element, record: Mounted) -> bool:
352
+ if record == null: return false
353
+ if desired.borrowed != null or record.borrowed != null:
354
+ return desired.borrowed != null and record.borrowed != null and desired.borrowed.get_ref() != null and desired.borrowed.get_ref() == record.node.get_ref()
287
355
  return record != null and is_same(record.type,desired.type) and record.keyed==desired.keyed and (not desired.keyed or typeof(record.key)==typeof(desired.key) and record.key==desired.key) and record.node.get_ref()!=null
288
356
  func _reconcile(desired, record, parent: Node, owner: Node):
289
357
  if Profile.is_enabled(): Profile.add("reconciles")
@@ -293,6 +361,7 @@ func _reconcile(desired, record, parent: Node, owner: Node):
293
361
  if not _compatible(desired,record):
294
362
  if record != null: _free_managed(record,owner)
295
363
  return _mount(desired,parent,owner)
364
+ if record.borrowed != null: return record
296
365
  _apply(desired,record)
297
366
  var node: Node = record.node.get_ref()
298
367
  if node.get_parent()!=parent:
@@ -340,7 +409,7 @@ func _prepare_names(desired: Array, matches: Array, parent: Node) -> void:
340
409
  func _order(children: Array, parent: Node) -> void:
341
410
  var nodes: Array = []
342
411
  for child in children:
343
- if child!=null: nodes.append(child.node.get_ref())
412
+ if child!=null and child.borrowed == null: nodes.append(child.node.get_ref())
344
413
  # Native child indices are unique. Binary-search minimal tails to recover
345
414
  # one longest increasing subsequence without quadratic comparisons.
346
415
  var tails: Array = []
@@ -381,6 +450,7 @@ func _order(children: Array, parent: Node) -> void:
381
450
  func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> bool:
382
451
  if Profile.is_enabled(): Profile.add("preflights")
383
452
  if desired == null: return true
453
+ if desired.borrowed != null: return desired.borrowed.get_ref() != null
384
454
  # Cache only within this synchronous desired-tree validation. No Script
385
455
  # contracts survive a commit or hide editor reload/metadata changes.
386
456
  if contracts==null: contracts = {}
@@ -401,9 +471,43 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
401
471
  contracts[desired.type] = {"properties":properties,"signals":signals}
402
472
  var properties: Dictionary = contracts[desired.type].properties
403
473
  var signals: Dictionary = contracts[desired.type].signals
474
+ if StackContract.registered(desired.type):
475
+ var policy: Dictionary = previous.properties.duplicate() if previous!=null and _compatible(desired,previous) else {}
476
+ policy.merge(desired.properties,true)
477
+ var fixed := StackContract.preset(desired.type)
478
+ var direction = policy.get("direction",fixed if not fixed.is_empty() else "row")
479
+ for key in ["direction","horizontal_align","vertical_align"]:
480
+ var value = policy.get(key,direction if key=="direction" else "start")
481
+ var message := StackContract.error(key,value,str(direction),fixed)
482
+ if not message.is_empty():
483
+ validation_error = desired.source+": "+message+"; previous tree retained"
484
+ return false
485
+ if VisualStyle.rect_conflict(desired.type,desired.properties.keys()):
486
+ validation_error = desired.source+": Rect fill and background_color conflict; previous tree retained"
487
+ return false
404
488
  for key in desired.properties:
405
489
  if not properties.has(key) or key in ["script","owner"] or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return false
406
490
  var value = desired.properties[key]
491
+ if VisualStyle.property(str(key)) and VisualStyle.has_api(desired.type) and not VisualStyle.supported(desired.type):
492
+ validation_error = desired.source+": shared visual styling is unsupported on this participant; previous tree retained"
493
+ return false
494
+ if key=="grow" and Length.registered(desired.type,"width") and (not typeof(value) in [TYPE_INT,TYPE_FLOAT] or not is_finite(float(value)) or value<0):
495
+ validation_error = desired.source+": grow requires a finite nonnegative weight; previous tree retained"
496
+ return false
497
+ if key=="fill" and VisualStyle.marked(desired.type,"ESTRAGON_RECT_STYLE"):
498
+ if not value is Color or VisualStyle.parse_color(value).has("error"):
499
+ validation_error = desired.source+": Rect fill requires a finite native Color; previous tree retained"
500
+ return false
501
+ if VisualStyle.registered(desired.type,key):
502
+ var parsed := VisualStyle.parse_color(value)
503
+ if parsed.has("error"):
504
+ validation_error = desired.source+": invalid style '"+str(key)+"': "+parsed.error+"; previous tree retained"
505
+ return false
506
+ if Length.registered(desired.type,key):
507
+ var parsed := Length.parse(value,Length.domain(key,desired.type))
508
+ if parsed.has("error"):
509
+ validation_error = desired.source+": invalid length '"+str(key)+"': "+parsed.error+"; previous tree retained"
510
+ return false
407
511
  var kind: int = properties[key].type
408
512
  if kind!=TYPE_NIL and typeof(value)!=kind and not (kind==TYPE_FLOAT and typeof(value)==TYPE_INT) and not (kind==TYPE_OBJECT and value==null) and not (kind in [TYPE_STRING,TYPE_STRING_NAME] and typeof(value) in [TYPE_STRING,TYPE_STRING_NAME]): return false
409
513
  if kind==TYPE_OBJECT and value!=null:
@@ -432,7 +536,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
432
536
  var matches := _matches(desired.children,previous.children if node!=null else [])
433
537
  for index in range(desired.children.size()):
434
538
  var child = desired.children[index]
435
- if child == null: continue
539
+ if child == null or child.borrowed != null: continue
436
540
  var old = matches[index]
437
541
  if not _preflight(child,old,null,contracts): return false
438
542
  var name: String = str(child.properties.get("name",str(old.node.get_ref().name) if old!=null and _compatible(child,old) else ""))
@@ -444,10 +548,13 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
444
548
  if str(existing.name)==name and not known.has(existing): return false
445
549
  return true
446
550
  func _free_managed(record: Mounted, rescue: Node = null) -> void:
551
+ if record.borrowed != null: return
447
552
  for child in record.children:
448
553
  if child != null: _free_managed(child,rescue)
449
554
  var node = record.node.get_ref()
450
- if node == null: return
555
+ if node == null:
556
+ state.get_ref().managed.erase(record.id)
557
+ return
451
558
  for binding in record.bindings.values(): binding.disconnect_edit()
452
559
  record.bindings.clear()
453
560
  # Foreign descendants have no record. Move them outside the managed region
@@ -461,7 +568,9 @@ func _free_managed(record: Mounted, rescue: Node = null) -> void:
461
568
  if owner != null:
462
569
  owner.add_child(child)
463
570
  if persisted_owner != null and persisted_owner.is_ancestor_of(child): child.owner = persisted_owner
571
+ var id: int = node.get_instance_id()
464
572
  node.free()
573
+ if manager != null: manager.managed.erase(id)
465
574
  frees += 1
466
575
  if Profile.is_enabled(): Profile.add("nodes_freed")
467
576
  func dispose(remove_nodes: bool, rescue: Node = null) -> void:
@@ -469,9 +578,32 @@ func dispose(remove_nodes: bool, rescue: Node = null) -> void:
469
578
  disposed = true
470
579
  suspend()
471
580
  if remove_nodes and mounted != null: _free_managed(mounted,rescue)
581
+ _unindex(mounted)
472
582
  mounted = null
473
583
 
474
584
  func _disconnect_bindings(record) -> void:
475
585
  if record==null: return
476
586
  for binding in record.bindings.values(): binding.disconnect_edit()
477
587
  for child in record.children: _disconnect_bindings(child)
588
+
589
+ func _projection_tree(record, projected: Dictionary, ordering: Dictionary) -> void:
590
+ if record == null or record.borrowed != null: return
591
+ var parent = record.node.get_ref()
592
+ if parent == null: return
593
+ var nodes: Array = []
594
+ var has_borrowed := false
595
+ for child in record.children:
596
+ if child == null: continue
597
+ var node = child.node.get_ref()
598
+ if node == null: continue
599
+ nodes.append(weakref(node))
600
+ if child.borrowed != null:
601
+ projected[node.get_instance_id()] = [node,parent]
602
+ has_borrowed = true
603
+ else: _projection_tree(child,projected,ordering)
604
+ if has_borrowed: ordering[parent.get_instance_id()] = nodes
605
+
606
+ func _unindex(record) -> void:
607
+ if record == null or record.borrowed != null: return
608
+ state.get_ref().managed.erase(record.id)
609
+ for child in record.children: _unindex(child)
@@ -1,7 +1,9 @@
1
1
  @tool
2
2
  extends RefCounted
3
- const Profile = preload("res://addons/estragon/runtime/composition/profile.tres")
3
+ const Profile = preload("profile.tres")
4
4
  ## Desired values only. No native Node is allocated during description creation.
5
+ # Internal normalized weak reference, only populated by child normalization.
6
+ var borrowed: WeakRef
5
7
  var type: Variant
6
8
  var properties: Dictionary
7
9
  var bindings: Dictionary = {}
@@ -0,0 +1,58 @@
1
+ extends RefCounted
2
+ ## One transparent managed-root bridge owned by an existing Computation.
3
+ ## No user fields, metadata, helper Node, authored-child adoption or layout math.
4
+ const Coordinator = preload("../node/internal/coordinator.gd")
5
+ const Hosts = preload("../node/internal/composition_hosts.tres")
6
+ var host: WeakRef
7
+ var root: WeakRef
8
+ var layout
9
+ var target
10
+ func _init(owner: Node) -> void:
11
+ host = weakref(owner)
12
+ # Native participants/entries already own a coordinator. Never duplicate it.
13
+ if owner.has_method("_get_layout_coordinator"): return
14
+ var dimension := 2 if owner is Node2D else (3 if owner is Node3D else 0)
15
+ if dimension == 0: return
16
+ layout = Coordinator.new(owner,dimension,Coordinator.Mode.COMPOSITION)
17
+ start()
18
+ func start() -> void:
19
+ if layout == null or layout.active: return
20
+ var owner = host.get_ref()
21
+ Hosts.add(owner,layout)
22
+ layout.start()
23
+ update(root.get_ref() if root != null else null)
24
+ func stop() -> void:
25
+ if layout == null or not layout.active: return
26
+ var owner = host.get_ref()
27
+ _disconnect()
28
+ # Keep registry identity until stop detaches the model from its parent;
29
+ # active=false already prevents other coordinators from adopting it.
30
+ layout.stop()
31
+ Hosts.remove(owner,layout)
32
+ func order_moved() -> void:
33
+ if layout != null and layout.active: layout.order_moved()
34
+ func _disconnect() -> void:
35
+ if target != null and target.model.invalidated.is_connected(_configure): target.model.invalidated.disconnect(_configure)
36
+ target = null
37
+ func update(view: Node) -> void:
38
+ root = weakref(view) if view != null else null
39
+ if layout == null or not layout.active: return
40
+ _disconnect()
41
+ layout.managed_root = root
42
+ target = layout.participant(view,true)
43
+ if target != null and target._mode == Coordinator.Mode.ENTRY: target = null
44
+ if target != null: target.model.invalidated.connect(_configure)
45
+ layout._sync()
46
+ _configure()
47
+ func _configure() -> void:
48
+ if layout == null or not layout.active: return
49
+ var requested := Vector3(-1,-1,0) if layout._dimension==2 else Vector3(-1,-1,-1)
50
+ var fills := Vector3.ZERO
51
+ var included: bool = target != null and (target._mode != Coordinator.Mode.CONTROL or target.control_adapter.participates())
52
+ if included:
53
+ requested = target.model.requested
54
+ fills = target.model.fill
55
+ layout.model.allocation_minimum = target.model.allocation_minimum if included else Vector3.ZERO
56
+ # One child, at zero local offset. Parent places the native host once;
57
+ # root constraints determine both proxy allocation and root allocation.
58
+ layout.model.configure(requested,0,false,0,fills,Vector3.ZERO,Vector4.ZERO,target.model.margin if included else Vector4.ZERO,true)
@@ -0,0 +1 @@
1
+ uid://dv8wymdhyov8f
@@ -1,6 +1,6 @@
1
1
  [gd_resource type="Resource" load_steps=2 format=3]
2
2
 
3
- [ext_resource type="Script" path="res://addons/estragon/runtime/composition/profile.gd" id="1"]
3
+ [ext_resource type="Script" path="profile.gd" id="1"]
4
4
 
5
5
  [resource]
6
6
  script = ExtResource("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
@@ -1,12 +1,17 @@
1
1
  @tool
2
2
  extends Resource
3
- const Profile = preload("res://addons/estragon/runtime/composition/profile.tres")
3
+ 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:
@@ -48,13 +53,19 @@ func lifecycle(host: Node, what: int) -> void:
48
53
  var id := host.get_instance_id()
49
54
  if what == Node.NOTIFICATION_READY:
50
55
  if not records.has(id):
51
- var record = preload("res://addons/estragon/runtime/composition/computation.gd").new(host,self)
56
+ var record = preload("computation.gd").new(host,self)
52
57
  records[id] = record
53
58
  record.schedule()
54
59
  elif what == Node.NOTIFICATION_ENTER_TREE and records.has(id):
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)
@@ -1,6 +1,6 @@
1
1
  [gd_resource type="Resource" load_steps=2 format=3]
2
2
 
3
- [ext_resource type="Script" path="res://addons/estragon/runtime/composition/state.gd" id="1"]
3
+ [ext_resource type="Script" path="state.gd" id="1"]
4
4
 
5
5
  [resource]
6
6
  script = ExtResource("1")
@@ -0,0 +1,57 @@
1
+ @tool
2
+ class_name EstragonBox
3
+ extends "component_2d.gd"
4
+ ## Constructible horizontal Box. VBox selects the vertical axis.
5
+ const ESTRAGON_STACK_POLICY := true
6
+ var _policy_commit := false
7
+ const StackContract = preload("internal/stack_contract.gd")
8
+ @export_enum("row", "column") var direction: String = "row":
9
+ set(value):
10
+ if value==direction: return
11
+ if _policy_commit:
12
+ direction = value
13
+ return
14
+ var message := StackContract.error("direction",value,value,StackContract.preset(get_script()))
15
+ if message.is_empty():
16
+ message = StackContract.error("horizontal_align",horizontal_align,value)
17
+ if message.is_empty(): message = StackContract.error("vertical_align",vertical_align,value)
18
+ if not message.is_empty():
19
+ push_error("Estragon Box: "+message)
20
+ return
21
+ direction = value
22
+ _changed()
23
+ @export_enum("start", "center", "end", "stretch") var horizontal_align: String = "start":
24
+ set(value):
25
+ if _policy_commit:
26
+ horizontal_align = value
27
+ return
28
+ if value==horizontal_align or not _valid_alignment("horizontal_align",value): return
29
+ horizontal_align = value
30
+ _changed()
31
+ @export_enum("start", "center", "end", "stretch") var vertical_align: String = "start":
32
+ set(value):
33
+ if _policy_commit:
34
+ vertical_align = value
35
+ return
36
+ if value==vertical_align or not _valid_alignment("vertical_align",value): return
37
+ vertical_align = value
38
+ _changed()
39
+ # Called only after whole-description preflight; avoids transient invalid states
40
+ # when direction and cross alignment change together in one reconciliation.
41
+ func _apply_stack_policy(values: Dictionary) -> void:
42
+ var before := [direction,horizontal_align,vertical_align]
43
+ _policy_commit = true
44
+ for key in ["direction","horizontal_align","vertical_align"]:
45
+ if values.has(key): set(key,values[key])
46
+ _policy_commit = false
47
+ if before!=[direction,horizontal_align,vertical_align]: _changed()
48
+ func _valid_alignment(property: String, value) -> bool:
49
+ var message := StackContract.error(property,value,"row" if _layout_axis()==0 else "column")
50
+ if not message.is_empty(): push_error("Estragon Box: "+message)
51
+ return message.is_empty()
52
+ func _layout_axis() -> int:
53
+ return 0 if direction=="row" else 1
54
+ func _layout_options() -> Dictionary:
55
+ var result := super._layout_options()
56
+ result["alignment"] = [horizontal_align,vertical_align,"start"]
57
+ return result
@@ -0,0 +1 @@
1
+ uid://beab4bf1a259
@@ -1,25 +1,55 @@
1
1
  @tool
2
2
  class_name EstragonButton
3
- extends "res://addons/estragon/runtime/node/text.gd"
3
+ extends "text.gd"
4
4
  ## Native primary-pointer button. No Control widget or polling wrapper.
5
5
  signal pressed
6
- const PADDING := Vector2(14,8)
6
+ const ESTRAGON_BUTTON_STYLE := true
7
+ var hover_background_color: Variant = Color("#705a9e"):
8
+ set(value):
9
+ if is_same(hover_background_color,value) or not _visual_style.assign("hover_background_color",value): return
10
+ hover_background_color = value
11
+ _queue_style_redraw()
12
+ var pressed_background_color: Variant = Color("#302440"):
13
+ set(value):
14
+ if is_same(pressed_background_color,value) or not _visual_style.assign("pressed_background_color",value): return
15
+ pressed_background_color = value
16
+ _queue_style_redraw()
17
+ var disabled_background_color: Variant = Color("#38343f"):
18
+ set(value):
19
+ if is_same(disabled_background_color,value) or not _visual_style.assign("disabled_background_color",value): return
20
+ disabled_background_color = value
21
+ _queue_style_redraw()
22
+ func _init() -> void:
23
+ background_color = Color("#514174")
24
+ padding = "auto"
25
+ func _default_padding() -> Vector4:
26
+ return Vector4(14,8,14,8)
27
+ func _get_property_list() -> Array[Dictionary]:
28
+ var result: Array[Dictionary] = super._get_property_list()
29
+ result.append_array(Length.properties(["hover_background_color","pressed_background_color","disabled_background_color"]))
30
+ return result
7
31
  @export var disabled: bool = false:
8
32
  set(value):
9
33
  if disabled == value: return
10
34
  disabled = value
11
35
  _cancel_pointer()
12
- queue_redraw()
36
+ _queue_style_redraw()
13
37
  var _router: WeakRef
14
38
  var _hovered: bool = false
15
39
  var _held: bool = false
16
40
  func _enter_tree() -> void:
17
41
  super._enter_tree()
42
+ _layout_scope_changed()
43
+ visibility_changed.connect(_cancel_pointer)
44
+ func _layout_scope_changed() -> void:
18
45
  var entry = get_layout_root()
46
+ var next = entry._get_pointer_router() if entry != null and entry.has_method("_get_pointer_router") else null
47
+ if _router != null and _router.get_ref() == next: return
48
+ if _router != null and _router.get_ref() != null: _router.get_ref().unregister_button(self)
49
+ _router = null
19
50
  if entry != null and entry.has_method("_get_pointer_router"):
20
51
  _router = weakref(entry._get_pointer_router())
21
52
  _router.get_ref().register_button(self)
22
- visibility_changed.connect(_cancel_pointer)
23
53
  func _exit_tree() -> void:
24
54
  if _router != null and _router.get_ref() != null: _router.get_ref().unregister_button(self)
25
55
  _router = null
@@ -33,21 +63,20 @@ func _set_pointer_state(hovered: bool, held: bool) -> void:
33
63
  if _hovered == hovered and _held == held: return
34
64
  _hovered = hovered
35
65
  _held = held
36
- queue_redraw()
66
+ _queue_style_redraw()
37
67
  func _pointer_contains(position_in_viewport: Vector2) -> bool:
38
68
  var transform := get_global_transform_with_canvas()
39
69
  # Transform2D.determinant() is absent from the 4.0 public API.
40
70
  if is_zero_approx(transform.x.cross(transform.y)): return false
41
71
  return Rect2(Vector2.ZERO,layout_size).has_point(transform.affine_inverse()*position_in_viewport)
42
- func _measure_native() -> Vector2:
43
- return _measure_label()+PADDING*2
44
72
  func get_background_color() -> Color:
45
- if disabled: return Color("38343f")
46
- if _held and _hovered: return Color("302440")
47
- return Color("705a9e") if _hovered else Color("514174")
73
+ if disabled: return _visual_style.colors.disabled_background_color
74
+ if _held and _hovered: return _visual_style.colors.pressed_background_color
75
+ return _visual_style.colors.hover_background_color if _hovered else super.get_background_color()
76
+ func get_label_origin() -> Vector2:
77
+ var content := get_content_rect()
78
+ var remaining := (content.size-_measure_label())*0.5
79
+ return content.position+Vector2(maxf(0,remaining.x),maxf(0,remaining.y))
48
80
  func _draw() -> void:
49
- if layout_size.x <= 0 or layout_size.y <= 0: return
50
- draw_rect(Rect2(Vector2.ZERO,layout_size),get_background_color())
51
- var offset := (layout_size-_measure_label())*0.5
52
- offset = Vector2(maxf(0,offset.x),maxf(0,offset.y))
53
- _draw_label(offset,Color(1,1,1,0.5) if disabled else Color.WHITE)
81
+ if get_content_rect().size.x<=0 or get_content_rect().size.y<=0: return
82
+ _draw_label(get_label_origin(),Color(1,1,1,0.5) if disabled else Color.WHITE)