@papercraftgames/estragon 0.1.0-beta.24 → 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.
- 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 +62 -0
- package/addons/estragon/editor/components.gd +1 -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 +31 -1
- 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 +11 -1
- package/addons/estragon/runtime/node/internal/coordinator.gd +1 -1
- package/addons/estragon/runtime/node/internal/grid_policy.gd +1 -0
- package/addons/estragon/runtime/node/internal/layout_core.gd +93 -11
- package/addons/estragon/runtime/node/internal/length.gd +5 -4
- package/addons/estragon/runtime/node/internal/pointer_2d.gd +11 -1
- 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/addons/estragon/runtime/node/scroll_view.gd +193 -0
- package/addons/estragon/runtime/node/scroll_view.gd.uid +1 -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_VIEW") and name in ["scroll_range","content_extent"]:
|
|
65
|
+
_error("Read-only ScrollView 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,47 @@ 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)
|
|
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
|
|
149
199
|
var sibling_names := {}
|
|
150
200
|
for child in node.children:
|
|
151
201
|
if child is Model.GdExpression:
|
|
@@ -371,3 +421,15 @@ func _color(attribute) -> void:
|
|
|
371
421
|
if parsed.has("error"): _error(parsed.error,value.span)
|
|
372
422
|
elif tokens.size()==1 and (tokens[0].kind=="number" or tokens[0].text in ["true","false","null","NAN","INF"]):
|
|
373
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)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
extends RefCounted
|
|
3
3
|
## Trusted installed resources, not guessed global classes or installation roots.
|
|
4
4
|
const ITEMS := [
|
|
5
|
+
{"alias":"ScrollView","canonical":"EstragonScrollView","script":preload("../runtime/node/scroll_view.gd"),"dimension":2,"origin":"native viewport"},
|
|
5
6
|
{"alias":"Grid","canonical":"EstragonGrid","script":preload("../runtime/node/grid.gd"),"dimension":2,"origin":"native layout"},
|
|
6
7
|
{"alias":"Spacer","canonical":"EstragonSpacer","script":preload("../runtime/node/spacer.gd"),"dimension":2,"origin":"native layout"},
|
|
7
8
|
{"alias":"Box","canonical":"EstragonBox","script":preload("../runtime/node/box.gd"),"dimension":2,"origin":"native layout"},
|
|
@@ -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()
|
|
@@ -299,6 +299,7 @@ func _boundary_clear(desired: Element, parent: Node) -> bool:
|
|
|
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_VIEW")
|
|
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
|
+
# 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")
|
|
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,16 @@ 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_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")
|
|
578
607
|
if GridDefinition.marked(desired.type):
|
|
579
608
|
var config := _grid_config(desired)
|
|
580
609
|
var grid_matches := _matches(desired.children,previous.children if previous!=null and _compatible(desired,previous) else [])
|
|
@@ -703,6 +732,7 @@ func _free_managed(record: Mounted, rescue: Node = null) -> void:
|
|
|
703
732
|
var manager = state.get_ref()
|
|
704
733
|
if manager != null and manager.records.has(node.get_instance_id()): manager.unmount(node,owner)
|
|
705
734
|
for child in node.get_children():
|
|
735
|
+
if node.has_method("_composition_is_private") and node._composition_is_private(child): continue
|
|
706
736
|
var persisted_owner: Node = child.owner
|
|
707
737
|
node.remove_child(child)
|
|
708
738
|
if owner != null:
|
|
@@ -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
|
|
@@ -90,6 +90,16 @@ var padding_left: Variant = "auto":
|
|
|
90
90
|
if is_same(padding_left,value) or not lengths.assign("padding_left",value): return
|
|
91
91
|
padding_left = value
|
|
92
92
|
_changed()
|
|
93
|
+
var max_width: Variant = "auto":
|
|
94
|
+
set(value):
|
|
95
|
+
if is_same(max_width,value) or not lengths.assign("max_width",value): return
|
|
96
|
+
max_width = value
|
|
97
|
+
_changed()
|
|
98
|
+
var max_height: Variant = "auto":
|
|
99
|
+
set(value):
|
|
100
|
+
if is_same(max_height,value) or not lengths.assign("max_height",value): return
|
|
101
|
+
max_height = value
|
|
102
|
+
_changed()
|
|
93
103
|
var min_width: Variant = 0.0:
|
|
94
104
|
set(value):
|
|
95
105
|
if is_same(min_width,value) or not lengths.assign("min_width",value): return
|
|
@@ -179,7 +189,7 @@ var layout_size: Vector2:
|
|
|
179
189
|
var _layout_size := Vector2.ZERO
|
|
180
190
|
var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
|
|
181
191
|
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"])
|
|
192
|
+
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
193
|
properties.append_array(Length.properties(["row_gap","column_gap"]))
|
|
184
194
|
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
195
|
return properties
|
|
@@ -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:
|
|
@@ -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 = {}
|
|
@@ -43,6 +44,8 @@ var intrinsic := Vector3.ZERO
|
|
|
43
44
|
# Native Control minimums constrain assigned slots, never read back from size.
|
|
44
45
|
var allocation_minimum := Vector3.ZERO
|
|
45
46
|
# Authored border-box floors are independent of native adapter minimums.
|
|
47
|
+
var authored_maximum := Vector3(-1,-1,-1)
|
|
48
|
+
var _reported_max_conflict := false
|
|
46
49
|
var authored_minimum := Vector3.ZERO
|
|
47
50
|
var padding := Vector4.ZERO # left, top, right, bottom; border-box insets
|
|
48
51
|
var border := Vector4.ZERO # inside the border-box, before padding
|
|
@@ -52,6 +55,7 @@ var alignment: Array = ["start","start","start"]
|
|
|
52
55
|
# Parent-owned border-box placements; no Node references or additive offsets.
|
|
53
56
|
var slots: Array = []
|
|
54
57
|
var children: Array = []
|
|
58
|
+
var natural_extent := Vector3.ZERO
|
|
55
59
|
var measured := Vector3.ZERO
|
|
56
60
|
# -1 is an unavailable/cyclic reference axis, distinct from an arranged zero.
|
|
57
61
|
var content_reference := Vector3(-1,-1,-1)
|
|
@@ -66,6 +70,9 @@ var _parent: WeakRef
|
|
|
66
70
|
|
|
67
71
|
var default_padding := Vector4.ZERO
|
|
68
72
|
|
|
73
|
+
func is_layout_dirty() -> bool:
|
|
74
|
+
return _measure_dirty or _arrange_dirty
|
|
75
|
+
|
|
69
76
|
func set_lengths(specs: Dictionary, growth: float, cross: int, scale: float, stack_axis: int, padding_fallback: Vector4 = Vector4.ZERO) -> void:
|
|
70
77
|
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
78
|
default_padding = padding_fallback
|
|
@@ -144,12 +151,13 @@ func prepare(reference: Vector3, viewport: Vector2) -> void:
|
|
|
144
151
|
if _length_context==context: return
|
|
145
152
|
_length_context = context
|
|
146
153
|
resolution_count += 1
|
|
147
|
-
var before := [requested,gap,physical_gaps,padding,border,margin,length_offset,authored_minimum]
|
|
154
|
+
var before := [requested,gap,physical_gaps,padding,border,margin,length_offset,authored_minimum,authored_maximum]
|
|
148
155
|
if not length_specs.is_empty():
|
|
149
156
|
for index in range(3):
|
|
150
157
|
requested[index] = _length(["width","height","depth"][index],index,requested[index])
|
|
151
158
|
length_offset[index] = _length(["x","y","z"][index],index,0)
|
|
152
159
|
authored_minimum = Vector3(maxf(0,_length("min_width",0,0)),maxf(0,_length("min_height",1,0)),0)
|
|
160
|
+
authored_maximum = Vector3(_length("max_width",0,-1),_length("max_height",1,-1),-1)
|
|
153
161
|
gap = _length("gap",axis,0)
|
|
154
162
|
physical_gaps = Vector2(_length("column_gap",0,-1),_length("row_gap",1,-1))
|
|
155
163
|
for index in range(2):
|
|
@@ -167,16 +175,30 @@ func minimum() -> Vector3:
|
|
|
167
175
|
for index in range(3): result[index] = maxf(result[index],maxf(allocation_minimum[index],inherited[index]))
|
|
168
176
|
return result
|
|
169
177
|
|
|
178
|
+
func maximum() -> Vector3:
|
|
179
|
+
if transparent and children.size()==1: return children[0].maximum()
|
|
180
|
+
return authored_maximum
|
|
181
|
+
|
|
170
182
|
func constrain(extent: Vector3) -> Vector3:
|
|
171
183
|
var floor := minimum()
|
|
172
|
-
|
|
184
|
+
var cap := maximum()
|
|
185
|
+
for index in range(3):
|
|
186
|
+
if cap[index]>=0:
|
|
187
|
+
if floor[index]>cap[index] and not _reported_max_conflict and not transparent:
|
|
188
|
+
_reported_max_conflict = true
|
|
189
|
+
push_warning("Estragon minimum exceeds maximum; minimum/native floor wins")
|
|
190
|
+
extent[index] = minf(extent[index],cap[index])
|
|
191
|
+
extent[index] = maxf(extent[index],floor[index])
|
|
173
192
|
return extent
|
|
174
193
|
|
|
175
194
|
func _content_basis() -> Vector3:
|
|
176
195
|
var basis := Vector3(-1,-1,-1)
|
|
177
196
|
for index in range(3):
|
|
178
|
-
var allocated: float = requested[index] if requested[index]>=0 else measurement_allocation[index]
|
|
197
|
+
var allocated: float = constrain(requested)[index] if requested[index]>=0 else measurement_allocation[index]
|
|
179
198
|
if allocated>=0: basis[index] = maxf(0,maxf(allocated,minimum()[index])-leading(padding+border)[index]-trailing(padding+border)[index])
|
|
199
|
+
if strategy=="scroll":
|
|
200
|
+
for index in range(2):
|
|
201
|
+
if grid_config.get(["horizontal_scroll","vertical_scroll"][index],false): basis[index] = -1
|
|
180
202
|
return basis
|
|
181
203
|
|
|
182
204
|
static func valid_extent(value: Vector3) -> bool:
|
|
@@ -249,12 +271,12 @@ func track_contribution() -> Vector3:
|
|
|
249
271
|
result[axis] = intrinsic[axis]
|
|
250
272
|
for child in children: result[axis] = maxf(result[axis],maxf(child.measured[axis],child.minimum()[axis])+child.outer_extent()[axis])
|
|
251
273
|
result[axis] += leading(padding+border)[axis]+trailing(padding+border)[axis]
|
|
252
|
-
return result
|
|
274
|
+
return constrain(result)
|
|
253
275
|
|
|
254
276
|
func _items() -> Array:
|
|
255
277
|
var items: Array = []
|
|
256
278
|
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})
|
|
279
|
+
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
280
|
return items
|
|
259
281
|
|
|
260
282
|
func _grid(items: Array, content: Vector3) -> Dictionary:
|
|
@@ -278,11 +300,33 @@ func _grid(items: Array, content: Vector3) -> Dictionary:
|
|
|
278
300
|
|
|
279
301
|
# Allocation-dependent measurement is a bounded second pass in this same core.
|
|
280
302
|
# Only independently assigned axes may supply a basis; auto cycles stay absent.
|
|
303
|
+
func set_capacity(value: Vector3) -> void:
|
|
304
|
+
if not transparent:
|
|
305
|
+
if strategy!="wrap" or requested[axis]>=0: return
|
|
306
|
+
var main: float = value[axis]
|
|
307
|
+
value = Vector3(-1,-1,-1)
|
|
308
|
+
value[axis] = main
|
|
309
|
+
if available_capacity==value: return
|
|
310
|
+
available_capacity = value
|
|
311
|
+
_measure_dirty = true
|
|
312
|
+
_arrange_dirty = true
|
|
313
|
+
if transparent and children.size()==1: children[0].set_capacity(value)
|
|
314
|
+
|
|
315
|
+
func _wrap_basis() -> Vector3:
|
|
316
|
+
var basis := _content_basis()
|
|
317
|
+
if strategy=="wrap" and requested[axis]<0 and basis[axis]<0 and available_capacity[axis]>=0:
|
|
318
|
+
basis[axis] = maxf(0,available_capacity[axis]-leading(padding+border)[axis]-trailing(padding+border)[axis])
|
|
319
|
+
var cap := maximum()
|
|
320
|
+
if strategy=="wrap" and cap[axis]>=0:
|
|
321
|
+
var available := maxf(0,maxf(cap[axis],minimum()[axis])-leading(padding+border)[axis]-trailing(padding+border)[axis])
|
|
322
|
+
basis[axis] = minf(basis[axis],available) if basis[axis]>=0 else available
|
|
323
|
+
return basis
|
|
324
|
+
|
|
281
325
|
func measure_allocated(extent: Vector3, authority: Vector3) -> void:
|
|
282
326
|
if transparent and children.size()==1:
|
|
283
327
|
children[0].measure_allocated(extent,authority)
|
|
284
328
|
_measure_dirty = true
|
|
285
|
-
elif strategy in ["wrap","grid"]:
|
|
329
|
+
elif strategy in ["wrap","grid","scroll"]:
|
|
286
330
|
var next := measurement_allocation
|
|
287
331
|
for index in range(2):
|
|
288
332
|
if requested[index]<0 and authority[index]>0: next[index] = extent[index]
|
|
@@ -292,7 +336,26 @@ func measure_allocated(extent: Vector3, authority: Vector3) -> void:
|
|
|
292
336
|
else: return
|
|
293
337
|
measure()
|
|
294
338
|
|
|
339
|
+
func _scroll_slots(items: Array, content: Vector3) -> Array:
|
|
340
|
+
var result: Array = []
|
|
341
|
+
for item in items:
|
|
342
|
+
var extent: Vector3 = item.preferred
|
|
343
|
+
for index in range(2):
|
|
344
|
+
if not grid_config.get(["horizontal_scroll","vertical_scroll"][index],false) and content[index]>=0 and item.requested[index]<0: extent[index] = maxf(item.minimum[index],content[index]-item.outer[index])
|
|
345
|
+
extent = StackPolicy.limit_extent(extent,item)
|
|
346
|
+
result.append({"position":item.leading-leading(padding+border),"extent":extent})
|
|
347
|
+
return result
|
|
348
|
+
|
|
349
|
+
func overflow_extent() -> Vector3:
|
|
350
|
+
var result := size
|
|
351
|
+
for index in range(3): result[index] = maxf(result[index],natural_extent[index])
|
|
352
|
+
for child in children:
|
|
353
|
+
var extent: Vector3 = child.offset+child.overflow_extent()+trailing(child.margin)
|
|
354
|
+
for index in range(3): result[index] = maxf(result[index],extent[index])
|
|
355
|
+
return result
|
|
356
|
+
|
|
295
357
|
func _slots(items: Array, content: Vector3, definite: Vector3) -> Array:
|
|
358
|
+
if strategy=="scroll": return _scroll_slots(items,content)
|
|
296
359
|
if strategy=="grid": return _grid(items,content).slots
|
|
297
360
|
if strategy=="wrap": return WrapPolicy.layout(items,content,axis,physical_gaps,alignment,align_content,Vector2(definite.x,definite.y)).slots
|
|
298
361
|
return StackPolicy.slots(items,content,axis,physical_gaps[axis] if axis<2 and not length_specs.is_empty() else gap,alignment)
|
|
@@ -301,7 +364,9 @@ func _authority(child, item: Dictionary, basis: Vector3) -> Vector3:
|
|
|
301
364
|
var authority := Vector3.ZERO
|
|
302
365
|
for index in range(3):
|
|
303
366
|
if basis[index]<0 or child.requested[index]>=0: continue
|
|
304
|
-
if strategy=="
|
|
367
|
+
if strategy=="scroll":
|
|
368
|
+
if index<2 and not grid_config.get(["horizontal_scroll","vertical_scroll"][index],false): authority[index] = 1
|
|
369
|
+
elif strategy=="grid":
|
|
305
370
|
if index<2 and alignment[index]=="stretch": authority[index] = 1
|
|
306
371
|
elif index==axis:
|
|
307
372
|
if child.grow>0 or child.fill[index]>0: authority[index] = 1
|
|
@@ -312,6 +377,7 @@ func measure() -> Vector3:
|
|
|
312
377
|
if transparent and children.size()==1:
|
|
313
378
|
var child = children[0]
|
|
314
379
|
child.prepare(parent_reference,viewport_size)
|
|
380
|
+
child.set_capacity(available_capacity)
|
|
315
381
|
child.measure()
|
|
316
382
|
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
383
|
requested = child.requested
|
|
@@ -329,6 +395,10 @@ func measure() -> Vector3:
|
|
|
329
395
|
var basis := _content_basis()
|
|
330
396
|
for child in children:
|
|
331
397
|
child.prepare(basis,viewport_size)
|
|
398
|
+
var capacity := basis
|
|
399
|
+
for index in range(3):
|
|
400
|
+
if capacity[index]>=0: capacity[index] = maxf(0,capacity[index]-child.outer_extent()[index])
|
|
401
|
+
child.set_capacity(capacity)
|
|
332
402
|
child.measure()
|
|
333
403
|
if basis.x>=0 or basis.y>=0:
|
|
334
404
|
var items := _items()
|
|
@@ -346,12 +416,14 @@ func measure() -> Vector3:
|
|
|
346
416
|
else: natural[index] = maxf(natural[index],child_size[index])
|
|
347
417
|
if children.size() > 1: natural[axis] += (physical_gaps[axis] if axis<2 and length_specs.has("column_gap") else gap) * (children.size() - 1)
|
|
348
418
|
if strategy=="wrap" and not transparent:
|
|
349
|
-
var basis :=
|
|
419
|
+
var basis := _wrap_basis()
|
|
350
420
|
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
|
|
421
|
+
if basis[axis]>=0 and requested[axis]<0: natural[axis] = minf(basis[axis],natural[axis])
|
|
351
422
|
if strategy=="grid" and not transparent:
|
|
352
423
|
natural = _grid(_items(),_content_basis()).extent
|
|
353
424
|
for index in range(3): natural[index] = maxf(natural[index],intrinsic[index])
|
|
354
425
|
if not transparent: natural += leading(padding+border)+trailing(padding+border)
|
|
426
|
+
natural_extent = natural
|
|
355
427
|
measured = natural
|
|
356
428
|
for axis in range(3):
|
|
357
429
|
if requested[axis] >= 0: measured[axis] = requested[axis]
|
|
@@ -363,10 +435,12 @@ func measure() -> Vector3:
|
|
|
363
435
|
# ignore this model's intrinsic extent and can inherit an independent basis.
|
|
364
436
|
func independent_axis(index: int) -> bool:
|
|
365
437
|
if requested[index] >= 0 or _external_axes[index] > 0: return true
|
|
438
|
+
if strategy=="scroll" and maximum()[index]>=0: return true
|
|
366
439
|
var parent = _parent.get_ref() if _parent != null else null
|
|
367
440
|
if parent == null: return false
|
|
368
441
|
var allocated := grow>0 or fill[index]>0
|
|
369
442
|
if index!=parent.axis: allocated = StackPolicy.cross_alignment({"align_self":align_self,"stretch":stretch,"fill":fill},parent.alignment[index],index)=="stretch"
|
|
443
|
+
if parent.strategy=="scroll" and index<2: allocated = not parent.grid_config.get(["horizontal_scroll","vertical_scroll"][index],false)
|
|
370
444
|
if parent.strategy=="grid" and index<2: allocated = parent.alignment[index]=="stretch"
|
|
371
445
|
return parent.independent_axis(index) if requested[index] < 0 and allocated else false
|
|
372
446
|
|
|
@@ -413,7 +487,11 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
413
487
|
# Assigned content is authoritative, including grow allocations. Resolve the
|
|
414
488
|
# immediate children against this box before measuring their slots.
|
|
415
489
|
for child in children:
|
|
416
|
-
|
|
490
|
+
var child_reference := reference
|
|
491
|
+
if strategy=="scroll":
|
|
492
|
+
for index in range(2):
|
|
493
|
+
if grid_config.get(["horizontal_scroll","vertical_scroll"][index],false): child_reference[index] = -1
|
|
494
|
+
child.prepare(child_reference,viewport_size)
|
|
417
495
|
child.measure()
|
|
418
496
|
if not _reported_full_percent and children.size()>1:
|
|
419
497
|
var main_name: String = ["width","height","depth"][axis]
|
|
@@ -426,8 +504,11 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
426
504
|
var items := _items()
|
|
427
505
|
var policy := alignment.duplicate()
|
|
428
506
|
if center: policy[axis] = "center"
|
|
429
|
-
if strategy=="
|
|
430
|
-
slots =
|
|
507
|
+
if strategy=="scroll":
|
|
508
|
+
slots = _scroll_slots(items,content)
|
|
509
|
+
elif strategy=="wrap":
|
|
510
|
+
var wrap_basis := _wrap_basis()
|
|
511
|
+
slots = WrapPolicy.layout(items,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
512
|
else:
|
|
432
513
|
slots = StackPolicy.slots(items,content,axis,physical_gaps[axis] if axis<2 and length_specs.has("column_gap") else gap,policy)
|
|
433
514
|
if strategy=="grid":
|
|
@@ -445,5 +526,6 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
445
526
|
for cross in range(3):
|
|
446
527
|
if strategy=="grid" and cross<2 and policy[cross]=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
|
|
447
528
|
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
|
|
529
|
+
if strategy=="scroll": authority = _authority(child,items[index],reference)
|
|
448
530
|
child.arrange(slot.extent,authority)
|
|
449
531
|
arranged.emit(size)
|
|
@@ -7,6 +7,7 @@ extends RefCounted
|
|
|
7
7
|
const VisualStyle = preload("visual_style_2d.gd")
|
|
8
8
|
const LIMIT := 1.0e12
|
|
9
9
|
const FACTORS := {"":1.0,"px":1.0,"in":96.0,"cm":96.0/2.54,"mm":96.0/25.4,"q":96.0/101.6,"pt":96.0/72.0,"pc":16.0}
|
|
10
|
+
const 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
|
|
@@ -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,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
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
class_name EstragonScrollView
|
|
3
|
+
extends "component_2d.gd"
|
|
4
|
+
## One authored content root, one existing layout model. Native Control supplies
|
|
5
|
+
## rectangular clipping/GUI exclusion; Node2D supplies local scroll translation.
|
|
6
|
+
const ESTRAGON_SCROLL_VIEW := true
|
|
7
|
+
const Hosts = preload("internal/composition_hosts.tres")
|
|
8
|
+
const Pointer = preload("internal/pointer_2d.gd")
|
|
9
|
+
@export var horizontal_scroll: bool = false:
|
|
10
|
+
set(value):
|
|
11
|
+
if horizontal_scroll==value: return
|
|
12
|
+
horizontal_scroll = value
|
|
13
|
+
_changed()
|
|
14
|
+
@export var vertical_scroll: bool = false:
|
|
15
|
+
set(value):
|
|
16
|
+
if vertical_scroll==value: return
|
|
17
|
+
vertical_scroll = value
|
|
18
|
+
_changed()
|
|
19
|
+
@export var scroll_offset := Vector2.ZERO:
|
|
20
|
+
set(value):
|
|
21
|
+
if not valid_offset(value):
|
|
22
|
+
push_error("Estragon ScrollView scroll_offset requires a finite nonnegative Vector2")
|
|
23
|
+
return
|
|
24
|
+
scroll_offset = value
|
|
25
|
+
# A new viewport/content allocation must resolve before restoring/clamping
|
|
26
|
+
# an authored offset. The existing arranged callback consumes it once.
|
|
27
|
+
if not layout.model.is_layout_dirty(): _update_scroll()
|
|
28
|
+
var scroll_range: Vector2:
|
|
29
|
+
get: return _scroll_range
|
|
30
|
+
set(_value): push_error("Estragon ScrollView scroll_range is read-only")
|
|
31
|
+
var content_extent: Vector2:
|
|
32
|
+
get: return _content_extent
|
|
33
|
+
set(_value): push_error("Estragon ScrollView content_extent is read-only")
|
|
34
|
+
var _scroll_range := Vector2.ZERO
|
|
35
|
+
var _content_extent := Vector2.ZERO
|
|
36
|
+
var _clip: Control
|
|
37
|
+
var _content: Node2D
|
|
38
|
+
var _horizontal: HScrollBar
|
|
39
|
+
var _vertical: VScrollBar
|
|
40
|
+
var _updating := false
|
|
41
|
+
var _input_guard = preload("internal/scroll_input.gd").new()
|
|
42
|
+
static func valid_offset(value) -> bool:
|
|
43
|
+
return value is Vector2 and is_finite(value.x) and is_finite(value.y) and value.x>=0 and value.y>=0
|
|
44
|
+
func _ensure_viewport() -> void:
|
|
45
|
+
if is_instance_valid(_clip):
|
|
46
|
+
Hosts.add(_content,layout)
|
|
47
|
+
_input_guard.start(_content)
|
|
48
|
+
return
|
|
49
|
+
_clip = get_node_or_null("_EstragonViewport")
|
|
50
|
+
if _clip==null:
|
|
51
|
+
_clip = Control.new()
|
|
52
|
+
_clip.name = "_EstragonViewport"
|
|
53
|
+
_clip.clip_contents = true
|
|
54
|
+
_clip.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
55
|
+
add_child(_clip,false,Node.INTERNAL_MODE_BACK)
|
|
56
|
+
_content = _clip.get_node_or_null("_EstragonContent")
|
|
57
|
+
if _content==null:
|
|
58
|
+
_content = Node2D.new()
|
|
59
|
+
_content.name = "_EstragonContent"
|
|
60
|
+
_clip.add_child(_content,false,Node.INTERNAL_MODE_BACK)
|
|
61
|
+
Hosts.add(_content,layout)
|
|
62
|
+
_input_guard.start(_content)
|
|
63
|
+
if not _content.child_entered_tree.is_connected(layout._child_entered): _content.child_entered_tree.connect(layout._child_entered)
|
|
64
|
+
if not _content.child_exiting_tree.is_connected(layout._child_exiting): _content.child_exiting_tree.connect(layout._child_exiting)
|
|
65
|
+
_horizontal = HScrollBar.new()
|
|
66
|
+
_vertical = VScrollBar.new()
|
|
67
|
+
add_child(_horizontal,false,Node.INTERNAL_MODE_BACK)
|
|
68
|
+
add_child(_vertical,false,Node.INTERNAL_MODE_FRONT)
|
|
69
|
+
_horizontal.step = 0
|
|
70
|
+
_vertical.step = 0
|
|
71
|
+
_horizontal.custom_step = 40
|
|
72
|
+
_vertical.custom_step = 40
|
|
73
|
+
_horizontal.value_changed.connect(_horizontal_changed)
|
|
74
|
+
_vertical.value_changed.connect(_vertical_changed)
|
|
75
|
+
func _composition_child_parent() -> Node:
|
|
76
|
+
_ensure_viewport()
|
|
77
|
+
return _content
|
|
78
|
+
func _layout_children() -> Array:
|
|
79
|
+
return _content.get_children() if is_instance_valid(_content) else []
|
|
80
|
+
func get_content_root() -> Node:
|
|
81
|
+
return _content.get_child(0) if is_instance_valid(_content) and _content.get_child_count()>0 else null
|
|
82
|
+
func _layout_options() -> Dictionary:
|
|
83
|
+
var result := super._layout_options()
|
|
84
|
+
result.strategy = "scroll"
|
|
85
|
+
result.grid = {"horizontal_scroll":horizontal_scroll,"vertical_scroll":vertical_scroll}
|
|
86
|
+
return result
|
|
87
|
+
func _composition_is_private(child: Node) -> bool:
|
|
88
|
+
return child==_clip or child==_horizontal or child==_vertical
|
|
89
|
+
func _remember_owners(node: Node, values: Dictionary) -> void:
|
|
90
|
+
if node.owner!=null: values[node] = node.owner
|
|
91
|
+
for child in node.get_children(): _remember_owners(child,values)
|
|
92
|
+
func _adopt_content(child: Node) -> void:
|
|
93
|
+
if child.get_parent()!=self or _composition_is_private(child): return
|
|
94
|
+
if _content.get_child_count()>0:
|
|
95
|
+
push_error("Estragon ScrollView requires one content root; wrap siblings in VBox/Grid")
|
|
96
|
+
return
|
|
97
|
+
var owners := {}
|
|
98
|
+
_remember_owners(child,owners)
|
|
99
|
+
var scene_owner := child.owner
|
|
100
|
+
remove_child(child)
|
|
101
|
+
_content.add_child(child)
|
|
102
|
+
if scene_owner!=null:
|
|
103
|
+
# Native scene persistence includes the necessary private ancestry only
|
|
104
|
+
# for an authored persistent root. Generated owner-null views serialize
|
|
105
|
+
# neither helpers nor content; descriptions remount after reload.
|
|
106
|
+
_clip.owner = scene_owner
|
|
107
|
+
_content.owner = scene_owner
|
|
108
|
+
for node in owners:
|
|
109
|
+
if owners[node].is_ancestor_of(node): node.owner = owners[node]
|
|
110
|
+
layout._sync()
|
|
111
|
+
func _enter_tree() -> void:
|
|
112
|
+
_ensure_viewport()
|
|
113
|
+
for child in get_children():
|
|
114
|
+
if not _composition_is_private(child): _adopt_content(child)
|
|
115
|
+
super._enter_tree()
|
|
116
|
+
if not child_entered_tree.is_connected(_external_child): child_entered_tree.connect(_external_child)
|
|
117
|
+
func _external_child(child: Node) -> void:
|
|
118
|
+
if not _composition_is_private(child): _adopt_later.call_deferred(weakref(child))
|
|
119
|
+
func _adopt_later(reference: WeakRef) -> void:
|
|
120
|
+
var child = reference.get_ref()
|
|
121
|
+
if child!=null and is_inside_tree(): _adopt_content(child)
|
|
122
|
+
func _exit_tree() -> void:
|
|
123
|
+
_input_guard.stop()
|
|
124
|
+
if child_entered_tree.is_connected(_external_child): child_entered_tree.disconnect(_external_child)
|
|
125
|
+
super._exit_tree()
|
|
126
|
+
if is_instance_valid(_content): Hosts.remove(_content,layout)
|
|
127
|
+
func apply_layout_size(extent: Vector3) -> void:
|
|
128
|
+
super.apply_layout_size(extent)
|
|
129
|
+
_refresh_viewport()
|
|
130
|
+
func _refresh_viewport() -> void:
|
|
131
|
+
if not is_instance_valid(_clip): return
|
|
132
|
+
var rect := get_content_rect()
|
|
133
|
+
_clip.position = rect.position
|
|
134
|
+
_clip.size = rect.size
|
|
135
|
+
_content_extent = Vector2.ZERO
|
|
136
|
+
if not layout.model.children.is_empty():
|
|
137
|
+
var extent: Vector3 = layout.model.children[0].overflow_extent()
|
|
138
|
+
_content_extent = Vector2(extent.x,extent.y)
|
|
139
|
+
_scroll_range = Vector2(maxf(0,content_extent.x-rect.size.x) if horizontal_scroll else 0,maxf(0,content_extent.y-rect.size.y) if vertical_scroll else 0)
|
|
140
|
+
_update_scroll()
|
|
141
|
+
func _update_scroll() -> void:
|
|
142
|
+
if _updating or not is_instance_valid(_content): return
|
|
143
|
+
_updating = true
|
|
144
|
+
scroll_offset = Vector2(clampf(scroll_offset.x,0,scroll_range.x),clampf(scroll_offset.y,0,scroll_range.y))
|
|
145
|
+
if _content.position!=-scroll_offset:
|
|
146
|
+
_input_guard.cancel()
|
|
147
|
+
var entry = get_layout_root()
|
|
148
|
+
if entry!=null and entry.has_method("_get_pointer_router"): entry._get_pointer_router().cancel()
|
|
149
|
+
_content.position = -scroll_offset
|
|
150
|
+
var rect := get_content_rect()
|
|
151
|
+
_horizontal.visible = scroll_range.x>0
|
|
152
|
+
_vertical.visible = scroll_range.y>0
|
|
153
|
+
_horizontal.position = rect.position+Vector2(0,maxf(0,rect.size.y-12))
|
|
154
|
+
_horizontal.size = Vector2(maxf(0,rect.size.x-(12 if _vertical.visible else 0)),12)
|
|
155
|
+
_vertical.position = rect.position+Vector2(maxf(0,rect.size.x-12),0)
|
|
156
|
+
_vertical.size = Vector2(12,maxf(0,rect.size.y-(12 if _horizontal.visible else 0)))
|
|
157
|
+
_horizontal.max_value = content_extent.x
|
|
158
|
+
_horizontal.page = rect.size.x
|
|
159
|
+
_horizontal.value = scroll_offset.x
|
|
160
|
+
_vertical.max_value = content_extent.y
|
|
161
|
+
_vertical.page = rect.size.y
|
|
162
|
+
_vertical.value = scroll_offset.y
|
|
163
|
+
_updating = false
|
|
164
|
+
func _horizontal_changed(value: float) -> void:
|
|
165
|
+
if not _updating: scroll_offset = Vector2(value,scroll_offset.y)
|
|
166
|
+
func _vertical_changed(value: float) -> void:
|
|
167
|
+
if not _updating: scroll_offset = Vector2(scroll_offset.x,value)
|
|
168
|
+
func _content_pointer_allowed(position: Vector2) -> bool:
|
|
169
|
+
for bar in [_horizontal,_vertical]:
|
|
170
|
+
if is_instance_valid(bar) and bar.is_visible_in_tree():
|
|
171
|
+
var point: Vector2 = bar.get_global_transform_with_canvas().affine_inverse()*position
|
|
172
|
+
if Rect2(Vector2.ZERO,bar.size).has_point(point): return false
|
|
173
|
+
return true
|
|
174
|
+
func _input(event: InputEvent) -> void:
|
|
175
|
+
if Engine.is_editor_hint() or not is_visible_in_tree() or not (event is InputEventMouse or event is InputEventPanGesture): return
|
|
176
|
+
var point: Vector2 = get_global_transform_with_canvas().affine_inverse()*event.position
|
|
177
|
+
if not get_content_rect().has_point(point) or not Pointer.inside_clips(self,event.position): return
|
|
178
|
+
var delta := Vector2.ZERO
|
|
179
|
+
if event is InputEventMouseButton and event.pressed:
|
|
180
|
+
match event.button_index:
|
|
181
|
+
MOUSE_BUTTON_WHEEL_DOWN: delta.y = 40*event.factor
|
|
182
|
+
MOUSE_BUTTON_WHEEL_UP: delta.y = -40*event.factor
|
|
183
|
+
MOUSE_BUTTON_WHEEL_RIGHT: delta.x = 40*event.factor
|
|
184
|
+
MOUSE_BUTTON_WHEEL_LEFT: delta.x = -40*event.factor
|
|
185
|
+
if event.shift_pressed: delta = Vector2(delta.y,delta.x)
|
|
186
|
+
elif event is InputEventPanGesture: delta = event.delta*40
|
|
187
|
+
else: return
|
|
188
|
+
var next := Vector2(clampf(scroll_offset.x+delta.x,0,scroll_range.x),clampf(scroll_offset.y+delta.y,0,scroll_range.y))
|
|
189
|
+
if next==scroll_offset: return # An exhausted nested viewport bubbles naturally.
|
|
190
|
+
scroll_offset = next
|
|
191
|
+
var entry = get_layout_root()
|
|
192
|
+
if entry!=null and entry.has_method("_get_pointer_router"): entry._get_pointer_router().cancel()
|
|
193
|
+
get_viewport().set_input_as_handled()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://cqrqp33qeuh6g
|
package/package.json
CHANGED