@papercraftgames/estragon 0.1.0-beta.15 → 0.1.0-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/addons/estragon/compiler/emitter.gd +1 -1
  2. package/addons/estragon/compiler/validator.gd +32 -16
  3. package/addons/estragon/editor/components.gd +1 -1
  4. package/addons/estragon/editor/length_property.gd +22 -0
  5. package/addons/estragon/editor/length_property.gd.uid +1 -0
  6. package/addons/estragon/editor/plugin.cfg +1 -1
  7. package/addons/estragon/editor/scene_inspector.gd +8 -2
  8. package/addons/estragon/runtime/composition/computation.gd +28 -6
  9. package/addons/estragon/runtime/composition/state.gd +1 -7
  10. package/addons/estragon/runtime/node/box.gd +69 -17
  11. package/addons/estragon/runtime/node/component_2d.gd +54 -45
  12. package/addons/estragon/runtime/node/component_3d.gd +52 -16
  13. package/addons/estragon/runtime/node/estragon_2d.gd +0 -15
  14. package/addons/estragon/runtime/node/estragon_3d.gd +0 -15
  15. package/addons/estragon/runtime/node/hbox.gd +3 -0
  16. package/addons/estragon/runtime/node/internal/coordinator.gd +15 -17
  17. package/addons/estragon/runtime/node/internal/grid_definition.gd +75 -0
  18. package/addons/estragon/runtime/node/internal/grid_definition.gd.uid +1 -0
  19. package/addons/estragon/runtime/node/internal/layout_core.gd +145 -44
  20. package/addons/estragon/runtime/node/internal/length.gd +86 -0
  21. package/addons/estragon/runtime/node/internal/length.gd.uid +1 -0
  22. package/addons/estragon/runtime/node/internal/stack_contract.gd +21 -0
  23. package/addons/estragon/runtime/node/internal/stack_contract.gd.uid +1 -0
  24. package/addons/estragon/runtime/node/internal/stack_policy.gd +59 -0
  25. package/addons/estragon/runtime/node/internal/stack_policy.gd.uid +1 -0
  26. package/addons/estragon/runtime/node/native_2d.gd +2 -2
  27. package/addons/estragon/runtime/node/native_3d.gd +2 -2
  28. package/addons/estragon/runtime/node/spacer.gd +4 -0
  29. package/addons/estragon/runtime/node/spacer.gd.uid +1 -0
  30. package/addons/estragon/runtime/node/vbox.gd +3 -0
  31. package/package.json +1 -1
  32. package/addons/estragon/runtime/composition/pixels.gd +0 -38
  33. package/addons/estragon/runtime/composition/pixels.gd.uid +0 -1
  34. package/addons/estragon/runtime/node/internal/pixel_contract.gd +0 -20
  35. package/addons/estragon/runtime/node/internal/pixel_contract.gd.uid +0 -1
@@ -86,7 +86,7 @@ static func _string(value: String) -> String:
86
86
  return output + '"'
87
87
 
88
88
  static func literal(value: Model.Literal) -> String:
89
- return str(value.value) if value.kind == "pixel-literal" else _string(value.value)
89
+ return _string(value.value)
90
90
 
91
91
  func _argument(expression: Model.GdExpression, type_name: String, factory: Factory) -> void:
92
92
  var argument := Argument.new()
@@ -5,7 +5,8 @@ const Element = preload("../runtime/composition/element.gd")
5
5
  const Model = preload("model.gd")
6
6
  const Source = preload("source.gd")
7
7
  const Resolver = preload("native/resolver.gd")
8
- const Pixels = preload("../runtime/node/internal/pixel_contract.gd")
8
+ const StackContract = preload("../runtime/node/internal/stack_contract.gd")
9
+ const Length = preload("../runtime/node/internal/length.gd")
9
10
  const Lexer = preload("lexer.gd")
10
11
  var file: Source
11
12
  var resolver
@@ -42,6 +43,10 @@ func _component(node: Model.Component) -> void:
42
43
  script = script.get_base_script()
43
44
  properties.merge(resolved.get("properties",{}),true)
44
45
  signals.merge(resolved.get("signals",{}),true)
