@papercraftgames/estragon 0.1.0-beta.21 → 0.1.0-beta.23
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 +10 -0
- package/addons/estragon/compiler/model.gd +1 -0
- package/addons/estragon/compiler/parser.gd +29 -3
- package/addons/estragon/compiler/validator.gd +14 -3
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/runtime/composition/computation.gd +112 -26
- package/addons/estragon/runtime/composition/element.gd +46 -0
- package/addons/estragon/runtime/composition/native_attributes.gd +26 -0
- package/addons/estragon/runtime/composition/native_attributes.gd.uid +1 -0
- package/addons/estragon/runtime/node/box.gd +2 -2
- package/addons/estragon/runtime/node/component_2d.gd +23 -1
- package/addons/estragon/runtime/node/internal/coordinator.gd +1 -0
- package/addons/estragon/runtime/node/internal/layout_core.gd +32 -7
- package/addons/estragon/runtime/node/internal/length.gd +5 -2
- package/addons/estragon/runtime/node/internal/stack_contract.gd +15 -3
- package/addons/estragon/runtime/node/internal/stack_policy.gd +26 -6
- package/addons/estragon/runtime/node/native_2d.gd +2 -3
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ const Source = preload("source.gd")
|
|
|
9
9
|
const MappedWriter = preload("source_map.gd")
|
|
10
10
|
|
|
11
11
|
class Argument extends RefCounted:
|
|
12
|
+
var spread := false
|
|
12
13
|
var expression: Model.GdExpression
|
|
13
14
|
var type_name: String
|
|
14
15
|
var name: String
|
|
@@ -100,6 +101,7 @@ func _collect(node: Model.Component, factory: Factory) -> void:
|
|
|
100
101
|
for attribute in node.attributes:
|
|
101
102
|
if attribute.value is Model.GdExpression:
|
|
102
103
|
_argument(attribute.value, attribute.type_name, factory)
|
|
104
|
+
factory.arguments.back().spread = attribute.kind=="spread"
|
|
103
105
|
if attribute.kind=="binding": factory.arguments.back().binding_path = attribute.binding_path
|
|
104
106
|
for child in node.children:
|
|
105
107
|
if child is Model.GdExpression: _argument(child,"Variant",factory)
|
|
@@ -143,8 +145,10 @@ func _call(node: Model.Component) -> void:
|
|
|
143
145
|
if index > 0: _writer.append("," if multiline else ", ", node.span)
|
|
144
146
|
if multiline: _writer.append("\n" + base + _module.indentation, argument.expression.span)
|
|
145
147
|
_writer.append("(", argument.expression.span)
|
|
148
|
+
if argument.spread: _writer.append("preload("+_resource(Element)+").snapshot(",argument.expression.span)
|
|
146
149
|
if argument.binding_path.is_empty(): _parts(argument.expression.parts)
|
|
147
150
|
else: _binding_argument(argument)
|
|
151
|
+
if argument.spread: _writer.append(")",argument.expression.span)
|
|
148
152
|
_writer.append(")", argument.expression.span)
|
|
149
153
|
_writer.append(("\n" + base if multiline else "") + ")", node.span)
|
|
150
154
|
|
|
@@ -172,6 +176,8 @@ func _description(node: Model.Component, indentation: String) -> String:
|
|
|
172
176
|
var bindings := PackedStringArray()
|
|
173
177
|
var key := "null"
|
|
174
178
|
var keyed := "false"
|
|
179
|
+
var expanded := node.attributes.any(func(item): return item.kind=="spread")
|
|
180
|
+
var ordered := PackedStringArray()
|
|
175
181
|
for attribute in node.attributes:
|
|
176
182
|
var value: String = _arguments[attribute.value].name if attribute.value is Model.GdExpression else literal(attribute.value)
|
|
177
183
|
if attribute.kind == "binding":
|
|
@@ -181,6 +187,9 @@ func _description(node: Model.Component, indentation: String) -> String:
|
|
|
181
187
|
key = value
|
|
182
188
|
keyed = "true"
|
|
183
189
|
continue
|
|
190
|
+
if expanded:
|
|
191
|
+
ordered.append("[%s, %s, %s]" % ["null" if attribute.kind=="spread" else _string(attribute.name),value,_string("%s:%d:%d" % [_file.name,attribute.name_span.start.line,attribute.name_span.start.column])])
|
|
192
|
+
continue
|
|
184
193
|
var target := events if attribute.kind == "signal" else props
|
|
185
194
|
target.append(_string(attribute.name)+": "+value)
|
|
186
195
|
var children := PackedStringArray()
|
|
@@ -188,6 +197,7 @@ func _description(node: Model.Component, indentation: String) -> String:
|
|
|
188
197
|
children.append(_arguments[child].name if child is Model.GdExpression else _description(child,indentation))
|
|
189
198
|
var native_type := _string(node.runtime_class) if ClassDB.class_exists(node.runtime_class) else node.runtime_class
|
|
190
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
|
+
if expanded: _line(variable+".expand(["+", ".join(ordered)+"])",node.span,indentation)
|
|
191
201
|
if not bindings.is_empty(): _line(variable+".bindings = {"+", ".join(bindings)+"}",node.span,indentation)
|
|
192
202
|
return variable
|
|
193
203
|
|
|
@@ -91,6 +91,15 @@ func _component(depth: int) -> Model.Component:
|
|
|
91
91
|
if not separated:
|
|
92
92
|
file.fail("Expected whitespace before a property, or a tag terminator", _cursor)
|
|
93
93
|
return null
|
|
94
|
+
if _at("{"):
|
|
95
|
+
var spread := Model.Attribute.new()
|
|
96
|
+
spread.kind = "spread"
|
|
97
|
+
spread.name_span = file.span(_cursor,_cursor+1)
|
|
98
|
+
spread.value = _expression(true)
|
|
99
|
+
if spread.value==null: return null
|
|
100
|
+
spread.span = spread.value.span
|
|
101
|
+
node.attributes.append(spread)
|
|
102
|
+
continue
|
|
94
103
|
var attribute_name := _name()
|
|
95
104
|
if attribute_name == null: return null
|
|
96
105
|
_whitespace()
|
|
@@ -124,6 +133,7 @@ func _component(depth: int) -> Model.Component:
|
|
|
124
133
|
_cursor += 1
|
|
125
134
|
lexer.token("markup-string", quote_start, _cursor)
|
|
126
135
|
if attribute.value == null: return null
|
|
136
|
+
attribute.span = file.span(attribute.name_span.start.index,_cursor)
|
|
127
137
|
node.attributes.append(attribute)
|
|
128
138
|
_trivia()
|
|
129
139
|
while not _at("</") and file.diagnostics.is_empty():
|
|
@@ -150,10 +160,23 @@ func _component(depth: int) -> Model.Component:
|
|
|
150
160
|
node.span = file.span(start, _cursor)
|
|
151
161
|
return node
|
|
152
162
|
|
|
153
|
-
func _expression() -> Model.GdExpression:
|
|
163
|
+
func _expression(spread: bool = false) -> Model.GdExpression:
|
|
154
164
|
var start := _cursor
|
|
155
|
-
|
|
156
|
-
|
|
165
|
+
var opening := 1
|
|
166
|
+
if spread:
|
|
167
|
+
var probe := Lexer.new(file)
|
|
168
|
+
var marker := start+1
|
|
169
|
+
while marker<file.text.length():
|
|
170
|
+
var token := probe.next_token(marker)
|
|
171
|
+
if token==null: return null
|
|
172
|
+
if token.kind not in ["whitespace","newline","comment","continuation"]: break
|
|
173
|
+
marker = token.span.end.index
|
|
174
|
+
if file.text.substr(marker,3)!="...":
|
|
175
|
+
file.fail("Expected ... in GGX spread attribute",marker)
|
|
176
|
+
return null
|
|
177
|
+
opening = marker+3-start
|
|
178
|
+
lexer.token("attribute-spread" if spread else "expression-open", start, start + opening)
|
|
179
|
+
var scanned := _scan(start + opening, true)
|
|
157
180
|
if not file.diagnostics.is_empty(): return null
|
|
158
181
|
if not scanned.has_token:
|
|
159
182
|
file.fail("Expected a GDScript expression inside braces", start, scanned.end)
|
|
@@ -180,6 +203,9 @@ func _scan(start: int, braced: bool) -> Dictionary:
|
|
|
180
203
|
var has_token := false
|
|
181
204
|
while offset < file.text.length() and file.diagnostics.is_empty():
|
|
182
205
|
var character := lexer.char_at(offset)
|
|
206
|
+
if file.text.substr(offset,3)=="...":
|
|
207
|
+
file.fail("Spread is only supported as {...expression} in a GGX opening attribute list",offset,offset+3)
|
|
208
|
+
break
|
|
183
209
|
if braced and stack.is_empty() and character == "}":
|
|
184
210
|
_copy(parts, copied, offset)
|
|
185
211
|
return {"parts": parts, "end": offset, "has_token": has_token}
|
|
@@ -8,6 +8,7 @@ const Resolver = preload("native/resolver.gd")
|
|
|
8
8
|
const StackContract = preload("../runtime/node/internal/stack_contract.gd")
|
|
9
9
|
const VisualStyle = preload("../runtime/node/internal/visual_style_2d.gd")
|
|
10
10
|
const Length = preload("../runtime/node/internal/length.gd")
|
|
11
|
+
const NativeAttributes = preload("../runtime/composition/native_attributes.gd")
|
|
11
12
|
const Lexer = preload("lexer.gd")
|
|
12
13
|
var file: Source
|
|
13
14
|
var resolver
|
|
@@ -52,7 +53,12 @@ func _component(node: Model.Component) -> void:
|
|
|
52
53
|
_error("Rect fill and background_color conflict; author only the canonical background_color or legacy fill",node.name_span)
|
|
53
54
|
return
|
|
54
55
|
var seen: Dictionary = {}
|
|
56
|
+
var expanded := node.attributes.any(func(item): return item.kind=="spread")
|
|
55
57
|
for attribute in node.attributes:
|
|
58
|
+
if attribute.kind=="spread":
|
|
59
|
+
attribute.type_name = "Variant"
|
|
60
|
+
_node(attribute.value)
|
|
61
|
+
continue
|
|
56
62
|
var name := attribute.name
|
|
57
63
|
if VisualStyle.property(name) and VisualStyle.has_api(resolved.script) and not VisualStyle.supported(resolved.script):
|
|
58
64
|
_error("Shared visual styling is unsupported on this participant",attribute.name_span)
|
|
@@ -87,7 +93,7 @@ func _component(node: Model.Component) -> void:
|
|
|
87
93
|
_error("Inline anonymous GGX handlers are not supported; use a named handler/Callable", token.span)
|
|
88
94
|
return
|
|
89
95
|
index = token.span.end.index
|
|
90
|
-
elif properties.has(name) and
|
|
96
|
+
elif properties.has(name) and NativeAttributes.writable(resolved.native,resolved.script,name,properties[name]):
|
|
91
97
|
attribute.type_name = "Variant" if Length.registered(resolved.script,name) or VisualStyle.registered(resolved.script,name) else _native_type(properties[name])
|
|
92
98
|
if attribute.type_name.is_empty():
|
|
93
99
|
_error("Unsupported Node property metadata: " + name, attribute.name_span)
|
|
@@ -95,11 +101,16 @@ func _component(node: Model.Component) -> void:
|
|
|
95
101
|
else:
|
|
96
102
|
_error("Removed layout API "+name+": use unit dimensions, grow and stretch" if name in ["flex","fill_width","fill_height","viewport_width_scale","viewport_height_scale"] else "Unknown, read-only or reserved Node property/signal " + name, attribute.name_span)
|
|
97
103
|
return
|
|
98
|
-
if StackContract.registered(resolved.script) and attribute.value is Model.Literal:
|
|
104
|
+
if not expanded and StackContract.registered(resolved.script) and attribute.value is Model.Literal:
|
|
99
105
|
var message := StackContract.error(name,attribute.value.value,stack_direction,StackContract.preset(resolved.script))
|
|
100
106
|
if not message.is_empty():
|
|
101
107
|
_error(message,attribute.value.span)
|
|
102
108
|
return
|
|
109
|
+
if name=="align_self" and StackContract.self_registered(resolved.script) and attribute.value is Model.Literal:
|
|
110
|
+
var message := StackContract.error(name,attribute.value.value,"")
|
|
111
|
+
if not message.is_empty():
|
|
112
|
+
_error(message,attribute.value.span)
|
|
113
|
+
return
|
|
103
114
|
var is_color := VisualStyle.registered(resolved.script,name)
|
|
104
115
|
if is_color:
|
|
105
116
|
_color(attribute)
|
|
@@ -129,7 +140,7 @@ func _component(node: Model.Component) -> void:
|
|
|
129
140
|
_error("Node GGX children must be newly declared Node elements; expression adoption is unsupported", child.span)
|
|
130
141
|
return
|
|
131
142
|
_node(child)
|
|
132
|
-
if child is Model.Component:
|
|
143
|
+
if child is Model.Component and not child.attributes.any(func(item): return item.kind=="spread"):
|
|
133
144
|
for attribute in child.attributes:
|
|
134
145
|
if attribute.name=="name" and attribute.value is Model.Literal:
|
|
135
146
|
var name: String = str(attribute.value.value)
|
|
@@ -2,6 +2,7 @@ extends RefCounted
|
|
|
2
2
|
const StackContract = preload("../node/internal/stack_contract.gd")
|
|
3
3
|
const VisualStyle = preload("../node/internal/visual_style_2d.gd")
|
|
4
4
|
const Length = preload("../node/internal/length.gd")
|
|
5
|
+
const NativeAttributes = preload("native_attributes.gd")
|
|
5
6
|
const Profile = preload("profile.tres")
|
|
6
7
|
## F01 computation and retained static-shape records external to native objects.
|
|
7
8
|
const Binding = preload("binding.gd")
|
|
@@ -16,6 +17,9 @@ class Mounted extends RefCounted:
|
|
|
16
17
|
var keyed := false
|
|
17
18
|
var slot: Array = []
|
|
18
19
|
var properties: Dictionary = {}
|
|
20
|
+
var defaults: Dictionary = {}
|
|
21
|
+
var spread_owned: Dictionary = {}
|
|
22
|
+
var spread_applied: Dictionary = {}
|
|
19
23
|
var handlers: Dictionary = {}
|
|
20
24
|
var bindings: Dictionary = {}
|
|
21
25
|
var children: Array = []
|
|
@@ -153,11 +157,16 @@ func _flush() -> void:
|
|
|
153
157
|
# descriptor: callers may reuse either, and cycles must fail before native edits.
|
|
154
158
|
func _normalize(value, ancestors: Array = [], level: int = 0):
|
|
155
159
|
if not value is Element or level>128 or ancestors.has(value): return null
|
|
160
|
+
if not value.attribute_error.is_empty():
|
|
161
|
+
validation_error = value.attribute_error
|
|
162
|
+
return null
|
|
156
163
|
if value.keyed and not _key_valid(value.key): return null
|
|
157
164
|
var next := ancestors.duplicate()
|
|
158
165
|
next.append(value)
|
|
159
166
|
if Profile.is_enabled(): Profile.add("normalized_elements")
|
|
160
167
|
var result := Element.new(value.type,value.properties,value.handlers,[],value.source,value.key,value.keyed)
|
|
168
|
+
result.origins = value.origins.duplicate()
|
|
169
|
+
result.spread_properties = value.spread_properties.duplicate()
|
|
161
170
|
result.bindings = value.bindings.duplicate()
|
|
162
171
|
if not _flatten(value.children,[],result.children,next,level+1): return null
|
|
163
172
|
return result
|
|
@@ -220,8 +229,9 @@ func _valid(desired: Element, previous: Mounted) -> bool:
|
|
|
220
229
|
else: return false
|
|
221
230
|
for binding in desired.bindings.values():
|
|
222
231
|
if not binding is Binding or not binding.valid: return false
|
|
223
|
-
for
|
|
224
|
-
|
|
232
|
+
for event in desired.handlers:
|
|
233
|
+
var handler = desired.handlers[event]
|
|
234
|
+
if not handler is Callable or not handler.is_valid(): return _invalid_attribute(desired,event,"signal requires a valid native Callable")
|
|
225
235
|
var names := {}
|
|
226
236
|
var keys := {}
|
|
227
237
|
if desired.keyed and not _key_valid(desired.key): return false
|
|
@@ -234,7 +244,7 @@ func _valid(desired: Element, previous: Mounted) -> bool:
|
|
|
234
244
|
keys[key] = true
|
|
235
245
|
var name: String = str(child.properties.get("name",""))
|
|
236
246
|
if not name.is_empty():
|
|
237
|
-
if names.has(name): return
|
|
247
|
+
if names.has(name): return _invalid_attribute(child,"name","duplicate declared sibling name "+name)
|
|
238
248
|
names[name] = true
|
|
239
249
|
return true
|
|
240
250
|
func _collect_foreign(record, result: Array) -> void:
|
|
@@ -310,6 +320,16 @@ func _mount(desired: Element, parent: Node, owner: Node) -> Mounted:
|
|
|
310
320
|
return record
|
|
311
321
|
func _apply(desired: Element, record: Mounted) -> void:
|
|
312
322
|
var node: Node = record.node.get_ref()
|
|
323
|
+
# Capture the real class/_init defaults before its first authored write, with
|
|
324
|
+
# no probe instances. Later first ownership preserves preexisting native state.
|
|
325
|
+
for key in desired.properties:
|
|
326
|
+
if not record.defaults.has(key):
|
|
327
|
+
record.defaults[key] = node.get(key)
|
|
328
|
+
# An unattached native Node starts unnamed, but set_name rejects empty
|
|
329
|
+
# names after attachment. Restore its native class label instead;
|
|
330
|
+
# Godot retains authority over sibling-name uniqueness.
|
|
331
|
+
if key=="name" and str(record.defaults[key]).is_empty(): record.defaults[key] = node.get_class()
|
|
332
|
+
var resets := _spread_resets(desired,record)
|
|
313
333
|
for key in record.bindings.keys():
|
|
314
334
|
if not desired.bindings.has(key) or not record.bindings[key].same(desired.bindings[key]):
|
|
315
335
|
record.bindings[key].disconnect_edit()
|
|
@@ -323,7 +343,14 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
323
343
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
324
344
|
binding.attach(node,self)
|
|
325
345
|
var stack := StackContract.registered(desired.type)
|
|
326
|
-
if stack:
|
|
346
|
+
if stack:
|
|
347
|
+
var policy := resets.duplicate()
|
|
348
|
+
policy.merge(desired.properties,true)
|
|
349
|
+
node._apply_stack_policy(policy)
|
|
350
|
+
for key in resets:
|
|
351
|
+
if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,resets[key])
|
|
352
|
+
writes += 1
|
|
353
|
+
if Profile.is_enabled(): Profile.add("property_writes")
|
|
327
354
|
# An omitted previously declared border side removes that local override;
|
|
328
355
|
# do not turn omission into permanent native state or change other props.
|
|
329
356
|
if VisualStyle.supported(desired.type):
|
|
@@ -332,6 +359,16 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
332
359
|
node.set(key,"auto")
|
|
333
360
|
writes += 1
|
|
334
361
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
362
|
+
if Length.registered(desired.type,"min_width"):
|
|
363
|
+
for key in Length.MINIMUMS:
|
|
364
|
+
if record.properties.has(key) and not desired.properties.has(key):
|
|
365
|
+
node.set(key,0.0)
|
|
366
|
+
writes += 1
|
|
367
|
+
if Profile.is_enabled(): Profile.add("property_writes")
|
|
368
|
+
if StackContract.self_registered(desired.type) and record.properties.has("align_self") and not desired.properties.has("align_self"):
|
|
369
|
+
node.set("align_self","auto")
|
|
370
|
+
writes += 1
|
|
371
|
+
if Profile.is_enabled(): Profile.add("property_writes")
|
|
335
372
|
for key in desired.properties:
|
|
336
373
|
if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
|
|
337
374
|
if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
|
|
@@ -348,6 +385,45 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
348
385
|
if node.connect(event,desired.handlers[event],Object.CONNECT_PERSIST)!=OK: push_error("F01 native handler connection failed: "+desired.source)
|
|
349
386
|
record.properties = desired.properties.duplicate()
|
|
350
387
|
record.handlers = desired.handlers.duplicate()
|
|
388
|
+
record.spread_owned = desired.spread_properties.duplicate()
|
|
389
|
+
record.spread_applied.clear()
|
|
390
|
+
for key in desired.properties:
|
|
391
|
+
if record.spread_owned.has(key): record.spread_applied[key] = node.get(key)
|
|
392
|
+
|
|
393
|
+
func _spread_resets(desired: Element, record) -> Dictionary:
|
|
394
|
+
var result := {}
|
|
395
|
+
if record==null or not _compatible(desired,record): return result
|
|
396
|
+
var node = record.node.get_ref()
|
|
397
|
+
for key in record.spread_applied:
|
|
398
|
+
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
|
|
399
|
+
# Do not overwrite imperative native changes made since our last commit.
|
|
400
|
+
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]
|
|
401
|
+
return result
|
|
402
|
+
|
|
403
|
+
func _effective_name(desired: Element, record) -> String:
|
|
404
|
+
if desired.properties.has("name"): return str(desired.properties.name)
|
|
405
|
+
var resets := _spread_resets(desired,record)
|
|
406
|
+
if resets.has("name"): return str(resets.name)
|
|
407
|
+
return str(record.node.get_ref().name) if _compatible(desired,record) else ""
|
|
408
|
+
|
|
409
|
+
func _invalid_attribute(desired: Element, key: String, message: String) -> bool:
|
|
410
|
+
validation_error = desired.location(key)+": attribute '"+key+"': "+message+"; previous tree retained"
|
|
411
|
+
return false
|
|
412
|
+
|
|
413
|
+
func _handler_error(handler: Callable, emitted: int) -> String:
|
|
414
|
+
# Named methods expose public metadata on both supported engines. Custom
|
|
415
|
+
# Callables without method metadata retain native invocation semantics.
|
|
416
|
+
if handler.is_custom(): return ""
|
|
417
|
+
var target = handler.get_object()
|
|
418
|
+
if target==null: return ""
|
|
419
|
+
for method in target.get_method_list():
|
|
420
|
+
if method.name!=handler.get_method(): continue
|
|
421
|
+
if int(method.flags)&METHOD_FLAG_VARARG: return ""
|
|
422
|
+
var supplied := emitted
|
|
423
|
+
var maximum: int = method.args.size()
|
|
424
|
+
if supplied<maximum-method.default_args.size() or supplied>maximum: return "Callable arity does not match native signal"
|
|
425
|
+
return ""
|
|
426
|
+
return ""
|
|
351
427
|
func _compatible(desired: Element, record: Mounted) -> bool:
|
|
352
428
|
if record == null: return false
|
|
353
429
|
if desired.borrowed != null or record.borrowed != null:
|
|
@@ -391,17 +467,20 @@ func _prepare_names(desired: Array, matches: Array, parent: Node) -> void:
|
|
|
391
467
|
for index in range(desired.size()):
|
|
392
468
|
var next = desired[index]
|
|
393
469
|
var old = matches[index]
|
|
394
|
-
if next==null or old==null
|
|
395
|
-
if
|
|
470
|
+
if next==null or old==null: continue
|
|
471
|
+
if not next.properties.has("name") and not _spread_resets(next,old).has("name"): continue
|
|
472
|
+
var final_name := _effective_name(next,old)
|
|
396
473
|
var node: Node = old.node.get_ref()
|
|
397
|
-
if node==null or node.get_parent()!=parent or str(node.name)==
|
|
398
|
-
pending.append(node)
|
|
399
|
-
targets[
|
|
400
|
-
for
|
|
474
|
+
if node==null or node.get_parent()!=parent or str(node.name)==final_name: continue
|
|
475
|
+
pending.append([node,old])
|
|
476
|
+
targets[final_name] = true
|
|
477
|
+
for pair in pending:
|
|
478
|
+
var node: Node = pair[0]
|
|
401
479
|
if not targets.has(str(node.name)): continue
|
|
402
480
|
var temporary := "_EstragonRename_"+str(node.get_instance_id())
|
|
403
481
|
while parent.has_node(NodePath(temporary)): temporary += "_"
|
|
404
482
|
node.name = temporary
|
|
483
|
+
if pair[1].spread_applied.has("name"): pair[1].spread_applied.name = node.name
|
|
405
484
|
writes += 1
|
|
406
485
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
407
486
|
# Keep a longest increasing subsequence of actual native indices. Everything
|
|
@@ -473,6 +552,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
473
552
|
var signals: Dictionary = contracts[desired.type].signals
|
|
474
553
|
if StackContract.registered(desired.type):
|
|
475
554
|
var policy: Dictionary = previous.properties.duplicate() if previous!=null and _compatible(desired,previous) else {}
|
|
555
|
+
policy.merge(_spread_resets(desired,previous),true)
|
|
476
556
|
policy.merge(desired.properties,true)
|
|
477
557
|
var fixed := StackContract.preset(desired.type)
|
|
478
558
|
var direction = policy.get("direction",fixed if not fixed.is_empty() else "row")
|
|
@@ -480,41 +560,45 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
480
560
|
var value = policy.get(key,direction if key=="direction" else "start")
|
|
481
561
|
var message := StackContract.error(key,value,str(direction),fixed)
|
|
482
562
|
if not message.is_empty():
|
|
483
|
-
validation_error = desired.
|
|
563
|
+
validation_error = desired.location(key)+": "+message+"; previous tree retained"
|
|
484
564
|
return false
|
|
485
565
|
if VisualStyle.rect_conflict(desired.type,desired.properties.keys()):
|
|
486
|
-
validation_error = desired.
|
|
566
|
+
validation_error = desired.location("fill")+": Rect fill and background_color conflict; previous tree retained"
|
|
487
567
|
return false
|
|
488
568
|
for key in desired.properties:
|
|
489
|
-
|
|
569
|
+
var native: String = desired.type if desired.type is String else desired.type.get_instance_base_type()
|
|
570
|
+
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")
|
|
490
571
|
var value = desired.properties[key]
|
|
572
|
+
if key=="align_self" and StackContract.self_registered(desired.type):
|
|
573
|
+
var message := StackContract.error(key,value,"")
|
|
574
|
+
if not message.is_empty(): return _invalid_attribute(desired,str(key),message)
|
|
491
575
|
if VisualStyle.property(str(key)) and VisualStyle.has_api(desired.type) and not VisualStyle.supported(desired.type):
|
|
492
|
-
validation_error = desired.
|
|
576
|
+
validation_error = desired.location(str(key))+": shared visual styling is unsupported on this participant; previous tree retained"
|
|
493
577
|
return false
|
|
494
578
|
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.
|
|
579
|
+
validation_error = desired.location(str(key))+": grow requires a finite nonnegative weight; previous tree retained"
|
|
496
580
|
return false
|
|
497
581
|
if key=="fill" and VisualStyle.marked(desired.type,"ESTRAGON_RECT_STYLE"):
|
|
498
582
|
if not value is Color or VisualStyle.parse_color(value).has("error"):
|
|
499
|
-
validation_error = desired.
|
|
583
|
+
validation_error = desired.location(str(key))+": Rect fill requires a finite native Color; previous tree retained"
|
|
500
584
|
return false
|
|
501
585
|
if VisualStyle.registered(desired.type,key):
|
|
502
586
|
var parsed := VisualStyle.parse_color(value)
|
|
503
587
|
if parsed.has("error"):
|
|
504
|
-
validation_error = desired.
|
|
588
|
+
validation_error = desired.location(str(key))+": invalid style '"+str(key)+"': "+parsed.error+"; previous tree retained"
|
|
505
589
|
return false
|
|
506
590
|
if Length.registered(desired.type,key):
|
|
507
591
|
var parsed := Length.parse(value,Length.domain(key,desired.type))
|
|
508
592
|
if parsed.has("error"):
|
|
509
|
-
validation_error = desired.
|
|
593
|
+
validation_error = desired.location(str(key))+": invalid length '"+str(key)+"': "+parsed.error+"; previous tree retained"
|
|
510
594
|
return false
|
|
511
595
|
var kind: int = properties[key].type
|
|
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
|
|
596
|
+
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 _invalid_attribute(desired,str(key),"incompatible native value type")
|
|
513
597
|
if kind==TYPE_OBJECT and value!=null:
|
|
514
598
|
var expected: String = str(properties[key].get("class_name",""))
|
|
515
|
-
if ClassDB.class_exists(expected) and not value.is_class(expected): return
|
|
599
|
+
if ClassDB.class_exists(expected) and not value.is_class(expected): return _invalid_attribute(desired,str(key),"incompatible native Object class "+expected)
|
|
516
600
|
for key in desired.bindings:
|
|
517
|
-
if key!="value" or desired.properties.has(key) or desired.handlers.has("value_changed") or not properties.has(key) or properties[key].type!=TYPE_BOOL or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return
|
|
601
|
+
if key!="value" or desired.properties.has(key) or desired.handlers.has("value_changed") or not properties.has(key) or properties[key].type!=TYPE_BOOL or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return _invalid_attribute(desired,"value_changed" if desired.handlers.has("value_changed") else str(key),"invalid or conflicting controlled binding")
|
|
518
602
|
var args: Array = signals.get("value_changed",{}).get("args",[])
|
|
519
603
|
|
|
520
604
|
# 4.0 lacks signal argument type metadata. Compiler source proof and
|
|
@@ -522,12 +606,14 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
522
606
|
# reject a valid input on that engine.
|
|
523
607
|
if args.size()!=1 or args[0].type not in [TYPE_NIL,TYPE_BOOL]: return false
|
|
524
608
|
for key in desired.handlers:
|
|
525
|
-
if not signals.has(key): return
|
|
609
|
+
if not signals.has(key): return _invalid_attribute(desired,str(key),"unknown native signal")
|
|
610
|
+
var message := _handler_error(desired.handlers[key],signals[key].get("args",[]).size())
|
|
611
|
+
if not message.is_empty(): return _invalid_attribute(desired,str(key),message)
|
|
526
612
|
var node: Node = previous.node.get_ref() if _compatible(desired,previous) else null
|
|
527
613
|
if parent != null:
|
|
528
|
-
var name
|
|
614
|
+
var name := _effective_name(desired,previous)
|
|
529
615
|
for existing in parent.get_children():
|
|
530
|
-
if str(existing.name)==name and (previous==null or existing!=previous.node.get_ref()): return
|
|
616
|
+
if str(existing.name)==name and (previous==null or existing!=previous.node.get_ref()): return _invalid_attribute(desired,"name","native sibling name conflict "+name)
|
|
531
617
|
var known: Array = []
|
|
532
618
|
if node != null:
|
|
533
619
|
for child in previous.children:
|
|
@@ -539,9 +625,9 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
539
625
|
if child == null or child.borrowed != null: continue
|
|
540
626
|
var old = matches[index]
|
|
541
627
|
if not _preflight(child,old,null,contracts): return false
|
|
542
|
-
var name
|
|
628
|
+
var name := _effective_name(child,old)
|
|
543
629
|
if not name.is_empty():
|
|
544
|
-
if names.has(name): return
|
|
630
|
+
if names.has(name): return _invalid_attribute(child,"name","duplicate effective sibling name "+name)
|
|
545
631
|
names[name] = true
|
|
546
632
|
if node != null:
|
|
547
633
|
for existing in node.get_children():
|
|
@@ -14,6 +14,52 @@ var keyed: bool
|
|
|
14
14
|
# Normalized authored child-slot/index path, external to native Nodes.
|
|
15
15
|
var slot: Array = []
|
|
16
16
|
var source: String
|
|
17
|
+
# Attribute provenance belongs to descriptions, never user Nodes or Dictionaries.
|
|
18
|
+
var origins: Dictionary = {}
|
|
19
|
+
var spread_properties: Dictionary = {}
|
|
20
|
+
var attribute_error := ""
|
|
21
|
+
|
|
22
|
+
# Snapshot at the argument evaluation point, before later expressions can mutate
|
|
23
|
+
# the same Dictionary. Values retain normal native reference semantics.
|
|
24
|
+
static func snapshot(value):
|
|
25
|
+
return value.duplicate() if value is Dictionary else value
|
|
26
|
+
|
|
27
|
+
func location(name: String) -> String:
|
|
28
|
+
return origins.get(name,source)
|
|
29
|
+
|
|
30
|
+
func expand(attributes: Array) -> void:
|
|
31
|
+
var values := {}
|
|
32
|
+
var signals := {}
|
|
33
|
+
var native: String = type if type is String else type.get_instance_base_type()
|
|
34
|
+
for event in ClassDB.class_get_signal_list(native): signals[str(event.name)] = true
|
|
35
|
+
var script = type if type is Script else null
|
|
36
|
+
while script != null:
|
|
37
|
+
for event in script.get_script_signal_list(): signals[str(event.name)] = true
|
|
38
|
+
script = script.get_base_script()
|
|
39
|
+
for entry in attributes:
|
|
40
|
+
if entry[0]!=null:
|
|
41
|
+
values[entry[0]] = entry[1]
|
|
42
|
+
origins[entry[0]] = entry[2]
|
|
43
|
+
spread_properties.erase(entry[0])
|
|
44
|
+
continue
|
|
45
|
+
if not entry[1] is Dictionary:
|
|
46
|
+
attribute_error = str(entry[2])+": GGX spread requires a Dictionary; previous tree retained"
|
|
47
|
+
return
|
|
48
|
+
for raw in entry[1]:
|
|
49
|
+
if not typeof(raw) in [TYPE_STRING,TYPE_STRING_NAME] or str(raw).is_empty():
|
|
50
|
+
attribute_error = str(entry[2])+": GGX spread key "+str(raw)+" requires a nonempty String/StringName; previous tree retained"
|
|
51
|
+
return
|
|
52
|
+
var name := str(raw)
|
|
53
|
+
if name=="key" or name.begins_with("bind:"):
|
|
54
|
+
attribute_error = str(entry[2])+": GGX spread key '"+name+"' must be explicitly authored; previous tree retained"
|
|
55
|
+
return
|
|
56
|
+
values[name] = entry[1][raw]
|
|
57
|
+
origins[name] = str(entry[2])+" (spread key '"+name+"')"
|
|
58
|
+
spread_properties[name] = true
|
|
59
|
+
for name in values:
|
|
60
|
+
if signals.has(name): handlers[name] = values[name]
|
|
61
|
+
else: properties[name] = values[name]
|
|
62
|
+
|
|
17
63
|
func _init(native_type: Variant = null, props: Dictionary = {}, events: Dictionary = {}, descendants: Array = [], location: String = "", identity_key: Variant = null, has_key: bool = false) -> void:
|
|
18
64
|
if Profile.is_enabled(): Profile.add("elements")
|
|
19
65
|
key = identity_key
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Native writable-property metadata, shared by compiler and description preflight.
|
|
4
|
+
# 4.0 lacks ClassDB's setter introspection. Its official 4.0.4 class reference
|
|
5
|
+
# declares these getter-only Node properties with setter="". This small bridge
|
|
6
|
+
# rejects them without probe Nodes or speculative setter-name inference. Newer
|
|
7
|
+
# engines use their actual ClassDB metadata, including newly introduced classes.
|
|
8
|
+
const BASELINE_READ_ONLY := {
|
|
9
|
+
"AnimationPlayer":["current_animation_length","current_animation_position"],
|
|
10
|
+
"Node":["multiplayer"],
|
|
11
|
+
"ShapeCast2D":["collision_result"],
|
|
12
|
+
"ShapeCast3D":["collision_result"],
|
|
13
|
+
"Timer":["time_left"],
|
|
14
|
+
}
|
|
15
|
+
static func writable(native: String, script, name: String, property: Dictionary) -> bool:
|
|
16
|
+
if name in ["owner","script"] or name.contains("/"): return false
|
|
17
|
+
if int(property.usage)&(PROPERTY_USAGE_READ_ONLY|PROPERTY_USAGE_CATEGORY|PROPERTY_USAGE_GROUP|PROPERTY_USAGE_SUBGROUP): return false
|
|
18
|
+
while script is Script:
|
|
19
|
+
for field in script.get_script_property_list():
|
|
20
|
+
if str(field.name)==name: return true
|
|
21
|
+
script = script.get_base_script()
|
|
22
|
+
if ClassDB.has_method("class_get_property_setter"):
|
|
23
|
+
return not str(ClassDB.call("class_get_property_setter",native,name)).is_empty()
|
|
24
|
+
for base in BASELINE_READ_ONLY:
|
|
25
|
+
if name in BASELINE_READ_ONLY[base] and ClassDB.is_parent_class(native,base): return false
|
|
26
|
+
return true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://ilri517yw03l
|
|
@@ -20,7 +20,7 @@ const StackContract = preload("internal/stack_contract.gd")
|
|
|
20
20
|
return
|
|
21
21
|
direction = value
|
|
22
22
|
_changed()
|
|
23
|
-
@export_enum("start", "center", "end", "stretch") var horizontal_align: String = "start":
|
|
23
|
+
@export_enum("start", "center", "end", "stretch", "space-between", "space-around", "space-evenly") var horizontal_align: String = "start":
|
|
24
24
|
set(value):
|
|
25
25
|
if _policy_commit:
|
|
26
26
|
horizontal_align = value
|
|
@@ -28,7 +28,7 @@ const StackContract = preload("internal/stack_contract.gd")
|
|
|
28
28
|
if value==horizontal_align or not _valid_alignment("horizontal_align",value): return
|
|
29
29
|
horizontal_align = value
|
|
30
30
|
_changed()
|
|
31
|
-
@export_enum("start", "center", "end", "stretch") var vertical_align: String = "start":
|
|
31
|
+
@export_enum("start", "center", "end", "stretch", "space-between", "space-around", "space-evenly") var vertical_align: String = "start":
|
|
32
32
|
set(value):
|
|
33
33
|
if _policy_commit:
|
|
34
34
|
vertical_align = value
|
|
@@ -6,6 +6,9 @@ extends Node2D
|
|
|
6
6
|
signal layout_applied(size: Vector2)
|
|
7
7
|
const Coordinator = preload("internal/coordinator.gd")
|
|
8
8
|
const ESTRAGON_LENGTHS := true
|
|
9
|
+
const ESTRAGON_MINIMUMS_2D := true
|
|
10
|
+
const ESTRAGON_ALIGN_SELF_2D := true
|
|
11
|
+
const AlignmentContract = preload("internal/stack_contract.gd")
|
|
9
12
|
const VisualStyle = preload("internal/visual_style_2d.gd")
|
|
10
13
|
var _visual_style = VisualStyle.new()
|
|
11
14
|
const Length = preload("internal/length.gd")
|
|
@@ -76,6 +79,16 @@ var padding_left: Variant = "auto":
|
|
|
76
79
|
if is_same(padding_left,value) or not lengths.assign("padding_left",value): return
|
|
77
80
|
padding_left = value
|
|
78
81
|
_changed()
|
|
82
|
+
var min_width: Variant = 0.0:
|
|
83
|
+
set(value):
|
|
84
|
+
if is_same(min_width,value) or not lengths.assign("min_width",value): return
|
|
85
|
+
min_width = value
|
|
86
|
+
_changed()
|
|
87
|
+
var min_height: Variant = 0.0:
|
|
88
|
+
set(value):
|
|
89
|
+
if is_same(min_height,value) or not lengths.assign("min_height",value): return
|
|
90
|
+
min_height = value
|
|
91
|
+
_changed()
|
|
79
92
|
var width: Variant = "auto":
|
|
80
93
|
set(value):
|
|
81
94
|
if is_same(width,value) or not lengths.assign("width",value): return
|
|
@@ -136,6 +149,15 @@ var margin_left: Variant = "auto":
|
|
|
136
149
|
if value not in [0,1] or value==stretch: return
|
|
137
150
|
stretch = value
|
|
138
151
|
_changed()
|
|
152
|
+
@export_enum("auto", "start", "center", "end", "stretch") var align_self: String = "auto":
|
|
153
|
+
set(value):
|
|
154
|
+
if value==align_self: return
|
|
155
|
+
var message := AlignmentContract.error("align_self",value,"")
|
|
156
|
+
if not message.is_empty():
|
|
157
|
+
push_error("Estragon alignment: "+message)
|
|
158
|
+
return
|
|
159
|
+
align_self = value
|
|
160
|
+
_changed()
|
|
139
161
|
@export var center: bool = false:
|
|
140
162
|
set(value):
|
|
141
163
|
if center == value: return
|
|
@@ -146,7 +168,7 @@ var layout_size: Vector2:
|
|
|
146
168
|
var _layout_size := Vector2.ZERO
|
|
147
169
|
var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
|
|
148
170
|
func _get_property_list() -> Array[Dictionary]:
|
|
149
|
-
var properties := Length.properties(["width","height","x","y","gap","padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"])
|
|
171
|
+
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"])
|
|
150
172
|
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"]))
|
|
151
173
|
return properties
|
|
152
174
|
static func valid_length(value) -> bool:
|
|
@@ -133,6 +133,7 @@ func changed() -> void:
|
|
|
133
133
|
if host.has_method("_layout_options"):
|
|
134
134
|
var options: Dictionary = host._layout_options()
|
|
135
135
|
model.set_policy(options.get("alignment",["start","start","start"]))
|
|
136
|
+
model.set_align_self(host.align_self if _dimension==2 and "align_self" in host else "auto")
|
|
136
137
|
if "lengths" in host:
|
|
137
138
|
for property in host._get_property_list():
|
|
138
139
|
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()))
|
|
@@ -10,6 +10,7 @@ signal arranged(size)
|
|
|
10
10
|
var length_specs: Dictionary = {}
|
|
11
11
|
var grow: float = 0.0
|
|
12
12
|
var stretch: int = 0
|
|
13
|
+
var align_self := "auto"
|
|
13
14
|
var pixels_per_unit: float = 1.0
|
|
14
15
|
var length_offset := Vector3.ZERO
|
|
15
16
|
var viewport_size := Vector2.ZERO
|
|
@@ -30,6 +31,8 @@ var fill := Vector3.ZERO
|
|
|
30
31
|
var intrinsic := Vector3.ZERO
|
|
31
32
|
# Native Control minimums constrain assigned slots, never read back from size.
|
|
32
33
|
var allocation_minimum := Vector3.ZERO
|
|
34
|
+
# Authored border-box floors are independent of native adapter minimums.
|
|
35
|
+
var authored_minimum := Vector3.ZERO
|
|
33
36
|
var padding := Vector4.ZERO # left, top, right, bottom; border-box insets
|
|
34
37
|
var border := Vector4.ZERO # inside the border-box, before padding
|
|
35
38
|
var margin := Vector4.ZERO # outside own geometry; consumed by the parent
|
|
@@ -70,6 +73,11 @@ func set_policy(values: Array) -> void:
|
|
|
70
73
|
alignment = values.duplicate()
|
|
71
74
|
invalidate()
|
|
72
75
|
|
|
76
|
+
func set_align_self(value: String) -> void:
|
|
77
|
+
if align_self==value: return
|
|
78
|
+
align_self = value
|
|
79
|
+
invalidate()
|
|
80
|
+
|
|
73
81
|
func _length(name: String, axis_index: int, fallback: float) -> float:
|
|
74
82
|
if not length_specs.has(name): return fallback
|
|
75
83
|
var spec: Dictionary = length_specs[name]
|
|
@@ -108,23 +116,35 @@ func prepare(reference: Vector3, viewport: Vector2) -> void:
|
|
|
108
116
|
if _length_context==context: return
|
|
109
117
|
_length_context = context
|
|
110
118
|
resolution_count += 1
|
|
111
|
-
var before := [requested,gap,padding,border,margin,length_offset]
|
|
119
|
+
var before := [requested,gap,padding,border,margin,length_offset,authored_minimum]
|
|
112
120
|
if not length_specs.is_empty():
|
|
113
121
|
for index in range(3):
|
|
114
122
|
requested[index] = _length(["width","height","depth"][index],index,requested[index])
|
|
115
123
|
length_offset[index] = _length(["x","y","z"][index],index,0)
|
|
124
|
+
authored_minimum = Vector3(maxf(0,_length("min_width",0,0)),maxf(0,_length("min_height",1,0)),0)
|
|
116
125
|
gap = _length("gap",axis,0)
|
|
117
126
|
padding = _edges("padding")
|
|
118
127
|
border = _edges("border")
|
|
119
128
|
margin = _edges("margin")
|
|
120
|
-
if before!=[requested,gap,padding,border,margin,length_offset]:
|
|
129
|
+
if before!=[requested,gap,padding,border,margin,length_offset,authored_minimum]:
|
|
121
130
|
_measure_dirty = true
|
|
122
131
|
_arrange_dirty = true
|
|
123
132
|
|
|
133
|
+
func minimum() -> Vector3:
|
|
134
|
+
var result := authored_minimum
|
|
135
|
+
var inherited: Vector3 = children[0].minimum() if transparent and children.size()==1 else Vector3.ZERO
|
|
136
|
+
for index in range(3): result[index] = maxf(result[index],maxf(allocation_minimum[index],inherited[index]))
|
|
137
|
+
return result
|
|
138
|
+
|
|
139
|
+
func constrain(extent: Vector3) -> Vector3:
|
|
140
|
+
var floor := minimum()
|
|
141
|
+
for index in range(3): extent[index] = maxf(extent[index],floor[index])
|
|
142
|
+
return extent
|
|
143
|
+
|
|
124
144
|
func _content_basis() -> Vector3:
|
|
125
145
|
var basis := Vector3(-1,-1,-1)
|
|
126
146
|
for index in range(3):
|
|
127
|
-
if requested[index]>=0: basis[index] = maxf(0,requested[index]-leading(padding+border)[index]-trailing(padding+border)[index])
|
|
147
|
+
if requested[index]>=0: basis[index] = maxf(0,maxf(requested[index],minimum()[index])-leading(padding+border)[index]-trailing(padding+border)[index])
|
|
128
148
|
return basis
|
|
129
149
|
|
|
130
150
|
static func valid_extent(value: Vector3) -> bool:
|
|
@@ -190,10 +210,11 @@ func measure() -> Vector3:
|
|
|
190
210
|
var child = children[0]
|
|
191
211
|
child.prepare(parent_reference,viewport_size)
|
|
192
212
|
child.measure()
|
|
193
|
-
if child.requested!=requested or child.grow!=grow or child.stretch!=stretch or child.margin!=margin or child.fill!=fill or child.length_offset!=length_offset:
|
|
213
|
+
if child.requested!=requested or child.grow!=grow or child.stretch!=stretch or child.align_self!=align_self or child.margin!=margin or child.fill!=fill or child.length_offset!=length_offset:
|
|
194
214
|
requested = child.requested
|
|
195
215
|
grow = child.grow
|
|
196
216
|
stretch = child.stretch
|
|
217
|
+
align_self = child.align_self
|
|
197
218
|
fill = child.fill
|
|
198
219
|
margin = child.margin
|
|
199
220
|
length_offset = child.length_offset
|
|
@@ -215,6 +236,7 @@ func measure() -> Vector3:
|
|
|
215
236
|
measured = natural
|
|
216
237
|
for axis in range(3):
|
|
217
238
|
if requested[axis] >= 0: measured[axis] = requested[axis]
|
|
239
|
+
measured = constrain(measured)
|
|
218
240
|
_measure_dirty = false
|
|
219
241
|
return measured
|
|
220
242
|
|
|
@@ -224,9 +246,12 @@ func independent_axis(index: int) -> bool:
|
|
|
224
246
|
if requested[index] >= 0 or _external_axes[index] > 0: return true
|
|
225
247
|
var parent = _parent.get_ref() if _parent != null else null
|
|
226
248
|
if parent == null: return false
|
|
227
|
-
|
|
249
|
+
var allocated := grow>0 or fill[index]>0
|
|
250
|
+
if index!=parent.axis: allocated = StackPolicy.cross_alignment({"align_self":align_self,"stretch":stretch,"fill":fill},parent.alignment[index],index)=="stretch"
|
|
251
|
+
return parent.independent_axis(index) if requested[index] < 0 and allocated else false
|
|
228
252
|
|
|
229
253
|
func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
254
|
+
available = constrain(available)
|
|
230
255
|
_external_axes = external_axes
|
|
231
256
|
_warn_unanchored()
|
|
232
257
|
var content := available-leading(padding+border)-trailing(padding+border)
|
|
@@ -280,7 +305,7 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
280
305
|
break
|
|
281
306
|
var items: Array = []
|
|
282
307
|
for child in children:
|
|
283
|
-
items.append({"preferred":child.measured,"minimum":child.
|
|
308
|
+
items.append({"preferred":child.measured,"minimum":child.minimum(),"requested":child.requested,"grow":child.grow,"stretch":child.stretch,"align_self":child.align_self,"fill":child.fill,"outer":child.outer_extent(),"leading":leading(child.margin)})
|
|
284
309
|
var policy := alignment.duplicate()
|
|
285
310
|
if center: policy[axis] = "center"
|
|
286
311
|
slots = StackPolicy.slots(items,content,axis,gap,policy)
|
|
@@ -293,6 +318,6 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
293
318
|
child.placed.emit(next)
|
|
294
319
|
var authority := Vector3.ZERO
|
|
295
320
|
for cross in range(3):
|
|
296
|
-
if cross!=axis and policy[cross]=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
|
|
321
|
+
if cross!=axis and StackPolicy.cross_alignment(items[index],policy[cross],cross)=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
|
|
297
322
|
child.arrange(slot.extent,authority)
|
|
298
323
|
arranged.emit(size)
|
|
@@ -7,6 +7,7 @@ extends RefCounted
|
|
|
7
7
|
const VisualStyle = preload("visual_style_2d.gd")
|
|
8
8
|
const LIMIT := 1.0e12
|
|
9
9
|
const FACTORS := {"":1.0,"px":1.0,"in":96.0,"cm":96.0/2.54,"mm":96.0/25.4,"q":96.0/101.6,"pt":96.0/72.0,"pc":16.0}
|
|
10
|
+
const MINIMUMS := ["min_width","min_height"]
|
|
10
11
|
const DIMENSIONS := ["width","height","depth"]
|
|
11
12
|
const BORDER_EDGES := ["border_top_width","border_right_width","border_bottom_width","border_left_width"]
|
|
12
13
|
const OFFSETS := ["x","y","z"]
|
|
@@ -16,6 +17,7 @@ var parse_count := 0
|
|
|
16
17
|
static func domain(name: String, script = null) -> String:
|
|
17
18
|
if name=="padding" and VisualStyle.marked(script,"ESTRAGON_BUTTON_STYLE"): return "edge"
|
|
18
19
|
if name in DIMENSIONS: return "extent"
|
|
20
|
+
if name in MINIMUMS: return "edge"
|
|
19
21
|
if name=="border_width": return "inset"
|
|
20
22
|
if name in BORDER_EDGES: return "edge"
|
|
21
23
|
if name in OFFSETS: return "offset"
|
|
@@ -23,6 +25,7 @@ static func domain(name: String, script = null) -> String:
|
|
|
23
25
|
return "inset" if name=="gap" else ""
|
|
24
26
|
static func registered(type, name: String) -> bool:
|
|
25
27
|
if domain(name).is_empty() or not type is Script: return false
|
|
28
|
+
if name in MINIMUMS and not VisualStyle.marked(type,"ESTRAGON_MINIMUMS_2D"): return false
|
|
26
29
|
if name=="border_width" or name in BORDER_EDGES:
|
|
27
30
|
if not VisualStyle.supported(type): return false
|
|
28
31
|
while type != null:
|
|
@@ -79,8 +82,8 @@ static func dependencies(specs: Dictionary, stack_axis: int) -> Array:
|
|
|
79
82
|
for name in specs:
|
|
80
83
|
var unit: String = specs[name].unit
|
|
81
84
|
if unit=="%":
|
|
82
|
-
if name in ["width","x","margin_left","margin_right","padding_left","padding_right","border_left_width","border_right_width"]: parent_axes.x = 1
|
|
83
|
-
elif name in ["height","y","margin_top","margin_bottom","padding_top","padding_bottom","border_top_width","border_bottom_width"]: parent_axes.y = 1
|
|
85
|
+
if name in ["width","min_width","x","margin_left","margin_right","padding_left","padding_right","border_left_width","border_right_width"]: parent_axes.x = 1
|
|
86
|
+
elif name in ["height","min_height","y","margin_top","margin_bottom","padding_top","padding_bottom","border_top_width","border_bottom_width"]: parent_axes.y = 1
|
|
84
87
|
elif name in ["depth","z"]: parent_axes.z = 1
|
|
85
88
|
elif name=="gap": parent_axes[stack_axis] = 1
|
|
86
89
|
else: parent_axes = Vector3(1,1,parent_axes.z)
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
extends RefCounted
|
|
3
|
+
const DISTRIBUTION := ["space-between","space-around","space-evenly"]
|
|
4
|
+
const SELF := ["auto","start","center","end","stretch"]
|
|
5
|
+
static func self_registered(script) -> bool:
|
|
6
|
+
while script is Script:
|
|
7
|
+
if script.get_script_constant_map().has("ESTRAGON_ALIGN_SELF_2D"): return true
|
|
8
|
+
script = script.get_base_script()
|
|
9
|
+
return false
|
|
3
10
|
## Shared static/preflight/native validation for the delivered Box policy.
|
|
4
11
|
static func registered(script) -> bool:
|
|
5
12
|
while script is Script:
|
|
@@ -12,10 +19,15 @@ static func preset(script) -> String:
|
|
|
12
19
|
script = script.get_base_script()
|
|
13
20
|
return ""
|
|
14
21
|
static func error(name: String, value, direction: String, fixed: String = "") -> String:
|
|
15
|
-
if name=="
|
|
22
|
+
if name=="align_self":
|
|
23
|
+
if value not in SELF: return "align_self requires auto, start, center, end or stretch"
|
|
24
|
+
elif name=="direction":
|
|
16
25
|
if value not in ["row","column"]: return "direction requires row or column"
|
|
17
26
|
if not fixed.is_empty() and value!=fixed: return "HBox/VBox direction is fixed; use Box to change direction"
|
|
18
27
|
elif name in ["horizontal_align","vertical_align"]:
|
|
19
|
-
if value not in ["start","center","end","stretch"]: return name+" requires start, center, end or cross-axis stretch
|
|
20
|
-
if
|
|
28
|
+
if value not in ["start","center","end","stretch"]+DISTRIBUTION: return name+" requires start, center, end, main-axis space-between/around/evenly or cross-axis stretch"
|
|
29
|
+
if direction in ["row","column"]:
|
|
30
|
+
var main := name==("horizontal_align" if direction=="row" else "vertical_align")
|
|
31
|
+
if main and value=="stretch": return "stretch is cross-axis only; use grow for remaining main-axis space"
|
|
32
|
+
if not main and value in DISTRIBUTION: return name+": space distribution is main-axis only"
|
|
21
33
|
return ""
|
|
@@ -12,7 +12,7 @@ static func slots(items: Array, content: Vector3, axis: int, gap: float, alignme
|
|
|
12
12
|
var extent: Vector3 = item.preferred
|
|
13
13
|
for index in range(3): extent[index] = maxf(extent[index],item.minimum[index])
|
|
14
14
|
for index in range(3):
|
|
15
|
-
if index != axis and item.requested[index]<0 and (item
|
|
15
|
+
if index != axis and item.requested[index]<0 and cross_alignment(item,alignment[index],index)=="stretch":
|
|
16
16
|
extent[index] = maxf(item.minimum[index],content[index]-item.outer[index])
|
|
17
17
|
# Native fill remains a zero-basis allocation with a native minimum floor.
|
|
18
18
|
if item.fill[axis]>0 and item.requested[axis]<0: extent[axis] = 0.0
|
|
@@ -23,7 +23,6 @@ static func slots(items: Array, content: Vector3, axis: int, gap: float, alignme
|
|
|
23
23
|
flexible.append(extents.size()-1)
|
|
24
24
|
var remaining := maxf(0,content[axis]-occupied)
|
|
25
25
|
var shares := {}
|
|
26
|
-
var total_weight := weight
|
|
27
26
|
# Preserve native expand minimum water-filling (70/20 minima in 100 ->70/30).
|
|
28
27
|
while not flexible.is_empty():
|
|
29
28
|
var constrained := false
|
|
@@ -42,18 +41,39 @@ static func slots(items: Array, content: Vector3, axis: int, gap: float, alignme
|
|
|
42
41
|
var item: Dictionary = items[index]
|
|
43
42
|
shares[index] = remaining*(item.grow if item.grow>0 else 1.0)/weight
|
|
44
43
|
break
|
|
45
|
-
|
|
44
|
+
# Growth/native minimum water-filling is complete before distribution. Count
|
|
45
|
+
# final extents and margins afresh: none of the allocated shares is free twice.
|
|
46
|
+
occupied = gap * maxi(0,items.size()-1)
|
|
47
|
+
for index in range(items.size()):
|
|
48
|
+
var extent: Vector3 = extents[index]
|
|
49
|
+
if shares.has(index): extent[axis] += shares[index]
|
|
50
|
+
extents[index] = extent
|
|
51
|
+
occupied += extent[axis]+items[index].outer[axis]
|
|
52
|
+
var free := maxf(0,content[axis]-occupied)
|
|
53
|
+
var cursor := free * factor(alignment[axis])
|
|
54
|
+
var extra_gap := 0.0
|
|
55
|
+
var count := items.size()
|
|
56
|
+
if alignment[axis]=="space-between" and count>1: extra_gap = free/(count-1)
|
|
57
|
+
elif alignment[axis]=="space-around" and count>0:
|
|
58
|
+
extra_gap = free/count
|
|
59
|
+
cursor = extra_gap/2
|
|
60
|
+
elif alignment[axis]=="space-evenly" and count>0:
|
|
61
|
+
extra_gap = free/(count+1)
|
|
62
|
+
cursor = extra_gap
|
|
46
63
|
var result: Array = []
|
|
47
64
|
for index in range(items.size()):
|
|
48
65
|
var item: Dictionary = items[index]
|
|
49
66
|
var extent: Vector3 = extents[index]
|
|
50
|
-
if shares.has(index): extent[axis] += shares[index]
|
|
51
67
|
var position: Vector3 = item.leading
|
|
52
68
|
position[axis] += cursor
|
|
53
69
|
for cross in range(3):
|
|
54
|
-
if cross != axis: position[cross] += maxf(0,content[cross]-extent[cross]-item.outer[cross])*factor(alignment[cross])
|
|
70
|
+
if cross != axis: position[cross] += maxf(0,content[cross]-extent[cross]-item.outer[cross])*factor(cross_alignment(item,alignment[cross],cross))
|
|
55
71
|
result.append({"position":position,"extent":extent})
|
|
56
|
-
cursor += extent[axis]+item.outer[axis]+gap
|
|
72
|
+
cursor += extent[axis]+item.outer[axis]+gap+extra_gap
|
|
57
73
|
return result
|
|
74
|
+
static func cross_alignment(item: Dictionary, parent: String, index: int) -> String:
|
|
75
|
+
var own: String = item.get("align_self","auto")
|
|
76
|
+
if own!="auto": return own
|
|
77
|
+
return "stretch" if item.stretch>0 or item.fill[index]>0 else parent
|
|
58
78
|
static func factor(value: String) -> float:
|
|
59
79
|
return 0.5 if value=="center" else (1.0 if value=="end" else 0.0)
|
|
@@ -29,9 +29,8 @@ func apply_layout_position(offset: Vector3) -> void:
|
|
|
29
29
|
position = Vector2(value.x, value.y)
|
|
30
30
|
|
|
31
31
|
func apply_layout_size(size: Vector3) -> void:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
layout_applied.emit(_layout_size)
|
|
32
|
+
# Preserve bounds-aware placement through the inherited native size/redraw hook.
|
|
33
|
+
super.apply_layout_size(size)
|
|
35
34
|
|
|
36
35
|
func get_native_bounds() -> Rect2:
|
|
37
36
|
return Rect2(Vector2(bounds.origin.x, bounds.origin.y), Vector2(bounds.extent.x, bounds.extent.y))
|
package/package.json
CHANGED