@papercraftgames/estragon 0.1.0-beta.23 → 0.1.0-beta.25

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 (34) hide show
  1. package/addons/estragon/compiler/composition.gd +10 -6
  2. package/addons/estragon/compiler/emitter.gd +12 -1
  3. package/addons/estragon/compiler/model.gd +1 -0
  4. package/addons/estragon/compiler/native/resolver.gd +11 -7
  5. package/addons/estragon/compiler/parser.gd +24 -7
  6. package/addons/estragon/compiler/validator.gd +83 -0
  7. package/addons/estragon/editor/completion.gd +11 -0
  8. package/addons/estragon/editor/components.gd +2 -0
  9. package/addons/estragon/editor/lexical_context.gd +5 -1
  10. package/addons/estragon/editor/plugin.cfg +1 -1
  11. package/addons/estragon/runtime/composition/computation.gd +90 -4
  12. package/addons/estragon/runtime/composition/element.gd +17 -0
  13. package/addons/estragon/runtime/composition/native_attributes.gd +3 -0
  14. package/addons/estragon/runtime/node/box.gd +16 -0
  15. package/addons/estragon/runtime/node/component_2d.gd +23 -1
  16. package/addons/estragon/runtime/node/grid.gd +73 -0
  17. package/addons/estragon/runtime/node/grid.gd.uid +1 -0
  18. package/addons/estragon/runtime/node/internal/composition_hosts.gd +37 -0
  19. package/addons/estragon/runtime/node/internal/coordinator.gd +11 -1
  20. package/addons/estragon/runtime/node/internal/grid_definition.gd +129 -27
  21. package/addons/estragon/runtime/node/internal/grid_policy.gd +69 -0
  22. package/addons/estragon/runtime/node/internal/grid_policy.gd.uid +1 -0
  23. package/addons/estragon/runtime/node/internal/layout_core.gd +219 -11
  24. package/addons/estragon/runtime/node/internal/length.gd +12 -5
  25. package/addons/estragon/runtime/node/internal/pointer_2d.gd +11 -1
  26. package/addons/estragon/runtime/node/internal/scroll_input.gd +59 -0
  27. package/addons/estragon/runtime/node/internal/scroll_input.gd.uid +1 -0
  28. package/addons/estragon/runtime/node/internal/stack_contract.gd +3 -1
  29. package/addons/estragon/runtime/node/internal/stack_policy.gd +16 -0
  30. package/addons/estragon/runtime/node/internal/wrap_policy.gd +59 -0
  31. package/addons/estragon/runtime/node/internal/wrap_policy.gd.uid +1 -0
  32. package/addons/estragon/runtime/node/scroll_view.gd +193 -0
  33. package/addons/estragon/runtime/node/scroll_view.gd.uid +1 -0
  34. package/package.json +1 -1
@@ -13,12 +13,16 @@ func apply(module) -> void:
13
13
  resolver.scan(module)
14
14
  var lexer := Lexer.new(file)
15
15
  var tokens: Array = []
16
- var cursor := 0
17
- while cursor < file.text.length():
18
- var token = lexer.next_token(cursor)
19
- if token == null: return
20
- cursor = token.span.end.index
21
- if token.kind not in ["whitespace","newline","comment","continuation"]: tokens.append(token)
16
+ # Only code spans contain declarations. Literal markup bodies are not GDScript
17
+ # (quotes, punctuation and Unicode must never enter its token scanner).
18
+ for part in module.parts:
19
+ if not part is Model.Code: continue
20
+ var cursor: int = part.span.start.index
21
+ while cursor<part.span.end.index:
22
+ var token = lexer.next_token(cursor)
23
+ if token==null: return
24
+ cursor = token.span.end.index
25
+ if token.kind not in ["whitespace","newline","comment","continuation"]: tokens.append(token)
22
26
  var has_ggx := false
23
27
  for part in module.parts:
24
28
  if part is Model.Component: has_ggx = true
@@ -87,7 +87,7 @@ static func _string(value: String) -> String:
87
87
  return output + '"'
88
88
 
89
89
  static func literal(value: Model.Literal) -> String:
90
- return _string(value.value)
90
+ return ("true" if value.value else "false") if value.value is bool else _string(value.value)
91
91
 
92
92
  func _argument(expression: Model.GdExpression, type_name: String, factory: Factory) -> void:
93
93
  var argument := Argument.new()
@@ -103,6 +103,8 @@ func _collect(node: Model.Component, factory: Factory) -> void:
103
103
  _argument(attribute.value, attribute.type_name, factory)