46
+ var stack_direction := StackContract.preset(resolved.script)
47
+ if stack_direction.is_empty(): stack_direction = "row"
48
+ for attribute in node.attributes:
49
+ if attribute.name=="direction": stack_direction = str(attribute.value.value) if attribute.value is Model.Literal else StackContract.preset(resolved.script)
45
50
  var seen: Dictionary = {}
46
51
  for attribute in node.attributes:
47
52
  var name := attribute.name
@@ -76,19 +81,26 @@ func _component(node: Model.Component) -> void:
76
81
  return
77
82
  index = token.span.end.index
78
83
  elif properties.has(name) and name not in ["owner", "script"] and not name.contains("/") and not (int(properties[name].usage) & PROPERTY_USAGE_READ_ONLY):
79
- attribute.type_name = _native_type(properties[name])
84
+ attribute.type_name = "Variant" if Length.registered(resolved.script,name) else _native_type(properties[name])
80
85
  if attribute.type_name.is_empty():
81
86
  _error("Unsupported Node property metadata: " + name, attribute.name_span)
82
87
  return
83
88
  else:
84
- _error("Unknown, read-only or reserved Node property/signal " + name, attribute.name_span)
89
+ _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)
85
90
  return
86
- var pixel_kind := Pixels.kind(resolved.script,name)
87
- if not pixel_kind.is_empty():
88
- _pixel(attribute,pixel_kind)
91
+ if StackContract.registered(resolved.script) and attribute.value is Model.Literal:
92
+ var message := StackContract.error(name,attribute.value.value,stack_direction,StackContract.preset(resolved.script))
93
+ if not message.is_empty():
94
+ _error(message,attribute.value.span)
95
+ return
96
+ var is_length := Length.registered(resolved.script,name)
97
+ if is_length:
98
+ _length(attribute,Length.domain(name))
89
99
  if not file.diagnostics.is_empty(): return
90
100
  if attribute.value is Model.Literal:
91
- if attribute.value.kind == "pixel-literal": continue
101
+ if is_length:
102
+ attribute.value.kind = "string-literal"
103
+ continue
92
104
  if attribute.type_name not in ["String", "StringName"]:
93
105
  _error("Typed Node values require {GDScript expressions}; only strings may be quoted", attribute.value.span)
94
106
  return
@@ -283,19 +295,23 @@ func _binding(attribute, node, properties: Dictionary, signals: Dictionary) -> v
283
295
  attribute.type_name = "Variant"
284
296
  attribute.binding_path = names
285
297
 
286
- func _pixel(attribute, domain: String) -> void:
298
+ func _length(attribute, domain: String) -> void:
287
299
  var value = attribute.value
288
300
  if value is Model.Literal:
289
- var text: String = str(value.value)
290
- if domain == "length" and (text == "auto" or text.is_valid_float() and Pixels.valid(float(text),domain)):
291
- value.value = -1.0 if text == "auto" else float(text)
292
- value.kind = "pixel-literal"
293
- return
294
- _error("Pixel lengths require finite nonnegative numbers; only width/height allow quoted numbers or auto",value.span)
301
+ var parsed := Length.parse(value.value,domain)
302
+ if parsed.has("error"): _error(parsed.error,value.span)
295
303
  return
296
304
  var tokens := _expression_tokens(value)
297
305
  var text := ""
298
306
  if tokens.size()==1: text = tokens[0].text
299
307
  elif tokens.size()==2 and tokens[0].text in ["+","-"] and tokens[1].kind=="number": text = tokens[0].text+tokens[1].text
300
- if text in ["NAN","INF","-INF","+INF"] or text.is_valid_float() and not Pixels.valid(float(text),domain):
301
- _error("Pixel lengths require finite nonnegative numbers (width/height also allow -1 for auto)",value.span)
308
+ if tokens.size()==1 and tokens[0].kind=="string":
309
+ var parsed := Length.parse(text.substr(1,text.length()-2).c_unescape(),domain)
310
+ if parsed.has("error"): _error(parsed.error,value.span)
311
+ elif text in ["true","false","null"]:
312
+ _error("Length requires int, float or a unit string",value.span)
313
+ elif text in ["NAN","INF","-INF","+INF"]:
314
+ _error("Length must be finite",value.span)
315
+ elif text.is_valid_float():
316
+ var parsed := Length.parse(float(text),domain)
317
+ if parsed.has("error"): _error(parsed.error,value.span)
@@ -2,7 +2,7 @@
2
2
  extends RefCounted
