@papercraftgames/estragon 0.1.0-beta.24 → 0.1.0-beta.26
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/composition.gd +10 -6
- package/addons/estragon/compiler/emitter.gd +9 -1
- package/addons/estragon/compiler/model.gd +1 -0
- package/addons/estragon/compiler/native/resolver.gd +11 -7
- package/addons/estragon/compiler/parser.gd +24 -7
- package/addons/estragon/compiler/validator.gd +58 -0
- package/addons/estragon/editor/lexical_context.gd +5 -1
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/runtime/composition/computation.gd +32 -8
- package/addons/estragon/runtime/composition/element.gd +16 -0
- package/addons/estragon/runtime/composition/native_attributes.gd +3 -0
- package/addons/estragon/runtime/node/component_2d.gd +69 -2
- package/addons/estragon/runtime/node/estragon_2d.gd +2 -0
- package/addons/estragon/runtime/node/internal/coordinator.gd +2 -1
- package/addons/estragon/runtime/node/internal/grid_policy.gd +1 -0
- package/addons/estragon/runtime/node/internal/layout_core.gd +98 -13
- package/addons/estragon/runtime/node/internal/length.gd +5 -4
- package/addons/estragon/runtime/node/internal/native_bounds.gd +5 -2
- package/addons/estragon/runtime/node/internal/pointer_2d.gd +11 -1
- package/addons/estragon/runtime/node/internal/scroll_2d.gd +175 -0
- package/addons/estragon/runtime/node/internal/scroll_2d.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/scroll_input.gd +59 -0
- package/addons/estragon/runtime/node/internal/scroll_input.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/stack_policy.gd +16 -0
- 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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if
|
|
20
|
-
cursor =
|
|
21
|
-
|
|
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)
|
|
@@ -201,6 +203,12 @@ func _description(node: Model.Component, indentation: String) -> String:
|
|
|
201
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)
|
|
202
204
|
|
|
203
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)
|
|
204
212
|
if not bindings.is_empty(): _line(variable+".bindings = {"+", ".join(bindings)+"}",node.span,indentation)
|
|
205
213
|
return variable
|
|
206
214
|
|
|
@@ -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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if
|
|
182
|
-
cursor =
|
|
183
|
-
|
|
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
|
-
|
|
107
|
-
|
|
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
|
|
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
|
-
|
|
148
|
-
|
|
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
|
|
@@ -61,6 +61,9 @@ func _component(node: Model.Component) -> void:
|
|
|
61
61
|
_node(attribute.value)
|
|
62
62
|
continue
|
|
63
63
|
var name := attribute.name
|
|
64
|
+
if VisualStyle.marked(resolved.script,"ESTRAGON_SCROLL_2D") and name in ["scroll_range","content_extent"]:
|
|
65
|
+
_error("Read-only scrolling measurement: "+name,attribute.name_span)
|
|
66
|
+
return
|
|
64
67
|
if VisualStyle.property(name) and VisualStyle.has_api(resolved.script) and not VisualStyle.supported(resolved.script):
|
|
65
68
|
_error("Shared visual styling is unsupported on this participant",attribute.name_span)
|
|
66
69
|
return
|
|
@@ -68,6 +71,12 @@ func _component(node: Model.Component) -> void:
|
|
|
68
71
|
_error("Duplicate Node property or signal " + name, attribute.name_span)
|
|
69
72
|
return
|
|
70
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
|
|
71
80
|
if name.begins_with("bind:"):
|
|
72
81
|
_binding(attribute,node,properties,signals)
|
|
73
82
|
if not file.diagnostics.is_empty(): return
|
|
@@ -146,6 +155,43 @@ func _component(node: Model.Component) -> void:
|
|
|
146
155
|
attribute.value.type_name = attribute.type_name
|
|
147
156
|
else:
|
|
148
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)
|
|
149
195
|
var sibling_names := {}
|
|
150
196
|
for child in node.children:
|
|
151
197
|
if child is Model.GdExpression:
|
|
@@ -371,3 +417,15 @@ func _color(attribute) -> void:
|
|
|
371
417
|
if parsed.has("error"): _error(parsed.error,value.span)
|
|
372
418
|
elif tokens.size()==1 and (tokens[0].kind=="number" or tokens[0].text in ["true","false","null","NAN","INF"]):
|
|
373
419
|
_error("Style color requires a native Color or validated hex/transparent string",value.span)
|
|
420
|
+
|
|
421
|
+
# JSX-like source line folding; inline spaces/Unicode remain ordinary String bytes.
|
|
422
|
+
func _body_whitespace(value: String) -> String:
|
|
423
|
+
if not value.contains("\n") and not value.contains("\r"): return value
|
|
424
|
+
var lines := value.replace("\r\n","\n").replace("\r","\n").replace("\t"," ").split("\n")
|
|
425
|
+
var words: Array[String] = []
|
|
426
|
+
for index in range(lines.size()):
|
|
427
|
+
var line: String = lines[index]
|
|
428
|
+
if index>0: line = line.strip_edges(true,false)
|
|
429
|
+
if index<lines.size()-1: line = line.strip_edges(false,true)
|
|
430
|
+
if not line.is_empty(): words.append(line)
|
|
431
|
+
return " ".join(words)
|
|
@@ -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()
|
|
@@ -264,7 +264,7 @@ func _collect_foreign(record, result: Array) -> void:
|
|
|
264
264
|
var nested = manager.records[node.get_instance_id()].mounted
|
|
265
265
|
_collect_foreign(nested,result)
|
|
266
266
|
if nested!=null and nested.node.get_ref()!=null: known.append(nested.node.get_ref())
|
|
267
|
-
for child in node.get_children():
|
|
267
|
+
for child in (node._layout_children() if node.has_method("_layout_children") else node.get_children()):
|
|
268
268
|
if not known.has(child) and not result.has(child): result.append(child)
|
|
269
269
|
func _planned_foreign(desired, previous, result: Array) -> void:
|
|
270
270
|
if previous==null: return
|
|
@@ -282,7 +282,7 @@ func _rescue_clear(desired, previous, owner: Node) -> bool:
|
|
|
282
282
|
var rescued: Array = []
|
|
283
283
|
_planned_foreign(desired,previous,rescued)
|
|
284
284
|
var names := {}
|
|
285
|
-
for existing in owner.get_children():
|
|
285
|
+
for existing in (owner._layout_children() if owner.has_method("_layout_children") else owner.get_children()):
|
|
286
286
|
if previous!=null and existing==previous.node.get_ref(): continue
|
|
287
287
|
names[str(existing.name)] = true
|
|
288
288
|
var desired_name: String = str(desired.properties.get("name",str(previous.node.get_ref().name) if previous!=null and _compatible(desired,previous) else ""))
|
|
@@ -295,10 +295,11 @@ func _rescue_clear(desired, previous, owner: Node) -> bool:
|
|
|
295
295
|
func _boundary_clear(desired: Element, parent: Node) -> bool:
|
|
296
296
|
var name: String = str(desired.properties.get("name",""))
|
|
297
297
|
if name.is_empty(): return true
|
|
298
|
-
for child in parent.get_children():
|
|
298
|
+
for child in (parent._layout_children() if parent.has_method("_layout_children") else parent.get_children()):
|
|
299
299
|
if str(child.name)==name: return false
|
|
300
300
|
return true
|
|
301
301
|
func _mount(desired: Element, parent: Node, owner: Node) -> Mounted:
|
|
302
|
+
if parent.has_method("_composition_child_parent"): parent = parent._composition_child_parent()
|
|
302
303
|
var record := Mounted.new()
|
|
303
304
|
if desired.borrowed != null:
|
|
304
305
|
record.borrowed = desired.borrowed
|
|
@@ -350,11 +351,13 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
350
351
|
if grid:
|
|
351
352
|
node._apply_grid(_grid_config(desired))
|
|
352
353
|
var stack := StackContract.registered(desired.type)
|
|
354
|
+
var scroll := VisualStyle.marked(desired.type,"ESTRAGON_SCROLL_2D")
|
|
353
355
|
if stack:
|
|
354
356
|
var policy := resets.duplicate()
|
|
355
357
|
policy.merge(desired.properties,true)
|
|
356
358
|
node._apply_stack_policy(policy)
|
|
357
359
|
for key in resets:
|
|
360
|
+
if scroll and key=="scroll_offset": continue
|
|
358
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])
|
|
359
362
|
writes += 1
|
|
360
363
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
@@ -372,15 +375,28 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
372
375
|
node.set(key,0.0)
|
|
373
376
|
writes += 1
|
|
374
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")
|
|
375
381
|
if StackContract.self_registered(desired.type) and record.properties.has("align_self") and not desired.properties.has("align_self"):
|
|
376
382
|
node.set("align_self","auto")
|
|
377
383
|
writes += 1
|
|
378
384
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
379
385
|
for key in desired.properties:
|
|
386
|
+
if scroll and key=="scroll_offset": continue
|
|
380
387
|
if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
|
|
381
388
|
if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
|
|
382
389
|
writes += 1
|
|
383
390
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
391
|
+
# Apply the effective authored offset after geometry/axis flags. A dirty
|
|
392
|
+
# component 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")
|
|
384
400
|
for event in record.handlers:
|
|
385
401
|
if not desired.handlers.has(event) or record.handlers[event]!=desired.handlers[event]:
|
|
386
402
|
if node.is_connected(event,record.handlers[event]):
|
|
@@ -402,7 +418,7 @@ func _spread_resets(desired: Element, record) -> Dictionary:
|
|
|
402
418
|
if record==null or not _compatible(desired,record): return result
|
|
403
419
|
var node = record.node.get_ref()
|
|
404
420
|
for key in record.spread_applied:
|
|
405
|
-
if desired.properties.has(key) or (key=="align_self" and StackContract.self_registered(desired.type)) or key in Length.BORDER_EDGES or key in Length.MINIMUMS: continue
|
|
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
|
|
406
422
|
# Do not overwrite imperative native changes made since our last commit.
|
|
407
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]
|
|
408
424
|
return result
|
|
@@ -437,6 +453,7 @@ func _compatible(desired: Element, record: Mounted) -> bool:
|
|
|
437
453
|
return desired.borrowed != null and record.borrowed != null and desired.borrowed.get_ref() != null and desired.borrowed.get_ref() == record.node.get_ref()
|
|
438
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
|
|
439
455
|
func _reconcile(desired, record, parent: Node, owner: Node):
|
|
456
|
+
if parent.has_method("_composition_child_parent"): parent = parent._composition_child_parent()
|
|
440
457
|
if Profile.is_enabled(): Profile.add("reconciles")
|
|
441
458
|
if desired == null:
|
|
442
459
|
if record != null: _free_managed(record,owner)
|
|
@@ -469,6 +486,7 @@ func _reconcile(desired, record, parent: Node, owner: Node):
|
|
|
469
486
|
# Release names that must change before applying final sibling names. Native
|
|
470
487
|
# Node otherwise silently renames a valid swap against the still-old sibling.
|
|
471
488
|
func _prepare_names(desired: Array, matches: Array, parent: Node) -> void:
|
|
489
|
+
if parent.has_method("_composition_child_parent"): parent = parent._composition_child_parent()
|
|
472
490
|
var pending: Array = []
|
|
473
491
|
var targets := {}
|
|
474
492
|
for index in range(desired.size()):
|
|
@@ -493,6 +511,7 @@ func _prepare_names(desired: Array, matches: Array, parent: Node) -> void:
|
|
|
493
511
|
# Keep a longest increasing subsequence of actual native indices. Everything
|
|
494
512
|
# else moves once, right to left beside its final successor; no-op moves zero.
|
|
495
513
|
func _order(children: Array, parent: Node) -> void:
|
|
514
|
+
if parent.has_method("_composition_child_parent"): parent = parent._composition_child_parent()
|
|
496
515
|
var nodes: Array = []
|
|
497
516
|
for child in children:
|
|
498
517
|
if child!=null and child.borrowed == null: nodes.append(child.node.get_ref())
|
|
@@ -575,6 +594,10 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
575
594
|
if not message.is_empty():
|
|
576
595
|
validation_error = desired.location(key)+": "+message+"; previous tree retained"
|
|
577
596
|
return false
|
|
597
|
+
if VisualStyle.marked(desired.type,"ESTRAGON_SCROLL_2D"):
|
|
598
|
+
if desired.properties.has("scroll_offset") and not preload("../node/internal/scroll_2d.gd").valid_offset(desired.properties.scroll_offset): return _invalid_attribute(desired,"scroll_offset","requires a finite nonnegative Vector2")
|
|
599
|
+
for key in ["scroll_range","content_extent"]:
|
|
600
|
+
if desired.properties.has(key): return _invalid_attribute(desired,key,"read-only scrolling measurement")
|
|
578
601
|
if GridDefinition.marked(desired.type):
|
|
579
602
|
var config := _grid_config(desired)
|
|
580
603
|
var grid_matches := _matches(desired.children,previous.children if previous!=null and _compatible(desired,previous) else [])
|
|
@@ -665,7 +688,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
665
688
|
var node: Node = previous.node.get_ref() if _compatible(desired,previous) else null
|
|
666
689
|
if parent != null:
|
|
667
690
|
var name := _effective_name(desired,previous)
|
|
668
|
-
for existing in parent.get_children():
|
|
691
|
+
for existing in (parent._layout_children() if parent.has_method("_layout_children") else parent.get_children()):
|
|
669
692
|
if str(existing.name)==name and (previous==null or existing!=previous.node.get_ref()): return _invalid_attribute(desired,"name","native sibling name conflict "+name)
|
|
670
693
|
var known: Array = []
|
|
671
694
|
if node != null:
|
|
@@ -683,7 +706,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
683
706
|
if names.has(name): return _invalid_attribute(child,"name","duplicate effective sibling name "+name)
|
|
684
707
|
names[name] = true
|
|
685
708
|
if node != null:
|
|
686
|
-
for existing in node.get_children():
|
|
709
|
+
for existing in (node._layout_children() if node.has_method("_layout_children") else node.get_children()):
|
|
687
710
|
if str(existing.name)==name and not known.has(existing): return false
|
|
688
711
|
return true
|
|
689
712
|
func _free_managed(record: Mounted, rescue: Node = null) -> void:
|
|
@@ -702,9 +725,10 @@ func _free_managed(record: Mounted, rescue: Node = null) -> void:
|
|
|
702
725
|
var owner: Node = rescue if rescue != null else host.get_ref()
|
|
703
726
|
var manager = state.get_ref()
|
|
704
727
|
if manager != null and manager.records.has(node.get_instance_id()): manager.unmount(node,owner)
|
|
705
|
-
for child in node.get_children():
|
|
728
|
+
for child in (node._layout_children() if node.has_method("_layout_children") else node.get_children()):
|
|
729
|
+
if node.has_method("_composition_is_private") and node._composition_is_private(child): continue
|
|
706
730
|
var persisted_owner: Node = child.owner
|
|
707
|
-
|
|
731
|
+
child.get_parent().remove_child(child)
|
|
708
732
|
if owner != null:
|
|
709
733
|
owner.add_child(child)
|
|
710
734
|
if persisted_owner != null and persisted_owner.is_ancestor_of(child): child.owner = persisted_owner
|
|
@@ -70,3 +70,19 @@ func _init(native_type: Variant = null, props: Dictionary = {}, events: Dictiona
|
|
|
70
70
|
handlers = events
|
|
71
71
|
children = descendants
|
|
72
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
|
|
@@ -4,10 +4,41 @@ class_name EstragonComponent2D
|
|
|
4
4
|
extends Node2D
|
|
5
5
|
## Native C1 participant. Needs a contiguous same-dimensional chain to an entry.
|
|
6
6
|
signal layout_applied(size: Vector2)
|
|
7
|
+
signal _layout_children_changed
|
|
7
8
|
const Coordinator = preload("internal/coordinator.gd")
|
|
8
9
|
const ESTRAGON_LENGTHS := true
|
|
9
10
|
const ESTRAGON_MINIMUMS_2D := true
|
|
10
11
|
const ESTRAGON_GAPS_2D := true
|
|
12
|
+
const ESTRAGON_SCROLL_2D := true
|
|
13
|
+
const Scroll = preload("internal/scroll_2d.gd")
|
|
14
|
+
var _scroll
|
|
15
|
+
@export var horizontal_scroll: bool = false:
|
|
16
|
+
set(value):
|
|
17
|
+
if horizontal_scroll==value: return
|
|
18
|
+
horizontal_scroll = value
|
|
19
|
+
_scroll_changed()
|
|
20
|
+
@export var vertical_scroll: bool = false:
|
|
21
|
+
set(value):
|
|
22
|
+
if vertical_scroll==value: return
|
|
23
|
+
vertical_scroll = value
|
|
24
|
+
_scroll_changed()
|
|
25
|
+
@export var scroll_offset := Vector2.ZERO:
|
|
26
|
+
set(value):
|
|
27
|
+
if not Scroll.valid_offset(value):
|
|
28
|
+
push_error("Estragon scrolling scroll_offset requires a finite nonnegative Vector2")
|
|
29
|
+
return
|
|
30
|
+
scroll_offset = value
|
|
31
|
+
if _scroll!=null: _scroll.offset_changed()
|
|
32
|
+
elif not horizontal_scroll and not vertical_scroll: scroll_offset = Vector2.ZERO
|
|
33
|
+
var scroll_range: Vector2:
|
|
34
|
+
get: return _scroll_range
|
|
35
|
+
set(_value): push_error("Estragon scrolling scroll_range is read-only")
|
|
36
|
+
var content_extent: Vector2:
|
|
37
|
+
get: return _content_extent
|
|
38
|
+
set(_value): push_error("Estragon scrolling content_extent is read-only")
|
|
39
|
+
var _scroll_range := Vector2.ZERO
|
|
40
|
+
var _content_extent := Vector2.ZERO
|
|
41
|
+
|
|
11
42
|
var row_gap: Variant = "auto":
|
|
12
43
|
set(value):
|
|
13
44
|
if is_same(row_gap,value) or not lengths.assign("row_gap",value): return
|
|
@@ -90,6 +121,16 @@ var padding_left: Variant = "auto":
|
|
|
90
121
|
if is_same(padding_left,value) or not lengths.assign("padding_left",value): return
|
|
91
122
|
padding_left = value
|
|
92
123
|
_changed()
|
|
124
|
+
var max_width: Variant = "auto":
|
|
125
|
+
set(value):
|
|
126
|
+
if is_same(max_width,value) or not lengths.assign("max_width",value): return
|
|
127
|
+
max_width = value
|
|
128
|
+
_changed()
|
|
129
|
+
var max_height: Variant = "auto":
|
|
130
|
+
set(value):
|
|
131
|
+
if is_same(max_height,value) or not lengths.assign("max_height",value): return
|
|
132
|
+
max_height = value
|
|
133
|
+
_changed()
|
|
93
134
|
var min_width: Variant = 0.0:
|
|
94
135
|
set(value):
|
|
95
136
|
if is_same(min_width,value) or not lengths.assign("min_width",value): return
|
|
@@ -179,7 +220,7 @@ var layout_size: Vector2:
|
|
|
179
220
|
var _layout_size := Vector2.ZERO
|
|
180
221
|
var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
|
|
181
222
|
func _get_property_list() -> Array[Dictionary]:
|
|
182
|
-
var properties := Length.properties(["width","height","min_width","min_height","x","y","gap","padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"])
|
|
223
|
+
var properties := Length.properties(["width","height","min_width","min_height","max_width","max_height","x","y","gap","padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"])
|
|
183
224
|
properties.append_array(Length.properties(["row_gap","column_gap"]))
|
|
184
225
|
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"]))
|
|
185
226
|
return properties
|
|
@@ -215,11 +256,32 @@ func get_content_rect() -> Rect2:
|
|
|
215
256
|
|
|
216
257
|
func _layout_options() -> Dictionary:
|
|
217
258
|
var natural := _measure_native()
|
|
218
|
-
return {"axis":_layout_axis(),"fill":Vector3.ZERO,"intrinsic":Vector3(natural.x,natural.y,0)}
|
|
259
|
+
return {"axis":_layout_axis(),"fill":Vector3.ZERO,"intrinsic":Vector3(natural.x,natural.y,0),"scroll_axes":Vector2(1 if horizontal_scroll else 0,1 if vertical_scroll else 0)}
|
|
219
260
|
|
|
220
261
|
func _is_layout_entry() -> bool:
|
|
221
262
|
return false
|
|
222
263
|
|
|
264
|
+
func _scroll_changed() -> void:
|
|
265
|
+
if _scroll==null and (horizontal_scroll or vertical_scroll): _scroll = Scroll.new(self)
|
|
266
|
+
_changed()
|
|
267
|
+
if _scroll!=null and is_inside_tree(): _scroll.start()
|
|
268
|
+
func _composition_child_parent() -> Node:
|
|
269
|
+
return _scroll.child_parent() if _scroll!=null and is_instance_valid(_scroll.child_parent()) else self
|
|
270
|
+
func _composition_is_private(child: Node) -> bool:
|
|
271
|
+
return _scroll!=null and _scroll.is_private(child)
|
|
272
|
+
func _layout_children() -> Array:
|
|
273
|
+
return _scroll.children() if _scroll!=null else get_children()
|
|
274
|
+
func get_layout_children() -> Array:
|
|
275
|
+
return _layout_children()
|
|
276
|
+
func get_layout_child(child_name: StringName) -> Node:
|
|
277
|
+
for child in _layout_children():
|
|
278
|
+
if child.name==child_name: return child
|
|
279
|
+
return null
|
|
280
|
+
func _content_pointer_allowed(point: Vector2) -> bool:
|
|
281
|
+
return _scroll==null or _scroll.pointer_allowed(point)
|
|
282
|
+
func _input(event: InputEvent) -> void:
|
|
283
|
+
if _scroll!=null: _scroll.input(event)
|
|
284
|
+
|
|
223
285
|
func _changed() -> void:
|
|
224
286
|
if layout != null: layout.changed()
|
|
225
287
|
|
|
@@ -232,10 +294,13 @@ func _enter_tree() -> void:
|
|
|
232
294
|
# cannot accidentally bypass the shared style. Legacy widget painters
|
|
233
295
|
# explicitly opt out of S01 styles and remain untouched until S02.
|
|
234
296
|
if VisualStyle.supported(get_script()) and not draw.is_connected(_paint_visual_style): draw.connect(_paint_visual_style)
|
|
297
|
+
if _scroll==null and (horizontal_scroll or vertical_scroll or get_node_or_null("_EstragonViewport")!=null): _scroll = Scroll.new(self)
|
|
298
|
+
if _scroll!=null: _scroll.start()
|
|
235
299
|
layout.changed()
|
|
236
300
|
layout.start()
|
|
237
301
|
|
|
238
302
|
func _exit_tree() -> void:
|
|
303
|
+
if _scroll!=null: _scroll.stop()
|
|
239
304
|
if draw.is_connected(_paint_visual_style): draw.disconnect(_paint_visual_style)
|
|
240
305
|
layout.stop()
|
|
241
306
|
|
|
@@ -258,8 +323,10 @@ func apply_layout_size(size: Vector3) -> void:
|
|
|
258
323
|
var next := Vector2(size.x,size.y)
|
|
259
324
|
if next!=_layout_size: _queue_style_redraw()
|
|
260
325
|
_layout_size = next
|
|
326
|
+
_content_extent = layout.model.content_extent()
|
|
261
327
|
# Explicit invalidation also restores a native position edited externally.
|
|
262
328
|
if layout.parent_coordinator() != null: layout._place(layout.model.offset)
|
|
329
|
+
if _scroll!=null: _scroll.refresh()
|
|
263
330
|
layout_applied.emit(_layout_size)
|
|
264
331
|
|
|
265
332
|
func _margin_insets() -> Vector4:
|
|
@@ -122,7 +122,7 @@ func _sync() -> void:
|
|
|
122
122
|
if not active or _mode == Mode.CONTROL: return
|
|
123
123
|
var values: Array = []
|
|
124
124
|
var host: Node = _host.get_ref()
|
|
125
|
-
var children: Array = host.get_children() if _mode != Mode.COMPOSITION else []
|
|
125
|
+
var children: Array = (host._layout_children() if host.has_method("_layout_children") else host.get_children()) if _mode != Mode.COMPOSITION else []
|
|
126
126
|
if _mode == Mode.COMPOSITION and managed_root != null and managed_root.get_ref() != null: children.append(managed_root.get_ref())
|
|
127
127
|
children = CompositionHosts.children(host,children)
|
|
128
128
|
for child in children:
|
|
@@ -140,6 +140,7 @@ func changed() -> void:
|
|
|
140
140
|
if host == null: return
|
|
141
141
|
if host.has_method("_layout_options"):
|
|
142
142
|
var options: Dictionary = host._layout_options()
|
|
143
|
+
model.set_scroll_axes(options.get("scroll_axes",Vector2.ZERO) if _dimension==2 else Vector2.ZERO)
|
|
143
144
|
model.set_strategy(options.get("strategy","stack") if _dimension==2 else "stack",options.get("align_content","start"),options.get("grid",{}))
|
|
144
145
|
model.set_policy(options.get("alignment",["start","start","start"]))
|
|
145
146
|
model.set_align_self(host.align_self if _dimension==2 and "align_self" in host else "auto")
|
|
@@ -63,6 +63,7 @@ static func layout(items: Array, definition: Dictionary, content: Vector3, gaps:
|
|
|
63
63
|
for axis in range(2):
|
|
64
64
|
extent[axis] = maxf(extent[axis],item.minimum[axis])
|
|
65
65
|
if item.requested[axis]<0 and alignment[axis]=="stretch": extent[axis] = maxf(item.minimum[axis],cell[axis]-item.outer[axis])
|
|
66
|
+
extent = Stack.limit_extent(extent,item)
|
|
66
67
|
position[axis] += maxf(0,cell[axis]-extent[axis]-item.outer[axis])*Stack.factor(alignment[axis])
|
|
67
68
|
slots.append({"position":position,"extent":extent})
|
|
68
69
|
return {"extent":natural,"slots":slots,"columns":columns,"rows":rows,"placements":definition.placements}
|
|
@@ -26,6 +26,7 @@ var _forward_context: Array = []
|
|
|
26
26
|
var _reported_unanchored := false
|
|
27
27
|
var _reported_full_percent := false
|
|
28
28
|
var _reported_fixed_growth := false
|
|
29
|
+
var available_capacity := Vector3(-1,-1,-1)
|
|
29
30
|
var measurement_allocation := Vector3(-1,-1,-1)
|
|
30
31
|
var requested := Vector3(-1, -1, -1)
|
|
31
32
|
var placement: Dictionary = {}
|
|
@@ -33,6 +34,8 @@ var grid_config: Dictionary = {}
|
|
|
33
34
|
var grid_definition: Dictionary = {}
|
|
34
35
|
var policy_result: Dictionary = {}
|
|
35
36
|
var strategy := "stack"
|
|
37
|
+
# Viewport decoration; never replaces Stack/Wrap/Grid.
|
|
38
|
+
var scroll_axes := Vector2.ZERO
|
|
36
39
|
var align_content := "start"
|
|
37
40
|
var physical_gaps := Vector2.ZERO
|
|
38
41
|
var gap: float = 0.0
|
|
@@ -43,6 +46,8 @@ var intrinsic := Vector3.ZERO
|
|
|
43
46
|
# Native Control minimums constrain assigned slots, never read back from size.
|
|
44
47
|
var allocation_minimum := Vector3.ZERO
|
|
45
48
|
# Authored border-box floors are independent of native adapter minimums.
|
|
49
|
+
var authored_maximum := Vector3(-1,-1,-1)
|
|
50
|
+
var _reported_max_conflict := false
|
|
46
51
|
var authored_minimum := Vector3.ZERO
|
|
47
52
|
var padding := Vector4.ZERO # left, top, right, bottom; border-box insets
|
|
48
53
|
var border := Vector4.ZERO # inside the border-box, before padding
|
|
@@ -52,6 +57,7 @@ var alignment: Array = ["start","start","start"]
|
|
|
52
57
|
# Parent-owned border-box placements; no Node references or additive offsets.
|
|
53
58
|
var slots: Array = []
|
|
54
59
|
var children: Array = []
|
|
60
|
+
var natural_extent := Vector3.ZERO
|
|
55
61
|
var measured := Vector3.ZERO
|
|
56
62
|
# -1 is an unavailable/cyclic reference axis, distinct from an arranged zero.
|
|
57
63
|
var content_reference := Vector3(-1,-1,-1)
|
|
@@ -66,6 +72,9 @@ var _parent: WeakRef
|
|
|
66
72
|
|
|
67
73
|
var default_padding := Vector4.ZERO
|
|
68
74
|
|
|
75
|
+
func is_layout_dirty() -> bool:
|
|
76
|
+
return _measure_dirty or _arrange_dirty
|
|
77
|
+
|
|
69
78
|
func set_lengths(specs: Dictionary, growth: float, cross: int, scale: float, stack_axis: int, padding_fallback: Vector4 = Vector4.ZERO) -> void:
|
|
70
79
|
if default_padding==padding_fallback and length_specs==specs and grow==growth and stretch==cross and pixels_per_unit==scale and axis==stack_axis: return
|
|
71
80
|
default_padding = padding_fallback
|
|
@@ -92,6 +101,11 @@ func set_strategy(value: String, content_alignment: String = "start", config: Di
|
|
|
92
101
|
align_content = content_alignment
|
|
93
102
|
invalidate()
|
|
94
103
|
|
|
104
|
+
func set_scroll_axes(value: Vector2) -> void:
|
|
105
|
+
if scroll_axes==value: return
|
|
106
|
+
scroll_axes = value
|
|
107
|
+
invalidate()
|
|
108
|
+
|
|
95
109
|
func set_policy(values: Array) -> void:
|
|
96
110
|
if alignment==values: return
|
|
97
111
|
alignment = values.duplicate()
|
|
@@ -144,12 +158,13 @@ func prepare(reference: Vector3, viewport: Vector2) -> void:
|
|
|
144
158
|
if _length_context==context: return
|
|
145
159
|
_length_context = context
|
|
146
160
|
resolution_count += 1
|
|
147
|
-
var before := [requested,gap,physical_gaps,padding,border,margin,length_offset,authored_minimum]
|
|
161
|
+
var before := [requested,gap,physical_gaps,padding,border,margin,length_offset,authored_minimum,authored_maximum]
|
|
148
162
|
if not length_specs.is_empty():
|
|
149
163
|
for index in range(3):
|
|
150
164
|
requested[index] = _length(["width","height","depth"][index],index,requested[index])
|
|
151
165
|
length_offset[index] = _length(["x","y","z"][index],index,0)
|
|
152
166
|
authored_minimum = Vector3(maxf(0,_length("min_width",0,0)),maxf(0,_length("min_height",1,0)),0)
|
|
167
|
+
authored_maximum = Vector3(_length("max_width",0,-1),_length("max_height",1,-1),-1)
|
|
153
168
|
gap = _length("gap",axis,0)
|
|
154
169
|
physical_gaps = Vector2(_length("column_gap",0,-1),_length("row_gap",1,-1))
|
|
155
170
|
for index in range(2):
|
|
@@ -157,7 +172,7 @@ func prepare(reference: Vector3, viewport: Vector2) -> void:
|
|
|
157
172
|
padding = _edges("padding")
|
|
158
173
|
border = _edges("border")
|
|
159
174
|
margin = _edges("margin")
|
|
160
|
-
if before!=[requested,gap,physical_gaps,padding,border,margin,length_offset,authored_minimum]:
|
|
175
|
+
if before!=[requested,gap,physical_gaps,padding,border,margin,length_offset,authored_minimum,authored_maximum]:
|
|
161
176
|
_measure_dirty = true
|
|
162
177
|
_arrange_dirty = true
|
|
163
178
|
|
|
@@ -167,16 +182,29 @@ func minimum() -> Vector3:
|
|
|
167
182
|
for index in range(3): result[index] = maxf(result[index],maxf(allocation_minimum[index],inherited[index]))
|
|
168
183
|
return result
|
|
169
184
|
|
|
185
|
+
func maximum() -> Vector3:
|
|
186
|
+
if transparent and children.size()==1: return children[0].maximum()
|
|
187
|
+
return authored_maximum
|
|
188
|
+
|
|
170
189
|
func constrain(extent: Vector3) -> Vector3:
|
|
171
190
|
var floor := minimum()
|
|
172
|
-
|
|
191
|
+
var cap := maximum()
|
|
192
|
+
for index in range(3):
|
|
193
|
+
if cap[index]>=0:
|
|
194
|
+
if floor[index]>cap[index] and not _reported_max_conflict and not transparent:
|
|
195
|
+
_reported_max_conflict = true
|
|
196
|
+
push_warning("Estragon minimum exceeds maximum; minimum/native floor wins")
|
|
197
|
+
extent[index] = minf(extent[index],cap[index])
|
|
198
|
+
extent[index] = maxf(extent[index],floor[index])
|
|
173
199
|
return extent
|
|
174
200
|
|
|
175
201
|
func _content_basis() -> Vector3:
|
|
176
202
|
var basis := Vector3(-1,-1,-1)
|
|
177
203
|
for index in range(3):
|
|
178
|
-
var allocated: float = requested[index] if requested[index]>=0 else measurement_allocation[index]
|
|
204
|
+
var allocated: float = constrain(requested)[index] if requested[index]>=0 else measurement_allocation[index]
|
|
179
205
|
if allocated>=0: basis[index] = maxf(0,maxf(allocated,minimum()[index])-leading(padding+border)[index]-trailing(padding+border)[index])
|
|
206
|
+
for index in range(2):
|
|
207
|
+
if scroll_axes[index]>0: basis[index] = -1
|
|
180
208
|
return basis
|
|
181
209
|
|
|
182
210
|
static func valid_extent(value: Vector3) -> bool:
|
|
@@ -245,16 +273,16 @@ func outer_extent() -> Vector3:
|
|
|
245
273
|
func track_contribution() -> Vector3:
|
|
246
274
|
if transparent and children.size()==1: return children[0].track_contribution()
|
|
247
275
|
var result := measured
|
|
248
|
-
if strategy=="wrap" and requested[axis]<0:
|
|
276
|
+
if strategy=="wrap" and scroll_axes[axis]==0 and requested[axis]<0:
|
|
249
277
|
result[axis] = intrinsic[axis]
|
|
250
278
|
for child in children: result[axis] = maxf(result[axis],maxf(child.measured[axis],child.minimum()[axis])+child.outer_extent()[axis])
|
|
251
279
|
result[axis] += leading(padding+border)[axis]+trailing(padding+border)[axis]
|
|
252
|
-
return result
|
|
280
|
+
return constrain(result)
|
|
253
281
|
|
|
254
282
|
func _items() -> Array:
|
|
255
283
|
var items: Array = []
|
|
256
284
|
for child in children:
|
|
257
|
-
items.append({"preferred":child.measured,"contribution":child.track_contribution(),"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),"placement":child.placement})
|
|
285
|
+
items.append({"preferred":child.measured,"contribution":child.track_contribution(),"minimum":child.minimum(),"maximum":child.maximum(),"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),"placement":child.placement})
|
|
258
286
|
return items
|
|
259
287
|
|
|
260
288
|
func _grid(items: Array, content: Vector3) -> Dictionary:
|
|
@@ -278,11 +306,33 @@ func _grid(items: Array, content: Vector3) -> Dictionary:
|
|
|
278
306
|
|
|
279
307
|
# Allocation-dependent measurement is a bounded second pass in this same core.
|
|
280
308
|
# Only independently assigned axes may supply a basis; auto cycles stay absent.
|
|
309
|
+
func set_capacity(value: Vector3) -> void:
|
|
310
|
+
if not transparent:
|
|
311
|
+
if strategy!="wrap" or requested[axis]>=0: return
|
|
312
|
+
var main: float = value[axis]
|
|
313
|
+
value = Vector3(-1,-1,-1)
|
|
314
|
+
value[axis] = main
|
|
315
|
+
if available_capacity==value: return
|
|
316
|
+
available_capacity = value
|
|
317
|
+
_measure_dirty = true
|
|
318
|
+
_arrange_dirty = true
|
|
319
|
+
if transparent and children.size()==1: children[0].set_capacity(value)
|
|
320
|
+
|
|
321
|
+
func _wrap_basis() -> Vector3:
|
|
322
|
+
var basis := _content_basis()
|
|
323
|
+
if strategy=="wrap" and scroll_axes[axis]==0 and requested[axis]<0 and basis[axis]<0 and available_capacity[axis]>=0:
|
|
324
|
+
basis[axis] = maxf(0,available_capacity[axis]-leading(padding+border)[axis]-trailing(padding+border)[axis])
|
|
325
|
+
var cap := maximum()
|
|
326
|
+
if strategy=="wrap" and scroll_axes[axis]==0 and cap[axis]>=0:
|
|
327
|
+
var available := maxf(0,maxf(cap[axis],minimum()[axis])-leading(padding+border)[axis]-trailing(padding+border)[axis])
|
|
328
|
+
basis[axis] = minf(basis[axis],available) if basis[axis]>=0 else available
|
|
329
|
+
return basis
|
|
330
|
+
|
|
281
331
|
func measure_allocated(extent: Vector3, authority: Vector3) -> void:
|
|
282
332
|
if transparent and children.size()==1:
|
|
283
333
|
children[0].measure_allocated(extent,authority)
|
|
284
334
|
_measure_dirty = true
|
|
285
|
-
elif strategy in ["wrap","grid"]:
|
|
335
|
+
elif strategy in ["wrap","grid"] or scroll_axes!=Vector2.ZERO:
|
|
286
336
|
var next := measurement_allocation
|
|
287
337
|
for index in range(2):
|
|
288
338
|
if requested[index]<0 and authority[index]>0: next[index] = extent[index]
|
|
@@ -292,6 +342,16 @@ func measure_allocated(extent: Vector3, authority: Vector3) -> void:
|
|
|
292
342
|
else: return
|
|
293
343
|
measure()
|
|
294
344
|
|
|
345
|
+
func overflow_extent() -> Vector3:
|
|
346
|
+
# Ancestors see the clipped participant's viewport, not its hidden content.
|
|
347
|
+
if scroll_axes!=Vector2.ZERO: return size
|
|
348
|
+
var result := size
|
|
349
|
+
for index in range(3): result[index] = maxf(result[index],natural_extent[index])
|
|
350
|
+
for child in children:
|
|
351
|
+
var extent: Vector3 = child.offset+child.overflow_extent()+trailing(child.margin)
|
|
352
|
+
for index in range(3): result[index] = maxf(result[index],extent[index])
|
|
353
|
+
return result
|
|
354
|
+
|
|
295
355
|
func _slots(items: Array, content: Vector3, definite: Vector3) -> Array:
|
|
296
356
|
if strategy=="grid": return _grid(items,content).slots
|
|
297
357
|
if strategy=="wrap": return WrapPolicy.layout(items,content,axis,physical_gaps,alignment,align_content,Vector2(definite.x,definite.y)).slots
|
|
@@ -300,7 +360,7 @@ func _slots(items: Array, content: Vector3, definite: Vector3) -> Array:
|
|
|
300
360
|
func _authority(child, item: Dictionary, basis: Vector3) -> Vector3:
|
|
301
361
|
var authority := Vector3.ZERO
|
|
302
362
|
for index in range(3):
|
|
303
|
-
if basis[index]<0 or child.requested[index]>=0: continue
|
|
363
|
+
if basis[index]<0 or child.requested[index]>=0 or index<2 and scroll_axes[index]>0: continue
|
|
304
364
|
if strategy=="grid":
|
|
305
365
|
if index<2 and alignment[index]=="stretch": authority[index] = 1
|
|
306
366
|
elif index==axis:
|
|
@@ -312,6 +372,7 @@ func measure() -> Vector3:
|
|
|
312
372
|
if transparent and children.size()==1:
|
|
313
373
|
var child = children[0]
|
|
314
374
|
child.prepare(parent_reference,viewport_size)
|
|
375
|
+
child.set_capacity(available_capacity)
|
|
315
376
|
child.measure()
|
|
316
377
|
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:
|
|
317
378
|
requested = child.requested
|
|
@@ -329,6 +390,10 @@ func measure() -> Vector3:
|
|
|
329
390
|
var basis := _content_basis()
|
|
330
391
|
for child in children:
|
|
331
392
|
child.prepare(basis,viewport_size)
|
|
393
|
+
var capacity := basis
|
|
394
|
+
for index in range(3):
|
|
395
|
+
if capacity[index]>=0: capacity[index] = maxf(0,capacity[index]-child.outer_extent()[index])
|
|
396
|
+
child.set_capacity(capacity)
|
|
332
397
|
child.measure()
|
|
333
398
|
if basis.x>=0 or basis.y>=0:
|
|
334
399
|
var items := _items()
|
|
@@ -346,12 +411,14 @@ func measure() -> Vector3:
|
|
|
346
411
|
else: natural[index] = maxf(natural[index],child_size[index])
|
|
347
412
|
if children.size() > 1: natural[axis] += (physical_gaps[axis] if axis<2 and length_specs.has("column_gap") else gap) * (children.size() - 1)
|
|
348
413
|
if strategy=="wrap" and not transparent:
|
|
349
|
-
var basis :=
|
|
414
|
+
var basis := _wrap_basis()
|
|
350
415
|
natural = WrapPolicy.layout(_items(),basis,axis,physical_gaps,alignment,align_content,Vector2(1 if basis.x>=0 else 0,1 if basis.y>=0 else 0)).extent
|
|
416
|
+
if basis[axis]>=0 and requested[axis]<0: natural[axis] = minf(basis[axis],natural[axis])
|
|
351
417
|
if strategy=="grid" and not transparent:
|
|
352
418
|
natural = _grid(_items(),_content_basis()).extent
|
|
353
419
|
for index in range(3): natural[index] = maxf(natural[index],intrinsic[index])
|
|
354
420
|
if not transparent: natural += leading(padding+border)+trailing(padding+border)
|
|
421
|
+
natural_extent = natural
|
|
355
422
|
measured = natural
|
|
356
423
|
for axis in range(3):
|
|
357
424
|
if requested[axis] >= 0: measured[axis] = requested[axis]
|
|
@@ -363,10 +430,12 @@ func measure() -> Vector3:
|
|
|
363
430
|
# ignore this model's intrinsic extent and can inherit an independent basis.
|
|
364
431
|
func independent_axis(index: int) -> bool:
|
|
365
432
|
if requested[index] >= 0 or _external_axes[index] > 0: return true
|
|
433
|
+
if index<2 and scroll_axes[index]>0 and maximum()[index]>=0: return true
|
|
366
434
|
var parent = _parent.get_ref() if _parent != null else null
|
|
367
435
|
if parent == null: return false
|
|
368
436
|
var allocated := grow>0 or fill[index]>0
|
|
369
437
|
if index!=parent.axis: allocated = StackPolicy.cross_alignment({"align_self":align_self,"stretch":stretch,"fill":fill},parent.alignment[index],index)=="stretch"
|
|
438
|
+
if index<2 and parent.scroll_axes[index]>0: return false
|
|
370
439
|
if parent.strategy=="grid" and index<2: allocated = parent.alignment[index]=="stretch"
|
|
371
440
|
return parent.independent_axis(index) if requested[index] < 0 and allocated else false
|
|
372
441
|
|
|
@@ -379,6 +448,8 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
379
448
|
for index in range(3):
|
|
380
449
|
content[index] = maxf(0,content[index])
|
|
381
450
|
if independent_axis(index): reference[index] = content[index]
|
|
451
|
+
for index in range(2):
|
|
452
|
+
if scroll_axes[index]>0: reference[index] = -1
|
|
382
453
|
var changed: bool = reference != content_reference
|
|
383
454
|
if not _arrange_dirty and size == available and not changed: return
|
|
384
455
|
content_reference = reference
|
|
@@ -413,7 +484,8 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
413
484
|
# Assigned content is authoritative, including grow allocations. Resolve the
|
|
414
485
|
# immediate children against this box before measuring their slots.
|
|
415
486
|
for child in children:
|
|
416
|
-
|
|
487
|
+
var child_reference := reference
|
|
488
|
+
child.prepare(child_reference,viewport_size)
|
|
417
489
|
child.measure()
|
|
418
490
|
if not _reported_full_percent and children.size()>1:
|
|
419
491
|
var main_name: String = ["width","height","depth"][axis]
|
|
@@ -423,13 +495,17 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
423
495
|
_reported_full_percent = true
|
|
424
496
|
push_warning("Estragon "+main_name+"=100% consumes the full definite parent content axis, not remaining space; siblings may overflow. Use an auto-sized Spacer with grow=1 for remaining space")
|
|
425
497
|
break
|
|
498
|
+
var layout_content := content
|
|
499
|
+
for index in range(2):
|
|
500
|
+
if scroll_axes[index]>0: layout_content[index] = maxf(content[index],natural_extent[index]-leading(padding+border)[index]-trailing(padding+border)[index])
|
|
426
501
|
var items := _items()
|
|
427
502
|
var policy := alignment.duplicate()
|
|
428
503
|
if center: policy[axis] = "center"
|
|
429
504
|
if strategy=="wrap":
|
|
430
|
-
|
|
505
|
+
var wrap_basis := _wrap_basis()
|
|
506
|
+
slots = WrapPolicy.layout(items,layout_content,axis,physical_gaps,policy,align_content,Vector2(1 if reference.x>=0 or axis==0 and wrap_basis.x>=0 else 0,1 if reference.y>=0 or axis==1 and wrap_basis.y>=0 else 0)).slots
|
|
431
507
|
else:
|
|
432
|
-
slots = StackPolicy.slots(items,
|
|
508
|
+
slots = StackPolicy.slots(items,layout_content,axis,physical_gaps[axis] if axis<2 and length_specs.has("column_gap") else gap,policy)
|
|
433
509
|
if strategy=="grid":
|
|
434
510
|
policy_result = _grid(items,reference)
|
|
435
511
|
if policy_result.has("error"): return
|
|
@@ -445,5 +521,14 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
445
521
|
for cross in range(3):
|
|
446
522
|
if strategy=="grid" and cross<2 and policy[cross]=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
|
|
447
523
|
elif strategy!="grid" and cross!=axis and StackPolicy.cross_alignment(items[index],policy[cross],cross)=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
|
|
524
|
+
for scrolling_axis in range(2):
|
|
525
|
+
if scroll_axes[scrolling_axis]>0: authority[scrolling_axis] = 0
|
|
448
526
|
child.arrange(slot.extent,authority)
|
|
449
527
|
arranged.emit(size)
|
|
528
|
+
|
|
529
|
+
func content_extent() -> Vector2:
|
|
530
|
+
var extent := Vector3.ZERO
|
|
531
|
+
for child in children:
|
|
532
|
+
var end: Vector3 = child.offset+child.overflow_extent()+trailing(child.margin)-leading(padding+border)
|
|
533
|
+
for index in range(2): extent[index] = maxf(extent[index],end[index])
|
|
534
|
+
return Vector2(extent.x,extent.y)
|
|
@@ -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 MAXIMUMS := ["max_width","max_height"]
|
|
10
11
|
const MINIMUMS := ["min_width","min_height"]
|
|
11
12
|
const DIMENSIONS := ["width","height","depth"]
|
|
12
13
|
const BORDER_EDGES := ["border_top_width","border_right_width","border_bottom_width","border_left_width"]
|
|
@@ -18,7 +19,7 @@ static func domain(name: String, script = null) -> String:
|
|
|
18
19
|
if name in ["row_gap","column_gap"]: return "edge"
|
|
19
20
|
if name=="padding" and VisualStyle.marked(script,"ESTRAGON_BUTTON_STYLE"): return "edge"
|
|
20
21
|
if name in DIMENSIONS: return "extent"
|
|
21
|
-
if name in MINIMUMS: return "edge"
|
|
22
|
+
if name in MINIMUMS or name in MAXIMUMS: return "edge"
|
|
22
23
|
if name=="border_width": return "inset"
|
|
23
24
|
if name in BORDER_EDGES: return "edge"
|
|
24
25
|
if name in OFFSETS: return "offset"
|
|
@@ -26,7 +27,7 @@ static func domain(name: String, script = null) -> String:
|
|
|
26
27
|
return "inset" if name=="gap" else ""
|
|
27
28
|
static func registered(type, name: String) -> bool:
|
|
28
29
|
if domain(name).is_empty() or not type is Script: return false
|
|
29
|
-
if name in MINIMUMS and not VisualStyle.marked(type,"ESTRAGON_MINIMUMS_2D"): return false
|
|
30
|
+
if (name in MINIMUMS or name in MAXIMUMS) and not VisualStyle.marked(type,"ESTRAGON_MINIMUMS_2D"): return false
|
|
30
31
|
if name in ["row_gap","column_gap"] and not VisualStyle.marked(type,"ESTRAGON_GAPS_2D"): return false
|
|
31
32
|
if name=="border_width" or name in BORDER_EDGES:
|
|
32
33
|
if not VisualStyle.supported(type): return false
|
|
@@ -84,8 +85,8 @@ static func dependencies(specs: Dictionary, stack_axis: int) -> Array:
|
|
|
84
85
|
for name in specs:
|
|
85
86
|
var unit: String = specs[name].unit
|
|
86
87
|
if unit=="%":
|
|
87
|
-
if name in ["width","min_width","x","column_gap","margin_left","margin_right","padding_left","padding_right","border_left_width","border_right_width"]: parent_axes.x = 1
|
|
88
|
-
elif name in ["height","min_height","y","row_gap","margin_top","margin_bottom","padding_top","padding_bottom","border_top_width","border_bottom_width"]: parent_axes.y = 1
|
|
88
|
+
if name in ["width","min_width","max_width","x","column_gap","margin_left","margin_right","padding_left","padding_right","border_left_width","border_right_width"]: parent_axes.x = 1
|
|
89
|
+
elif name in ["height","min_height","max_height","y","row_gap","margin_top","margin_bottom","padding_top","padding_bottom","border_top_width","border_bottom_width"]: parent_axes.y = 1
|
|
89
90
|
elif name in ["depth","z"]: parent_axes.z = 1
|
|
90
91
|
elif name=="gap":
|
|
91
92
|
parent_axes[stack_axis] = 1
|
|
@@ -22,6 +22,7 @@ func start() -> void:
|
|
|
22
22
|
var host: Node = _host.get_ref()
|
|
23
23
|
host.child_entered_tree.connect(_child_changed)
|
|
24
24
|
host.child_exiting_tree.connect(_child_changed)
|
|
25
|
+
if host.has_signal("_layout_children_changed"): host.connect("_layout_children_changed",invalidate)
|
|
25
26
|
invalidate()
|
|
26
27
|
|
|
27
28
|
func stop() -> void:
|
|
@@ -30,6 +31,7 @@ func stop() -> void:
|
|
|
30
31
|
var host: Node = _host.get_ref()
|
|
31
32
|
if host.child_entered_tree.is_connected(_child_changed): host.child_entered_tree.disconnect(_child_changed)
|
|
32
33
|
if host.child_exiting_tree.is_connected(_child_changed): host.child_exiting_tree.disconnect(_child_changed)
|
|
34
|
+
if host.has_signal("_layout_children_changed") and host.is_connected("_layout_children_changed",invalidate): host.disconnect("_layout_children_changed",invalidate)
|
|
33
35
|
|
|
34
36
|
func _child_changed(_child: Node) -> void:
|
|
35
37
|
invalidate()
|
|
@@ -57,10 +59,11 @@ func _refresh() -> void:
|
|
|
57
59
|
extent = Vector3.ZERO
|
|
58
60
|
var host = _host.get_ref()
|
|
59
61
|
status = ERR_INVALID_PARAMETER
|
|
60
|
-
|
|
62
|
+
var native_children: Array = host.get_layout_children() if host!=null and host.has_method("get_layout_children") else (host.get_children() if host!=null else [])
|
|
63
|
+
if host == null or native_children.size() != 1:
|
|
61
64
|
_publish(host)
|
|
62
65
|
return
|
|
63
|
-
var child: Node =
|
|
66
|
+
var child: Node = native_children[0]
|
|
64
67
|
var points: Array[Vector3] = []
|
|
65
68
|
if _dimension == 2 and child is Polygon2D:
|
|
66
69
|
var basis: Transform2D = host.transform
|
|
@@ -40,11 +40,21 @@ func _z(button: CanvasItem) -> int:
|
|
|
40
40
|
button = parent
|
|
41
41
|
parent = button.get_parent_item()
|
|
42
42
|
return result
|
|
43
|
+
static func inside_clips(item: CanvasItem, position: Vector2, exclude_bars: bool = true) -> bool:
|
|
44
|
+
var parent := item.get_parent()
|
|
45
|
+
while parent!=null:
|
|
46
|
+
if exclude_bars and parent.has_method("_content_pointer_allowed") and not parent._content_pointer_allowed(position): return false
|
|
47
|
+
if parent is Control and parent.clip_contents:
|
|
48
|
+
var point: Vector2 = parent.get_global_transform_with_canvas().affine_inverse()*position
|
|
49
|
+
if not Rect2(Vector2.ZERO,parent.size).has_point(point): return false
|
|
50
|
+
parent = parent.get_parent()
|
|
51
|
+
return true
|
|
52
|
+
|
|
43
53
|
func pick(position: Vector2):
|
|
44
54
|
var found
|
|
45
55
|
for ref in _buttons:
|
|
46
56
|
var button = ref.get_ref()
|
|
47
|
-
if button == null or button.is_queued_for_deletion() or not button.is_inside_tree() or not button.is_visible_in_tree() or not button._pointer_contains(position): continue
|
|
57
|
+
if button == null or button.is_queued_for_deletion() or not button.is_inside_tree() or not button.is_visible_in_tree() or not button._pointer_contains(position) or not inside_clips(button,position): continue
|
|
48
58
|
if found == null or _z(button) > _z(found) or _z(button) == _z(found) and button.is_greater_than(found): found = button
|
|
49
59
|
return found
|
|
50
60
|
func input(event: InputEvent) -> bool:
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Lazy native viewport decoration. One owner coordinator; no child layout policy.
|
|
4
|
+
const Hosts = preload("composition_hosts.tres")
|
|
5
|
+
const Pointer = preload("pointer_2d.gd")
|
|
6
|
+
var owner_ref: WeakRef
|
|
7
|
+
var host:
|
|
8
|
+
get: return owner_ref.get_ref()
|
|
9
|
+
var _clip: Control
|
|
10
|
+
var _content: Node2D
|
|
11
|
+
var _horizontal: HScrollBar
|
|
12
|
+
var _vertical: VScrollBar
|
|
13
|
+
var _updating := false
|
|
14
|
+
var _input_guard = preload("scroll_input.gd").new()
|
|
15
|
+
func _init(owner: Node2D) -> void:
|
|
16
|
+
owner_ref = weakref(owner)
|
|
17
|
+
static func valid_offset(value) -> bool:
|
|
18
|
+
return value is Vector2 and is_finite(value.x) and is_finite(value.y) and value.x>=0 and value.y>=0
|
|
19
|
+
func _ensure_viewport() -> void:
|
|
20
|
+
if is_instance_valid(_clip):
|
|
21
|
+
Hosts.add(_content,host.layout)
|
|
22
|
+
if enabled(): _input_guard.start(_content)
|
|
23
|
+
return
|
|
24
|
+
_clip = host.get_node_or_null("_EstragonViewport")
|
|
25
|
+
if _clip==null:
|
|
26
|
+
_clip = Control.new()
|
|
27
|
+
_clip.name = "_EstragonViewport"
|
|
28
|
+
_clip.clip_contents = true
|
|
29
|
+
_clip.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
30
|
+
host.add_child(_clip,false,Node.INTERNAL_MODE_BACK)
|
|
31
|
+
_content = _clip.get_node_or_null("_EstragonContent")
|
|
32
|
+
if _content==null:
|
|
33
|
+
_content = Node2D.new()
|
|
34
|
+
_content.name = "_EstragonContent"
|
|
35
|
+
_clip.add_child(_content,false,Node.INTERNAL_MODE_BACK)
|
|
36
|
+
Hosts.add(_content,host.layout)
|
|
37
|
+
_input_guard.start(_content)
|
|
38
|
+
if not _content.child_entered_tree.is_connected(host.layout._child_entered): _content.child_entered_tree.connect(host.layout._child_entered)
|
|
39
|
+
if not _content.child_exiting_tree.is_connected(host.layout._child_exiting): _content.child_exiting_tree.connect(host.layout._child_exiting)
|
|
40
|
+
_content.child_entered_tree.connect(_children_changed)
|
|
41
|
+
_content.child_exiting_tree.connect(_children_changed)
|
|
42
|
+
_horizontal = HScrollBar.new()
|
|
43
|
+
_vertical = VScrollBar.new()
|
|
44
|
+
host.add_child(_horizontal,false,Node.INTERNAL_MODE_BACK)
|
|
45
|
+
# BACK appends internal children after the clip/content branch. FRONT is
|
|
46
|
+
# the beginning of SceneTree order and would let native Controls win GUI
|
|
47
|
+
# picking over this scrollbar, regardless of how the bar appears to paint.
|
|
48
|
+
host.add_child(_vertical,false,Node.INTERNAL_MODE_BACK)
|
|
49
|
+
_horizontal.step = 0
|
|
50
|
+
_vertical.step = 0
|
|
51
|
+
_horizontal.custom_step = 40
|
|
52
|
+
_vertical.custom_step = 40
|
|
53
|
+
_horizontal.value_changed.connect(_horizontal_changed)
|
|
54
|
+
_vertical.value_changed.connect(_vertical_changed)
|
|
55
|
+
func is_private(child: Node) -> bool:
|
|
56
|
+
return child==_clip or child==_horizontal or child==_vertical
|
|
57
|
+
func _children_changed(_child: Node) -> void:
|
|
58
|
+
if host!=null: host._layout_children_changed.emit()
|
|
59
|
+
func _remember_owners(node: Node, values: Dictionary) -> void:
|
|
60
|
+
if node.owner!=null: values[node] = node.owner
|
|
61
|
+
for child in node.get_children(): _remember_owners(child,values)
|
|
62
|
+
func _adopt_content(child: Node) -> void:
|
|
63
|
+
if child.get_parent()!=host or is_private(child): return
|
|
64
|
+
var owners := {}
|
|
65
|
+
_remember_owners(child,owners)
|
|
66
|
+
var scene_owner := child.owner
|
|
67
|
+
var focus: Control = host.get_viewport().gui_get_focus_owner() if host.is_inside_tree() else null
|
|
68
|
+
host.remove_child(child)
|
|
69
|
+
_content.add_child(child)
|
|
70
|
+
if scene_owner!=null:
|
|
71
|
+
# Native scene persistence includes the necessary private ancestry only
|
|
72
|
+
# for an authored persistent root. Generated owner-null views serialize
|
|
73
|
+
# neither helpers nor content; descriptions remount after reload.
|
|
74
|
+
_clip.owner = scene_owner
|
|
75
|
+
_content.owner = scene_owner
|
|
76
|
+
for node in owners:
|
|
77
|
+
if owners[node].is_ancestor_of(node): node.owner = owners[node]
|
|
78
|
+
if is_instance_valid(focus) and focus.is_inside_tree(): focus.grab_focus()
|
|
79
|
+
host.layout._sync()
|
|
80
|
+
func start() -> void:
|
|
81
|
+
if not enabled() and not is_instance_valid(_clip) and host.get_node_or_null("_EstragonViewport")==null: return
|
|
82
|
+
_ensure_viewport()
|
|
83
|
+
for child in host.get_children():
|
|
84
|
+
if not is_private(child): _adopt_content(child)
|
|
85
|
+
if not host.child_entered_tree.is_connected(_external_child): host.child_entered_tree.connect(_external_child)
|
|
86
|
+
_clip.clip_contents = enabled()
|
|
87
|
+
if enabled(): _input_guard.start(_content)
|
|
88
|
+
else: _input_guard.stop()
|
|
89
|
+
# Re-entry/scene reload must retain offsets until children and the existing
|
|
90
|
+
# coordinator are active again. Their arranged signal refreshes the viewport.
|
|
91
|
+
if host.layout.active: _refresh_viewport()
|
|
92
|
+
func children() -> Array:
|
|
93
|
+
var values: Array = _content.get_children() if is_instance_valid(_content) else []
|
|
94
|
+
for child in host.get_children():
|
|
95
|
+
if not is_private(child): values.append(child)
|
|
96
|
+
return values
|
|
97
|
+
func child_parent() -> Node:
|
|
98
|
+
return _content
|
|
99
|
+
func enabled() -> bool:
|
|
100
|
+
return host.horizontal_scroll or host.vertical_scroll
|
|
101
|
+
func _external_child(child: Node) -> void:
|
|
102
|
+
if not is_private(child): _adopt_later.call_deferred(weakref(child))
|
|
103
|
+
func _adopt_later(reference: WeakRef) -> void:
|
|
104
|
+
var child = reference.get_ref()
|
|
105
|
+
if child!=null and host!=null and host.is_inside_tree(): _adopt_content(child)
|
|
106
|
+
func stop() -> void:
|
|
107
|
+
_input_guard.stop()
|
|
108
|
+
if host.child_entered_tree.is_connected(_external_child): host.child_entered_tree.disconnect(_external_child)
|
|
109
|
+
if is_instance_valid(_content): Hosts.remove(_content,host.layout)
|
|
110
|
+
func refresh() -> void:
|
|
111
|
+
_refresh_viewport()
|
|
112
|
+
func offset_changed() -> void:
|
|
113
|
+
if not host.layout.model.is_layout_dirty(): _update_scroll()
|
|
114
|
+
func _refresh_viewport() -> void:
|
|
115
|
+
if not is_instance_valid(_clip): return
|
|
116
|
+
var rect: Rect2 = host.get_content_rect()
|
|
117
|
+
_clip.position = rect.position
|
|
118
|
+
_clip.size = rect.size
|
|
119
|
+
host._content_extent = host.layout.model.content_extent()
|
|
120
|
+
host._scroll_range = Vector2(maxf(0,host.content_extent.x-rect.size.x) if host.horizontal_scroll else 0,maxf(0,host.content_extent.y-rect.size.y) if host.vertical_scroll else 0)
|
|
121
|
+
_update_scroll()
|
|
122
|
+
func _update_scroll() -> void:
|
|
123
|
+
if _updating or not is_instance_valid(_content): return
|
|
124
|
+
_updating = true
|
|
125
|
+
host.scroll_offset = Vector2(clampf(host.scroll_offset.x,0,host.scroll_range.x),clampf(host.scroll_offset.y,0,host.scroll_range.y))
|
|
126
|
+
if _content.position!=-host.get_content_rect().position-host.scroll_offset:
|
|
127
|
+
_input_guard.cancel()
|
|
128
|
+
var entry = host.get_layout_root()
|
|
129
|
+
if entry!=null and entry.has_method("_get_pointer_router"): entry._get_pointer_router().cancel()
|
|
130
|
+
_content.position = -host.get_content_rect().position-host.scroll_offset
|
|
131
|
+
var rect: Rect2 = host.get_content_rect()
|
|
132
|
+
_horizontal.visible = host.scroll_range.x>0
|
|
133
|
+
_vertical.visible = host.scroll_range.y>0
|
|
134
|
+
_horizontal.position = rect.position+Vector2(0,maxf(0,rect.size.y-12))
|
|
135
|
+
_horizontal.size = Vector2(maxf(0,rect.size.x-(12 if _vertical.visible else 0)),12)
|
|
136
|
+
_vertical.position = rect.position+Vector2(maxf(0,rect.size.x-12),0)
|
|
137
|
+
_vertical.size = Vector2(12,maxf(0,rect.size.y-(12 if _horizontal.visible else 0)))
|
|
138
|
+
_horizontal.max_value = host.content_extent.x
|
|
139
|
+
_horizontal.page = rect.size.x
|
|
140
|
+
_horizontal.value = host.scroll_offset.x
|
|
141
|
+
_vertical.max_value = host.content_extent.y
|
|
142
|
+
_vertical.page = rect.size.y
|
|
143
|
+
_vertical.value = host.scroll_offset.y
|
|
144
|
+
_updating = false
|
|
145
|
+
func _horizontal_changed(value: float) -> void:
|
|
146
|
+
if not _updating: host.scroll_offset = Vector2(value,host.scroll_offset.y)
|
|
147
|
+
func _vertical_changed(value: float) -> void:
|
|
148
|
+
if not _updating: host.scroll_offset = Vector2(host.scroll_offset.x,value)
|
|
149
|
+
func pointer_allowed(position: Vector2) -> bool:
|
|
150
|
+
if not enabled(): return true
|
|
151
|
+
for bar in [_horizontal,_vertical]:
|
|
152
|
+
if is_instance_valid(bar) and bar.is_visible_in_tree():
|
|
153
|
+
var point: Vector2 = bar.get_global_transform_with_canvas().affine_inverse()*position
|
|
154
|
+
if Rect2(Vector2.ZERO,bar.size).has_point(point): return false
|
|
155
|
+
return true
|
|
156
|
+
func input(event: InputEvent) -> void:
|
|
157
|
+
if not enabled() or Engine.is_editor_hint() or not host.is_visible_in_tree() or not (event is InputEventMouse or event is InputEventPanGesture): return
|
|
158
|
+
var point: Vector2 = host.get_global_transform_with_canvas().affine_inverse()*event.position
|
|
159
|
+
if not host.get_content_rect().has_point(point) or not Pointer.inside_clips(host,event.position): return
|
|
160
|
+
var delta := Vector2.ZERO
|
|
161
|
+
if event is InputEventMouseButton and event.pressed:
|
|
162
|
+
match event.button_index:
|
|
163
|
+
MOUSE_BUTTON_WHEEL_DOWN: delta.y = 40*event.factor
|
|
164
|
+
MOUSE_BUTTON_WHEEL_UP: delta.y = -40*event.factor
|
|
165
|
+
MOUSE_BUTTON_WHEEL_RIGHT: delta.x = 40*event.factor
|
|
166
|
+
MOUSE_BUTTON_WHEEL_LEFT: delta.x = -40*event.factor
|
|
167
|
+
if event.shift_pressed: delta = Vector2(delta.y,delta.x)
|
|
168
|
+
elif event is InputEventPanGesture: delta = event.delta*40
|
|
169
|
+
else: return
|
|
170
|
+
var next := Vector2(clampf(host.scroll_offset.x+delta.x,0,host.scroll_range.x),clampf(host.scroll_offset.y+delta.y,0,host.scroll_range.y))
|
|
171
|
+
if next==host.scroll_offset: return # An exhausted nested viewport bubbles naturally.
|
|
172
|
+
host.scroll_offset = next
|
|
173
|
+
var entry = host.get_layout_root()
|
|
174
|
+
if entry!=null and entry.has_method("_get_pointer_router"): entry._get_pointer_router().cancel()
|
|
175
|
+
host.get_viewport().set_input_as_handled()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://b4qhcxualkktg
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Event-driven native GUI capture guard, including opaque Container descendants.
|
|
4
|
+
## Weak subscriptions only; no layout, property mutation, input polling or user data.
|
|
5
|
+
const Pointer = preload("pointer_2d.gd")
|
|
6
|
+
var root: WeakRef
|
|
7
|
+
var watched: Dictionary = {}
|
|
8
|
+
func start(node: Node) -> void:
|
|
9
|
+
root = weakref(node)
|
|
10
|
+
_watch(node)
|
|
11
|
+
func stop() -> void:
|
|
12
|
+
for id in watched.keys(): _remove(id)
|
|
13
|
+
root = null
|
|
14
|
+
func _watch(node: Node) -> void:
|
|
15
|
+
var id := node.get_instance_id()
|
|
16
|
+
if watched.has(id): return
|
|
17
|
+
var reference: WeakRef = weakref(node)
|
|
18
|
+
var child_callback := _watch
|
|
19
|
+
var exit_callback := _left.bind(id,reference)
|
|
20
|
+
var gui_callback := _gui.bind(reference)
|
|
21
|
+
node.child_entered_tree.connect(child_callback)
|
|
22
|
+
node.tree_exited.connect(exit_callback)
|
|
23
|
+
if node is Control: node.gui_input.connect(gui_callback)
|
|
24
|
+
watched[id] = [reference,child_callback,exit_callback,gui_callback]
|
|
25
|
+
for child in node.get_children(true): _watch(child)
|
|
26
|
+
func _left(id: int, reference: WeakRef) -> void:
|
|
27
|
+
_prune.call_deferred(id,reference)
|
|
28
|
+
func _prune(id: int, reference: WeakRef) -> void:
|
|
29
|
+
if not watched.has(id) or watched[id][0]!=reference: return
|
|
30
|
+
var node = reference.get_ref()
|
|
31
|
+
var owner = root.get_ref() if root!=null else null
|
|
32
|
+
if node==null or owner==null or node!=owner and not owner.is_ancestor_of(node): _remove(id)
|
|
33
|
+
func _remove(id: int) -> void:
|
|
34
|
+
var entry: Array = watched[id]
|
|
35
|
+
watched.erase(id)
|
|
36
|
+
var node = entry[0].get_ref()
|
|
37
|
+
if node==null: return
|
|
38
|
+
if node.child_entered_tree.is_connected(entry[1]): node.child_entered_tree.disconnect(entry[1])
|
|
39
|
+
if node.tree_exited.is_connected(entry[2]): node.tree_exited.disconnect(entry[2])
|
|
40
|
+
if node is Control and node.gui_input.is_connected(entry[3]): node.gui_input.disconnect(entry[3])
|
|
41
|
+
func _gui(event: InputEvent, reference: WeakRef) -> void:
|
|
42
|
+
if not event is InputEventMouse: return
|
|
43
|
+
var node = reference.get_ref()
|
|
44
|
+
if node==null: return
|
|
45
|
+
var point: Vector2 = node.get_global_transform_with_canvas()*event.position
|
|
46
|
+
# Signal precedes native BaseButton processing (verified4.0.4/4.7).
|
|
47
|
+
# BaseButton release uses cached pressing_inside, not the event position.
|
|
48
|
+
# The public scroll notification cancels that press; an outside-local point
|
|
49
|
+
# also keeps custom Control handlers from treating capture as an inside hit.
|
|
50
|
+
# Native GUI already chooses the topmost scrollbar. Bar exclusion belongs
|
|
51
|
+
# only to Estragon's separate custom picker, never to native GUI events.
|
|
52
|
+
if not Pointer.inside_clips(node,point,false):
|
|
53
|
+
if node is BaseButton: node.notification(Control.NOTIFICATION_SCROLL_BEGIN)
|
|
54
|
+
event.position = Vector2(-1,-1)
|
|
55
|
+
|
|
56
|
+
func cancel() -> void:
|
|
57
|
+
for entry in watched.values():
|
|
58
|
+
var node = entry[0].get_ref()
|
|
59
|
+
if node is BaseButton: node.notification(Control.NOTIFICATION_SCROLL_BEGIN)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://dlsw63qx3dyfv
|
|
@@ -14,6 +14,7 @@ static func slots(items: Array, content: Vector3, axis: int, gap: float, alignme
|
|
|
14
14
|
for index in range(3):
|
|
15
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
|
+
extent = limit_extent(extent,item)
|
|
17
18
|
# Native fill remains a zero-basis allocation with a native minimum floor.
|
|
18
19
|
if item.fill[axis]>0 and item.requested[axis]<0: extent[axis] = 0.0
|
|
19
20
|
extents.append(extent)
|
|
@@ -29,6 +30,14 @@ static func slots(items: Array, content: Vector3, axis: int, gap: float, alignme
|
|
|
29
30
|
for index in flexible.duplicate():
|
|
30
31
|
var item: Dictionary = items[index]
|
|
31
32
|
var part: float = remaining*(item.grow if item.grow>0 else 1.0)/weight
|
|
33
|
+
var cap: Vector3 = item.get("maximum",Vector3(-1,-1,-1))
|
|
34
|
+
if cap[axis]>=0 and part>maxf(0,maxf(item.minimum[axis],cap[axis])-extents[index][axis]):
|
|
35
|
+
shares[index] = maxf(0,maxf(item.minimum[axis],cap[axis])-extents[index][axis])
|
|
36
|
+
remaining = maxf(0,remaining-shares[index])
|
|
37
|
+
weight -= item.grow if item.grow>0 else 1.0
|
|
38
|
+
flexible.erase(index)
|
|
39
|
+
constrained = true
|
|
40
|
+
continue
|
|
32
41
|
var floor_extra: float = maxf(0,item.minimum[axis]-extents[index][axis])
|
|
33
42
|
if floor_extra>part:
|
|
34
43
|
shares[index] = floor_extra
|
|
@@ -77,3 +86,10 @@ static func cross_alignment(item: Dictionary, parent: String, index: int) -> Str
|
|
|
77
86
|
return "stretch" if item.stretch>0 or item.fill[index]>0 else parent
|
|
78
87
|
static func factor(value: String) -> float:
|
|
79
88
|
return 0.5 if value=="center" else (1.0 if value=="end" else 0.0)
|
|
89
|
+
|
|
90
|
+
static func limit_extent(extent: Vector3, item: Dictionary) -> Vector3:
|
|
91
|
+
var cap: Vector3 = item.get("maximum",Vector3(-1,-1,-1))
|
|
92
|
+
for index in range(3):
|
|
93
|
+
if cap[index]>=0: extent[index] = minf(extent[index],cap[index])
|
|
94
|
+
extent[index] = maxf(extent[index],item.minimum[index])
|
|
95
|
+
return extent
|
package/package.json
CHANGED