104
104
  factory.arguments.back().spread = attribute.kind=="spread"
105
105
  if attribute.kind=="binding": factory.arguments.back().binding_path = attribute.binding_path
106
+ for part in node.text_body:
107
+ if part is Model.GdExpression: _argument(part,"Variant",factory)
106
108
  for child in node.children:
107
109
  if child is Model.GdExpression: _argument(child,"Variant",factory)
108
110
  else: _collect(child, factory)
@@ -197,7 +199,16 @@ func _description(node: Model.Component, indentation: String) -> String:
197
199
  children.append(_arguments[child].name if child is Model.GdExpression else _description(child,indentation))
198
200
  var native_type := _string(node.runtime_class) if ClassDB.class_exists(node.runtime_class) else node.runtime_class
199
201
  _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)
202
+ for attribute in node.attributes:
203
+ 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)
204
+
200
205
  if expanded: _line(variable+".expand(["+", ".join(ordered)+"])",node.span,indentation)
206
+ if not node.text_body.is_empty():
207
+ var parts := PackedStringArray()
208
+ for part in node.text_body:
209
+ var value: String = _arguments[part].name if part is Model.GdExpression else literal(part)
210
+ parts.append("[%s, %s]" % [value,_string("%s:%d:%d" % [_file.name,part.span.start.line,part.span.start.column])])
211
+ _line(variable+".set_text_body(["+", ".join(parts)+"])",node.span,indentation)
201
212
  if not bindings.is_empty(): _line(variable+".bindings = {"+", ".join(bindings)+"}",node.span,indentation)
202
213
  return variable
203
214
 
@@ -71,6 +71,7 @@ class Component extends SyntaxNode:
71
71
  var runtime_class: String
72
72
  var attributes: Array[Attribute] = []
73
73
  var children: Array[SyntaxNode] = []
74
+ var text_body: Array[SyntaxNode] = []
74
75
  func _init() -> void:
75
76
  kind = "component-expression"
76
77
 
