@papercraftgames/estragon 0.1.0-beta.30 → 0.1.0-beta.31
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 +21 -6
- package/addons/estragon/compiler/layouts.gd +2 -2
- package/addons/estragon/compiler/native/resolver.gd +19 -30
- package/addons/estragon/compiler/validator.gd +13 -28
- package/addons/estragon/editor/completion.gd +0 -1
- package/addons/estragon/editor/components.gd +1 -0
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/runtime/composition/binding.gd +24 -7
- package/addons/estragon/runtime/composition/computation.gd +9 -6
- package/addons/estragon/runtime/composition/element.gd +8 -0
- package/addons/estragon/runtime/node/checkbox.gd +33 -0
- package/addons/estragon/runtime/node/checkbox.gd.uid +1 -0
- package/addons/estragon/runtime/node/toggle.gd +8 -2
- package/package.json +1 -1
|
@@ -60,6 +60,13 @@ func emit() -> MappedWriter:
|
|
|
60
60
|
while _module.identifiers.has(metadata): metadata += "_"
|
|
61
61
|
_writer.append("\nconst "+metadata+" = "+var_to_str({"reactive":_module.render_functions,"ordinary":_module.ordinary_functions}))
|
|
62
62
|
_writer.append("\n")
|
|
63
|
+
var observable := {}
|
|
64
|
+
for part in _module.parts:
|
|
65
|
+
if part is Model.Bindable: observable[part.name] = part.type_name
|
|
66
|
+
if not observable.is_empty():
|
|
67
|
+
var contract := "_GOGO_BINDABLE_PROPERTIES_"+_file.name.sha256_text().substr(0,16)
|
|
68
|
+
while _module.identifiers.has(contract): contract += "_"
|
|
69
|
+
_writer.append("const "+contract+" = "+var_to_str(observable)+"\n")
|
|
63
70
|
var exports := {}
|
|
64
71
|
for binding in _module.presets:
|
|
65
72
|
if binding.exported: exports[binding.name] = binding
|
|
@@ -221,16 +228,12 @@ func _description(node: Model.Component, indentation: String) -> String:
|
|
|
221
228
|
_variable += 1
|
|
222
229
|
var props := PackedStringArray()
|
|
223
230
|
var events := PackedStringArray()
|
|
224
|
-
var bindings := PackedStringArray()
|
|
225
231
|
var key := "null"
|
|
226
232
|
var keyed := "false"
|
|
227
233
|
var expanded := node.attributes.any(func(item): return item.kind=="spread")
|
|
228
234
|
var ordered := PackedStringArray()
|
|
229
235
|
for attribute in node.attributes:
|
|
230
236
|
var value: String = _arguments[attribute.value].name if attribute.value is Model.GdExpression else literal(attribute.value)
|
|
231
|
-
if attribute.kind == "binding":
|
|
232
|
-
bindings.append(_string("value")+": "+value)
|
|
233
|
-
continue
|
|
234
237
|
if attribute.kind == "key":
|
|
235
238
|
key = value
|
|
236
239
|
keyed = "true"
|
|
@@ -248,15 +251,16 @@ func _description(node: Model.Component, indentation: String) -> String:
|
|
|
248
251
|
_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)
|
|
249
252
|
for attribute in node.attributes:
|
|
250
253
|
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)
|
|
254
|
+
if attribute.kind=="binding": _line(variable+".origins[\"value\"] = "+_string("%s:%d:%d" % [_file.name,attribute.name_span.start.line,attribute.name_span.start.column]),attribute.name_span,indentation)
|
|
251
255
|
|
|
252
256
|
if expanded: _line(variable+".expand(["+", ".join(ordered)+"])",node.span,indentation)
|
|
257
|
+
_line(variable+".resolve_bindings()",node.span,indentation)
|
|
253
258
|
if not node.text_body.is_empty():
|
|
254
259
|
var parts := PackedStringArray()
|
|
255
260
|
for part in node.text_body:
|
|
256
261
|
var value: String = _arguments[part].name if part is Model.GdExpression else literal(part)
|
|
257
262
|
parts.append("[%s, %s]" % [value,_string("%s:%d:%d" % [_file.name,part.span.start.line,part.span.start.column])])
|
|
258
263
|
_line(variable+".set_text_body(["+", ".join(parts)+"])",node.span,indentation)
|
|
259
|
-
if not bindings.is_empty(): _line(variable+".bindings = {"+", ".join(bindings)+"}",node.span,indentation)
|
|
260
264
|
if node.preset!=null: _line(variable+" = preload("+_resource(Preset)+").apply("+_arguments[node.preset_expression].name+", "+variable+")",node.span,indentation)
|
|
261
265
|
return variable
|
|
262
266
|
|
|
@@ -329,6 +333,7 @@ func _bindable(property: Model.Bindable) -> void:
|
|
|
329
333
|
|
|
330
334
|
func _binding_argument(argument: Argument) -> void:
|
|
331
335
|
var path := argument.binding_path.duplicate()
|
|
336
|
+
var root: String = path.pop_front()
|
|
332
337
|
var field: String = path.pop_back()
|
|
333
338
|
var owner := "_gogo_root"
|
|
334
339
|
var source := "_gogo_source"
|
|
@@ -341,7 +346,17 @@ func _binding_argument(argument: Argument) -> void:
|
|
|
341
346
|
for name in path:
|
|
342
347
|
endpoint += "."+str(name)
|
|
343
348
|
checks.append(endpoint+" != null")
|
|
344
|
-
_writer.append("preload("+_resource(Binding)+").new(
|
|
349
|
+
_writer.append("preload("+_resource(Binding)+").new("+root+", func("+owner+"): return "+endpoint+" if "+" and ".join(checks)+" else null, "+_string(field)+", func("+source+", "+edit+": bool): "+source+"."+field+" = "+edit+", "+_string(".".join(argument.binding_path))+", (",argument.expression.span)
|
|
350
|
+
# Keep the original property read in authored scope: native semantic
|
|
351
|
+
# validation still rejects unknown members, and the getter runs once.
|
|
352
|
+
_parts(argument.expression.parts)
|
|
353
|
+
var original_checks: Array[String] = []
|
|
354
|
+
var original := root
|
|
355
|
+
original_checks.append(original+" != null")
|
|
356
|
+
for name in path:
|
|
357
|
+
original += "."+str(name)
|
|
358
|
+
original_checks.append(original+" != null")
|
|
359
|
+
_writer.append(") if "+" and ".join(original_checks)+" else null)",argument.expression.span)
|
|
345
360
|
|
|
346
361
|
func _render_call(node: Model.RenderCall) -> void:
|
|
347
362
|
var cast: String = node.result_type
|
|
@@ -196,8 +196,8 @@ func _binding(node, groups: Array, layout, scope: int, root: bool):
|
|
|
196
196
|
for group in groups:
|
|
197
197
|
var seen := {}
|
|
198
198
|
for attribute in group.attributes:
|
|
199
|
-
if attribute.name
|
|
200
|
-
_error("layout defaults cannot preset key or bind
|
|
199
|
+
if attribute.name=="key" or attribute.name.begins_with("bind:"):
|
|
200
|
+
_error("layout defaults cannot preset key or removed bind:* syntax; author instance properties at the use site",attribute.name_span)
|
|
201
201
|
return null
|
|
202
202
|
if attribute.kind=="spread": continue
|
|
203
203
|
if seen.has(attribute.name):
|
|
@@ -256,8 +256,8 @@ func _gogo(name: String, path: String, authored: String, span: Model.Span, check
|
|
|
256
256
|
qualified = name+"."+module.import_aliases.get(root_name,root_name)+type.trim_prefix(root_name)
|
|
257
257
|
elif ClassDB.class_exists(type.get_slice(".",0)) or imported.globals.has(type.get_slice(".",0)): qualified = type
|
|
258
258
|
else: qualified = name+"."+type
|
|
259
|
-
properties[part.name] = {"name":part.name,"type":kind,"class_name":qualified,"usage":PROPERTY_USAGE_DEFAULT,"source_writable":true}
|
|
260
|
-
if not part.signal_name.is_empty(): signals[part.signal_name] = {"name":part.signal_name}
|
|
259
|
+
properties[part.name] = {"name":part.name,"type":kind,"class_name":qualified,"usage":PROPERTY_USAGE_DEFAULT,"source_writable":true,"source_bindable":not part.signal_name.is_empty()}
|
|
260
|
+
if not part.signal_name.is_empty(): signals[part.signal_name] = {"name":part.signal_name,"args":[{"type":kind},{"type":kind}]}
|
|
261
261
|
if check_constructor and required: return _fail("GGX construction requires a zero-argument initializer: "+name,span)
|
|
262
262
|
return {"native":base.native,"script":base.script,"properties":properties,"signals":signals,"required_initializer":required,"gogo_path":path}
|
|
263
263
|
|
|
@@ -265,33 +265,12 @@ func _fail(message: String, span: Model.Span) -> Dictionary:
|
|
|
265
265
|
file.fail(message, span.start.index, span.end.index)
|
|
266
266
|
return {}
|
|
267
267
|
|
|
268
|
-
# Source-only proof for a writable Gogo path. Native fields never gain an
|
|
269
|
-
# observation contract merely because an unrelated signal shares their name.
|
|
270
|
-
func bindable_path(module, names: Array) -> bool:
|
|
271
|
-
if names.is_empty(): return false
|
|
272
|
-
for part in module.parts:
|
|
273
|
-
if not part is Model.Bindable or part.name!=names[0]: continue
|
|
274
|
-
if names.size()==1: return part.type_name=="bool"
|
|
275
|
-
var path: String = aliases.get(part.type_name,globals.get(part.type_name,""))
|
|
276
|
-
if path.is_empty(): return false
|
|
277
|
-
var authored := path.get_base_dir().get_base_dir().path_join(path.get_file().get_basename()+".gogo")
|
|
278
|
-
if path.get_base_dir().get_file()!="generated" or not FileAccess.file_exists(authored): return false
|
|
279
|
-
var source := Source.new(FileAccess.get_file_as_string(authored),authored)
|
|
280
|
-
var parsed = Parser.new(source).parse()
|
|
281
|
-
if parsed==null: return false
|
|
282
|
-
Bindable.new(source).apply(parsed)
|
|
283
|
-
if not source.diagnostics.is_empty(): return false
|
|
284
|
-
var imported = get_script().new(source)
|
|
285
|
-
imported.scan(parsed)
|
|
286
|
-
return imported.bindable_path(parsed,names.slice(1))
|
|
287
|
-
return false
|
|
288
|
-
|
|
289
268
|
# Godot 4.0 reports TYPE_NIL even for typed GDScript signal arguments.
|
|
290
269
|
# Recover only this lexical declaration contract; native reload remains the
|
|
291
270
|
# semantic authority. Never instantiate a control to inspect its signals.
|
|
292
271
|
func signal_contract(script: Script, event: Dictionary) -> Dictionary:
|
|
293
272
|
var args: Array = event.get("args",[])
|
|
294
|
-
if args.
|
|
273
|
+
if args.is_empty() or not args.any(func(arg): return arg.type==TYPE_NIL) or not script is GDScript: return event
|
|
295
274
|
var source := Source.new(script.source_code,script.resource_path)
|
|
296
275
|
var lexer := Lexer.new(source)
|
|
297
276
|
var tokens: Array = []
|
|
@@ -301,11 +280,21 @@ func signal_contract(script: Script, event: Dictionary) -> Dictionary:
|
|
|
301
280
|
if token==null: return event
|
|
302
281
|
cursor = token.span.end.index
|
|
303
282
|
if token.kind not in ["whitespace","newline","comment","continuation"]: tokens.append(token)
|
|
304
|
-
for index in range(tokens.size()-
|
|
283
|
+
for index in range(tokens.size()-3):
|
|
305
284
|
if tokens[index].text!="signal" or tokens[index].span.start.column!=1 or tokens[index+1].text!=event.name: continue
|
|
306
|
-
if tokens[index+2].text!="("
|
|
307
|
-
var
|
|
285
|
+
if tokens[index+2].text!="(": return event
|
|
286
|
+
var argument_cursor := index+3
|
|
308
287
|
var result := event.duplicate(true)
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
288
|
+
for arg in range(args.size()):
|
|
289
|
+
if argument_cursor+3>=tokens.size() or tokens[argument_cursor].kind!="identifier" or tokens[argument_cursor+1].text!=":": return event
|
|
290
|
+
result.args[arg].type = {"bool":TYPE_BOOL,"int":TYPE_INT,"float":TYPE_FLOAT,"String":TYPE_STRING}.get(tokens[argument_cursor+2].text,TYPE_NIL)
|
|
291
|
+
argument_cursor += 3
|
|
292
|
+
if arg<args.size()-1:
|
|
293
|
+
if tokens[argument_cursor].text!=",": return event
|
|
294
|
+
argument_cursor += 1
|
|
295
|
+
if tokens[argument_cursor].text==")": return result
|
|
296
|
+
# Older native metadata can list inherited signals on the leaf Script.
|
|
297
|
+
# Recover the declaration from its real base rather than treating NIL as
|
|
298
|
+
# proof that a valid inherited Bool endpoint is unobservable.
|
|
299
|
+
var base = script.get_base_script()
|
|
300
|
+
return signal_contract(base,event) if base!=null else event
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
extends RefCounted
|
|
3
3
|
## Static native Node property/signal contracts; no SceneTree or editor dependency.
|
|
4
4
|
const Element = preload("../runtime/composition/element.gd")
|
|
5
|
+
const Binding = preload("../runtime/composition/binding.gd")
|
|
5
6
|
const Model = preload("model.gd")
|
|
6
7
|
const Source = preload("source.gd")
|
|
7
8
|
const Resolver = preload("native/resolver.gd")
|
|
@@ -81,13 +82,13 @@ func _component(node: Model.Component) -> void:
|
|
|
81
82
|
return
|
|
82
83
|
seen[name] = true
|
|
83
84
|
if attribute.kind=="boolean-shorthand":
|
|
84
|
-
if name
|
|
85
|
+
if name=="key" 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]):
|
|
85
86
|
_error("Valueless attribute requires a writable native Bool property: "+name,attribute.name_span)
|
|
86
87
|
return
|
|
87
88
|
attribute.type_name = "bool"
|
|
88
89
|
continue
|
|
89
90
|
if name.begins_with("bind:"):
|
|
90
|
-
|
|
91
|
+
_error("Authored bind:* syntax was removed; use value={direct.observable.path}",attribute.name_span)
|
|
91
92
|
if not file.diagnostics.is_empty(): return
|
|
92
93
|
continue
|
|
93
94
|
if name=="key":
|
|
@@ -123,6 +124,7 @@ func _component(node: Model.Component) -> void:
|
|
|
123
124
|
else:
|
|
124
125
|
_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)
|
|
125
126
|
return
|
|
127
|
+
_implicit_binding(attribute,properties,signals,resolved.script)
|
|
126
128
|
if not expanded and StackContract.registered(resolved.script) and attribute.value is Model.Literal:
|
|
127
129
|
var message := StackContract.error(name,attribute.value.value,stack_direction,StackContract.preset(resolved.script),StackContract.grid_capable(resolved.script))
|
|
128
130
|
if not message.is_empty():
|
|
@@ -365,35 +367,18 @@ func _native_type(property: Dictionary) -> String:
|
|
|
365
367
|
# Names are stable Variant types, not an engine-version-specific type_string API.
|
|
366
368
|
return {TYPE_BOOL:"bool", TYPE_INT:"int", TYPE_FLOAT:"float", TYPE_STRING:"String", TYPE_STRING_NAME:"StringName", TYPE_VECTOR2:"Vector2", TYPE_VECTOR2I:"Vector2i", TYPE_RECT2:"Rect2", TYPE_RECT2I:"Rect2i", TYPE_VECTOR3:"Vector3", TYPE_VECTOR3I:"Vector3i", TYPE_TRANSFORM2D:"Transform2D", TYPE_VECTOR4:"Vector4", TYPE_VECTOR4I:"Vector4i", TYPE_PLANE:"Plane", TYPE_QUATERNION:"Quaternion", TYPE_AABB:"AABB", TYPE_BASIS:"Basis", TYPE_TRANSFORM3D:"Transform3D", TYPE_PROJECTION:"Projection", TYPE_COLOR:"Color", TYPE_NODE_PATH:"NodePath", TYPE_RID:"RID", TYPE_CALLABLE:"Callable", TYPE_SIGNAL:"Signal", TYPE_DICTIONARY:"Dictionary", TYPE_ARRAY:"Array", TYPE_PACKED_BYTE_ARRAY:"PackedByteArray", TYPE_PACKED_INT32_ARRAY:"PackedInt32Array", TYPE_PACKED_INT64_ARRAY:"PackedInt64Array", TYPE_PACKED_FLOAT32_ARRAY:"PackedFloat32Array", TYPE_PACKED_FLOAT64_ARRAY:"PackedFloat64Array", TYPE_PACKED_STRING_ARRAY:"PackedStringArray", TYPE_PACKED_VECTOR2_ARRAY:"PackedVector2Array", TYPE_PACKED_VECTOR3_ARRAY:"PackedVector3Array", TYPE_PACKED_COLOR_ARRAY:"PackedColorArray"}.get(property.type, "")
|
|
367
369
|
|
|
368
|
-
func
|
|
369
|
-
if attribute.name!="
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
_error("bind:value conflicts with value/value_changed",peer.name_span)
|
|
375
|
-
return
|
|
376
|
-
var event: Dictionary = signals.get("value_changed",{})
|
|
377
|
-
var args: Array = event.get("args",[])
|
|
378
|
-
if not properties.has("value") or properties.value.type!=TYPE_BOOL or int(properties.value.usage)&PROPERTY_USAGE_READ_ONLY or args.size()!=1 or args[0].type!=TYPE_BOOL:
|
|
379
|
-
_error("bind:value requires writable bool value and value_changed(value: bool)",attribute.name_span)
|
|
380
|
-
return
|
|
381
|
-
if not attribute.value is Model.GdExpression:
|
|
382
|
-
_error("bind:value requires an explicit self bindable lvalue path",attribute.value.span)
|
|
383
|
-
return
|
|
370
|
+
func _implicit_binding(attribute, properties: Dictionary, signals: Dictionary, script) -> void:
|
|
371
|
+
if attribute.name!="value" or not attribute.value is Model.GdExpression: return
|
|
372
|
+
if not properties.has("value") or properties.value.type!=TYPE_BOOL or int(properties.value.usage)&PROPERTY_USAGE_READ_ONLY: return
|
|
373
|
+
if not properties.value.get("source_bindable",false) and not Binding.declared(script,"value"): return
|
|
374
|
+
var args: Array = signals.get("value_changed",{}).get("args",[])
|
|
375
|
+
if args.size()!=2 or args.any(func(arg): return arg.type!=TYPE_BOOL): return
|
|
384
376
|
var tokens := _expression_tokens(attribute.value)
|
|
385
|
-
if tokens.size()<3 or tokens.size()%2!=1
|
|
386
|
-
_error("bind:value requires self.field or self.model.field",attribute.value.span)
|
|
387
|
-
return
|
|
377
|
+
if tokens.size()<3 or tokens.size()%2!=1: return
|
|
388
378
|
var names: Array = []
|
|
389
|
-
for index in range(
|
|
390
|
-
if index%2==1 and tokens[index].text!="." or index%2==0 and tokens[index].kind!="identifier":
|
|
391
|
-
_error("bind:value accepts only assignable identifier paths",tokens[index].span)
|
|
392
|
-
return
|
|
379
|
+
for index in range(tokens.size()):
|
|
380
|
+
if index%2==1 and tokens[index].text!="." or index%2==0 and tokens[index].kind!="identifier": return
|
|
393
381
|
if index%2==0: names.append(tokens[index].text)
|
|
394
|
-
if not resolver.bindable_path(current_module,names):
|
|
395
|
-
_error("bind:value path requires typed Gogo bindable fields ending in bool",attribute.value.span)
|
|
396
|
-
return
|
|
397
382
|
attribute.kind = "binding"
|
|
398
383
|
attribute.type_name = "Variant"
|
|
399
384
|
attribute.binding_path = names
|
|
@@ -514,7 +514,6 @@ func candidates(text: String, source: String, lexical: RefCounted, row: int, col
|
|
|
514
514
|
for name in members:
|
|
515
515
|
if members[name].kind in [CodeEdit.KIND_MEMBER,CodeEdit.KIND_SIGNAL] and members[name].get("writable",true) and name not in ["owner","script"]: offered[name] = members[name]
|
|
516
516
|
if _node_type(context.tag,_aliases): offered.key = {"kind":CodeEdit.KIND_MEMBER}
|
|
517
|
-
if members.has("value") and (members.value.get("value_type") == TYPE_BOOL or members.value.get("type") == "bool") and members.has("value_changed") and members.value_changed.get("args",[]).size() == 1 and members.value_changed.args[0] in ["bool",TYPE_BOOL]: offered["bind:value"] = {"kind":CodeEdit.KIND_MEMBER}
|
|
518
517
|
elif context.mode == "body": return []
|
|
519
518
|
elif member_cursor >= 0 and left[member_cursor] == ".":
|
|
520
519
|
var tokens := _chain_tokens(lexical,row,member_cursor)
|
|
@@ -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":"Checkbox","canonical":"EstragonCheckbox","script":preload("../runtime/node/checkbox.gd"),"dimension":2,"origin":"Estragon native; explicit import"},
|
|
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"},
|
|
@@ -10,12 +10,15 @@ var read: Callable
|
|
|
10
10
|
var write: Callable
|
|
11
11
|
var value: Variant
|
|
12
12
|
var valid := false
|
|
13
|
+
var observable := false
|
|
13
14
|
var node: WeakRef
|
|
14
15
|
var computation: WeakRef
|
|
15
16
|
var connected := false
|
|
16
17
|
var writing := false
|
|
17
|
-
func _init(owner:
|
|
18
|
-
|
|
18
|
+
func _init(owner: Variant, reader: Callable, property: StringName, writer: Callable, identity: String, snapshot_value: Variant) -> void:
|
|
19
|
+
value = snapshot_value
|
|
20
|
+
valid = typeof(value)==TYPE_BOOL
|
|
21
|
+
if not owner is Object or not is_instance_valid(owner): return
|
|
19
22
|
route = identity
|
|
20
23
|
root = weakref(owner)
|
|
21
24
|
read = reader
|
|
@@ -24,12 +27,21 @@ func _init(owner: Object, reader: Callable, property: StringName, writer: Callab
|
|
|
24
27
|
var endpoint = current()
|
|
25
28
|
if endpoint == null: return
|
|
26
29
|
source = weakref(endpoint)
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
if not valid: return
|
|
31
|
+
observable = declared(endpoint.get_script(),str(field))
|
|
32
|
+
if observable:
|
|
33
|
+
valid = endpoint.has_signal(str(field)+"_changed")
|
|
34
|
+
static func declared(script, property: String) -> bool:
|
|
35
|
+
while script is Script:
|
|
36
|
+
for name in script.get_script_constant_map():
|
|
37
|
+
var contract = script.get_script_constant_map()[name]
|
|
38
|
+
if str(name).begins_with("_GOGO_BINDABLE_PROPERTIES_") and contract is Dictionary and contract.get(property,"")=="bool": return true
|
|
39
|
+
script = script.get_base_script()
|
|
40
|
+
return false
|
|
29
41
|
func current():
|
|
30
42
|
var owner = root.get_ref() if root!=null else null
|
|
31
43
|
var endpoint = read.call(owner) if is_instance_valid(owner) else null
|
|
32
|
-
return endpoint if is_instance_valid(endpoint) else null
|
|
44
|
+
return endpoint if endpoint is Object and is_instance_valid(endpoint) else null
|
|
33
45
|
func same(other) -> bool:
|
|
34
46
|
return other!=null and valid and other.valid and source.get_ref()==other.source.get_ref() and root.get_ref()==other.root.get_ref() and field==other.field and route==other.route
|
|
35
47
|
func attach(target: Node, scope) -> void:
|
|
@@ -49,7 +61,7 @@ func _target_exit() -> void:
|
|
|
49
61
|
disconnect_edit()
|
|
50
62
|
var scope = computation.get_ref() if computation!=null else null
|
|
51
63
|
if scope!=null and scope.active and not scope.disposed: scope.schedule()
|
|
52
|
-
func edit(next: bool) -> void:
|
|
64
|
+
func edit(_previous: bool, next: bool) -> void:
|
|
53
65
|
var scope = computation.get_ref() if computation!=null else null
|
|
54
66
|
var target = node.get_ref() if node!=null else null
|
|
55
67
|
var endpoint = source.get_ref() if source!=null else null
|
|
@@ -61,11 +73,15 @@ func edit(next: bool) -> void:
|
|
|
61
73
|
# Reentrant model callbacks can restore the old value; commit must still
|
|
62
74
|
# restore a control whose local user value diverged from its snapshot.
|
|
63
75
|
scope.schedule()
|
|
76
|
+
func project(target: Node, next: bool) -> void:
|
|
77
|
+
writing = true
|
|
78
|
+
target.set("value",next)
|
|
79
|
+
writing = false
|
|
64
80
|
|
|
65
81
|
# A desired linkage is reusable data; each native mount owns its mutable edit
|
|
66
82
|
# connection. Copy without evaluating getters outside the render read scope.
|
|
67
83
|
func snapshot():
|
|
68
|
-
var result = get_script().new(null,Callable(),&"",Callable(),"")
|
|
84
|
+
var result = get_script().new(null,Callable(),&"",Callable(),"",null)
|
|
69
85
|
result.root = root
|
|
70
86
|
result.source = source
|
|
71
87
|
result.field = field
|
|
@@ -74,4 +90,5 @@ func snapshot():
|
|
|
74
90
|
result.write = write
|
|
75
91
|
result.value = value
|
|
76
92
|
result.valid = valid
|
|
93
|
+
result.observable = observable
|
|
77
94
|
return result
|
|
@@ -248,8 +248,11 @@ func _valid(desired: Element, previous: Mounted) -> bool:
|
|
|
248
248
|
elif desired.type is Script:
|
|
249
249
|
if not desired.type.can_instantiate() or not ClassDB.is_parent_class(desired.type.get_instance_base_type(),"Node"): return false
|
|
250
250
|
else: return false
|
|
251
|
-
for
|
|
252
|
-
|
|
251
|
+
for key in desired.bindings:
|
|
252
|
+
var binding = desired.bindings[key]
|
|
253
|
+
if not binding is Binding or not binding.valid:
|
|
254
|
+
validation_error = desired.location(str(key))+": invalid observable Bool binding endpoint; previous tree retained"
|
|
255
|
+
return false
|
|
253
256
|
for event in desired.handlers:
|
|
254
257
|
var handler = desired.handlers[event]
|
|
255
258
|
if not handler is Callable or not handler.is_valid(): return _invalid_attribute(desired,event,"signal requires a valid native Callable")
|
|
@@ -360,7 +363,7 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
360
363
|
var binding = record.bindings.get(key,desired.bindings[key])
|
|
361
364
|
record.bindings[key] = binding
|
|
362
365
|
if not is_same(node.get(key),desired.bindings[key].value):
|
|
363
|
-
|
|
366
|
+
binding.project(node,desired.bindings[key].value)
|
|
364
367
|
writes += 1
|
|
365
368
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
366
369
|
binding.attach(node,self)
|
|
@@ -402,7 +405,7 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
402
405
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
403
406
|
for key in desired.properties:
|
|
404
407
|
if scroll and key=="scroll_offset": continue
|
|
405
|
-
if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
|
|
408
|
+
if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]) or key=="value" and Binding.declared(node.get_script(),"value") and not is_same(node.get(key),desired.properties[key]):
|
|
406
409
|
if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
|
|
407
410
|
writes += 1
|
|
408
411
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
@@ -699,13 +702,13 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
699
702
|
var expected: String = str(properties[key].get("class_name",""))
|
|
700
703
|
if ClassDB.class_exists(expected) and not value.is_class(expected): return _invalid_attribute(desired,str(key),"incompatible native Object class "+expected)
|
|
701
704
|
for key in desired.bindings:
|
|
702
|
-
if key!="value" or desired.properties.has(key) or
|
|
705
|
+
if key!="value" or desired.properties.has(key) or not properties.has(key) or properties[key].type!=TYPE_BOOL or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return _invalid_attribute(desired,str(key),"invalid or conflicting controlled binding")
|
|
703
706
|
var args: Array = signals.get("value_changed",{}).get("args",[])
|
|
704
707
|
|
|
705
708
|
# 4.0 lacks signal argument type metadata. Compiler source proof and
|
|
706
709
|
# native typed callback still apply; optional introspection cannot
|
|
707
710
|
# reject a valid input on that engine.
|
|
708
|
-
if args.size()!=
|
|
711
|
+
if args.size()!=2 or args.any(func(arg): return arg.type not in [TYPE_NIL,TYPE_BOOL]): return false
|
|
709
712
|
for key in desired.handlers:
|
|
710
713
|
if not signals.has(key): return _invalid_attribute(desired,str(key),"unknown native signal")
|
|
711
714
|
var message := _handler_error(desired.handlers[key],signals[key].get("args",[]).size())
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
extends RefCounted
|
|
3
3
|
const Profile = preload("profile.tres")
|
|
4
|
+
const Binding = preload("binding.gd")
|
|
4
5
|
## Desired values only. No native Node is allocated during description creation.
|
|
5
6
|
# Internal normalized weak reference, only populated by child normalization.
|
|
6
7
|
var borrowed: WeakRef
|
|
@@ -8,6 +9,13 @@ var type: Variant
|
|
|
8
9
|
var properties: Dictionary
|
|
9
10
|
var placement: Dictionary = {}
|
|
10
11
|
var bindings: Dictionary = {}
|
|
12
|
+
func resolve_bindings() -> void:
|
|
13
|
+
var value = properties.get("value")
|
|
14
|
+
if not value is Binding: return
|
|
15
|
+
if value.observable or not value.valid and value.value==null:
|
|
16
|
+
bindings.value = value
|
|
17
|
+
properties.erase("value")
|
|
18
|
+
else: properties.value = value.value
|
|
11
19
|
var handlers: Dictionary
|
|
12
20
|
var children: Array
|
|
13
21
|
var key: Variant
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
class_name EstragonCheckbox
|
|
3
|
+
extends "toggle.gd"
|
|
4
|
+
## Square/checkmark and label on the shared observable Bool/focus/input path.
|
|
5
|
+
func _init() -> void:
|
|
6
|
+
super._init()
|
|
7
|
+
background_color = "transparent"
|
|
8
|
+
func _square_size() -> float:
|
|
9
|
+
return maxf(16.0,float(font_size))
|
|
10
|
+
func _measure_native() -> Vector2:
|
|
11
|
+
var label := _measure_label() if not text.is_empty() else Vector2.ZERO
|
|
12
|
+
return Vector2(_square_size()+(8.0+label.x if not text.is_empty() else 0.0),maxf(_square_size(),label.y))
|
|
13
|
+
func get_label_origin() -> Vector2:
|
|
14
|
+
var content := get_content_rect()
|
|
15
|
+
return content.position+Vector2(_square_size()+8.0,maxf(0.0,(content.size.y-_measure_label().y)*0.5))
|
|
16
|
+
func get_background_color() -> Color:
|
|
17
|
+
# Checkbox is distinct from Toggle's checked full-surface fill/underline.
|
|
18
|
+
if disabled: return _visual_style.colors.disabled_background_color
|
|
19
|
+
if _held and _hovered or _keyboard_held: return _visual_style.colors.pressed_background_color
|
|
20
|
+
return _visual_style.colors.hover_background_color if _hovered else _visual_style.colors.background_color
|
|
21
|
+
func _draw() -> void:
|
|
22
|
+
var content := get_content_rect()
|
|
23
|
+
if content.size.x<=0 or content.size.y<=0: return
|
|
24
|
+
var side := minf(_square_size(),minf(content.size.x,content.size.y))
|
|
25
|
+
var square := Rect2(content.position+Vector2(0,maxf(0,(content.size.y-side)*0.5)),Vector2(side,side))
|
|
26
|
+
var tint := Color(1,1,1,0.5) if disabled else Color.WHITE
|
|
27
|
+
draw_rect(square,_visual_style.colors.disabled_background_color if disabled else _visual_style.colors.checked_background_color if value else Color("#252525"))
|
|
28
|
+
draw_rect(square,Color("#c5d4df")*tint,false,1.5)
|
|
29
|
+
if value and side>=8:
|
|
30
|
+
draw_polyline(PackedVector2Array([square.position+Vector2(side*0.2,side*0.52),square.position+Vector2(side*0.43,side*0.76),square.position+Vector2(side*0.82,side*0.25)]),tint,2.0,true)
|
|
31
|
+
_draw_label(get_label_origin(),tint)
|
|
32
|
+
if has_focus() and layout_size.x>4 and layout_size.y>4:
|
|
33
|
+
draw_rect(Rect2(Vector2(2,2),layout_size-Vector2(4,4)),Color("#9cdcff"),false,2)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://bhx8qo8oamg8g
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
class_name EstragonToggle
|
|
3
3
|
extends "button.gd"
|
|
4
4
|
## Controlled boolean input. Completed native pointer/keyboard activation edits.
|
|
5
|
-
signal value_changed(value: bool)
|
|
5
|
+
signal value_changed(previous: bool, value: bool)
|
|
6
|
+
const _GOGO_BINDABLE_PROPERTIES_NATIVE := {"value":"bool"}
|
|
7
|
+
const State = preload("../composition/state.tres")
|
|
6
8
|
const ESTRAGON_TOGGLE_STYLE := true
|
|
7
9
|
var checked_background_color: Variant = Color("#227a60"):
|
|
8
10
|
set(next):
|
|
@@ -16,15 +18,19 @@ func _get_property_list() -> Array[Dictionary]:
|
|
|
16
18
|
@export var value: bool = false:
|
|
17
19
|
set(next):
|
|
18
20
|
if value == next: return
|
|
21
|
+
var previous := value
|
|
19
22
|
value = next
|
|
20
23
|
_queue_style_redraw()
|
|
24
|
+
value_changed.emit(previous,next)
|
|
25
|
+
get:
|
|
26
|
+
State.observe(self,&"value_changed")
|
|
27
|
+
return value
|
|
21
28
|
func _init() -> void:
|
|
22
29
|
super._init()
|
|
23
30
|
pressed.connect(_activate)
|
|
24
31
|
func _activate() -> void:
|
|
25
32
|
if disabled: return
|
|
26
33
|
value = not value
|
|
27
|
-
value_changed.emit(value)
|
|
28
34
|
func get_background_color() -> Color:
|
|
29
35
|
if disabled: return super.get_background_color()
|
|
30
36
|
return _visual_style.colors.checked_background_color if value else super.get_background_color()
|
package/package.json
CHANGED