3
3
  ## Trusted installed resources, not guessed global classes or installation roots.
4
4
  const ITEMS := [
5
- {"alias":"Pixels","canonical":"EstragonPixels","script":preload("../runtime/composition/pixels.gd"),"dimension":0,"origin":"observed pixel helper"},
5
+ {"alias":"Spacer","canonical":"EstragonSpacer","script":preload("../runtime/node/spacer.gd"),"dimension":2,"origin":"native layout"},
6
6
  {"alias":"Box","canonical":"EstragonBox","script":preload("../runtime/node/box.gd"),"dimension":2,"origin":"native layout"},
7
7
  {"alias":"Text","canonical":"EstragonText","script":preload("../runtime/node/text.gd"),"dimension":2,"origin":"native widget"},
8
8
  {"alias":"Rect","canonical":"EstragonRect","script":preload("../runtime/node/rect.gd"),"dimension":2,"origin":"native widget"},
@@ -0,0 +1,22 @@
1
+ @tool
2
+ extends EditorProperty
3
+ const Length = preload("../runtime/node/internal/length.gd")
4
+ var input := LineEdit.new()
5
+ func _init() -> void:
6
+ input.placeholder_text = "200, 50%, 2.5in, auto"
7
+ add_child(input)
8
+ add_focusable(input)
9
+ input.text_submitted.connect(_submit)
10
+ func _submit(text: String) -> void:
11
+ var name := str(get_edited_property())
12
+ var value: Variant = float(text) if text.is_valid_float() else text
13
+ var parsed := Length.parse(value,Length.domain(name))
14
+ if parsed.has("error"):
15
+ input.tooltip_text = parsed.error
16
+ input.modulate = Color(1,0.5,0.5)
17
+ return
18
+ input.modulate = Color.WHITE
19
+ input.tooltip_text = ""
20
+ emit_changed(get_edited_property(),value)
21
+ func _update_property() -> void:
22
+ input.text = str(get_edited_object().get(get_edited_property()))
@@ -0,0 +1 @@
1
+ uid://b36hmqsxprn3d
@@ -3,5 +3,5 @@
3
3
  name="Estragon"
4
4
  description="Native Gogo/GGX highlighting, compilation and validation before Play."
5
5
  author="Resist Design"
6
- version="0.1.0-beta.15"
6
+ version="0.1.0-beta.18"
7
7
  script="plugin.gd"
@@ -1,13 +1,19 @@
1
1
  @tool
2
2
  extends EditorInspectorPlugin
3
3
  ## Authored-source presentation alongside the untouched native Script property.
4
+ const Length = preload("../runtime/node/internal/length.gd")
5
+ const LengthProperty = preload("length_property.gd")
4
6
  var service: WeakRef
5
7
  func _can_handle(object: Object) -> bool:
6
8
  var owner = service.get_ref() if service != null else null
7
- return owner != null and owner.active and object is Node and owner.editable(object)
9
+ return owner != null and owner.active and object is Node and (owner.editable(object) or object.has_method("_get_layout_coordinator"))
10
+ func _parse_property(object: Object, _type: Variant.Type, name: String, _hint: PropertyHint, _hint_text: String, _usage: int, _wide: bool) -> bool:
11
+ if not Length.registered(object.get_script(),name): return false
12
+ add_property_editor(name,LengthProperty.new())
13
+ return true
8
14
  func _parse_begin(object: Object) -> void:
9
15
  var owner = service.get_ref() if service != null else null
10
- if owner == null: return
16
+ if owner == null or not owner.editable(object): return
11
17
  var panel := VBoxContainer.new()
12
18
  panel.name = "GogoSceneComponent"
13
19
  var label := Label.new()
@@ -1,5 +1,6 @@
1
1
  extends RefCounted
2
- const Pixels = preload("../node/internal/pixel_contract.gd")
2
+ const StackContract = preload("../node/internal/stack_contract.gd")
3
+ const Length = preload("../node/internal/length.gd")
3
4
  const Profile = preload("profile.tres")
4
5
  ## F01 computation and retained static-shape records external to native objects.
5
6
  const Binding = preload("binding.gd")
@@ -37,6 +38,7 @@ var moves := 0
37
38
  var _rendering := false
38
39
  var _again := false
39
40
  var _consecutive := 0
41
+ var validation_error := ""
40
42
  func _init(owner: Node, manager: Resource) -> void:
41
43
  host = weakref(owner)
42
44
  state = weakref(manager)
@@ -110,16 +112,17 @@ func _flush() -> void:
110
112
  if Profile.is_enabled(): Profile.add("views")
111
113
  _rendering = true
112
114
  _again = false
113
- manager.begin(owner)
115
+ manager.begin()
114
116
  var desired = owner.call("build_view")
115
117
  var reads: Dictionary = manager.finish()
116
118
  if Profile.is_enabled(): Profile.elapsed("view",started)
117
119
  _borrow_seen.clear()
118
120
  _observes_children = false
121
+ validation_error = ""
119
122
  desired = _normalize(desired)
120
123
  _rendering = false
121
124
  if not desired is Element or not _valid(desired,mounted) or not _preflight(desired,mounted,owner) or not _rescue_clear(desired,mounted,owner):
122
- push_error("Invalid composition output or foreign boundary conflict; previous tree retained")
125
+ push_error(validation_error if not validation_error.is_empty() else "Invalid composition output or foreign boundary conflict; previous tree retained")
123
126
  return
124
127
  # A nested array may be an empty get_children() result. Observe native
125
128
  # changes without inspecting the expression source or polling the tree.
@@ -318,9 +321,11 @@ func _apply(desired: Element, record: Mounted) -> void:
318
321
  writes += 1
319
322
  if Profile.is_enabled(): Profile.add("property_writes")
320
323
  binding.attach(node,self)
324
+ var stack := StackContract.registered(desired.type)
325
+ if stack: node._apply_stack_policy(desired.properties)
321
326
  for key in desired.properties:
322
327
  if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
323
- node.set(key,desired.properties[key])
328
+ if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
324
329
  writes += 1
325
330
  if Profile.is_enabled(): Profile.add("property_writes")
326
331
  for event in record.handlers:
@@ -457,11 +462,28 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
457
462
  contracts[desired.type] = {"properties":properties,"signals":signals}
458
463
  var properties: Dictionary = contracts[desired.type].properties
459
464
  var signals: Dictionary = contracts[desired.type].signals
465
+ if StackContract.registered(desired.type):
466
+ var policy: Dictionary = previous.properties.duplicate() if previous!=null and _compatible(desired,previous) else {}
467
+ policy.merge(desired.properties,true)
468
+ var fixed := StackContract.preset(desired.type)
469
+ var direction = policy.get("direction",fixed if not fixed.is_empty() else "row")
470
+ for key in ["direction","horizontal_align","vertical_align"]:
471
+ var value = policy.get(key,direction if key=="direction" else "start")
472
+ var message := StackContract.error(key,value,str(direction),fixed)
473
+ if not message.is_empty():
474
+ validation_error = desired.source+": "+message+"; previous tree retained"
475
+ return false
460
476
  for key in desired.properties:
461
477
  if not properties.has(key) or key in ["script","owner"] or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return false
462
478
  var value = desired.properties[key]
463
- var pixel_kind := Pixels.kind(desired.type,key)
464
- if not pixel_kind.is_empty() and not Pixels.valid(value,pixel_kind): return false
479
+ 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):
480
+ validation_error = desired.source+": grow requires a finite nonnegative weight; previous tree retained"
481
+ return false
482
+ if Length.registered(desired.type,key):
483
+ var parsed := Length.parse(value,Length.domain(key))
484
+ if parsed.has("error"):
485
+ validation_error = desired.source+": invalid length '"+str(key)+"': "+parsed.error+"; previous tree retained"
486
+ return false
465
487
  var kind: int = properties[key].type