@@ -175,12 +175,16 @@ func _gogo(name: String, path: String, authored: String, span: Model.Span, check
175
175
  imported.scan(module)
176
176
  var lexer := Lexer.new(source)
177
177
  var tokens: Array = []
178
- var cursor := 0
179
- while cursor < source.text.length():
180
- var token = lexer.next_token(cursor)
181
- if token == null: break
182
- cursor = token.span.end.index
183
- if token.kind not in ["whitespace","comment","newline","continuation"]: tokens.append(token)
178
+ # Declarations belong to GDScript Code spans. Body punctuation/quotes are
179
+ # markup data and must never enter the GDScript lexer during import lookup.
180
+ for part in module.parts:
181
+ if not part is Model.Code: continue
182
+ var cursor: int = part.span.start.index
183
+ while cursor < part.span.end.index:
184
+ var token = lexer.next_token(cursor)
185
+ if token == null: break
186
+ cursor = token.span.end.index
187
+ if token.kind not in ["whitespace","comment","newline","continuation"]: tokens.append(token)
184
188
  var base := {}
185
189
  var declared_name := ""
186
190
  for index in range(tokens.size()-1):
@@ -241,7 +245,7 @@ func _gogo(name: String, path: String, authored: String, span: Model.Span, check
241
245
  if type==declared_name: qualified = name
242
246
  elif ClassDB.class_exists(type.get_slice(".",0)) or imported.globals.has(type.get_slice(".",0)): qualified = type
243
247
  else: qualified = name+"."+type
244
- properties[part.name] = {"name":part.name,"type":kind,"class_name":qualified,"usage":PROPERTY_USAGE_DEFAULT}
248
+ properties[part.name] = {"name":part.name,"type":kind,"class_name":qualified,"usage":PROPERTY_USAGE_DEFAULT,"source_writable":true}
245
249
  if not part.signal_name.is_empty(): signals[part.signal_name] = {"name":part.signal_name}
246
250
  if check_constructor and required: return _fail("GGX construction requires a zero-argument initializer: "+name,span)
247
251
  return {"native":base.native,"script":base.script,"properties":properties,"signals":signals,"required_initializer":required,"gogo_path":path}
@@ -102,13 +102,23 @@ func _component(depth: int) -> Model.Component:
102
102
  continue
103
103
  var attribute_name := _name()
104
104
  if attribute_name == null: return null
105
+ var after_name := _cursor
105
106
  _whitespace()
106
- if not _take("="): return null
107
- _whitespace()
107
+ var bare := not _at("=")
108
+ if not bare:
109
+ if not _take("="): return null
110
+ _whitespace()
111
+ else: _cursor = after_name
108
112
  var attribute := Model.Attribute.new()
109
113
  attribute.name = attribute_name.text
110
114
  attribute.name_span = attribute_name.span
111
- if _at("{"):
115
+ if bare:
116
+ attribute.kind = "boolean-shorthand"
117
+ var value := Model.Literal.new()
118
+ value.value = true
119
+ value.span = attribute.name_span
120
+ attribute.value = value
121
+ elif _at("{"):
112
122
  attribute.value = _expression()
113
123
  else:
114
124
  var quote := lexer.char_at(_cursor)
@@ -135,20 +145,27 @@ func _component(depth: int) -> Model.Component:
135
145
  if attribute.value == null: return null
136
146
  attribute.span = file.span(attribute.name_span.start.index,_cursor)
137
147
  node.attributes.append(attribute)
138
- _trivia()
139
148
  while not _at("</") and file.diagnostics.is_empty():
140
149
  if _cursor >= file.text.length():
141
150
  file.fail("Missing closing tag </%s>" % node.name, _cursor)
142
151
  return null
143
152
  var child: Model.SyntaxNode
144
153
  if _at("{"): child = _expression()
154
+ elif _at("<!--"):
155
+ _trivia()
156
+ continue
145
157
  elif _at("<"): child = _component(depth + 1)
146
158
  else:
147
- file.fail("GGX children must be Node elements", _cursor)
148
- return null
159
+ var text_start := _cursor
160
+ while _cursor<file.text.length() and not _at("<") and not _at("{"): _cursor += 1
161
+ var literal := Model.Literal.new()
162
+ literal.kind = "body-text"
163
+ literal.value = file.text.substr(text_start,_cursor-text_start)
164
+ literal.span = file.span(text_start,_cursor)
165
+ lexer.token("markup-text",text_start,_cursor)
166
+ child = literal
149
167
  if child == null: return null
150
168
  node.children.append(child)
151
- _trivia()
152
169
  if not file.diagnostics.is_empty() or not _take("</"): return null
153
170
  var closing := _name()
154
171
  if closing == null: return null
@@ -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")
@@ -60,6 +61,9 @@ func _component(node: Model.Component) -> void:
60
61
  _node(attribute.value)
61
62
  continue
62
63
  var name := attribute.name
64
+ if VisualStyle.marked(resolved.script,"ESTRAGON_SCROLL_VIEW") and name in ["scroll_range","content_extent"]:
65
+ _error("Read-only ScrollView measurement: "+name,attribute.name_span)
66
+ return
63
67
  if VisualStyle.property(name) and VisualStyle.has_api(resolved.script) and not VisualStyle.supported(resolved.script):
64
68
  _error("Shared visual styling is unsupported on this participant",attribute.name_span)
65
69
  return
@@ -67,6 +71,12 @@ func _component(node: Model.Component) -> void:
67
71
  _error("Duplicate Node property or signal " + name, attribute.name_span)
68
72
  return
69
73
  seen[name] = true
74
+ if attribute.kind=="boolean-shorthand":
75
+ if name in ["key","bind:value"] or signals.has(name) or not properties.has(name) or properties[name].type!=TYPE_BOOL or not NativeAttributes.writable(resolved.native,resolved.script,name,properties[name]):
76
+ _error("Valueless attribute requires a writable native Bool property: "+name,attribute.name_span)
77
+ return
78
+ attribute.type_name = "bool"
79
+ continue
70
80
  if name.begins_with("bind:"):
71
81
  _binding(attribute,node,properties,signals)
72
82
  if not file.diagnostics.is_empty(): return
@@ -93,6 +103,9 @@ func _component(node: Model.Component) -> void:
93
103
  _error("Inline anonymous GGX handlers are not supported; use a named handler/Callable", token.span)
94
104
  return
95
105
  index = token.span.end.index
106
+ elif name in GridDefinition.PLACEMENT and not properties.has(name):
107
+ attribute.kind = "placement"
108
+ attribute.type_name = "String" if attribute.value is Model.Literal and name=="area" else "Variant"
96
109
  elif properties.has(name) and NativeAttributes.writable(resolved.native,resolved.script,name,properties[name]):
97
110
  attribute.type_name = "Variant" if Length.registered(resolved.script,name) or VisualStyle.registered(resolved.script,name) else _native_type(properties[name])
98
111
  if attribute.type_name.is_empty():
@@ -106,11 +119,23 @@ func _component(node: Model.Component) -> void:
106
119
  if not message.is_empty():
107
120
  _error(message,attribute.value.span)
108
121
  return
122
+ if not expanded and GridDefinition.marked(resolved.script) and attribute.value is Model.Literal:
123
+ if name in ["horizontal_align","vertical_align"] and attribute.value.value not in ["start","center","end","stretch"]:
124
+ _error("Grid per-cell "+name+" requires start/center/end/stretch",attribute.value.span)
125
+ return
126
+ if name=="template":
127
+ var parsed := GridDefinition.resolve(null,null,[],str(attribute.value.value))
128
+ if parsed.has("error"):
129
+ _error("Grid template: "+parsed.error,attribute.value.span)
130
+ return
109
131
  if name=="align_self" and StackContract.self_registered(resolved.script) and attribute.value is Model.Literal:
110
132
  var message := StackContract.error(name,attribute.value.value,"")
111
133
  if not message.is_empty():
112
134
  _error(message,attribute.value.span)
113
135
  return
136
+ 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"]:
137
+ _error("Grid "+name+" requires start, center, end or stretch",attribute.value.span)
138
+ return
114
139
  var is_color := VisualStyle.registered(resolved.script,name)
115
140
  if is_color:
116
141
  _color(attribute)
@@ -130,6 +155,47 @@ func _component(node: Model.Component) -> void:
130
155
  attribute.value.type_name = attribute.type_name
131
156
  else:
132
157
  _node(attribute.value)
158
+ var has_literal := node.children.any(func(child): return child is Model.Literal and not str(child.value).strip_edges().is_empty())
159
+ var has_expression := node.children.any(func(child): return child is Model.GdExpression)
160
+ var text_eligible: bool = properties.has("text") and properties.text.type==TYPE_STRING and NativeAttributes.writable(resolved.native,resolved.script,"text",properties.text)
161
+ if has_literal or text_eligible and has_expression:
162
+ if not text_eligible:
163
+ _error("Literal text requires a writable String text property",node.children[0].span)
164
+ return
165
+ if seen.has("text"):
166
+ _error("Text body conflicts with explicit text property",node.name_span)
167
+ return
168
+ for index in range(node.children.size()):
169
+ var child = node.children[index]
170
+ if child is Model.Component:
171
+ _error("Text body cannot mix nested Element children; use a layout container",child.span)
172
+ return
173
+ if child is Model.Literal:
174
+ var raw: String = str(child.value)
175
+ child.value = _body_whitespace(raw)
176
+ if raw.contains("\n"):
177
+ var lines := raw.split("\n")
178
+ if index>0 and node.children[index-1] is Model.GdExpression and lines[0].strip_edges().is_empty() and not str(child.value).is_empty(): child.value = " "+child.value
179
+ if index<node.children.size()-1 and node.children[index+1] is Model.GdExpression and lines[-1].strip_edges().is_empty() and (not str(child.value).is_empty() or index>0 and node.children[index-1] is Model.GdExpression): child.value += " "
180
+ child.kind = "string-literal"
181
+ else:
182
+ _node(child)
183
+ var tokens := _expression_tokens(child)
184
+ if tokens.size()==1 and (tokens[0].kind=="number" or tokens[0].text in ["true","false","null","NAN","INF"]):
185
+ _error("Text body expression requires String; use explicit str(value)",child.span)
186
+ return
187
+ if child.parts.any(func(part): return part is Model.Component):
188
+ _error("Text body expressions require String, not Element children",child.span)
189
+ return
190
+ node.text_body.append(child)
191
+ node.children.clear()
192
+ else:
193
+ for index in range(node.children.size()-1,-1,-1):
194
+ if node.children[index] is Model.Literal: node.children.remove_at(index)
195
+ if VisualStyle.marked(resolved.script,"ESTRAGON_SCROLL_VIEW"):
196
+ if node.children.is_empty() or node.children.size()>1 and node.children.all(func(child): return child is Model.Component):
197
+ _error("ScrollView requires exactly one content root; use an explicit VBox or Grid",node.name_span)
198
+ return
133
199
  var sibling_names := {}
134
200
  for child in node.children:
135
201
  if child is Model.GdExpression:
@@ -140,6 +206,11 @@ func _component(node: Model.Component) -> void:
140
206
  _error("Node GGX children must be newly declared Node elements; expression adoption is unsupported", child.span)
141
207
  return
142
208
  _node(child)
209
+ if not GridDefinition.marked(resolved.script):
210
+ for attribute in child.attributes:
211
+ if attribute.kind=="placement":
212
+ _error("GGX placement "+attribute.name+" requires a Grid parent",attribute.name_span)
213
+ return
143
214
  if child is Model.Component and not child.attributes.any(func(item): return item.kind=="spread"):
144
215
  for attribute in child.attributes:
145
216
  if attribute.name=="name" and attribute.value is Model.Literal:
@@ -350,3 +421,15 @@ func _color(attribute) -> void:
350
421
  if parsed.has("error"): _error(parsed.error,value.span)
351
422
  elif tokens.size()==1 and (tokens[0].kind=="number" or tokens[0].text in ["true","false","null","NAN","INF"]):
352
423
  _error("Style color requires a native Color or validated hex/transparent string",value.span)
424
+
425
+ # JSX-like source line folding; inline spaces/Unicode remain ordinary String bytes.
426
+ func _body_whitespace(value: String) -> String:
427
+ if not value.contains("\n") and not value.contains("\r"): return value
428
+ var lines := value.replace("\r\n","\n").replace("\r","\n").replace("\t"," ").split("\n")
429
+ var words: Array[String] = []
430
+ for index in range(lines.size()):
431
+ var line: String = lines[index]
432
+ if index>0: line = line.strip_edges(true,false)
433
+ if index<lines.size()-1: line = line.strip_edges(false,true)
434
+ if not line.is_empty(): words.append(line)
435
+ return " ".join(words)
@@ -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,8 @@
2
2
  extends RefCounted
3
3
  ## Trusted installed resources, not guessed global classes or installation roots.
4
4
  const ITEMS := [
5
+ {"alias":"ScrollView","canonical":"EstragonScrollView","script":preload("../runtime/node/scroll_view.gd"),"dimension":2,"origin":"native viewport"},
6
+ {"alias":"Grid","canonical":"EstragonGrid","script":preload("../runtime/node/grid.gd"),"dimension":2,"origin":"native layout"},
5
7
  {"alias":"Spacer","canonical":"EstragonSpacer","script":preload("../runtime/node/spacer.gd"),"dimension":2,"origin":"native layout"},
6
8
  {"alias":"Box","canonical":"EstragonBox","script":preload("../runtime/node/box.gd"),"dimension":2,"origin":"native layout"},
7
9
  {"alias":"Text","canonical":"EstragonText","script":preload("../runtime/node/text.gd"),"dimension":2,"origin":"native widget"},
@@ -33,7 +33,7 @@ func context(index: int, column: int) -> Dictionary:
33
33
  var result := scan(lines[index].left(column), state, false)
34
34
  var end: Dictionary = result.state
35
35
  end["tokens"] = result.tokens
36
- end["suppressed"] = end.comment or not end.quote.is_empty()
36
+ end["suppressed"] = end.comment or not end.quote.is_empty() or end.mode=="body"
37
37
  return end
38
38
 
39
39
  static func _add(tokens: Array, kind: String, start: int, end: int, word: String, native: bool = true) -> void:
@@ -76,6 +76,10 @@ func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
76
76
  if not newline: state.comment = true
77
77
  i = text.length()
78
78
  continue
79
+ if state.mode=="body" and ch not in ["<","{"]:
80
+ while i<text.length() and text[i] not in ["<","{"]: i += 1
81
+ _add(tokens,"string",start,i,text.substr(start,i-start),false)
82
+ continue
79
83
  if ch in ['"',"'"]:
80
84
  state.quote = ch.repeat(3) if text.substr(i,3) == ch.repeat(3) else ch
81
85
  i += state.quote.length()
@@ -3,5 +3,5 @@
3
3
  name="Estragon"
4
4
  description="Native Gogo/GGX highlighting, compilation and validation before Play."
5
5
  author="Resist Design"
6
- version="0.1.0-beta.23"
6
+ version="0.1.0-beta.25"
7
7
  script="plugin.gd"
@@ -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()
@@ -296,6 +299,7 @@ func _boundary_clear(desired: Element, parent: Node) -> bool:
296
299
  if str(child.name)==name: return false
297
300
  return true
298
301
  func _mount(desired: Element, parent: Node, owner: Node) -> Mounted:
302
+ if parent.has_method("_composition_child_parent"): parent = parent._composition_child_parent()
299
303
  var record := Mounted.new()
300
304
  if desired.borrowed != null:
301
305
  record.borrowed = desired.borrowed
@@ -342,13 +346,19 @@ func _apply(desired: Element, record: Mounted) -> void:
342
346
  writes += 1
343
347
  if Profile.is_enabled(): Profile.add("property_writes")
344
348
  binding.attach(node,self)
349
+ Hosts.set_placement(node,desired.placement)
350
+ var grid := GridDefinition.marked(desired.type)
351
+ if grid:
352
+ node._apply_grid(_grid_config(desired))
345
353
  var stack := StackContract.registered(desired.type)
354
+ var scroll := VisualStyle.marked(desired.type,"ESTRAGON_SCROLL_VIEW")
346
355
  if stack:
347
356
  var policy := resets.duplicate()
348
357
  policy.merge(desired.properties,true)
349
358
  node._apply_stack_policy(policy)
350
359
  for key in resets:
351
- if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,resets[key])
360
+ if scroll and key=="scroll_offset": continue
361
+ 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
362
  writes += 1
353
363
  if Profile.is_enabled(): Profile.add("property_writes")
354
364
  # An omitted previously declared border side removes that local override;
@@ -365,15 +375,28 @@ func _apply(desired: Element, record: Mounted) -> void:
365
375
  node.set(key,0.0)
366
376
  writes += 1
367
377
  if Profile.is_enabled(): Profile.add("property_writes")
378
+ if Length.registered(desired.type,"max_width"):
379
+ for key in Length.MAXIMUMS:
380
+ if record.properties.has(key) and not desired.properties.has(key): node.set(key,"auto")
368
381
  if StackContract.self_registered(desired.type) and record.properties.has("align_self") and not desired.properties.has("align_self"):
369
382
  node.set("align_self","auto")
370
383
  writes += 1
371
384
  if Profile.is_enabled(): Profile.add("property_writes")
372
385
  for key in desired.properties:
386
+ if scroll and key=="scroll_offset": continue
373
387
  if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
374
388
  if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
375
389
  writes += 1
376
390
  if Profile.is_enabled(): Profile.add("property_writes")
391
+ # Apply the effective authored offset after geometry/axis flags. A dirty
392
+ # ScrollView retains it until the same core's next arrangement, so attribute
393
+ # order cannot clamp restoration against the previous viewport range.
394
+ if scroll:
395
+ var offset = desired.properties if desired.properties.has("scroll_offset") else resets
396
+ if offset.has("scroll_offset") and (not desired.properties.has("scroll_offset") or not record.properties.has("scroll_offset") or not is_same(record.properties.scroll_offset,offset.scroll_offset)):
397
+ node.set("scroll_offset",offset.scroll_offset)
398
+ writes += 1
399
+ if Profile.is_enabled(): Profile.add("property_writes")
377
400
  for event in record.handlers:
378
401
  if not desired.handlers.has(event) or record.handlers[event]!=desired.handlers[event]:
379
402
  if node.is_connected(event,record.handlers[event]):
@@ -395,7 +418,7 @@ func _spread_resets(desired: Element, record) -> Dictionary:
395
418
  if record==null or not _compatible(desired,record): return result
396
419
  var node = record.node.get_ref()
397
420
  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
421
+ 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 or key in Length.MAXIMUMS: continue
399
422
  # Do not overwrite imperative native changes made since our last commit.
400
423
  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
424
  return result
@@ -430,6 +453,7 @@ func _compatible(desired: Element, record: Mounted) -> bool:
430
453
  return desired.borrowed != null and record.borrowed != null and desired.borrowed.get_ref() != null and desired.borrowed.get_ref() == record.node.get_ref()
431
454
  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
432
455
  func _reconcile(desired, record, parent: Node, owner: Node):
456
+ if parent.has_method("_composition_child_parent"): parent = parent._composition_child_parent()
433
457
  if Profile.is_enabled(): Profile.add("reconciles")
434
458
  if desired == null:
435
459
  if record != null: _free_managed(record,owner)
@@ -462,6 +486,7 @@ func _reconcile(desired, record, parent: Node, owner: Node):
462
486
  # Release names that must change before applying final sibling names. Native
463
487
  # Node otherwise silently renames a valid swap against the still-old sibling.
464
488
  func _prepare_names(desired: Array, matches: Array, parent: Node) -> void:
489
+ if parent.has_method("_composition_child_parent"): parent = parent._composition_child_parent()
465
490
  var pending: Array = []
466
491
  var targets := {}
467
492
  for index in range(desired.size()):
@@ -486,6 +511,7 @@ func _prepare_names(desired: Array, matches: Array, parent: Node) -> void:
486
511
  # Keep a longest increasing subsequence of actual native indices. Everything
487
512
  # else moves once, right to left beside its final successor; no-op moves zero.
488
513
  func _order(children: Array, parent: Node) -> void:
514
+ if parent.has_method("_composition_child_parent"): parent = parent._composition_child_parent()
489
515
  var nodes: Array = []
490
516
  for child in children:
491
517
  if child!=null and child.borrowed == null: nodes.append(child.node.get_ref())
@@ -526,6 +552,12 @@ func _order(children: Array, parent: Node) -> void:
526
552
  if Profile.is_enabled(): Profile.add("moves")
527
553
  anchor = actual
528
554
 
555
+ func _grid_config(desired: Element) -> Dictionary:
556
+ var result := {"columns":null,"rows":null,"areas":[],"template":"","horizontal_align":"stretch","vertical_align":"stretch"}
557
+ for key in GRID_CONFIG:
558
+ if desired.properties.has(key): result[key] = desired.properties[key]
559
+ return result
560
+
529
561
  func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> bool:
530
562
  if Profile.is_enabled(): Profile.add("preflights")
531
563
  if desired == null: return true
@@ -556,12 +588,62 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
556
588
  policy.merge(desired.properties,true)
557
589
  var fixed := StackContract.preset(desired.type)
558
590
  var direction = policy.get("direction",fixed if not fixed.is_empty() else "row")
559
- for key in ["direction","horizontal_align","vertical_align"]:
591
+ for key in ["direction","horizontal_align","vertical_align","align_content"]:
560
592
  var value = policy.get(key,direction if key=="direction" else "start")
561
593
  var message := StackContract.error(key,value,str(direction),fixed)
562
594
  if not message.is_empty():
563
595
  validation_error = desired.location(key)+": "+message+"; previous tree retained"
564
596
  return false
597
+ if VisualStyle.marked(desired.type,"ESTRAGON_SCROLL_VIEW"):
598
+ var content: Array = desired.children.filter(func(child): return child!=null)
599
+ if content.size()!=1: return _invalid_attribute(desired,"children","ScrollView requires exactly one content root; use an explicit VBox or Grid")
600
+ if desired.properties.has("scroll_offset") and not preload("../node/scroll_view.gd").valid_offset(desired.properties.scroll_offset): return _invalid_attribute(desired,"scroll_offset","requires a finite nonnegative Vector2")
601
+ for key in ["scroll_range","content_extent"]:
602
+ if desired.properties.has(key): return _invalid_attribute(desired,key,"read-only ScrollView measurement")
603
+ var child = content[0]
604
+ var type = child.type if child.borrowed==null else child.borrowed.get_ref().get_script()
605
+ var native: String = (child.type if child.type is String else child.type.get_instance_base_type()) if child.borrowed==null else child.borrowed.get_ref().get_class()
606
+ if not ClassDB.is_parent_class(native,"Control") and not (ClassDB.is_parent_class(native,"Node2D") and (Length.registered(type,"width") or GridDefinition.component(type))): return _invalid_attribute(child,"children","ScrollView content needs a bounded native 2D participant, Control or Gogo component")
607
+ if GridDefinition.marked(desired.type):
608
+ var config := _grid_config(desired)
609
+ var grid_matches := _matches(desired.children,previous.children if previous!=null and _compatible(desired,previous) else [])
610
+ var placements: Array = []
611
+ var grid_children: Array = []
612
+ for child in desired.children:
613
+ if child==null: continue
614
+ if child.borrowed==null:
615
+ for key in GridDefinition.PLACEMENT:
616
+ if child.properties.has(key):
617
+ child.placement[key] = child.properties[key]
618
+ child.properties.erase(key)
619
+ child.spread_properties.erase(key)
620
+ var native: String = child.type if child.type is String else child.type.get_instance_base_type()
621
+ 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))):
622
+ return _invalid_attribute(child,"area","Grid child requires a native 2D layout participant, Control or Gogo component")
623
+ if child.borrowed!=null:
624
+ var borrowed: Node = child.borrowed.get_ref()
625
+ 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")
626
+ 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())
627
+ if ClassDB.is_parent_class(native,"Control"):
628
+ var values := {}
629
+ var old = grid_matches[desired.children.find(child)]
630
+ var existing = child.borrowed.get_ref() if child.borrowed!=null else (old.node.get_ref() if old!=null else null)
631
+ if existing!=null:
632
+ 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()
633
+ values.merge(child.properties,true)
634
+ var message := GridDefinition.control_error(values)
635
+ if not message.is_empty():
636
+ var field := "area"
637
+ for key in ["anchor_left","anchor_right","anchor_top","anchor_bottom","rotation","scale","pivot_offset","top_level"]:
638
+ if child.properties.has(key): field = key
639
+ return _invalid_attribute(child,field,message)
640
+ placements.append(child.placement)
641
+ grid_children.append(child)
642
+ var parsed := GridDefinition.configuration(config,placements)
643
+ if parsed.has("error"):
644
+ var origin = grid_children[parsed.item] if parsed.has("item") else desired
645
+ var key: String = str(origin.placement.keys()[0]) if parsed.has("item") and not origin.placement.is_empty() else parsed.get("field","columns")
646
+ return _invalid_attribute(origin,key,parsed.error)
565
647
  if VisualStyle.rect_conflict(desired.type,desired.properties.keys()):
