@papercraftgames/estragon 0.1.0-beta.22 → 0.1.0-beta.24
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/emitter.gd +3 -0
- package/addons/estragon/compiler/validator.gd +26 -0
- package/addons/estragon/editor/completion.gd +11 -0
- package/addons/estragon/editor/components.gd +1 -0
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/runtime/composition/computation.gd +67 -4
- package/addons/estragon/runtime/composition/element.gd +1 -0
- package/addons/estragon/runtime/node/box.gd +18 -2
- package/addons/estragon/runtime/node/component_2d.gd +23 -0
- package/addons/estragon/runtime/node/grid.gd +73 -0
- package/addons/estragon/runtime/node/grid.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/composition_hosts.gd +37 -0
- package/addons/estragon/runtime/node/internal/coordinator.gd +11 -0
- package/addons/estragon/runtime/node/internal/grid_definition.gd +129 -27
- package/addons/estragon/runtime/node/internal/grid_policy.gd +68 -0
- package/addons/estragon/runtime/node/internal/grid_policy.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/layout_core.gd +146 -11
- package/addons/estragon/runtime/node/internal/length.gd +9 -3
- package/addons/estragon/runtime/node/internal/stack_contract.gd +17 -3
- package/addons/estragon/runtime/node/internal/stack_policy.gd +26 -6
- package/addons/estragon/runtime/node/internal/wrap_policy.gd +59 -0
- package/addons/estragon/runtime/node/internal/wrap_policy.gd.uid +1 -0
- package/package.json +1 -1
|
@@ -197,6 +197,9 @@ func _description(node: Model.Component, indentation: String) -> String:
|
|
|
197
197
|
children.append(_arguments[child].name if child is Model.GdExpression else _description(child,indentation))
|
|
198
198
|
var native_type := _string(node.runtime_class) if ClassDB.class_exists(node.runtime_class) else node.runtime_class
|
|
199
199
|
_line("var %s := %s.new(%s, {%s}, {%s}, [%s], %s, %s, %s)" % [variable,_element_class,native_type,", ".join(props),", ".join(events),", ".join(children),_string("%s:%d:%d" % [_file.name,node.span.start.line,node.span.start.column]),key,keyed],node.span,indentation)
|
|
200
|
+
for attribute in node.attributes:
|
|
201
|
+
if attribute.kind=="placement" and not expanded: _line(variable+".origins["+_string(attribute.name)+"] = "+_string("%s:%d:%d" % [_file.name,attribute.name_span.start.line,attribute.name_span.start.column]),attribute.name_span,indentation)
|
|
202
|
+
|
|
200
203
|
if expanded: _line(variable+".expand(["+", ".join(ordered)+"])",node.span,indentation)
|
|
201
204
|
if not bindings.is_empty(): _line(variable+".bindings = {"+", ".join(bindings)+"}",node.span,indentation)
|
|
202
205
|
return variable
|
|
@@ -5,6 +5,7 @@ const Element = preload("../runtime/composition/element.gd")
|
|
|
5
5
|
const Model = preload("model.gd")
|
|
6
6
|
const Source = preload("source.gd")
|
|
7
7
|
const Resolver = preload("native/resolver.gd")
|
|
8
|
+
const GridDefinition = preload("../runtime/node/internal/grid_definition.gd")
|
|
8
9
|
const StackContract = preload("../runtime/node/internal/stack_contract.gd")
|
|
9
10
|
const VisualStyle = preload("../runtime/node/internal/visual_style_2d.gd")
|
|
10
11
|
const Length = preload("../runtime/node/internal/length.gd")
|
|
@@ -93,6 +94,9 @@ func _component(node: Model.Component) -> void:
|
|
|
93
94
|
_error("Inline anonymous GGX handlers are not supported; use a named handler/Callable", token.span)
|
|
94
95
|
return
|
|
95
96
|
index = token.span.end.index
|
|
97
|
+
elif name in GridDefinition.PLACEMENT and not properties.has(name):
|
|
98
|
+
attribute.kind = "placement"
|
|
99
|
+
attribute.type_name = "String" if attribute.value is Model.Literal and name=="area" else "Variant"
|
|
96
100
|
elif properties.has(name) and NativeAttributes.writable(resolved.native,resolved.script,name,properties[name]):
|
|
97
101
|
attribute.type_name = "Variant" if Length.registered(resolved.script,name) or VisualStyle.registered(resolved.script,name) else _native_type(properties[name])
|
|
98
102
|
if attribute.type_name.is_empty():
|
|
@@ -106,6 +110,23 @@ func _component(node: Model.Component) -> void:
|
|
|
106
110
|
if not message.is_empty():
|
|
107
111
|
_error(message,attribute.value.span)
|
|
108
112
|
return
|
|
113
|
+
if not expanded and GridDefinition.marked(resolved.script) and attribute.value is Model.Literal:
|
|
114
|
+
if name in ["horizontal_align","vertical_align"] and attribute.value.value not in ["start","center","end","stretch"]:
|
|
115
|
+
_error("Grid per-cell "+name+" requires start/center/end/stretch",attribute.value.span)
|
|
116
|
+
return
|
|
117
|
+
if name=="template":
|
|
118
|
+
var parsed := GridDefinition.resolve(null,null,[],str(attribute.value.value))
|
|
119
|
+
if parsed.has("error"):
|
|
120
|
+
_error("Grid template: "+parsed.error,attribute.value.span)
|
|
121
|
+
return
|
|
122
|
+
if name=="align_self" and StackContract.self_registered(resolved.script) and attribute.value is Model.Literal:
|
|
123
|
+
var message := StackContract.error(name,attribute.value.value,"")
|
|
124
|
+
if not message.is_empty():
|
|
125
|
+
_error(message,attribute.value.span)
|
|
126
|
+
return
|
|
127
|
+
if GridDefinition.marked(resolved.script) and name in ["horizontal_align","vertical_align"] and attribute.value is Model.Literal and attribute.value.value not in ["start","center","end","stretch"]:
|
|
128
|
+
_error("Grid "+name+" requires start, center, end or stretch",attribute.value.span)
|
|
129
|
+
return
|
|
109
130
|
var is_color := VisualStyle.registered(resolved.script,name)
|
|
110
131
|
if is_color:
|
|
111
132
|
_color(attribute)
|
|
@@ -135,6 +156,11 @@ func _component(node: Model.Component) -> void:
|
|
|
135
156
|
_error("Node GGX children must be newly declared Node elements; expression adoption is unsupported", child.span)
|
|
136
157
|
return
|
|
137
158
|
_node(child)
|
|
159
|
+
if not GridDefinition.marked(resolved.script):
|
|
160
|
+
for attribute in child.attributes:
|
|
161
|
+
if attribute.kind=="placement":
|
|
162
|
+
_error("GGX placement "+attribute.name+" requires a Grid parent",attribute.name_span)
|
|
163
|
+
return
|
|
138
164
|
if child is Model.Component and not child.attributes.any(func(item): return item.kind=="spread"):
|
|
139
165
|
for attribute in child.attributes:
|
|
140
166
|
if attribute.name=="name" and attribute.value is Model.Literal:
|
|
@@ -450,6 +450,15 @@ func definition(text: String, source: String, symbol: String) -> String:
|
|
|
450
450
|
for item in _project_items():
|
|
451
451
|
if item.path == target: return item.source
|
|
452
452
|
return target
|
|
453
|
+
func _grid_type(type: String, aliases: Dictionary, visited: Array = []) -> bool:
|
|
454
|
+
var name: String = aliases.get(type,type)
|
|
455
|
+
if name in visited or visited.size()>=12: return false
|
|
456
|
+
var grid := Catalog.named("EstragonGrid")
|
|
457
|
+
if not grid.is_empty() and name==Catalog.path(grid): return true
|
|
458
|
+
if not name.begins_with("res://") or not FileAccess.file_exists(name): return false
|
|
459
|
+
var declarations := _script(name)
|
|
460
|
+
return _grid_type(declarations.base,declarations.aliases,visited+[name])
|
|
461
|
+
|
|
453
462
|
func candidates(text: String, source: String, lexical: RefCounted, row: int, column: int) -> Array:
|
|
454
463
|
_index(text,source)
|
|
455
464
|
lexical.update(text)
|
|
@@ -491,6 +500,8 @@ func candidates(text: String, source: String, lexical: RefCounted, row: int, col
|
|
|
491
500
|
else:
|
|
492
501
|
if not _node_type(context.tag,_aliases): return []
|
|
493
502
|
var members := _members(context.tag,_aliases)
|
|
503
|
+
if not context.tags.is_empty() and _grid_type(context.tags[-1],_aliases):
|
|
504
|
+
for name in ["area","row","column","row_span","column_span"]: offered[name] = {"kind":CodeEdit.KIND_MEMBER,"origin":"Grid child placement"}
|
|
494
505
|
for name in members:
|
|
495
506
|
if members[name].kind in [CodeEdit.KIND_MEMBER,CodeEdit.KIND_SIGNAL] and members[name].get("writable",true) and name not in ["owner","script"]: offered[name] = members[name]
|
|
496
507
|
if _node_type(context.tag,_aliases): offered.key = {"kind":CodeEdit.KIND_MEMBER}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
extends RefCounted
|
|
3
3
|
## Trusted installed resources, not guessed global classes or installation roots.
|
|
4
4
|
const ITEMS := [
|
|
5
|
+
{"alias":"Grid","canonical":"EstragonGrid","script":preload("../runtime/node/grid.gd"),"dimension":2,"origin":"native layout"},
|
|
5
6
|
{"alias":"Spacer","canonical":"EstragonSpacer","script":preload("../runtime/node/spacer.gd"),"dimension":2,"origin":"native layout"},
|
|
6
7
|
{"alias":"Box","canonical":"EstragonBox","script":preload("../runtime/node/box.gd"),"dimension":2,"origin":"native layout"},
|
|
7
8
|
{"alias":"Text","canonical":"EstragonText","script":preload("../runtime/node/text.gd"),"dimension":2,"origin":"native widget"},
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
extends RefCounted
|
|
2
|
+
const GridDefinition = preload("../node/internal/grid_definition.gd")
|
|
3
|
+
const GRID_CONFIG := ["columns","rows","areas","template","horizontal_align","vertical_align"]
|
|
2
4
|
const StackContract = preload("../node/internal/stack_contract.gd")
|
|
3
5
|
const VisualStyle = preload("../node/internal/visual_style_2d.gd")
|
|
4
6
|
const Length = preload("../node/internal/length.gd")
|
|
@@ -164,7 +166,8 @@ func _normalize(value, ancestors: Array = [], level: int = 0):
|
|
|
164
166
|
var next := ancestors.duplicate()
|
|
165
167
|
next.append(value)
|
|
166
168
|
if Profile.is_enabled(): Profile.add("normalized_elements")
|
|
167
|
-
var result := Element.new(value.type,value.properties,value.handlers,[],value.source,value.key,value.keyed)
|
|
169
|
+
var result := Element.new(value.type,value.properties.duplicate(),value.handlers,[],value.source,value.key,value.keyed)
|
|
170
|
+
result.placement = value.placement.duplicate(true)
|
|
168
171
|
result.origins = value.origins.duplicate()
|
|
169
172
|
result.spread_properties = value.spread_properties.duplicate()
|
|
170
173
|
result.bindings = value.bindings.duplicate()
|
|
@@ -342,13 +345,17 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
342
345
|
writes += 1
|
|
343
346
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
344
347
|
binding.attach(node,self)
|
|
348
|
+
Hosts.set_placement(node,desired.placement)
|
|
349
|
+
var grid := GridDefinition.marked(desired.type)
|
|
350
|
+
if grid:
|
|
351
|
+
node._apply_grid(_grid_config(desired))
|
|
345
352
|
var stack := StackContract.registered(desired.type)
|
|
346
353
|
if stack:
|
|
347
354
|
var policy := resets.duplicate()
|
|
348
355
|
policy.merge(desired.properties,true)
|
|
349
356
|
node._apply_stack_policy(policy)
|
|
350
357
|
for key in resets:
|
|
351
|
-
if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,resets[key])
|
|
358
|
+
if (not stack or key not in ["direction","horizontal_align","vertical_align"]) and (not grid or key not in GRID_CONFIG): node.set(key,resets[key])
|
|
352
359
|
writes += 1
|
|
353
360
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
354
361
|
# An omitted previously declared border side removes that local override;
|
|
@@ -365,6 +372,10 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
365
372
|
node.set(key,0.0)
|
|
366
373
|
writes += 1
|
|
367
374
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
375
|
+
if StackContract.self_registered(desired.type) and record.properties.has("align_self") and not desired.properties.has("align_self"):
|
|
376
|
+
node.set("align_self","auto")
|
|
377
|
+
writes += 1
|
|
378
|
+
if Profile.is_enabled(): Profile.add("property_writes")
|
|
368
379
|
for key in desired.properties:
|
|
369
380
|
if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
|
|
370
381
|
if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
|
|
@@ -391,7 +402,7 @@ func _spread_resets(desired: Element, record) -> Dictionary:
|
|
|
391
402
|
if record==null or not _compatible(desired,record): return result
|
|
392
403
|
var node = record.node.get_ref()
|
|
393
404
|
for key in record.spread_applied:
|
|
394
|
-
if desired.properties.has(key) or key in Length.BORDER_EDGES or key in Length.MINIMUMS: continue
|
|
405
|
+
if desired.properties.has(key) or (key=="align_self" and StackContract.self_registered(desired.type)) or key in Length.BORDER_EDGES or key in Length.MINIMUMS: continue
|
|
395
406
|
# Do not overwrite imperative native changes made since our last commit.
|
|
396
407
|
if is_same(node.get(key),record.spread_applied[key]) and not is_same(node.get(key),record.defaults[key]): result[key] = record.defaults[key]
|
|
397
408
|
return result
|
|
@@ -522,6 +533,12 @@ func _order(children: Array, parent: Node) -> void:
|
|
|
522
533
|
if Profile.is_enabled(): Profile.add("moves")
|
|
523
534
|
anchor = actual
|
|
524
535
|
|
|
536
|
+
func _grid_config(desired: Element) -> Dictionary:
|
|
537
|
+
var result := {"columns":null,"rows":null,"areas":[],"template":"","horizontal_align":"stretch","vertical_align":"stretch"}
|
|
538
|
+
for key in GRID_CONFIG:
|
|
539
|
+
if desired.properties.has(key): result[key] = desired.properties[key]
|
|
540
|
+
return result
|
|
541
|
+
|
|
525
542
|
func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> bool:
|
|
526
543
|
if Profile.is_enabled(): Profile.add("preflights")
|
|
527
544
|
if desired == null: return true
|
|
@@ -552,12 +569,52 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
552
569
|
policy.merge(desired.properties,true)
|
|
553
570
|
var fixed := StackContract.preset(desired.type)
|
|
554
571
|
var direction = policy.get("direction",fixed if not fixed.is_empty() else "row")
|
|
555
|
-
for key in ["direction","horizontal_align","vertical_align"]:
|
|
572
|
+
for key in ["direction","horizontal_align","vertical_align","align_content"]:
|
|
556
573
|
var value = policy.get(key,direction if key=="direction" else "start")
|
|
557
574
|
var message := StackContract.error(key,value,str(direction),fixed)
|
|
558
575
|
if not message.is_empty():
|
|
559
576
|
validation_error = desired.location(key)+": "+message+"; previous tree retained"
|
|
560
577
|
return false
|
|
578
|
+
if GridDefinition.marked(desired.type):
|
|
579
|
+
var config := _grid_config(desired)
|
|
580
|
+
var grid_matches := _matches(desired.children,previous.children if previous!=null and _compatible(desired,previous) else [])
|
|
581
|
+
var placements: Array = []
|
|
582
|
+
var grid_children: Array = []
|
|
583
|
+
for child in desired.children:
|
|
584
|
+
if child==null: continue
|
|
585
|
+
if child.borrowed==null:
|
|
586
|
+
for key in GridDefinition.PLACEMENT:
|
|
587
|
+
if child.properties.has(key):
|
|
588
|
+
child.placement[key] = child.properties[key]
|
|
589
|
+
child.properties.erase(key)
|
|
590
|
+
child.spread_properties.erase(key)
|
|
591
|
+
var native: String = child.type if child.type is String else child.type.get_instance_base_type()
|
|
592
|
+
if not ClassDB.is_parent_class(native,"Control") and not (ClassDB.is_parent_class(native,"Node2D") and (Length.registered(child.type,"width") or GridDefinition.component(child.type))):
|
|
593
|
+
return _invalid_attribute(child,"area","Grid child requires a native 2D layout participant, Control or Gogo component")
|
|
594
|
+
if child.borrowed!=null:
|
|
595
|
+
var borrowed: Node = child.borrowed.get_ref()
|
|
596
|
+
if not borrowed is Control and not (borrowed is Node2D and (Length.registered(borrowed.get_script(),"width") or GridDefinition.component(borrowed.get_script()))): return _invalid_attribute(child,"area","Grid borrowed child has no bounded 2D layout participant")
|
|
597
|
+
var native: String = child.type if child.type is String else (child.borrowed.get_ref().get_class() if child.borrowed!=null else child.type.get_instance_base_type())
|
|
598
|
+
if ClassDB.is_parent_class(native,"Control"):
|
|
599
|
+
var values := {}
|
|
600
|
+
var old = grid_matches[desired.children.find(child)]
|
|
601
|
+
var existing = child.borrowed.get_ref() if child.borrowed!=null else (old.node.get_ref() if old!=null else null)
|
|
602
|
+
if existing!=null:
|
|
603
|
+
for key in ["anchor_left","anchor_right","anchor_top","anchor_bottom","rotation","scale","pivot_offset","top_level"]: values[key] = existing.get(key) if key!="top_level" else existing.is_set_as_top_level()
|
|
604
|
+
values.merge(child.properties,true)
|
|
605
|
+
var message := GridDefinition.control_error(values)
|
|
606
|
+
if not message.is_empty():
|
|
607
|
+
var field := "area"
|
|
608
|
+
for key in ["anchor_left","anchor_right","anchor_top","anchor_bottom","rotation","scale","pivot_offset","top_level"]:
|
|
609
|
+
if child.properties.has(key): field = key
|
|
610
|
+
return _invalid_attribute(child,field,message)
|
|
611
|
+
placements.append(child.placement)
|
|
612
|
+
grid_children.append(child)
|
|
613
|
+
var parsed := GridDefinition.configuration(config,placements)
|
|
614
|
+
if parsed.has("error"):
|
|
615
|
+
var origin = grid_children[parsed.item] if parsed.has("item") else desired
|
|
616
|
+
var key: String = str(origin.placement.keys()[0]) if parsed.has("item") and not origin.placement.is_empty() else parsed.get("field","columns")
|
|
617
|
+
return _invalid_attribute(origin,key,parsed.error)
|
|
561
618
|
if VisualStyle.rect_conflict(desired.type,desired.properties.keys()):
|
|
562
619
|
validation_error = desired.location("fill")+": Rect fill and background_color conflict; previous tree retained"
|
|
563
620
|
return false
|
|
@@ -565,6 +622,9 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
565
622
|
var native: String = desired.type if desired.type is String else desired.type.get_instance_base_type()
|
|
566
623
|
if not properties.has(key) or not NativeAttributes.writable(native,desired.type,str(key),properties[key]): return _invalid_attribute(desired,str(key),"unknown, read-only or reserved native property")
|
|
567
624
|
var value = desired.properties[key]
|
|
625
|
+
if key=="align_self" and StackContract.self_registered(desired.type):
|
|
626
|
+
var message := StackContract.error(key,value,"")
|
|
627
|
+
if not message.is_empty(): return _invalid_attribute(desired,str(key),message)
|
|
568
628
|
if VisualStyle.property(str(key)) and VisualStyle.has_api(desired.type) and not VisualStyle.supported(desired.type):
|
|
569
629
|
validation_error = desired.location(str(key))+": shared visual styling is unsupported on this participant; previous tree retained"
|
|
570
630
|
return false
|
|
@@ -632,6 +692,7 @@ func _free_managed(record: Mounted, rescue: Node = null) -> void:
|
|
|
632
692
|
if child != null: _free_managed(child,rescue)
|
|
633
693
|
var node = record.node.get_ref()
|
|
634
694
|
if node == null:
|
|
695
|
+
Hosts.clear_placement(record.id)
|
|
635
696
|
state.get_ref().managed.erase(record.id)
|
|
636
697
|
return
|
|
637
698
|
for binding in record.bindings.values(): binding.disconnect_edit()
|
|
@@ -648,6 +709,7 @@ func _free_managed(record: Mounted, rescue: Node = null) -> void:
|
|
|
648
709
|
owner.add_child(child)
|
|
649
710
|
if persisted_owner != null and persisted_owner.is_ancestor_of(child): child.owner = persisted_owner
|
|
650
711
|
var id: int = node.get_instance_id()
|
|
712
|
+
Hosts.set_placement(node,{})
|
|
651
713
|
node.free()
|
|
652
714
|
if manager != null: manager.managed.erase(id)
|
|
653
715
|
frees += 1
|
|
@@ -685,4 +747,5 @@ func _projection_tree(record, projected: Dictionary, ordering: Dictionary) -> vo
|
|
|
685
747
|
func _unindex(record) -> void:
|
|
686
748
|
if record == null or record.borrowed != null: return
|
|
687
749
|
state.get_ref().managed.erase(record.id)
|
|
750
|
+
Hosts.clear_placement(record.id)
|
|
688
751
|
for child in record.children: _unindex(child)
|
|
@@ -3,6 +3,20 @@ class_name EstragonBox
|
|
|
3
3
|
extends "component_2d.gd"
|
|
4
4
|
## Constructible horizontal Box. VBox selects the vertical axis.
|
|
5
5
|
const ESTRAGON_STACK_POLICY := true
|
|
6
|
+
@export var wrap: bool = false:
|
|
7
|
+
set(value):
|
|
8
|
+
if value==wrap: return
|
|
9
|
+
wrap = value
|
|
10
|
+
_changed()
|
|
11
|
+
@export_enum("start","center","end","space-between","space-around","space-evenly","stretch") var align_content: String = "start":
|
|
12
|
+
set(value):
|
|
13
|
+
if value==align_content: return
|
|
14
|
+
var message := StackContract.error("align_content",value,"")
|
|
15
|
+
if not message.is_empty():
|
|
16
|
+
push_error("Estragon Box: "+message)
|
|
17
|
+
return
|
|
18
|
+
align_content = value
|
|
19
|
+
_changed()
|
|
6
20
|
var _policy_commit := false
|
|
7
21
|
const StackContract = preload("internal/stack_contract.gd")
|
|
8
22
|
@export_enum("row", "column") var direction: String = "row":
|
|
@@ -20,7 +34,7 @@ const StackContract = preload("internal/stack_contract.gd")
|
|
|
20
34
|
return
|
|
21
35
|
direction = value
|
|
22
36
|
_changed()
|
|
23
|
-
@export_enum("start", "center", "end", "stretch") var horizontal_align: String = "start":
|
|
37
|
+
@export_enum("start", "center", "end", "stretch", "space-between", "space-around", "space-evenly") var horizontal_align: String = "start":
|
|
24
38
|
set(value):
|
|
25
39
|
if _policy_commit:
|
|
26
40
|
horizontal_align = value
|
|
@@ -28,7 +42,7 @@ const StackContract = preload("internal/stack_contract.gd")
|
|
|
28
42
|
if value==horizontal_align or not _valid_alignment("horizontal_align",value): return
|
|
29
43
|
horizontal_align = value
|
|
30
44
|
_changed()
|
|
31
|
-
@export_enum("start", "center", "end", "stretch") var vertical_align: String = "start":
|
|
45
|
+
@export_enum("start", "center", "end", "stretch", "space-between", "space-around", "space-evenly") var vertical_align: String = "start":
|
|
32
46
|
set(value):
|
|
33
47
|
if _policy_commit:
|
|
34
48
|
vertical_align = value
|
|
@@ -54,4 +68,6 @@ func _layout_axis() -> int:
|
|
|
54
68
|
func _layout_options() -> Dictionary:
|
|
55
69
|
var result := super._layout_options()
|
|
56
70
|
result["alignment"] = [horizontal_align,vertical_align,"start"]
|
|
71
|
+
result["strategy"] = "wrap" if wrap else "stack"
|
|
72
|
+
result["align_content"] = align_content
|
|
57
73
|
return result
|
|
@@ -7,6 +7,19 @@ signal layout_applied(size: Vector2)
|
|
|
7
7
|
const Coordinator = preload("internal/coordinator.gd")
|
|
8
8
|
const ESTRAGON_LENGTHS := true
|
|
9
9
|
const ESTRAGON_MINIMUMS_2D := true
|
|
10
|
+
const ESTRAGON_GAPS_2D := true
|
|
11
|
+
var row_gap: Variant = "auto":
|
|
12
|
+
set(value):
|
|
13
|
+
if is_same(row_gap,value) or not lengths.assign("row_gap",value): return
|
|
14
|
+
row_gap = value
|
|
15
|
+
_changed()
|
|
16
|
+
var column_gap: Variant = "auto":
|
|
17
|
+
set(value):
|
|
18
|
+
if is_same(column_gap,value) or not lengths.assign("column_gap",value): return
|
|
19
|
+
column_gap = value
|
|
20
|
+
_changed()
|
|
21
|
+
const ESTRAGON_ALIGN_SELF_2D := true
|
|
22
|
+
const AlignmentContract = preload("internal/stack_contract.gd")
|
|
10
23
|
const VisualStyle = preload("internal/visual_style_2d.gd")
|
|
11
24
|
var _visual_style = VisualStyle.new()
|
|
12
25
|
const Length = preload("internal/length.gd")
|
|
@@ -147,6 +160,15 @@ var margin_left: Variant = "auto":
|
|
|
147
160
|
if value not in [0,1] or value==stretch: return
|
|
148
161
|
stretch = value
|
|
149
162
|
_changed()
|
|
163
|
+
@export_enum("auto", "start", "center", "end", "stretch") var align_self: String = "auto":
|
|
164
|
+
set(value):
|
|
165
|
+
if value==align_self: return
|
|
166
|
+
var message := AlignmentContract.error("align_self",value,"")
|
|
167
|
+
if not message.is_empty():
|
|
168
|
+
push_error("Estragon alignment: "+message)
|
|
169
|
+
return
|
|
170
|
+
align_self = value
|
|
171
|
+
_changed()
|
|
150
172
|
@export var center: bool = false:
|
|
151
173
|
set(value):
|
|
152
174
|
if center == value: return
|
|
@@ -158,6 +180,7 @@ var _layout_size := Vector2.ZERO
|
|
|
158
180
|
var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
|
|
159
181
|
func _get_property_list() -> Array[Dictionary]:
|
|
160
182
|
var properties := Length.properties(["width","height","min_width","min_height","x","y","gap","padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"])
|
|
183
|
+
properties.append_array(Length.properties(["row_gap","column_gap"]))
|
|
161
184
|
if VisualStyle.supported(get_script()): properties.append_array(Length.properties(["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width","background_color","border_color"]))
|
|
162
185
|
return properties
|
|
163
186
|
static func valid_length(value) -> bool:
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
class_name EstragonGrid
|
|
3
|
+
extends "component_2d.gd"
|
|
4
|
+
## Native 2D parent-owned track layout, using the shared mathematical core.
|
|
5
|
+
const ESTRAGON_GRID := true
|
|
6
|
+
const Definition = preload("internal/grid_definition.gd")
|
|
7
|
+
const CONFIG := ["columns","rows","areas","template","horizontal_align","vertical_align"]
|
|
8
|
+
var _committing := false
|
|
9
|
+
var columns: Variant = null:
|
|
10
|
+
set(value):
|
|
11
|
+
if typeof(columns)==typeof(value) and columns==value: return
|
|
12
|
+
if not _committing and not _accept("columns",value): return
|
|
13
|
+
columns = value.duplicate(true) if value is Array else value
|
|
14
|
+
if not _committing: _changed()
|
|
15
|
+
var rows: Variant = null:
|
|
16
|
+
set(value):
|
|
17
|
+
if typeof(rows)==typeof(value) and rows==value: return
|
|
18
|
+
if not _committing and not _accept("rows",value): return
|
|
19
|
+
rows = value.duplicate(true) if value is Array else value
|
|
20
|
+
if not _committing: _changed()
|
|
21
|
+
@export var areas: Array = []:
|
|
22
|
+
set(value):
|
|
23
|
+
if areas==value: return
|
|
24
|
+
if not _committing and not _accept("areas",value): return
|
|
25
|
+
areas = value.duplicate(true)
|
|
26
|
+
if not _committing: _changed()
|
|
27
|
+
@export_multiline var template: String = "":
|
|
28
|
+
set(value):
|
|
29
|
+
if template==value: return
|
|
30
|
+
if not _committing and not _accept("template",value): return
|
|
31
|
+
template = value
|
|
32
|
+
if not _committing: _changed()
|
|
33
|
+
@export_enum("start","center","end","stretch") var horizontal_align: String = "stretch":
|
|
34
|
+
set(value):
|
|
35
|
+
if value==horizontal_align: return
|
|
36
|
+
if not _committing and not _accept("horizontal_align",value): return
|
|
37
|
+
horizontal_align = value
|
|
38
|
+
if not _committing: _changed()
|
|
39
|
+
@export_enum("start","center","end","stretch") var vertical_align: String = "stretch":
|
|
40
|
+
set(value):
|
|
41
|
+
if value==vertical_align: return
|
|
42
|
+
if not _committing and not _accept("vertical_align",value): return
|
|
43
|
+
vertical_align = value
|
|
44
|
+
if not _committing: _changed()
|
|
45
|
+
func _config() -> Dictionary:
|
|
46
|
+
return {"columns":columns,"rows":rows,"areas":areas,"template":template,"horizontal_align":horizontal_align,"vertical_align":vertical_align}
|
|
47
|
+
func _accept(key: String, value) -> bool:
|
|
48
|
+
var config := _config()
|
|
49
|
+
config[key] = value
|
|
50
|
+
var placements: Array = []
|
|
51
|
+
for child in _get_layout_coordinator().model.children: placements.append(child.placement)
|
|
52
|
+
var parsed := Definition.configuration(config,placements)
|
|
53
|
+
if parsed.has("error"): push_error("Estragon Grid: "+parsed.error)
|
|
54
|
+
return not parsed.has("error")
|
|
55
|
+
# Whole-description preflight validated the final config and all placements.
|
|
56
|
+
func _apply_grid(values: Dictionary) -> void:
|
|
57
|
+
var before := _config()
|
|
58
|
+
_committing = true
|
|
59
|
+
for key in CONFIG:
|
|
60
|
+
if values.has(key): set(key,values[key])
|
|
61
|
+
_committing = false
|
|
62
|
+
if before!=_config(): _changed()
|
|
63
|
+
func _layout_options() -> Dictionary:
|
|
64
|
+
var result := super._layout_options()
|
|
65
|
+
result.strategy = "grid"
|
|
66
|
+
result.grid = _config()
|
|
67
|
+
result.alignment = [horizontal_align,vertical_align,"start"]
|
|
68
|
+
return result
|
|
69
|
+
|
|
70
|
+
func _get_property_list() -> Array[Dictionary]:
|
|
71
|
+
var result := super._get_property_list()
|
|
72
|
+
for key in ["columns","rows"]: result.append({"name":key,"type":TYPE_NIL,"usage":PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_NIL_IS_VARIANT})
|
|
73
|
+
return result
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://ch5su6sf182dt
|
|
@@ -157,3 +157,40 @@ func refresh_positions(root: RefCounted) -> void:
|
|
|
157
157
|
var node = item.node.get_ref()
|
|
158
158
|
var coordinator = _coordinator(node)
|
|
159
159
|
if coordinator != null and coordinator._mode != coordinator.Mode.ENTRY and coordinator.scope_root() == root: coordinator._place(coordinator.model.offset)
|
|
160
|
+
|
|
161
|
+
# Authored Grid placements are external weak records, never foreign properties.
|
|
162
|
+
var placements: Dictionary = {}
|
|
163
|
+
func set_placement(node: Node, value: Dictionary) -> void:
|
|
164
|
+
var id := node.get_instance_id()
|
|
165
|
+
if value.is_empty():
|
|
166
|
+
clear_placement(id)
|
|
167
|
+
return
|
|
168
|
+
var entry: Array = placements.get(id,[])
|
|
169
|
+
if entry.is_empty():
|
|
170
|
+
var reference: WeakRef = weakref(node)
|
|
171
|
+
var callback: Callable = _placement_exited.bind(id,reference)
|
|
172
|
+
node.tree_exited.connect(callback)
|
|
173
|
+
entry = [reference,{},callback]
|
|
174
|
+
entry[1] = value.duplicate(true)
|
|
175
|
+
placements[id] = entry
|
|
176
|
+
var coordinator = _coordinator(node)
|
|
177
|
+
if coordinator!=null: coordinator.model.set_placement(value)
|
|
178
|
+
func clear_placement(id: int) -> void:
|
|
179
|
+
var entry: Array = placements.get(id,[])
|
|
180
|
+
placements.erase(id)
|
|
181
|
+
if entry.is_empty(): return
|
|
182
|
+
var node = entry[0].get_ref()
|
|
183
|
+
if node==null: return
|
|
184
|
+
if node.tree_exited.is_connected(entry[2]): node.tree_exited.disconnect(entry[2])
|
|
185
|
+
var coordinator = _coordinator(node)
|
|
186
|
+
if coordinator!=null: coordinator.model.set_placement({})
|
|
187
|
+
func _placement_exited(id: int, reference: WeakRef) -> void:
|
|
188
|
+
# Exit alone may be a reversible native remove/re-entry. Prune only after
|
|
189
|
+
# native destruction, without retaining the Node or polling idle frames.
|
|
190
|
+
_prune_placement.call_deferred(id,reference)
|
|
191
|
+
func _prune_placement(id: int, reference: WeakRef) -> void:
|
|
192
|
+
var entry: Array = placements.get(id,[])
|
|
193
|
+
if not entry.is_empty() and entry[0]==reference and reference.get_ref()==null: clear_placement(id)
|
|
194
|
+
func get_placement(node: Node) -> Dictionary:
|
|
195
|
+
var entry: Array = placements.get(node.get_instance_id(),[])
|
|
196
|
+
return entry[1] if not entry.is_empty() and entry[0].get_ref()==node else {}
|
|
@@ -73,6 +73,7 @@ func start() -> void:
|
|
|
73
73
|
# PackedScene restores metadata after construction. Refresh the proof-only
|
|
74
74
|
# weak registry at entry; C1 resolves the live script field instead.
|
|
75
75
|
if _mode == Mode.PROOF: host.set_meta(META, weakref(self))
|
|
76
|
+
if _dimension==2 and host is CanvasItem: host.visibility_changed.connect(_visibility_changed)
|
|
76
77
|
host.child_entered_tree.connect(_child_entered)
|
|
77
78
|
host.child_exiting_tree.connect(_child_exiting)
|
|
78
79
|
if host.has_signal("child_order_changed"): host.connect("child_order_changed", _sync)
|
|
@@ -91,6 +92,7 @@ func stop() -> void:
|
|
|
91
92
|
if control_adapter != null: control_adapter.stop()
|
|
92
93
|
model.set_children([])
|
|
93
94
|
return
|
|
95
|
+
if _dimension==2 and host is CanvasItem and host.visibility_changed.is_connected(_visibility_changed): host.visibility_changed.disconnect(_visibility_changed)
|
|
94
96
|
if host.child_entered_tree.is_connected(_child_entered): host.child_entered_tree.disconnect(_child_entered)
|
|
95
97
|
if host.child_exiting_tree.is_connected(_child_exiting): host.child_exiting_tree.disconnect(_child_exiting)
|
|
96
98
|
if host.has_signal("child_order_changed") and host.is_connected("child_order_changed", _sync): host.disconnect("child_order_changed", _sync)
|
|
@@ -100,6 +102,10 @@ func stop() -> void:
|
|
|
100
102
|
var parent = parent_coordinator()
|
|
101
103
|
if parent != null: parent._sync()
|
|
102
104
|
|
|
105
|
+
func _visibility_changed() -> void:
|
|
106
|
+
var parent = parent_coordinator()
|
|
107
|
+
if parent!=null and parent.model.strategy in ["wrap","grid"]: parent._sync()
|
|
108
|
+
|
|
103
109
|
func _child_entered(child: Node) -> void:
|
|
104
110
|
if child is Control: CompositionHosts.enter_control(child)
|
|
105
111
|
_sync()
|
|
@@ -120,9 +126,11 @@ func _sync() -> void:
|
|
|
120
126
|
if _mode == Mode.COMPOSITION and managed_root != null and managed_root.get_ref() != null: children.append(managed_root.get_ref())
|
|
121
127
|
children = CompositionHosts.children(host,children)
|
|
122
128
|
for child in children:
|
|
129
|
+
if _dimension==2 and model.strategy in ["wrap","grid"] and child is CanvasItem and not child.is_visible_in_tree(): continue
|
|
123
130
|
var found = participant(child,true)
|
|
124
131
|
if found != null and found._mode != Mode.ENTRY:
|
|
125
132
|
if found._mode == Mode.CONTROL and not found.control_adapter.participates(): continue
|
|
133
|
+
found.model.set_placement(CompositionHosts.get_placement(child))
|
|
126
134
|
values.append(found.model)
|
|
127
135
|
var error := model.set_children(values)
|
|
128
136
|
if error != OK: push_error("Estragon layout model ownership: " + error_string(error))
|
|
@@ -132,13 +140,16 @@ func changed() -> void:
|
|
|
132
140
|
if host == null: return
|
|
133
141
|
if host.has_method("_layout_options"):
|
|
134
142
|
var options: Dictionary = host._layout_options()
|
|
143
|
+
model.set_strategy(options.get("strategy","stack") if _dimension==2 else "stack",options.get("align_content","start"),options.get("grid",{}))
|
|
135
144
|
model.set_policy(options.get("alignment",["start","start","start"]))
|
|
145
|
+
model.set_align_self(host.align_self if _dimension==2 and "align_self" in host else "auto")
|
|
136
146
|
if "lengths" in host:
|
|
137
147
|
for property in host._get_property_list():
|
|
138
148
|
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
149
|
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
150
|
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))
|
|
141
151
|
else: model.configure(host.requested_extent(), host.gap, host.center)
|
|
152
|
+
if active: _sync()
|
|
142
153
|
|
|
143
154
|
func _viewport_changed() -> void:
|
|
144
155
|
var host = _host.get_ref()
|