466
488
  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 false
467
489
  if kind==TYPE_OBJECT and value!=null:
@@ -3,7 +3,6 @@ extends Resource
3
3
  const Profile = preload("profile.tres")
4
4
  ## Framework-owned shared scope stack; never stored on application objects.
5
5
  var scopes: Array = []
6
- var composing_hosts: Array = []
7
6
  var records: Dictionary = {}
8
7
  var managed: Dictionary = {}
9
8
  var dirty: Array = []
@@ -40,19 +39,14 @@ func drain() -> void:
40
39
  break
41
40
  flushing = false
42
41
  if Profile.is_enabled() and passes>0: Profile.elapsed("drain",started)
43
- func begin(host: Node = null) -> void:
42
+ func begin() -> void:
44
43
  scopes.append({})
45
- composing_hosts.append(weakref(host) if host != null else null)
46
- func current_host() -> Node:
47
- if composing_hosts.is_empty() or composing_hosts.back() == null: return null
48
- return composing_hosts.back().get_ref()
49
44
  func observe(source: Object, event: StringName) -> void:
50
45
  if scopes.is_empty(): return
51
46
  if Profile.is_enabled(): Profile.add("getter_reads")
52
47
  var key := str(source.get_instance_id())+":"+str(event)
53
48
  scopes.back()[key] = [weakref(source),event]