566
648
  validation_error = desired.location("fill")+": Rect fill and background_color conflict; previous tree retained"
567
649
  return false
@@ -639,6 +721,7 @@ func _free_managed(record: Mounted, rescue: Node = null) -> void:
639
721
  if child != null: _free_managed(child,rescue)
640
722
  var node = record.node.get_ref()
641
723
  if node == null:
724
+ Hosts.clear_placement(record.id)
642
725
  state.get_ref().managed.erase(record.id)
643
726
  return
644
727
  for binding in record.bindings.values(): binding.disconnect_edit()
@@ -649,12 +732,14 @@ func _free_managed(record: Mounted, rescue: Node = null) -> void:
649
732
  var manager = state.get_ref()
650
733
  if manager != null and manager.records.has(node.get_instance_id()): manager.unmount(node,owner)
651
734
  for child in node.get_children():
735
+ if node.has_method("_composition_is_private") and node._composition_is_private(child): continue
652
736
  var persisted_owner: Node = child.owner
653
737
  node.remove_child(child)
654
738
  if owner != null:
655
739
  owner.add_child(child)
656
740
  if persisted_owner != null and persisted_owner.is_ancestor_of(child): child.owner = persisted_owner
657
741
  var id: int = node.get_instance_id()
742
+ Hosts.set_placement(node,{})
658
743
  node.free()
