@papercraftgames/estragon 0.1.0-beta.20 → 0.1.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addons/estragon/compiler/emitter.gd +10 -0
- package/addons/estragon/compiler/model.gd +1 -0
- package/addons/estragon/compiler/native/resolver.gd +3 -0
- package/addons/estragon/compiler/parser.gd +29 -3
- package/addons/estragon/compiler/validator.gd +14 -5
- package/addons/estragon/editor/length_property.gd +1 -1
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/runtime/composition/computation.gd +111 -25
- package/addons/estragon/runtime/composition/element.gd +46 -0
- package/addons/estragon/runtime/composition/native_attributes.gd +26 -0
- package/addons/estragon/runtime/composition/native_attributes.gd.uid +1 -0
- package/addons/estragon/runtime/node/box.gd +0 -33
- package/addons/estragon/runtime/node/button.gd +36 -13
- package/addons/estragon/runtime/node/component_2d.gd +53 -3
- package/addons/estragon/runtime/node/internal/component_2d_icon.tres +4 -0
- package/addons/estragon/runtime/node/internal/coordinator.gd +2 -2
- package/addons/estragon/runtime/node/internal/layout_core.gd +28 -7
- package/addons/estragon/runtime/node/internal/length.gd +9 -5
- package/addons/estragon/runtime/node/internal/visual_style_2d.gd +15 -5
- package/addons/estragon/runtime/node/native_2d.gd +2 -3
- package/addons/estragon/runtime/node/rect.gd +12 -13
- package/addons/estragon/runtime/node/text.gd +4 -3
- package/addons/estragon/runtime/node/toggle.gd +17 -4
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ const Source = preload("source.gd")
|
|
|
9
9
|
const MappedWriter = preload("source_map.gd")
|
|
10
10
|
|
|
11
11
|
class Argument extends RefCounted:
|
|
12
|
+
var spread := false
|
|
12
13
|
var expression: Model.GdExpression
|
|
13
14
|
var type_name: String
|
|
14
15
|
var name: String
|
|
@@ -100,6 +101,7 @@ func _collect(node: Model.Component, factory: Factory) -> void:
|
|
|
100
101
|
for attribute in node.attributes:
|
|
101
102
|
if attribute.value is Model.GdExpression:
|
|
102
103
|
_argument(attribute.value, attribute.type_name, factory)
|
|
104
|
+
factory.arguments.back().spread = attribute.kind=="spread"
|
|
103
105
|
if attribute.kind=="binding": factory.arguments.back().binding_path = attribute.binding_path
|
|
104
106
|
for child in node.children:
|
|
105
107
|
if child is Model.GdExpression: _argument(child,"Variant",factory)
|
|
@@ -143,8 +145,10 @@ func _call(node: Model.Component) -> void:
|
|
|
143
145
|
if index > 0: _writer.append("," if multiline else ", ", node.span)
|
|
144
146
|
if multiline: _writer.append("\n" + base + _module.indentation, argument.expression.span)
|
|
145
147
|
_writer.append("(", argument.expression.span)
|
|
148
|
+
if argument.spread: _writer.append("preload("+_resource(Element)+").snapshot(",argument.expression.span)
|
|
146
149
|
if argument.binding_path.is_empty(): _parts(argument.expression.parts)
|
|
147
150
|
else: _binding_argument(argument)
|
|
151
|
+
if argument.spread: _writer.append(")",argument.expression.span)
|
|
148
152
|
_writer.append(")", argument.expression.span)
|
|
149
153
|
_writer.append(("\n" + base if multiline else "") + ")", node.span)
|
|
150
154
|
|
|
@@ -172,6 +176,8 @@ func _description(node: Model.Component, indentation: String) -> String:
|
|
|
172
176
|
var bindings := PackedStringArray()
|
|
173
177
|
var key := "null"
|
|
174
178
|
var keyed := "false"
|
|
179
|
+
var expanded := node.attributes.any(func(item): return item.kind=="spread")
|
|
180
|
+
var ordered := PackedStringArray()
|
|
175
181
|
for attribute in node.attributes:
|
|
176
182
|
var value: String = _arguments[attribute.value].name if attribute.value is Model.GdExpression else literal(attribute.value)
|
|
177
183
|
if attribute.kind == "binding":
|
|
@@ -181,6 +187,9 @@ func _description(node: Model.Component, indentation: String) -> String:
|
|
|
181
187
|
key = value
|
|
182
188
|
keyed = "true"
|
|
183
189
|
continue
|
|
190
|
+
if expanded:
|
|
191
|
+
ordered.append("[%s, %s, %s]" % ["null" if attribute.kind=="spread" else _string(attribute.name),value,_string("%s:%d:%d" % [_file.name,attribute.name_span.start.line,attribute.name_span.start.column])])
|
|
192
|
+
continue
|
|
184
193
|
var target := events if attribute.kind == "signal" else props
|
|
185
194
|
target.append(_string(attribute.name)+": "+value)
|
|
186
195
|
var children := PackedStringArray()
|
|
@@ -188,6 +197,7 @@ func _description(node: Model.Component, indentation: String) -> String:
|
|
|
188
197
|
children.append(_arguments[child].name if child is Model.GdExpression else _description(child,indentation))
|
|
189
198
|
var native_type := _string(node.runtime_class) if ClassDB.class_exists(node.runtime_class) else node.runtime_class
|
|
190
199
|
_line("var %s := %s.new(%s, {%s}, {%s}, [%s], %s, %s, %s)" % [variable,_element_class,native_type,", ".join(props),", ".join(events),", ".join(children),_string("%s:%d:%d" % [_file.name,node.span.start.line,node.span.start.column]),key,keyed],node.span,indentation)
|
|
200
|
+
if expanded: _line(variable+".expand(["+", ".join(ordered)+"])",node.span,indentation)
|
|
191
201
|
if not bindings.is_empty(): _line(variable+".bindings = {"+", ".join(bindings)+"}",node.span,indentation)
|
|
192
202
|
return variable
|
|
193
203
|
|
|
@@ -159,6 +159,9 @@ func _script(name: String, path: String, span: Model.Span, check_constructor: bo
|
|
|
159
159
|
func _gogo(name: String, path: String, authored: String, span: Model.Span, check_constructor: bool = true) -> Dictionary:
|
|
160
160
|
if visiting.has(path): return _fail("Cyclic Gogo component inheritance: "+path,span)
|
|
161
161
|
visiting[path] = true
|
|
162
|
+
# Explicit imports can reach this path before project-tag lookup initializes
|
|
163
|
+
# the optional scope. Initialize it before testing its source index.
|
|
164
|
+
scope()
|
|
162
165
|
var text: String = scope().read(project.authored(authored)) if project.sources.has(project.authored(authored)) else FileAccess.get_file_as_string(authored)
|
|
163
166
|
var source := Source.new(text,authored,path,project)
|
|
164
167
|
var module = Parser.new(source).parse()
|
|
@@ -91,6 +91,15 @@ func _component(depth: int) -> Model.Component:
|
|
|
91
91
|
if not separated:
|
|
92
92
|
file.fail("Expected whitespace before a property, or a tag terminator", _cursor)
|
|
93
93
|
return null
|
|
94
|
+
if _at("{"):
|
|
95
|
+
var spread := Model.Attribute.new()
|
|
96
|
+
spread.kind = "spread"
|
|
97
|
+
spread.name_span = file.span(_cursor,_cursor+1)
|
|
98
|
+
spread.value = _expression(true)
|
|
99
|
+
if spread.value==null: return null
|
|
100
|
+
spread.span = spread.value.span
|
|
101
|
+
node.attributes.append(spread)
|
|
102
|
+
continue
|
|
94
103
|
var attribute_name := _name()
|
|
95
104
|
if attribute_name == null: return null
|
|
96
105
|
_whitespace()
|
|
@@ -124,6 +133,7 @@ func _component(depth: int) -> Model.Component:
|
|
|
124
133
|
_cursor += 1
|
|
125
134
|
lexer.token("markup-string", quote_start, _cursor)
|
|
126
135
|
if attribute.value == null: return null
|
|
136
|
+
attribute.span = file.span(attribute.name_span.start.index,_cursor)
|
|
127
137
|
node.attributes.append(attribute)
|
|
128
138
|
_trivia()
|
|
129
139
|
while not _at("</") and file.diagnostics.is_empty():
|
|
@@ -150,10 +160,23 @@ func _component(depth: int) -> Model.Component:
|
|
|
150
160
|
node.span = file.span(start, _cursor)
|
|
151
161
|
return node
|
|
152
162
|
|
|
153
|
-
func _expression() -> Model.GdExpression:
|
|
163
|
+
func _expression(spread: bool = false) -> Model.GdExpression:
|
|
154
164
|
var start := _cursor
|
|
155
|
-
|
|
156
|
-
|
|
165
|
+
var opening := 1
|
|
166
|
+
if spread:
|
|
167
|
+
var probe := Lexer.new(file)
|
|
168
|
+
var marker := start+1
|
|
169
|
+
while marker<file.text.length():
|
|
170
|
+
var token := probe.next_token(marker)
|
|
171
|
+
if token==null: return null
|
|
172
|
+
if token.kind not in ["whitespace","newline","comment","continuation"]: break
|
|
173
|
+
marker = token.span.end.index
|
|
174
|
+
if file.text.substr(marker,3)!="...":
|
|
175
|
+
file.fail("Expected ... in GGX spread attribute",marker)
|
|
176
|
+
return null
|
|
177
|
+
opening = marker+3-start
|
|
178
|
+
lexer.token("attribute-spread" if spread else "expression-open", start, start + opening)
|
|
179
|
+
var scanned := _scan(start + opening, true)
|
|
157
180
|
if not file.diagnostics.is_empty(): return null
|
|
158
181
|
if not scanned.has_token:
|
|
159
182
|
file.fail("Expected a GDScript expression inside braces", start, scanned.end)
|
|
@@ -180,6 +203,9 @@ func _scan(start: int, braced: bool) -> Dictionary:
|
|
|
180
203
|
var has_token := false
|
|
181
204
|
while offset < file.text.length() and file.diagnostics.is_empty():
|
|
182
205
|
var character := lexer.char_at(offset)
|
|
206
|
+
if file.text.substr(offset,3)=="...":
|
|
207
|
+
file.fail("Spread is only supported as {...expression} in a GGX opening attribute list",offset,offset+3)
|
|
208
|
+
break
|
|
183
209
|
if braced and stack.is_empty() and character == "}":
|
|
184
210
|
_copy(parts, copied, offset)
|
|
185
211
|
return {"parts": parts, "end": offset, "has_token": has_token}
|
|
@@ -8,6 +8,7 @@ const Resolver = preload("native/resolver.gd")
|
|
|
8
8
|
const StackContract = preload("../runtime/node/internal/stack_contract.gd")
|
|
9
9
|
const VisualStyle = preload("../runtime/node/internal/visual_style_2d.gd")
|
|
10
10
|
const Length = preload("../runtime/node/internal/length.gd")
|
|
11
|
+
const NativeAttributes = preload("../runtime/composition/native_attributes.gd")
|
|
11
12
|
const Lexer = preload("lexer.gd")
|
|
12
13
|
var file: Source
|
|
13
14
|
var resolver
|
|
@@ -48,11 +49,19 @@ func _component(node: Model.Component) -> void:
|
|
|
48
49
|
if stack_direction.is_empty(): stack_direction = "row"
|
|
49
50
|
for attribute in node.attributes:
|
|
50
51
|
if attribute.name=="direction": stack_direction = str(attribute.value.value) if attribute.value is Model.Literal else StackContract.preset(resolved.script)
|
|
52
|
+
if VisualStyle.rect_conflict(resolved.script,node.attributes.map(func(item): return item.name)):
|
|
53
|
+
_error("Rect fill and background_color conflict; author only the canonical background_color or legacy fill",node.name_span)
|
|
54
|
+
return
|
|
51
55
|
var seen: Dictionary = {}
|
|
56
|
+
var expanded := node.attributes.any(func(item): return item.kind=="spread")
|
|
52
57
|
for attribute in node.attributes:
|
|
58
|
+
if attribute.kind=="spread":
|
|
59
|
+
attribute.type_name = "Variant"
|
|
60
|
+
_node(attribute.value)
|
|
61
|
+
continue
|
|
53
62
|
var name := attribute.name
|
|
54
63
|
if VisualStyle.property(name) and VisualStyle.has_api(resolved.script) and not VisualStyle.supported(resolved.script):
|
|
55
|
-
_error("Shared visual styling
|
|
64
|
+
_error("Shared visual styling is unsupported on this participant",attribute.name_span)
|
|
56
65
|
return
|
|
57
66
|
if seen.has(name):
|
|
58
67
|
_error("Duplicate Node property or signal " + name, attribute.name_span)
|
|
@@ -84,7 +93,7 @@ func _component(node: Model.Component) -> void:
|
|
|
84
93
|
_error("Inline anonymous GGX handlers are not supported; use a named handler/Callable", token.span)
|
|
85
94
|
return
|
|
86
95
|
index = token.span.end.index
|
|
87
|
-
elif properties.has(name) and
|
|
96
|
+
elif properties.has(name) and NativeAttributes.writable(resolved.native,resolved.script,name,properties[name]):
|
|
88
97
|
attribute.type_name = "Variant" if Length.registered(resolved.script,name) or VisualStyle.registered(resolved.script,name) else _native_type(properties[name])
|
|
89
98
|
if attribute.type_name.is_empty():
|
|
90
99
|
_error("Unsupported Node property metadata: " + name, attribute.name_span)
|
|
@@ -92,7 +101,7 @@ func _component(node: Model.Component) -> void:
|
|
|
92
101
|
else:
|
|
93
102
|
_error("Removed layout API "+name+": use unit dimensions, grow and stretch" if name in ["flex","fill_width","fill_height","viewport_width_scale","viewport_height_scale"] else "Unknown, read-only or reserved Node property/signal " + name, attribute.name_span)
|
|
94
103
|
return
|
|
95
|
-
if StackContract.registered(resolved.script) and attribute.value is Model.Literal:
|
|
104
|
+
if not expanded and StackContract.registered(resolved.script) and attribute.value is Model.Literal:
|
|
96
105
|
var message := StackContract.error(name,attribute.value.value,stack_direction,StackContract.preset(resolved.script))
|
|
97
106
|
if not message.is_empty():
|
|
98
107
|
_error(message,attribute.value.span)
|
|
@@ -103,7 +112,7 @@ func _component(node: Model.Component) -> void:
|
|
|
103
112
|
if not file.diagnostics.is_empty(): return
|
|
104
113
|
var is_length := Length.registered(resolved.script,name)
|
|
105
114
|
if is_length:
|
|
106
|
-
_length(attribute,Length.domain(name))
|
|
115
|
+
_length(attribute,Length.domain(name,resolved.script))
|
|
107
116
|
if not file.diagnostics.is_empty(): return
|
|
108
117
|
if attribute.value is Model.Literal:
|
|
109
118
|
if is_length or is_color:
|
|
@@ -126,7 +135,7 @@ func _component(node: Model.Component) -> void:
|
|
|
126
135
|
_error("Node GGX children must be newly declared Node elements; expression adoption is unsupported", child.span)
|
|
127
136
|
return
|
|
128
137
|
_node(child)
|
|
129
|
-
if child is Model.Component:
|
|
138
|
+
if child is Model.Component and not child.attributes.any(func(item): return item.kind=="spread"):
|
|
130
139
|
for attribute in child.attributes:
|
|
131
140
|
if attribute.name=="name" and attribute.value is Model.Literal:
|
|
132
141
|
var name: String = str(attribute.value.value)
|
|
@@ -10,7 +10,7 @@ func _init() -> void:
|
|
|
10
10
|
func _submit(text: String) -> void:
|
|
11
11
|
var name := str(get_edited_property())
|
|
12
12
|
var value: Variant = float(text) if text.is_valid_float() else text
|
|
13
|
-
var parsed := Length.parse(value,Length.domain(name))
|
|
13
|
+
var parsed := Length.parse(value,Length.domain(name,get_edited_object().get_script()))
|
|
14
14
|
if parsed.has("error"):
|
|
15
15
|
input.tooltip_text = parsed.error
|
|
16
16
|
input.modulate = Color(1,0.5,0.5)
|
|
@@ -2,6 +2,7 @@ extends RefCounted
|
|
|
2
2
|
const StackContract = preload("../node/internal/stack_contract.gd")
|
|
3
3
|
const VisualStyle = preload("../node/internal/visual_style_2d.gd")
|
|
4
4
|
const Length = preload("../node/internal/length.gd")
|
|
5
|
+
const NativeAttributes = preload("native_attributes.gd")
|
|
5
6
|
const Profile = preload("profile.tres")
|
|
6
7
|
## F01 computation and retained static-shape records external to native objects.
|
|
7
8
|
const Binding = preload("binding.gd")
|
|
@@ -16,6 +17,9 @@ class Mounted extends RefCounted:
|
|
|
16
17
|
var keyed := false
|
|
17
18
|
var slot: Array = []
|
|
18
19
|
var properties: Dictionary = {}
|
|
20
|
+
var defaults: Dictionary = {}
|
|
21
|
+
var spread_owned: Dictionary = {}
|
|
22
|
+
var spread_applied: Dictionary = {}
|
|
19
23
|
var handlers: Dictionary = {}
|
|
20
24
|
var bindings: Dictionary = {}
|
|
21
25
|
var children: Array = []
|
|
@@ -153,11 +157,16 @@ func _flush() -> void:
|
|
|
153
157
|
# descriptor: callers may reuse either, and cycles must fail before native edits.
|
|
154
158
|
func _normalize(value, ancestors: Array = [], level: int = 0):
|
|
155
159
|
if not value is Element or level>128 or ancestors.has(value): return null
|
|
160
|
+
if not value.attribute_error.is_empty():
|
|
161
|
+
validation_error = value.attribute_error
|
|
162
|
+
return null
|
|
156
163
|
if value.keyed and not _key_valid(value.key): return null
|
|
157
164
|
var next := ancestors.duplicate()
|
|
158
165
|
next.append(value)
|
|
159
166
|
if Profile.is_enabled(): Profile.add("normalized_elements")
|
|
160
167
|
var result := Element.new(value.type,value.properties,value.handlers,[],value.source,value.key,value.keyed)
|
|
168
|
+
result.origins = value.origins.duplicate()
|
|
169
|
+
result.spread_properties = value.spread_properties.duplicate()
|
|
161
170
|
result.bindings = value.bindings.duplicate()
|
|
162
171
|
if not _flatten(value.children,[],result.children,next,level+1): return null
|
|
163
172
|
return result
|
|
@@ -220,8 +229,9 @@ func _valid(desired: Element, previous: Mounted) -> bool:
|
|
|
220
229
|
else: return false
|
|
221
230
|
for binding in desired.bindings.values():
|
|
222
231
|
if not binding is Binding or not binding.valid: return false
|
|
223
|
-
for
|
|
224
|
-
|
|
232
|
+
for event in desired.handlers:
|
|
233
|
+
var handler = desired.handlers[event]
|
|
234
|
+
if not handler is Callable or not handler.is_valid(): return _invalid_attribute(desired,event,"signal requires a valid native Callable")
|
|
225
235
|
var names := {}
|
|
226
236
|
var keys := {}
|
|
227
237
|
if desired.keyed and not _key_valid(desired.key): return false
|
|
@@ -234,7 +244,7 @@ func _valid(desired: Element, previous: Mounted) -> bool:
|
|
|
234
244
|
keys[key] = true
|
|
235
245
|
var name: String = str(child.properties.get("name",""))
|
|
236
246
|
if not name.is_empty():
|
|
237
|
-
if names.has(name): return
|
|
247
|
+
if names.has(name): return _invalid_attribute(child,"name","duplicate declared sibling name "+name)
|
|
238
248
|
names[name] = true
|
|
239
249
|
return true
|
|
240
250
|
func _collect_foreign(record, result: Array) -> void:
|
|
@@ -310,6 +320,16 @@ func _mount(desired: Element, parent: Node, owner: Node) -> Mounted:
|
|
|
310
320
|
return record
|
|
311
321
|
func _apply(desired: Element, record: Mounted) -> void:
|
|
312
322
|
var node: Node = record.node.get_ref()
|
|
323
|
+
# Capture the real class/_init defaults before its first authored write, with
|
|
324
|
+
# no probe instances. Later first ownership preserves preexisting native state.
|
|
325
|
+
for key in desired.properties:
|
|
326
|
+
if not record.defaults.has(key):
|
|
327
|
+
record.defaults[key] = node.get(key)
|
|
328
|
+
# An unattached native Node starts unnamed, but set_name rejects empty
|
|
329
|
+
# names after attachment. Restore its native class label instead;
|
|
330
|
+
# Godot retains authority over sibling-name uniqueness.
|
|
331
|
+
if key=="name" and str(record.defaults[key]).is_empty(): record.defaults[key] = node.get_class()
|
|
332
|
+
var resets := _spread_resets(desired,record)
|
|
313
333
|
for key in record.bindings.keys():
|
|
314
334
|
if not desired.bindings.has(key) or not record.bindings[key].same(desired.bindings[key]):
|
|
315
335
|
record.bindings[key].disconnect_edit()
|
|
@@ -323,7 +343,14 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
323
343
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
324
344
|
binding.attach(node,self)
|
|
325
345
|
var stack := StackContract.registered(desired.type)
|
|
326
|
-
if stack:
|
|
346
|
+
if stack:
|
|
347
|
+
var policy := resets.duplicate()
|
|
348
|
+
policy.merge(desired.properties,true)
|
|
349
|
+
node._apply_stack_policy(policy)
|
|
350
|
+
for key in resets:
|
|
351
|
+
if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,resets[key])
|
|
352
|
+
writes += 1
|
|
353
|
+
if Profile.is_enabled(): Profile.add("property_writes")
|
|
327
354
|
# An omitted previously declared border side removes that local override;
|
|
328
355
|
# do not turn omission into permanent native state or change other props.
|
|
329
356
|
if VisualStyle.supported(desired.type):
|
|
@@ -332,6 +359,12 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
332
359
|
node.set(key,"auto")
|
|
333
360
|
writes += 1
|
|
334
361
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
362
|
+
if Length.registered(desired.type,"min_width"):
|
|
363
|
+
for key in Length.MINIMUMS:
|
|
364
|
+
if record.properties.has(key) and not desired.properties.has(key):
|
|
365
|
+
node.set(key,0.0)
|
|
366
|
+
writes += 1
|
|
367
|
+
if Profile.is_enabled(): Profile.add("property_writes")
|
|
335
368
|
for key in desired.properties:
|
|
336
369
|
if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
|
|
337
370
|
if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
|
|
@@ -348,6 +381,45 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
348
381
|
if node.connect(event,desired.handlers[event],Object.CONNECT_PERSIST)!=OK: push_error("F01 native handler connection failed: "+desired.source)
|
|
349
382
|
record.properties = desired.properties.duplicate()
|
|
350
383
|
record.handlers = desired.handlers.duplicate()
|
|
384
|
+
record.spread_owned = desired.spread_properties.duplicate()
|
|
385
|
+
record.spread_applied.clear()
|
|
386
|
+
for key in desired.properties:
|
|
387
|
+
if record.spread_owned.has(key): record.spread_applied[key] = node.get(key)
|
|
388
|
+
|
|
389
|
+
func _spread_resets(desired: Element, record) -> Dictionary:
|
|
390
|
+
var result := {}
|
|
391
|
+
if record==null or not _compatible(desired,record): return result
|
|
392
|
+
var node = record.node.get_ref()
|
|
393
|
+
for key in record.spread_applied:
|
|
394
|
+
if desired.properties.has(key) or key in Length.BORDER_EDGES or key in Length.MINIMUMS: continue
|
|
395
|
+
# Do not overwrite imperative native changes made since our last commit.
|
|
396
|
+
if is_same(node.get(key),record.spread_applied[key]) and not is_same(node.get(key),record.defaults[key]): result[key] = record.defaults[key]
|
|
397
|
+
return result
|
|
398
|
+
|
|
399
|
+
func _effective_name(desired: Element, record) -> String:
|
|
400
|
+
if desired.properties.has("name"): return str(desired.properties.name)
|
|
401
|
+
var resets := _spread_resets(desired,record)
|
|
402
|
+
if resets.has("name"): return str(resets.name)
|
|
403
|
+
return str(record.node.get_ref().name) if _compatible(desired,record) else ""
|
|
404
|
+
|
|
405
|
+
func _invalid_attribute(desired: Element, key: String, message: String) -> bool:
|
|
406
|
+
validation_error = desired.location(key)+": attribute '"+key+"': "+message+"; previous tree retained"
|
|
407
|
+
return false
|
|
408
|
+
|
|
409
|
+
func _handler_error(handler: Callable, emitted: int) -> String:
|
|
410
|
+
# Named methods expose public metadata on both supported engines. Custom
|
|
411
|
+
# Callables without method metadata retain native invocation semantics.
|
|
412
|
+
if handler.is_custom(): return ""
|
|
413
|
+
var target = handler.get_object()
|
|
414
|
+
if target==null: return ""
|
|
415
|
+
for method in target.get_method_list():
|
|
416
|
+
if method.name!=handler.get_method(): continue
|
|
417
|
+
if int(method.flags)&METHOD_FLAG_VARARG: return ""
|
|
418
|
+
var supplied := emitted
|
|
419
|
+
var maximum: int = method.args.size()
|
|
420
|
+
if supplied<maximum-method.default_args.size() or supplied>maximum: return "Callable arity does not match native signal"
|
|
421
|
+
return ""
|
|
422
|
+
return ""
|
|
351
423
|
func _compatible(desired: Element, record: Mounted) -> bool:
|
|
352
424
|
if record == null: return false
|
|
353
425
|
if desired.borrowed != null or record.borrowed != null:
|
|
@@ -391,17 +463,20 @@ func _prepare_names(desired: Array, matches: Array, parent: Node) -> void:
|
|
|
391
463
|
for index in range(desired.size()):
|
|
392
464
|
var next = desired[index]
|
|
393
465
|
var old = matches[index]
|
|
394
|
-
if next==null or old==null
|
|
395
|
-
if
|
|
466
|
+
if next==null or old==null: continue
|
|
467
|
+
if not next.properties.has("name") and not _spread_resets(next,old).has("name"): continue
|
|
468
|
+
var final_name := _effective_name(next,old)
|
|
396
469
|
var node: Node = old.node.get_ref()
|
|
397
|
-
if node==null or node.get_parent()!=parent or str(node.name)==
|
|
398
|
-
pending.append(node)
|
|
399
|
-
targets[
|
|
400
|
-
for
|
|
470
|
+
if node==null or node.get_parent()!=parent or str(node.name)==final_name: continue
|
|
471
|
+
pending.append([node,old])
|
|
472
|
+
targets[final_name] = true
|
|
473
|
+
for pair in pending:
|
|
474
|
+
var node: Node = pair[0]
|
|
401
475
|
if not targets.has(str(node.name)): continue
|
|
402
476
|
var temporary := "_EstragonRename_"+str(node.get_instance_id())
|
|
403
477
|
while parent.has_node(NodePath(temporary)): temporary += "_"
|
|
404
478
|
node.name = temporary
|
|
479
|
+
if pair[1].spread_applied.has("name"): pair[1].spread_applied.name = node.name
|
|
405
480
|
writes += 1
|
|
406
481
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
407
482
|
# Keep a longest increasing subsequence of actual native indices. Everything
|
|
@@ -473,6 +548,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
473
548
|
var signals: Dictionary = contracts[desired.type].signals
|
|
474
549
|
if StackContract.registered(desired.type):
|
|
475
550
|
var policy: Dictionary = previous.properties.duplicate() if previous!=null and _compatible(desired,previous) else {}
|
|
551
|
+
policy.merge(_spread_resets(desired,previous),true)
|
|
476
552
|
policy.merge(desired.properties,true)
|
|
477
553
|
var fixed := StackContract.preset(desired.type)
|
|
478
554
|
var direction = policy.get("direction",fixed if not fixed.is_empty() else "row")
|
|
@@ -480,34 +556,42 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
480
556
|
var value = policy.get(key,direction if key=="direction" else "start")
|
|
481
557
|
var message := StackContract.error(key,value,str(direction),fixed)
|
|
482
558
|
if not message.is_empty():
|
|
483
|
-
validation_error = desired.
|
|
559
|
+
validation_error = desired.location(key)+": "+message+"; previous tree retained"
|
|
484
560
|
return false
|
|
561
|
+
if VisualStyle.rect_conflict(desired.type,desired.properties.keys()):
|
|
562
|
+
validation_error = desired.location("fill")+": Rect fill and background_color conflict; previous tree retained"
|
|
563
|
+
return false
|
|
485
564
|
for key in desired.properties:
|
|
486
|
-
|
|
565
|
+
var native: String = desired.type if desired.type is String else desired.type.get_instance_base_type()
|
|
566
|
+
if not properties.has(key) or not NativeAttributes.writable(native,desired.type,str(key),properties[key]): return _invalid_attribute(desired,str(key),"unknown, read-only or reserved native property")
|
|
487
567
|
var value = desired.properties[key]
|
|
488
568
|
if VisualStyle.property(str(key)) and VisualStyle.has_api(desired.type) and not VisualStyle.supported(desired.type):
|
|
489
|
-
validation_error = desired.
|
|
569
|
+
validation_error = desired.location(str(key))+": shared visual styling is unsupported on this participant; previous tree retained"
|
|
490
570
|
return false
|
|
491
571
|
if key=="grow" and Length.registered(desired.type,"width") and (not typeof(value) in [TYPE_INT,TYPE_FLOAT] or not is_finite(float(value)) or value<0):
|
|
492
|
-
validation_error = desired.
|
|
572
|
+
validation_error = desired.location(str(key))+": grow requires a finite nonnegative weight; previous tree retained"
|
|
493
573
|
return false
|
|
574
|
+
if key=="fill" and VisualStyle.marked(desired.type,"ESTRAGON_RECT_STYLE"):
|
|
575
|
+
if not value is Color or VisualStyle.parse_color(value).has("error"):
|
|
576
|
+
validation_error = desired.location(str(key))+": Rect fill requires a finite native Color; previous tree retained"
|
|
577
|
+
return false
|
|
494
578
|
if VisualStyle.registered(desired.type,key):
|
|
495
579
|
var parsed := VisualStyle.parse_color(value)
|
|
496
580
|
if parsed.has("error"):
|
|
497
|
-
validation_error = desired.
|
|
581
|
+
validation_error = desired.location(str(key))+": invalid style '"+str(key)+"': "+parsed.error+"; previous tree retained"
|
|
498
582
|
return false
|
|
499
583
|
if Length.registered(desired.type,key):
|
|
500
|
-
var parsed := Length.parse(value,Length.domain(key))
|
|
584
|
+
var parsed := Length.parse(value,Length.domain(key,desired.type))
|
|
501
585
|
if parsed.has("error"):
|
|
502
|
-
validation_error = desired.
|
|
586
|
+
validation_error = desired.location(str(key))+": invalid length '"+str(key)+"': "+parsed.error+"; previous tree retained"
|
|
503
587
|
return false
|
|
504
588
|
var kind: int = properties[key].type
|
|
505
|
-
if kind!=TYPE_NIL and typeof(value)!=kind and not (kind==TYPE_FLOAT and typeof(value)==TYPE_INT) and not (kind==TYPE_OBJECT and value==null) and not (kind in [TYPE_STRING,TYPE_STRING_NAME] and typeof(value) in [TYPE_STRING,TYPE_STRING_NAME]): return
|
|
589
|
+
if kind!=TYPE_NIL and typeof(value)!=kind and not (kind==TYPE_FLOAT and typeof(value)==TYPE_INT) and not (kind==TYPE_OBJECT and value==null) and not (kind in [TYPE_STRING,TYPE_STRING_NAME] and typeof(value) in [TYPE_STRING,TYPE_STRING_NAME]): return _invalid_attribute(desired,str(key),"incompatible native value type")
|
|
506
590
|
if kind==TYPE_OBJECT and value!=null:
|
|
507
591
|
var expected: String = str(properties[key].get("class_name",""))
|
|
508
|
-
if ClassDB.class_exists(expected) and not value.is_class(expected): return
|
|
592
|
+
if ClassDB.class_exists(expected) and not value.is_class(expected): return _invalid_attribute(desired,str(key),"incompatible native Object class "+expected)
|
|
509
593
|
for key in desired.bindings:
|
|
510
|
-
if key!="value" or desired.properties.has(key) or desired.handlers.has("value_changed") or not properties.has(key) or properties[key].type!=TYPE_BOOL or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return
|
|
594
|
+
if key!="value" or desired.properties.has(key) or desired.handlers.has("value_changed") or not properties.has(key) or properties[key].type!=TYPE_BOOL or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return _invalid_attribute(desired,"value_changed" if desired.handlers.has("value_changed") else str(key),"invalid or conflicting controlled binding")
|
|
511
595
|
var args: Array = signals.get("value_changed",{}).get("args",[])
|
|
512
596
|
|
|
513
597
|
# 4.0 lacks signal argument type metadata. Compiler source proof and
|
|
@@ -515,12 +599,14 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
515
599
|
# reject a valid input on that engine.
|
|
516
600
|
if args.size()!=1 or args[0].type not in [TYPE_NIL,TYPE_BOOL]: return false
|
|
517
601
|
for key in desired.handlers:
|
|
518
|
-
if not signals.has(key): return
|
|
602
|
+
if not signals.has(key): return _invalid_attribute(desired,str(key),"unknown native signal")
|
|
603
|
+
var message := _handler_error(desired.handlers[key],signals[key].get("args",[]).size())
|
|
604
|
+
if not message.is_empty(): return _invalid_attribute(desired,str(key),message)
|
|
519
605
|
var node: Node = previous.node.get_ref() if _compatible(desired,previous) else null
|
|
520
606
|
if parent != null:
|
|
521
|
-
var name
|
|
607
|
+
var name := _effective_name(desired,previous)
|
|
522
608
|
for existing in parent.get_children():
|
|
523
|
-
if str(existing.name)==name and (previous==null or existing!=previous.node.get_ref()): return
|
|
609
|
+
if str(existing.name)==name and (previous==null or existing!=previous.node.get_ref()): return _invalid_attribute(desired,"name","native sibling name conflict "+name)
|
|
524
610
|
var known: Array = []
|
|
525
611
|
if node != null:
|
|
526
612
|
for child in previous.children:
|
|
@@ -532,9 +618,9 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
532
618
|
if child == null or child.borrowed != null: continue
|
|
533
619
|
var old = matches[index]
|
|
534
620
|
if not _preflight(child,old,null,contracts): return false
|
|
535
|
-
var name
|
|
621
|
+
var name := _effective_name(child,old)
|
|
536
622
|
if not name.is_empty():
|
|
537
|
-
if names.has(name): return
|
|
623
|
+
if names.has(name): return _invalid_attribute(child,"name","duplicate effective sibling name "+name)
|
|
538
624
|
names[name] = true
|
|
539
625
|
if node != null:
|
|
540
626
|
for existing in node.get_children():
|
|
@@ -14,6 +14,52 @@ var keyed: bool
|
|
|
14
14
|
# Normalized authored child-slot/index path, external to native Nodes.
|
|
15
15
|
var slot: Array = []
|
|
16
16
|
var source: String
|
|
17
|
+
# Attribute provenance belongs to descriptions, never user Nodes or Dictionaries.
|
|
18
|
+
var origins: Dictionary = {}
|
|
19
|
+
var spread_properties: Dictionary = {}
|
|
20
|
+
var attribute_error := ""
|
|
21
|
+
|
|
22
|
+
# Snapshot at the argument evaluation point, before later expressions can mutate
|
|
23
|
+
# the same Dictionary. Values retain normal native reference semantics.
|
|
24
|
+
static func snapshot(value):
|
|
25
|
+
return value.duplicate() if value is Dictionary else value
|
|
26
|
+
|
|
27
|
+
func location(name: String) -> String:
|
|
28
|
+
return origins.get(name,source)
|
|
29
|
+
|
|
30
|
+
func expand(attributes: Array) -> void:
|
|
31
|
+
var values := {}
|
|
32
|
+
var signals := {}
|
|
33
|
+
var native: String = type if type is String else type.get_instance_base_type()
|
|
34
|
+
for event in ClassDB.class_get_signal_list(native): signals[str(event.name)] = true
|
|
35
|
+
var script = type if type is Script else null
|
|
36
|
+
while script != null:
|
|
37
|
+
for event in script.get_script_signal_list(): signals[str(event.name)] = true
|
|
38
|
+
script = script.get_base_script()
|
|
39
|
+
for entry in attributes:
|
|
40
|
+
if entry[0]!=null:
|
|
41
|
+
values[entry[0]] = entry[1]
|
|
42
|
+
origins[entry[0]] = entry[2]
|
|
43
|
+
spread_properties.erase(entry[0])
|
|
44
|
+
continue
|
|
45
|
+
if not entry[1] is Dictionary:
|
|
46
|
+
attribute_error = str(entry[2])+": GGX spread requires a Dictionary; previous tree retained"
|
|
47
|
+
return
|
|
48
|
+
for raw in entry[1]:
|
|
49
|
+
if not typeof(raw) in [TYPE_STRING,TYPE_STRING_NAME] or str(raw).is_empty():
|
|
50
|
+
attribute_error = str(entry[2])+": GGX spread key "+str(raw)+" requires a nonempty String/StringName; previous tree retained"
|
|
51
|
+
return
|
|
52
|
+
var name := str(raw)
|
|
53
|
+
if name=="key" or name.begins_with("bind:"):
|
|
54
|
+
attribute_error = str(entry[2])+": GGX spread key '"+name+"' must be explicitly authored; previous tree retained"
|
|
55
|
+
return
|
|
56
|
+
values[name] = entry[1][raw]
|
|
57
|
+
origins[name] = str(entry[2])+" (spread key '"+name+"')"
|
|
58
|
+
spread_properties[name] = true
|
|
59
|
+
for name in values:
|
|
60
|
+
if signals.has(name): handlers[name] = values[name]
|
|
61
|
+
else: properties[name] = values[name]
|
|
62
|
+
|
|
17
63
|
func _init(native_type: Variant = null, props: Dictionary = {}, events: Dictionary = {}, descendants: Array = [], location: String = "", identity_key: Variant = null, has_key: bool = false) -> void:
|
|
18
64
|
if Profile.is_enabled(): Profile.add("elements")
|
|
19
65
|
key = identity_key
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Native writable-property metadata, shared by compiler and description preflight.
|
|
4
|
+
# 4.0 lacks ClassDB's setter introspection. Its official 4.0.4 class reference
|
|
5
|
+
# declares these getter-only Node properties with setter="". This small bridge
|
|
6
|
+
# rejects them without probe Nodes or speculative setter-name inference. Newer
|
|
7
|
+
# engines use their actual ClassDB metadata, including newly introduced classes.
|
|
8
|
+
const BASELINE_READ_ONLY := {
|
|
9
|
+
"AnimationPlayer":["current_animation_length","current_animation_position"],
|
|
10
|
+
"Node":["multiplayer"],
|
|
11
|
+
"ShapeCast2D":["collision_result"],
|
|
12
|
+
"ShapeCast3D":["collision_result"],
|
|
13
|
+
"Timer":["time_left"],
|
|
14
|
+
}
|
|
15
|
+
static func writable(native: String, script, name: String, property: Dictionary) -> bool:
|
|
16
|
+
if name in ["owner","script"] or name.contains("/"): return false
|
|
17
|
+
if int(property.usage)&(PROPERTY_USAGE_READ_ONLY|PROPERTY_USAGE_CATEGORY|PROPERTY_USAGE_GROUP|PROPERTY_USAGE_SUBGROUP): return false
|
|
18
|
+
while script is Script:
|
|
19
|
+
for field in script.get_script_property_list():
|
|
20
|
+
if str(field.name)==name: return true
|
|
21
|
+
script = script.get_base_script()
|
|
22
|
+
if ClassDB.has_method("class_get_property_setter"):
|
|
23
|
+
return not str(ClassDB.call("class_get_property_setter",native,name)).is_empty()
|
|
24
|
+
for base in BASELINE_READ_ONLY:
|
|
25
|
+
if name in BASELINE_READ_ONLY[base] and ClassDB.is_parent_class(native,base): return false
|
|
26
|
+
return true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://ilri517yw03l
|
|
@@ -55,36 +55,3 @@ func _layout_options() -> Dictionary:
|
|
|
55
55
|
var result := super._layout_options()
|
|
56
56
|
result["alignment"] = [horizontal_align,vertical_align,"start"]
|
|
57
57
|
return result
|
|
58
|
-
var padding: Variant = 0.0:
|
|
59
|
-
set(value):
|
|
60
|
-
if is_same(padding,value) or not lengths.assign("padding",value): return
|
|
61
|
-
padding = value
|
|
62
|
-
_changed()
|
|
63
|
-
var padding_top: Variant = "auto":
|
|
64
|
-
set(value):
|
|
65
|
-
if is_same(padding_top,value) or not lengths.assign("padding_top",value): return
|
|
66
|
-
padding_top = value
|
|
67
|
-
_changed()
|
|
68
|
-
var padding_right: Variant = "auto":
|
|
69
|
-
set(value):
|
|
70
|
-
if is_same(padding_right,value) or not lengths.assign("padding_right",value): return
|
|
71
|
-
padding_right = value
|
|
72
|
-
_changed()
|
|
73
|
-
var padding_bottom: Variant = "auto":
|
|
74
|
-
set(value):
|
|
75
|
-
if is_same(padding_bottom,value) or not lengths.assign("padding_bottom",value): return
|
|
76
|
-
padding_bottom = value
|
|
77
|
-
_changed()
|
|
78
|
-
var padding_left: Variant = "auto":
|
|
79
|
-
set(value):
|
|
80
|
-
if is_same(padding_left,value) or not lengths.assign("padding_left",value): return
|
|
81
|
-
padding_left = value
|
|
82
|
-
_changed()
|
|
83
|
-
func _get_property_list() -> Array[Dictionary]:
|
|
84
|
-
var result: Array[Dictionary] = super._get_property_list()
|
|
85
|
-
result.append_array(Length.properties(["padding","padding_top","padding_right","padding_bottom","padding_left"]))
|
|
86
|
-
return result
|
|
87
|
-
|
|
88
|
-
func _padding_insets() -> Vector4:
|
|
89
|
-
layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
|
|
90
|
-
return layout.model.padding
|
|
@@ -3,13 +3,37 @@ class_name EstragonButton
|
|
|
3
3
|
extends "text.gd"
|
|
4
4
|
## Native primary-pointer button. No Control widget or polling wrapper.
|
|
5
5
|
signal pressed
|
|
6
|
-
const
|
|
6
|
+
const ESTRAGON_BUTTON_STYLE := true
|
|
7
|
+
var hover_background_color: Variant = Color("#705a9e"):
|
|
8
|
+
set(value):
|
|
9
|
+
if is_same(hover_background_color,value) or not _visual_style.assign("hover_background_color",value): return
|
|
10
|
+
hover_background_color = value
|
|
11
|
+
_queue_style_redraw()
|
|
12
|
+
var pressed_background_color: Variant = Color("#302440"):
|
|
13
|
+
set(value):
|
|
14
|
+
if is_same(pressed_background_color,value) or not _visual_style.assign("pressed_background_color",value): return
|
|
15
|
+
pressed_background_color = value
|
|
16
|
+
_queue_style_redraw()
|
|
17
|
+
var disabled_background_color: Variant = Color("#38343f"):
|
|
18
|
+
set(value):
|
|
19
|
+
if is_same(disabled_background_color,value) or not _visual_style.assign("disabled_background_color",value): return
|
|
20
|
+
disabled_background_color = value
|
|
21
|
+
_queue_style_redraw()
|
|
22
|
+
func _init() -> void:
|
|
23
|
+
background_color = Color("#514174")
|
|
24
|
+
padding = "auto"
|
|
25
|
+
func _default_padding() -> Vector4:
|
|
26
|
+
return Vector4(14,8,14,8)
|
|
27
|
+
func _get_property_list() -> Array[Dictionary]:
|
|
28
|
+
var result: Array[Dictionary] = super._get_property_list()
|
|
29
|
+
result.append_array(Length.properties(["hover_background_color","pressed_background_color","disabled_background_color"]))
|
|
30
|
+
return result
|
|
7
31
|
@export var disabled: bool = false:
|
|
8
32
|
set(value):
|
|
9
33
|
if disabled == value: return
|
|
10
34
|
disabled = value
|
|
11
35
|
_cancel_pointer()
|
|
12
|
-
|
|
36
|
+
_queue_style_redraw()
|
|
13
37
|
var _router: WeakRef
|
|
14
38
|
var _hovered: bool = false
|
|
15
39
|
var _held: bool = false
|
|
@@ -39,21 +63,20 @@ func _set_pointer_state(hovered: bool, held: bool) -> void:
|
|
|
39
63
|
if _hovered == hovered and _held == held: return
|
|
40
64
|
_hovered = hovered
|
|
41
65
|
_held = held
|
|
42
|
-
|
|
66
|
+
_queue_style_redraw()
|
|
43
67
|
func _pointer_contains(position_in_viewport: Vector2) -> bool:
|
|
44
68
|
var transform := get_global_transform_with_canvas()
|
|
45
69
|
# Transform2D.determinant() is absent from the 4.0 public API.
|
|
46
70
|
if is_zero_approx(transform.x.cross(transform.y)): return false
|
|
47
71
|
return Rect2(Vector2.ZERO,layout_size).has_point(transform.affine_inverse()*position_in_viewport)
|
|
48
|
-
func _measure_native() -> Vector2:
|
|
49
|
-
return _measure_label()+PADDING*2
|
|
50
72
|
func get_background_color() -> Color:
|
|
51
|
-
if disabled: return
|
|
52
|
-
if _held and _hovered: return
|
|
53
|
-
return
|
|
73
|
+
if disabled: return _visual_style.colors.disabled_background_color
|
|
74
|
+
if _held and _hovered: return _visual_style.colors.pressed_background_color
|
|
75
|
+
return _visual_style.colors.hover_background_color if _hovered else super.get_background_color()
|
|
76
|
+
func get_label_origin() -> Vector2:
|
|
77
|
+
var content := get_content_rect()
|
|
78
|
+
var remaining := (content.size-_measure_label())*0.5
|
|
79
|
+
return content.position+Vector2(maxf(0,remaining.x),maxf(0,remaining.y))
|
|
54
80
|
func _draw() -> void:
|
|
55
|
-
if
|
|
56
|
-
|
|
57
|
-
var offset := (layout_size-_measure_label())*0.5
|
|
58
|
-
offset = Vector2(maxf(0,offset.x),maxf(0,offset.y))
|
|
59
|
-
_draw_label(offset,Color(1,1,1,0.5) if disabled else Color.WHITE)
|
|
81
|
+
if get_content_rect().size.x<=0 or get_content_rect().size.y<=0: return
|
|
82
|
+
_draw_label(get_label_origin(),Color(1,1,1,0.5) if disabled else Color.WHITE)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
@icon("internal/component_2d_icon.tres")
|
|
1
2
|
@tool
|
|
2
3
|
class_name EstragonComponent2D
|
|
3
4
|
extends Node2D
|
|
@@ -5,6 +6,7 @@ extends Node2D
|
|
|
5
6
|
signal layout_applied(size: Vector2)
|
|
6
7
|
const Coordinator = preload("internal/coordinator.gd")
|
|
7
8
|
const ESTRAGON_LENGTHS := true
|
|
9
|
+
const ESTRAGON_MINIMUMS_2D := true
|
|
8
10
|
const VisualStyle = preload("internal/visual_style_2d.gd")
|
|
9
11
|
var _visual_style = VisualStyle.new()
|
|
10
12
|
const Length = preload("internal/length.gd")
|
|
@@ -50,6 +52,41 @@ var border_left_width: Variant = "auto":
|
|
|
50
52
|
border_left_width = value
|
|
51
53
|
_changed()
|
|
52
54
|
_queue_style_redraw()
|
|
55
|
+
var padding: Variant = 0.0:
|
|
56
|
+
set(value):
|
|
57
|
+
if is_same(padding,value) or not lengths.assign("padding",value,Length.domain("padding",get_script())): return
|
|
58
|
+
padding = value
|
|
59
|
+
_changed()
|
|
60
|
+
var padding_top: Variant = "auto":
|
|
61
|
+
set(value):
|
|
62
|
+
if is_same(padding_top,value) or not lengths.assign("padding_top",value): return
|
|
63
|
+
padding_top = value
|
|
64
|
+
_changed()
|
|
65
|
+
var padding_right: Variant = "auto":
|
|
66
|
+
set(value):
|
|
67
|
+
if is_same(padding_right,value) or not lengths.assign("padding_right",value): return
|
|
68
|
+
padding_right = value
|
|
69
|
+
_changed()
|
|
70
|
+
var padding_bottom: Variant = "auto":
|
|
71
|
+
set(value):
|
|
72
|
+
if is_same(padding_bottom,value) or not lengths.assign("padding_bottom",value): return
|
|
73
|
+
padding_bottom = value
|
|
74
|
+
_changed()
|
|
75
|
+
var padding_left: Variant = "auto":
|
|
76
|
+
set(value):
|
|
77
|
+
if is_same(padding_left,value) or not lengths.assign("padding_left",value): return
|
|
78
|
+
padding_left = value
|
|
79
|
+
_changed()
|
|
80
|
+
var min_width: Variant = 0.0:
|
|
81
|
+
set(value):
|
|
82
|
+
if is_same(min_width,value) or not lengths.assign("min_width",value): return
|
|
83
|
+
min_width = value
|
|
84
|
+
_changed()
|
|
85
|
+
var min_height: Variant = 0.0:
|
|
86
|
+
set(value):
|
|
87
|
+
if is_same(min_height,value) or not lengths.assign("min_height",value): return
|
|
88
|
+
min_height = value
|
|
89
|
+
_changed()
|
|
53
90
|
var width: Variant = "auto":
|
|
54
91
|
set(value):
|
|
55
92
|
if is_same(width,value) or not lengths.assign("width",value): return
|
|
@@ -120,7 +157,7 @@ var layout_size: Vector2:
|
|
|
120
157
|
var _layout_size := Vector2.ZERO
|
|
121
158
|
var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
|
|
122
159
|
func _get_property_list() -> Array[Dictionary]:
|
|
123
|
-
var properties := Length.properties(["width","height","x","y","gap","margin","margin_top","margin_right","margin_bottom","margin_left"])
|
|
160
|
+
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"])
|
|
124
161
|
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"]))
|
|
125
162
|
return properties
|
|
126
163
|
static func valid_length(value) -> bool:
|
|
@@ -142,6 +179,17 @@ func _layout_axis() -> int:
|
|
|
142
179
|
func _measure_native() -> Vector2:
|
|
143
180
|
return Vector2.ZERO
|
|
144
181
|
|
|
182
|
+
func _default_padding() -> Vector4:
|
|
183
|
+
return Vector4.ZERO
|
|
184
|
+
|
|
185
|
+
func _padding_insets() -> Vector4:
|
|
186
|
+
layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
|
|
187
|
+
return layout.model.padding
|
|
188
|
+
|
|
189
|
+
func get_content_rect() -> Rect2:
|
|
190
|
+
var insets: Vector4 = layout.model.padding+layout.model.border
|
|
191
|
+
return Rect2(Vector2(insets.x,insets.y),Vector2(maxf(0,layout_size.x-insets.x-insets.z),maxf(0,layout_size.y-insets.y-insets.w)))
|
|
192
|
+
|
|
145
193
|
func _layout_options() -> Dictionary:
|
|
146
194
|
var natural := _measure_native()
|
|
147
195
|
return {"axis":_layout_axis(),"fill":Vector3.ZERO,"intrinsic":Vector3(natural.x,natural.y,0)}
|
|
@@ -199,11 +247,13 @@ func _queue_style_redraw() -> void:
|
|
|
199
247
|
_visual_style.redraw_count += 1
|
|
200
248
|
queue_redraw()
|
|
201
249
|
func _paint_visual_style() -> void:
|
|
202
|
-
_visual_style.paint(self,layout_size,layout.model.border)
|
|
250
|
+
_visual_style.paint(self,layout_size,layout.model.border,get_background_color())
|
|
251
|
+
func get_background_color() -> Color:
|
|
252
|
+
return _visual_style.colors.background_color
|
|
203
253
|
func get_visual_style_stats() -> Dictionary:
|
|
204
254
|
return {"parse":_visual_style.parse_count,"draw":_visual_style.draw_count,"commands":_visual_style.command_count,"redraw":_visual_style.redraw_count}
|
|
205
255
|
|
|
206
256
|
func _style_supported() -> bool:
|
|
207
257
|
if VisualStyle.supported(get_script()): return true
|
|
208
|
-
push_error("Estragon style:
|
|
258
|
+
push_error("Estragon style: shared visual styling is unsupported on this participant")
|
|
209
259
|
return false
|
|
@@ -135,8 +135,8 @@ func changed() -> void:
|
|
|
135
135
|
model.set_policy(options.get("alignment",["start","start","start"]))
|
|
136
136
|
if "lengths" in host:
|
|
137
137
|
for property in host._get_property_list():
|
|
138
|
-
if not Core.Length.domain(property.name).is_empty() and not host.lengths.specs.has(property.name): host.lengths.assign(property.name,host.get(property.name))
|
|
139
|
-
model.set_lengths(host.lengths.specs,host.grow,host.stretch,host.pixels_per_unit if _dimension==3 else 1.0,options.axis)
|
|
138
|
+
if not Core.Length.domain(property.name).is_empty() and not host.lengths.specs.has(property.name): host.lengths.assign(property.name,host.get(property.name),Core.Length.domain(property.name,host.get_script()))
|
|
139
|
+
model.set_lengths(host.lengths.specs,host.grow,host.stretch,host.pixels_per_unit if _dimension==3 else 1.0,options.axis,host._default_padding() if host.has_method("_default_padding") else Vector4.ZERO)
|
|
140
140
|
model.configure(host.requested_extent(),model.gap,host.center,options.axis,options.fill,options.intrinsic,model.padding if "lengths" in host else options.get("padding",Vector4.ZERO),model.margin if "lengths" in host else options.get("margin",Vector4.ZERO))
|
|
141
141
|
else: model.configure(host.requested_extent(), host.gap, host.center)
|
|
142
142
|
|
|
@@ -30,6 +30,8 @@ var fill := Vector3.ZERO
|
|
|
30
30
|
var intrinsic := Vector3.ZERO
|
|
31
31
|
# Native Control minimums constrain assigned slots, never read back from size.
|
|
32
32
|
var allocation_minimum := Vector3.ZERO
|
|
33
|
+
# Authored border-box floors are independent of native adapter minimums.
|
|
34
|
+
var authored_minimum := Vector3.ZERO
|
|
33
35
|
var padding := Vector4.ZERO # left, top, right, bottom; border-box insets
|
|
34
36
|
var border := Vector4.ZERO # inside the border-box, before padding
|
|
35
37
|
var margin := Vector4.ZERO # outside own geometry; consumed by the parent
|
|
@@ -50,8 +52,11 @@ var _measure_dirty: bool = true
|
|
|
50
52
|
var _arrange_dirty: bool = true
|
|
51
53
|
var _parent: WeakRef
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
var default_padding := Vector4.ZERO
|
|
56
|
+
|
|
57
|
+
func set_lengths(specs: Dictionary, growth: float, cross: int, scale: float, stack_axis: int, padding_fallback: Vector4 = Vector4.ZERO) -> void:
|
|
58
|
+
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
|
|
59
|
+
default_padding = padding_fallback
|
|
55
60
|
length_specs = specs.duplicate(true)
|
|
56
61
|
grow = growth
|
|
57
62
|
stretch = cross
|
|
@@ -87,7 +92,9 @@ func _edges(prefix: String) -> Vector4:
|
|
|
87
92
|
var index: int = edge%2
|
|
88
93
|
var key: String = prefix+"_"+names[edge]+("_width" if prefix=="border" else "")
|
|
89
94
|
var value := _length(key,index,-1)
|
|
90
|
-
|
|
95
|
+
var uniform := _length("border_width" if prefix=="border" else prefix,index,0)
|
|
96
|
+
if prefix=="padding" and uniform<0: uniform = default_padding[edge]
|
|
97
|
+
result[edge] = uniform if value<0 else value
|
|
91
98
|
return result
|
|
92
99
|
|
|
93
100
|
# Resolve specs only on a changed parent/viewport/spec context. No property
|
|
@@ -103,23 +110,35 @@ func prepare(reference: Vector3, viewport: Vector2) -> void:
|
|
|
103
110
|
if _length_context==context: return
|
|
104
111
|
_length_context = context
|
|
105
112
|
resolution_count += 1
|
|
106
|
-
var before := [requested,gap,padding,border,margin,length_offset]
|
|
113
|
+
var before := [requested,gap,padding,border,margin,length_offset,authored_minimum]
|
|
107
114
|
if not length_specs.is_empty():
|
|
108
115
|
for index in range(3):
|
|
109
116
|
requested[index] = _length(["width","height","depth"][index],index,requested[index])
|
|
110
117
|
length_offset[index] = _length(["x","y","z"][index],index,0)
|
|
118
|
+
authored_minimum = Vector3(maxf(0,_length("min_width",0,0)),maxf(0,_length("min_height",1,0)),0)
|
|
111
119
|
gap = _length("gap",axis,0)
|
|
112
120
|
padding = _edges("padding")
|
|
113
121
|
border = _edges("border")
|
|
114
122
|
margin = _edges("margin")
|
|
115
|
-
if before!=[requested,gap,padding,border,margin,length_offset]:
|
|
123
|
+
if before!=[requested,gap,padding,border,margin,length_offset,authored_minimum]:
|
|
116
124
|
_measure_dirty = true
|
|
117
125
|
_arrange_dirty = true
|
|
118
126
|
|
|
127
|
+
func minimum() -> Vector3:
|
|
128
|
+
var result := authored_minimum
|
|
129
|
+
var inherited: Vector3 = children[0].minimum() if transparent and children.size()==1 else Vector3.ZERO
|
|
130
|
+
for index in range(3): result[index] = maxf(result[index],maxf(allocation_minimum[index],inherited[index]))
|
|
131
|
+
return result
|
|
132
|
+
|
|
133
|
+
func constrain(extent: Vector3) -> Vector3:
|
|
134
|
+
var floor := minimum()
|
|
135
|
+
for index in range(3): extent[index] = maxf(extent[index],floor[index])
|
|
136
|
+
return extent
|
|
137
|
+
|
|
119
138
|
func _content_basis() -> Vector3:
|
|
120
139
|
var basis := Vector3(-1,-1,-1)
|
|
121
140
|
for index in range(3):
|
|
122
|
-
if requested[index]>=0: basis[index] = maxf(0,requested[index]-leading(padding+border)[index]-trailing(padding+border)[index])
|
|
141
|
+
if requested[index]>=0: basis[index] = maxf(0,maxf(requested[index],minimum()[index])-leading(padding+border)[index]-trailing(padding+border)[index])
|
|
123
142
|
return basis
|
|
124
143
|
|
|
125
144
|
static func valid_extent(value: Vector3) -> bool:
|
|
@@ -210,6 +229,7 @@ func measure() -> Vector3:
|
|
|
210
229
|
measured = natural
|
|
211
230
|
for axis in range(3):
|
|
212
231
|
if requested[axis] >= 0: measured[axis] = requested[axis]
|
|
232
|
+
measured = constrain(measured)
|
|
213
233
|
_measure_dirty = false
|
|
214
234
|
return measured
|
|
215
235
|
|
|
@@ -222,6 +242,7 @@ func independent_axis(index: int) -> bool:
|
|
|
222
242
|
return parent.independent_axis(index) if requested[index] < 0 and (fill[index] > 0 or (grow>0 if index==parent.axis else stretch>0)) else false
|
|
223
243
|
|
|
224
244
|
func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
245
|
+
available = constrain(available)
|
|
225
246
|
_external_axes = external_axes
|
|
226
247
|
_warn_unanchored()
|
|
227
248
|
var content := available-leading(padding+border)-trailing(padding+border)
|
|
@@ -275,7 +296,7 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
275
296
|
break
|
|
276
297
|
var items: Array = []
|
|
277
298
|
for child in children:
|
|
278
|
-
items.append({"preferred":child.measured,"minimum":child.
|
|
299
|
+
items.append({"preferred":child.measured,"minimum":child.minimum(),"requested":child.requested,"grow":child.grow,"stretch":child.stretch,"fill":child.fill,"outer":child.outer_extent(),"leading":leading(child.margin)})
|
|
279
300
|
var policy := alignment.duplicate()
|
|
280
301
|
if center: policy[axis] = "center"
|
|
281
302
|
slots = StackPolicy.slots(items,content,axis,gap,policy)
|
|
@@ -7,14 +7,17 @@ extends RefCounted
|
|
|
7
7
|
const VisualStyle = preload("visual_style_2d.gd")
|
|
8
8
|
const LIMIT := 1.0e12
|
|
9
9
|
const FACTORS := {"":1.0,"px":1.0,"in":96.0,"cm":96.0/2.54,"mm":96.0/25.4,"q":96.0/101.6,"pt":96.0/72.0,"pc":16.0}
|
|
10
|
+
const MINIMUMS := ["min_width","min_height"]
|
|
10
11
|
const DIMENSIONS := ["width","height","depth"]
|
|
11
12
|
const BORDER_EDGES := ["border_top_width","border_right_width","border_bottom_width","border_left_width"]
|
|
12
13
|
const OFFSETS := ["x","y","z"]
|
|
13
14
|
const EDGES := ["padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"]
|
|
14
15
|
var specs: Dictionary = {}
|
|
15
16
|
var parse_count := 0
|
|
16
|
-
static func domain(name: String) -> String:
|
|
17
|
+
static func domain(name: String, script = null) -> String:
|
|
18
|
+
if name=="padding" and VisualStyle.marked(script,"ESTRAGON_BUTTON_STYLE"): return "edge"
|
|
17
19
|
if name in DIMENSIONS: return "extent"
|
|
20
|
+
if name in MINIMUMS: return "edge"
|
|
18
21
|
if name=="border_width": return "inset"
|
|
19
22
|
if name in BORDER_EDGES: return "edge"
|
|
20
23
|
if name in OFFSETS: return "offset"
|
|
@@ -22,6 +25,7 @@ static func domain(name: String) -> String:
|
|
|
22
25
|
return "inset" if name=="gap" else ""
|
|
23
26
|
static func registered(type, name: String) -> bool:
|
|
24
27
|
if domain(name).is_empty() or not type is Script: return false
|
|
28
|
+
if name in MINIMUMS and not VisualStyle.marked(type,"ESTRAGON_MINIMUMS_2D"): return false
|
|
25
29
|
if name=="border_width" or name in BORDER_EDGES:
|
|
26
30
|
if not VisualStyle.supported(type): return false
|
|
27
31
|
while type != null:
|
|
@@ -50,8 +54,8 @@ static func parse(value, kind: String) -> Dictionary:
|
|
|
50
54
|
return {"unit":unit,"value":number}
|
|
51
55
|
static func valid(value, kind: String) -> bool:
|
|
52
56
|
return not parse(value,kind).has("error")
|
|
53
|
-
func assign(name: String, value) -> bool:
|
|
54
|
-
var parsed := parse(value,domain(name))
|
|
57
|
+
func assign(name: String, value, kind: String = "") -> bool:
|
|
58
|
+
var parsed := parse(value,domain(name) if kind.is_empty() else kind)
|
|
55
59
|
parse_count += 1
|
|
56
60
|
if parsed.has("error"):
|
|
57
61
|
push_error("Estragon length '"+name+"': "+parsed.error)
|
|
@@ -78,8 +82,8 @@ static func dependencies(specs: Dictionary, stack_axis: int) -> Array:
|
|
|
78
82
|
for name in specs:
|
|
79
83
|
var unit: String = specs[name].unit
|
|
80
84
|
if unit=="%":
|
|
81
|
-
if name in ["width","x","margin_left","margin_right","padding_left","padding_right","border_left_width","border_right_width"]: parent_axes.x = 1
|
|
82
|
-
elif name in ["height","y","margin_top","margin_bottom","padding_top","padding_bottom","border_top_width","border_bottom_width"]: parent_axes.y = 1
|
|
85
|
+
if name in ["width","min_width","x","margin_left","margin_right","padding_left","padding_right","border_left_width","border_right_width"]: parent_axes.x = 1
|
|
86
|
+
elif name in ["height","min_height","y","margin_top","margin_bottom","padding_top","padding_bottom","border_top_width","border_bottom_width"]: parent_axes.y = 1
|
|
83
87
|
elif name in ["depth","z"]: parent_axes.z = 1
|
|
84
88
|
elif name=="gap": parent_axes[stack_axis] = 1
|
|
85
89
|
else: parent_axes = Vector3(1,1,parent_axes.z)
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
extends RefCounted
|
|
3
3
|
## Local values and native paint only. No parent lookup, cascade or Nodes.
|
|
4
|
-
const COLORS := ["background_color","border_color"]
|
|
5
|
-
var colors := {"background_color":Color.TRANSPARENT,"border_color":Color.TRANSPARENT}
|
|
4
|
+
const COLORS := ["background_color","border_color","hover_background_color","pressed_background_color","disabled_background_color","checked_background_color"]
|
|
5
|
+
var colors := {"background_color":Color.TRANSPARENT,"border_color":Color.TRANSPARENT,"hover_background_color":Color("#705a9e"),"pressed_background_color":Color("#302440"),"disabled_background_color":Color("#38343f"),"checked_background_color":Color("#227a60")}
|
|
6
6
|
var parse_count := 0
|
|
7
7
|
var draw_count := 0
|
|
8
8
|
var command_count := 0
|
|
9
9
|
var redraw_count := 0
|
|
10
|
+
static func marked(script, marker: String) -> bool:
|
|
11
|
+
while script is Script:
|
|
12
|
+
if script.get_script_constant_map().get(marker,false): return true
|
|
13
|
+
script = script.get_base_script()
|
|
14
|
+
return false
|
|
10
15
|
static func has_api(script) -> bool:
|
|
11
16
|
while script is Script:
|
|
12
17
|
if script.get_script_constant_map().get("ESTRAGON_VISUAL_STYLE",false): return true
|
|
@@ -21,7 +26,12 @@ static func supported(script) -> bool:
|
|
|
21
26
|
static func property(name: String) -> bool:
|
|
22
27
|
return name in COLORS or name in ["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width"]
|
|
23
28
|
static func registered(script, name: String) -> bool:
|
|
24
|
-
|
|
29
|
+
if not supported(script): return false
|
|
30
|
+
if name in ["background_color","border_color"]: return true
|
|
31
|
+
if name=="checked_background_color": return marked(script,"ESTRAGON_TOGGLE_STYLE")
|
|
32
|
+
return name in COLORS and marked(script,"ESTRAGON_BUTTON_STYLE")
|
|
33
|
+
static func rect_conflict(script, names: Array) -> bool:
|
|
34
|
+
return marked(script,"ESTRAGON_RECT_STYLE") and "fill" in names and "background_color" in names
|
|
25
35
|
static func parse_color(value) -> Dictionary:
|
|
26
36
|
if value is Color:
|
|
27
37
|
for channel in [value.r,value.g,value.b,value.a]:
|
|
@@ -48,10 +58,10 @@ func _rect(canvas: CanvasItem, rect: Rect2, color: Color) -> void:
|
|
|
48
58
|
if rect.size.x<=0 or rect.size.y<=0 or color.a<=0: return
|
|
49
59
|
canvas.draw_rect(rect,color)
|
|
50
60
|
command_count += 1
|
|
51
|
-
func paint(canvas: CanvasItem, extent: Vector2, border: Vector4) -> void:
|
|
61
|
+
func paint(canvas: CanvasItem, extent: Vector2, border: Vector4, background: Color) -> void:
|
|
52
62
|
draw_count += 1
|
|
53
63
|
if extent.x<=0 or extent.y<=0: return
|
|
54
|
-
_rect(canvas,Rect2(Vector2.ZERO,extent),
|
|
64
|
+
_rect(canvas,Rect2(Vector2.ZERO,extent),background)
|
|
55
65
|
# Filled strips stay inside the border-box, including fractional/huge edges.
|
|
56
66
|
# Top/bottom own the corners; side strips never double-blend those pixels.
|
|
57
67
|
var left := minf(border.x,extent.x)
|
|
@@ -29,9 +29,8 @@ func apply_layout_position(offset: Vector3) -> void:
|
|
|
29
29
|
position = Vector2(value.x, value.y)
|
|
30
30
|
|
|
31
31
|
func apply_layout_size(size: Vector3) -> void:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
layout_applied.emit(_layout_size)
|
|
32
|
+
# Preserve bounds-aware placement through the inherited native size/redraw hook.
|
|
33
|
+
super.apply_layout_size(size)
|
|
35
34
|
|
|
36
35
|
func get_native_bounds() -> Rect2:
|
|
37
36
|
return Rect2(Vector2(bounds.origin.x, bounds.origin.y), Vector2(bounds.extent.x, bounds.extent.y))
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
class_name EstragonRect
|
|
3
3
|
extends "component_2d.gd"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
func
|
|
12
|
-
super.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
draw_rect(Rect2(Vector2.ZERO,layout_size),fill)
|
|
4
|
+
## background_color is canonical; fill is the legacy native Color view.
|
|
5
|
+
const ESTRAGON_RECT_STYLE := true
|
|
6
|
+
var fill: Color:
|
|
7
|
+
get: return _visual_style.colors.background_color
|
|
8
|
+
set(value): background_color = value
|
|
9
|
+
func _init() -> void:
|
|
10
|
+
background_color = Color.WHITE
|
|
11
|
+
func _get_property_list() -> Array[Dictionary]:
|
|
12
|
+
var result: Array[Dictionary] = super._get_property_list()
|
|
13
|
+
# Store only the canonical value, preserving its authored String/Color type.
|
|
14
|
+
result.append({"name":"fill","type":TYPE_COLOR,"usage":PROPERTY_USAGE_EDITOR})
|
|
15
|
+
return result
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
class_name EstragonText
|
|
3
3
|
extends "component_2d.gd"
|
|
4
|
-
const ESTRAGON_LEGACY_PAINT := true
|
|
5
4
|
## Native Font measure/draw, explicit lines only. No wrapping or rich text.
|
|
6
5
|
@export var text: String = "":
|
|
7
6
|
set(value):
|
|
@@ -62,6 +61,8 @@ func _draw_label(offset: Vector2 = Vector2.ZERO, tint: Color = Color.WHITE) -> v
|
|
|
62
61
|
for line in text.split("\n"):
|
|
63
62
|
if not line.is_empty(): draw_string(font,offset+Vector2(0,font.get_ascent(font_size)),line,HORIZONTAL_ALIGNMENT_LEFT,-1,font_size,color*tint)
|
|
64
63
|
offset.y += font.get_height(font_size)
|
|
64
|
+
func get_label_origin() -> Vector2:
|
|
65
|
+
return get_content_rect().position
|
|
65
66
|
func _draw() -> void:
|
|
66
|
-
if
|
|
67
|
-
_draw_label()
|
|
67
|
+
if get_content_rect().size.x <= 0 or get_content_rect().size.y <= 0: return
|
|
68
|
+
_draw_label(get_label_origin())
|
|
@@ -3,12 +3,23 @@ class_name EstragonToggle
|
|
|
3
3
|
extends "button.gd"
|
|
4
4
|
## Controlled boolean input. Only pointer activation emits a user edit.
|
|
5
5
|
signal value_changed(value: bool)
|
|
6
|
+
const ESTRAGON_TOGGLE_STYLE := true
|
|
7
|
+
var checked_background_color: Variant = Color("#227a60"):
|
|
8
|
+
set(next):
|
|
9
|
+
if is_same(checked_background_color,next) or not _visual_style.assign("checked_background_color",next): return
|
|
10
|
+
checked_background_color = next
|
|
11
|
+
_queue_style_redraw()
|
|
12
|
+
func _get_property_list() -> Array[Dictionary]:
|
|
13
|
+
var result: Array[Dictionary] = super._get_property_list()
|
|
14
|
+
result.append_array(Length.properties(["checked_background_color"]))
|
|
15
|
+
return result
|
|
6
16
|
@export var value: bool = false:
|
|
7
17
|
set(next):
|
|
8
18
|
if value == next: return
|
|
9
19
|
value = next
|
|
10
|
-
|
|
20
|
+
_queue_style_redraw()
|
|
11
21
|
func _init() -> void:
|
|
22
|
+
super._init()
|
|
12
23
|
pressed.connect(_activate)
|
|
13
24
|
func _activate() -> void:
|
|
14
25
|
if disabled: return
|
|
@@ -16,8 +27,10 @@ func _activate() -> void:
|
|
|
16
27
|
value_changed.emit(value)
|
|
17
28
|
func get_background_color() -> Color:
|
|
18
29
|
if disabled: return super.get_background_color()
|
|
19
|
-
return
|
|
30
|
+
return _visual_style.colors.checked_background_color if value else super.get_background_color()
|
|
20
31
|
func _draw() -> void:
|
|
21
32
|
super._draw()
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
var border: Vector4 = layout.model.border
|
|
34
|
+
var inner := Rect2(Vector2(border.x,border.y),layout_size-Vector2(border.x+border.z,border.y+border.w))
|
|
35
|
+
if value and inner.size.x>4 and inner.size.y>4:
|
|
36
|
+
draw_line(inner.position+Vector2(2,inner.size.y-3),inner.position+Vector2(inner.size.x-2,inner.size.y-3),Color("65f4b0"),3)
|
package/package.json
CHANGED