54
49
  func finish() -> Dictionary:
55
- composing_hosts.pop_back()
56
50
  return scopes.pop_back()
57
51
  func lifecycle(host: Node, what: int) -> void:
58
52
  if Engine.is_editor_hint(): return
@@ -2,37 +2,89 @@
2
2
  class_name EstragonBox
3
3
  extends "component_2d.gd"
4
4
  ## Constructible horizontal Box. VBox selects the vertical axis.
5
- # -1 means an unset edge; explicit edges always override the shorthand.
6
- @export var padding: float = 0.0:
5
+ const ESTRAGON_STACK_POLICY := true
6
+ var _policy_commit := false
7
+ const StackContract = preload("internal/stack_contract.gd")
8
+ @export_enum("row", "column") var direction: String = "row":
7
9
  set(value):
8
- if not is_finite(value) or value < 0 or value == padding: return
10
+ if value==direction: return
11
+ if _policy_commit:
12
+ direction = value
13
+ return
14
+ var message := StackContract.error("direction",value,value,StackContract.preset(get_script()))
15
+ if message.is_empty():
16
+ message = StackContract.error("horizontal_align",horizontal_align,value)
17
+ if message.is_empty(): message = StackContract.error("vertical_align",vertical_align,value)
18
+ if not message.is_empty():
19
+ push_error("Estragon Box: "+message)
20
+ return
21
+ direction = value
22
+ _changed()
23
+ @export_enum("start", "center", "end", "stretch") var horizontal_align: String = "start":
24
+ set(value):
25
+ if _policy_commit:
26
+ horizontal_align = value
27
+ return
28
+ if value==horizontal_align or not _valid_alignment("horizontal_align",value): return
29
+ horizontal_align = value
30
+ _changed()
31
+ @export_enum("start", "center", "end", "stretch") var vertical_align: String = "start":
32
+ set(value):
33
+ if _policy_commit:
34
+ vertical_align = value
35
+ return
36
+ if value==vertical_align or not _valid_alignment("vertical_align",value): return
37
+ vertical_align = value
38
+ _changed()
39
+ # Called only after whole-description preflight; avoids transient invalid states
40
+ # when direction and cross alignment change together in one reconciliation.
41
+ func _apply_stack_policy(values: Dictionary) -> void:
42
+ var before := [direction,horizontal_align,vertical_align]
43
+ _policy_commit = true
44
+ for key in ["direction","horizontal_align","vertical_align"]:
45
+ if values.has(key): set(key,values[key])
46
+ _policy_commit = false
47
+ if before!=[direction,horizontal_align,vertical_align]: _changed()
48
+ func _valid_alignment(property: String, value) -> bool:
49
+ var message := StackContract.error(property,value,"row" if _layout_axis()==0 else "column")
50
+ if not message.is_empty(): push_error("Estragon Box: "+message)
51
+ return message.is_empty()
52
+ func _layout_axis() -> int:
53
+ return 0 if direction=="row" else 1
54
+ func _layout_options() -> Dictionary:
55
+ var result := super._layout_options()
56
+ result["alignment"] = [horizontal_align,vertical_align,"start"]
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
9
61
  padding = value
10
62
  _changed()
11
- @export var padding_top: float = -1.0:
63
+ var padding_top: Variant = "auto":
12
64
  set(value):
13
- if not valid_length(value) or value == padding_top: return
65
+ if is_same(padding_top,value) or not lengths.assign("padding_top",value): return
14
66
  padding_top = value