659
744
  if manager != null: manager.managed.erase(id)
660
745
  frees += 1
@@ -692,4 +777,5 @@ func _projection_tree(record, projected: Dictionary, ordering: Dictionary) -> vo
692
777
  func _unindex(record) -> void:
693
778
  if record == null or record.borrowed != null: return
694
779
  state.get_ref().managed.erase(record.id)
780
+ Hosts.clear_placement(record.id)
695
781
  for child in record.children: _unindex(child)
@@ -6,6 +6,7 @@ const Profile = preload("profile.tres")
6
6
  var borrowed: WeakRef
7
7
  var type: Variant
8
8
  var properties: Dictionary
9
+ var placement: Dictionary = {}
9
10
  var bindings: Dictionary = {}
10
11
  var handlers: Dictionary
11
12
  var children: Array
@@ -69,3 +70,19 @@ func _init(native_type: Variant = null, props: Dictionary = {}, events: Dictiona
69
70
  handlers = events
70
71
  children = descendants
71
72
  source = location
73
+
74
+ # Called after ordered explicit/spread attributes, before desired-tree preflight.
75
+ # No conversion: a dynamic non-String rejects the entire description transaction.
76
+ func set_text_body(parts: Array) -> void:
77
+ if not attribute_error.is_empty(): return
78
+ if properties.has("text"):
79
+ attribute_error = location("text")+": text property conflicts with text body; previous tree retained"
80
+ return
81
+ var value := ""
82
+ for part in parts:
83
+ if not part[0] is String:
84
+ attribute_error = str(part[1])+": text body expression requires String; previous tree retained"
85
+ return
86
+ value += part[0]
87
+ properties["text"] = value
88
+ origins["text"] = parts[0][1] if not parts.is_empty() else source
@@ -15,6 +15,9 @@ const BASELINE_READ_ONLY := {
15
15
  static func writable(native: String, script, name: String, property: Dictionary) -> bool:
16
16
  if name in ["owner","script"] or name.contains("/"): return false
17
17
  if int(property.usage)&(PROPERTY_USAGE_READ_ONLY|PROPERTY_USAGE_CATEGORY|PROPERTY_USAGE_GROUP|PROPERTY_USAGE_SUBGROUP): return false
18
+ # Source-resolved Gogo fields belong to the authored subtype, not the native
19
+ # base Script used for metadata lookup. They have ordinary GDScript setters.
20
+ if property.get("source_writable",false): return true
18
21
  while script is Script:
19
22
  for field in script.get_script_property_list():
20
23
  if str(field.name)==name: return true
@@ -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":
@@ -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