15
67
  _changed()
16
- @export var padding_right: float = -1.0:
68
+ var padding_right: Variant = "auto":
17
69
  set(value):
18
- if not valid_length(value) or value == padding_right: return
70
+ if is_same(padding_right,value) or not lengths.assign("padding_right",value): return
19
71
  padding_right = value
20
72
  _changed()
21
- @export var padding_bottom: float = -1.0:
73
+ var padding_bottom: Variant = "auto":
22
74
  set(value):
23
- if not valid_length(value) or value == padding_bottom: return
75
+ if is_same(padding_bottom,value) or not lengths.assign("padding_bottom",value): return
24
76
  padding_bottom = value
25
77
  _changed()
26
- @export var padding_left: float = -1.0:
78
+ var padding_left: Variant = "auto":
27
79
  set(value):
28
- if not valid_length(value) or value == padding_left: return
80
+ if is_same(padding_left,value) or not lengths.assign("padding_left",value): return
29
81
  padding_left = value
30
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
31
87
 
32
88
  func _padding_insets() -> Vector4:
33
- return Vector4(padding_left if padding_left >= 0 else padding,padding_top if padding_top >= 0 else padding,padding_right if padding_right >= 0 else padding,padding_bottom if padding_bottom >= 0 else padding)
34
-
35
- func _layout_options() -> Dictionary:
36
- var options := super._layout_options()
37
- options.padding = _padding_insets()
38
- return options
89
+ layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
90
+ return layout.model.padding
@@ -4,74 +4,82 @@ extends Node2D
4
4
  ## Native C1 participant. Needs a contiguous same-dimensional chain to an entry.
5
5
  signal layout_applied(size: Vector2)
6
6
  const Coordinator = preload("internal/coordinator.gd")
7
- @export var width: float = -1.0:
7
+ const ESTRAGON_LENGTHS := true
8
+ const Length = preload("internal/length.gd")
9
+ var lengths = Length.new()
10
+ var width: Variant = "auto":
8
11
  set(value):
9
- if not valid_length(value) or width == value: return
12
+ if is_same(width,value) or not lengths.assign("width",value): return
10
13
  width = value
11
14
  _changed()
12
- @export var height: float = -1.0:
15
+ var height: Variant = "auto":
13
16
  set(value):
14
- if not valid_length(value) or height == value: return
17
+ if is_same(height,value) or not lengths.assign("height",value): return
15
18
  height = value
16
19
  _changed()
17
- @export var fill_width: bool = false:
20
+ var x: Variant = 0.0:
18
21
  set(value):
19
- if fill_width == value: return
20
- fill_width = value
22
+ if is_same(x,value) or not lengths.assign("x",value): return
23
+ x = value
21
24
  _changed()
22
- @export var fill_height: bool = false:
25
+ var y: Variant = 0.0:
23
26
  set(value):
24
- if fill_height == value: return
25
- fill_height = value
27
+ if is_same(y,value) or not lengths.assign("y",value): return
28
+ y = value
26
29
  _changed()
27
- @export var gap: float = 0.0:
30
+ var gap: Variant = 0.0:
28
31
  set(value):
29
- if not is_finite(value) or value < 0 or value == gap: return
32
+ if is_same(gap,value) or not lengths.assign("gap",value): return
30
33
  gap = value
31
34
  _changed()
32
- @export var center: bool = false:
35
+ var margin: Variant = 0.0:
33
36
  set(value):
34
- if center == value: return
35
- center = value
36
- _changed()
37
- var layout_size: Vector2:
38
- get: return _layout_size
39
- var _layout_size := Vector2.ZERO
40
- # Internal bridge, deliberately not the public authoring API.
41
- var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
42
-
43
- # -1 means an unset edge; explicit edges always override the shorthand.
44
- @export var margin: float = 0.0:
45
- set(value):
46
- if not is_finite(value) or value < 0 or value == margin: return
37
+ if is_same(margin,value) or not lengths.assign("margin",value): return
47
38
  margin = value
48
39
  _changed()
49
- @export var margin_top: float = -1.0:
40
+ var margin_top: Variant = "auto":
50
41
  set(value):
51
- if not valid_length(value) or value == margin_top: return
42
+ if is_same(margin_top,value) or not lengths.assign("margin_top",value): return
52
43
  margin_top = value
53
44
  _changed()
54
- @export var margin_right: float = -1.0:
45
+ var margin_right: Variant = "auto":
55
46
  set(value):
56
- if not valid_length(value) or value == margin_right: return
47
+ if is_same(margin_right,value) or not lengths.assign("margin_right",value): return
57
48
  margin_right = value
58
49
  _changed()
59
- @export var margin_bottom: float = -1.0:
50
+ var margin_bottom: Variant = "auto":
60
51
  set(value):
61
- if not valid_length(value) or value == margin_bottom: return
52
+ if is_same(margin_bottom,value) or not lengths.assign("margin_bottom",value): return
62
53
  margin_bottom = value
63
54
  _changed()
64
- @export var margin_left: float = -1.0:
55
+ var margin_left: Variant = "auto":
65
56
  set(value):
66
- if not valid_length(value) or value == margin_left: return
57
+ if is_same(margin_left,value) or not lengths.assign("margin_left",value): return
67
58
  margin_left = value
68
59
  _changed()
69
-
70
- func _margin_insets() -> Vector4:
71
- return Vector4(margin_left if margin_left >= 0 else margin,margin_top if margin_top >= 0 else margin,margin_right if margin_right >= 0 else margin,margin_bottom if margin_bottom >= 0 else margin)
72
-
73
- static func valid_length(value: float) -> bool:
74
- return is_finite(value) and (value >= 0 or value == -1)
60
+ @export var grow: float = 0.0:
61
+ set(value):
62
+ if not is_finite(value) or value<0 or value==grow: return
63
+ grow = value
64
+ _changed()
65
+ @export_enum("Natural", "Stretch") var stretch: int = 0:
66
+ set(value):
67
+ if value not in [0,1] or value==stretch: return
68
+ stretch = value
69
+ _changed()
70
+ @export var center: bool = false:
71
+ set(value):
72
+ if center == value: return
73
+ center = value
74
+ _changed()
75
+ var layout_size: Vector2:
76
+ get: return _layout_size
77
+ var _layout_size := Vector2.ZERO
78
+ var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
79
+ func _get_property_list() -> Array[Dictionary]:
80
+ return Length.properties(["width","height","x","y","gap","margin","margin_top","margin_right","margin_bottom","margin_left"])
81
+ static func valid_length(value) -> bool:
82
+ return Length.valid(value,"extent")
75
83
 
76
84
  func set_extent(value: Vector2) -> Error:
77
85
  for axis in range(2):
@@ -81,7 +89,7 @@ func set_extent(value: Vector2) -> Error:
81
89
  return OK
82
90
 
83
91
  func requested_extent() -> Vector3:
84
- return Vector3(width, height, 0.0)
92
+ return layout.model.requested
85
93
 
86
94
  func _layout_axis() -> int:
87
95
  return 0
@@ -91,14 +99,11 @@ func _measure_native() -> Vector2:
91
99
 
92
100
  func _layout_options() -> Dictionary:
93
101
  var natural := _measure_native()
94
- return {"margin":_margin_insets(),"axis":_layout_axis(),"fill":Vector3(1 if fill_width else 0,1 if fill_height else 0,0),"intrinsic":Vector3(natural.x,natural.y,0)}
102
+ return {"axis":_layout_axis(),"fill":Vector3.ZERO,"intrinsic":Vector3(natural.x,natural.y,0)}
95
103
 
96
104
  func _is_layout_entry() -> bool:
97
105
  return false
98
106
 
99
- func _layout_viewport_scale() -> Vector2:
100
- return Vector2.ZERO
101
-
102
107
  func _changed() -> void:
103
108
  if layout != null: layout.changed()
104
109
 
@@ -133,3 +138,7 @@ func apply_layout_size(size: Vector3) -> void:
133
138
  # Explicit invalidation also restores a native position edited externally.
134
139
  if layout.parent_coordinator() != null: layout._place(layout.model.offset)
135
140
  layout_applied.emit(_layout_size)
141
+
142
+ func _margin_insets() -> Vector4:
143
+ layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
144
+ return layout.model.margin
@@ -4,26 +4,59 @@ extends Node3D
4
4
  ## Native C1 participant. Needs a contiguous same-dimensional chain to an entry.
5
5
  signal layout_applied(size: Vector3)
6
6
  const Coordinator = preload("internal/coordinator.gd")
7
- @export var width: float = -1.0:
7
+ const ESTRAGON_LENGTHS := true
8
+ const Length = preload("internal/length.gd")
9
+ var lengths = Length.new()
10
+ var width: Variant = "auto":
8
11
  set(value):
9
- if not valid_length(value) or width == value: return
12
+ if is_same(width,value) or not lengths.assign("width",value): return
10
13
  width = value
11
14
  _changed()
12
- @export var height: float = -1.0:
15
+ var height: Variant = "auto":
13
16
  set(value):
14
- if not valid_length(value) or height == value: return
17
+ if is_same(height,value) or not lengths.assign("height",value): return
15
18
  height = value
16
19
  _changed()
17
- @export var depth: float = -1.0:
20
+ var depth: Variant = "auto":
18
21
  set(value):
19
- if not valid_length(value) or depth == value: return
22
+ if is_same(depth,value) or not lengths.assign("depth",value): return
20
23
  depth = value
21
24
  _changed()
22
- @export var gap: float = 0.0:
25
+ var x: Variant = 0.0:
23
26
  set(value):
24
- if not is_finite(value) or value < 0 or value == gap: return
27
+ if is_same(x,value) or not lengths.assign("x",value): return
28
+ x = value
29
+ _changed()
30
+ var y: Variant = 0.0:
31
+ set(value):
32
+ if is_same(y,value) or not lengths.assign("y",value): return
33
+ y = value
34
+ _changed()
35
+ var z: Variant = 0.0:
36
+ set(value):
37
+ if is_same(z,value) or not lengths.assign("z",value): return
38
+ z = value
39
+ _changed()
40
+ var gap: Variant = 0.0:
41
+ set(value):
42
+ if is_same(gap,value) or not lengths.assign("gap",value): return
25
43
  gap = value
26
44
  _changed()
45
+ @export var grow: float = 0.0:
46
+ set(value):
47
+ if not is_finite(value) or value<0 or value==grow: return
48
+ grow = value
49
+ _changed()
50
+ @export_enum("Natural", "Stretch") var stretch: int = 0:
51
+ set(value):
52
+ if value not in [0,1] or value==stretch: return
53
+ stretch = value
54
+ _changed()
55
+ @export var pixels_per_unit: float = 100.0:
56
+ set(value):
57
+ if not is_finite(value) or value<=0 or pixels_per_unit==value: return
58
+ pixels_per_unit = value
59
+ _changed()
27
60
  @export var center: bool = false:
28
61
  set(value):
29
62
  if center == value: return
@@ -32,11 +65,11 @@ const Coordinator = preload("internal/coordinator.gd")
32
65
  var layout_size: Vector3:
33
66
  get: return _layout_size
34
67
  var _layout_size := Vector3.ZERO
35
- # Internal bridge, deliberately not the public authoring API.
36
68
  var layout = Coordinator.new(self, 3, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
37
-
38
- static func valid_length(value: float) -> bool:
39
- return is_finite(value) and (value >= 0 or value == -1)
69
+ func _get_property_list() -> Array[Dictionary]:
70
+ return Length.properties(["width","height","depth","x","y","z","gap"])
71
+ static func valid_length(value) -> bool:
72
+ return Length.valid(value,"extent")
40
73
 
41
74
  func set_extent(value: Vector3) -> Error:
42
75
  for axis in range(3):
@@ -47,14 +80,17 @@ func set_extent(value: Vector3) -> Error:
47
80
  return OK
48
81
 
49
82
  func requested_extent() -> Vector3:
50
- return Vector3(width, height, depth)
83
+ return layout.model.requested
84
+
85
+ func _measure_native() -> Vector3:
86
+ return Vector3.ZERO
87
+
88
+ func _layout_options() -> Dictionary:
89
+ return {"axis":0,"fill":Vector3.ZERO,"intrinsic":_measure_native()}
51
90
 
52
91
  func _is_layout_entry() -> bool:
53
92
  return false
54
93
 
55
- func _layout_viewport_scale() -> Vector2:
56
- return Vector2.ZERO
57
-
58
94
  func _changed() -> void:
59
95
  if layout != null: layout.changed()
60
96