@papercraftgames/estragon 0.1.0-beta.31 → 0.1.0-beta.33

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.
@@ -15,6 +15,7 @@ class Argument extends RefCounted:
15
15
  var type_name: String
16
16
  var name: String
17
17
  var binding_path: Array = []
18
+ var binding_type := "bool"
18
19
 
19
20
  class Factory extends RefCounted:
20
21
  var name: String
@@ -135,7 +136,9 @@ func _collect(node: Model.Component, factory: Factory) -> void:
135
136
  if attribute.value is Model.GdExpression:
136
137
  _argument(attribute.value, attribute.type_name, factory)
137
138
  factory.arguments.back().spread = attribute.kind=="spread"
138
- if attribute.kind=="binding": factory.arguments.back().binding_path = attribute.binding_path
139
+ if attribute.kind=="binding":
140
+ factory.arguments.back().binding_path = attribute.binding_path
141
+ factory.arguments.back().binding_type = attribute.binding_type
139
142
  for part in node.text_body:
140
143
  if part is Model.GdExpression: _argument(part,"Variant",factory)
141
144
  for child in node.children:
@@ -346,7 +349,7 @@ func _binding_argument(argument: Argument) -> void:
346
349
  for name in path:
347
350
  endpoint += "."+str(name)
348
351
  checks.append(endpoint+" != null")
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)
352
+ _writer.append("preload("+_resource(Binding)+").new("+root+", func("+owner+"): return "+endpoint+" if "+" and ".join(checks)+" else null, "+_string(field)+", func("+source+", "+edit+": "+argument.binding_type+"): "+source+"."+field+" = "+edit+", "+_string(".".join(argument.binding_path))+", (",argument.expression.span)
350
353
  # Keep the original property read in authored scope: native semantic
351
354
  # validation still rejects unknown members, and the getter runs once.
352
355
  _parts(argument.expression.parts)
@@ -356,7 +359,7 @@ func _binding_argument(argument: Argument) -> void:
356
359
  for name in path:
357
360
  original += "."+str(name)
358
361
  original_checks.append(original+" != null")
359
- _writer.append(") if "+" and ".join(original_checks)+" else null)",argument.expression.span)
362
+ _writer.append(") if "+" and ".join(original_checks)+" else null"+(", TYPE_STRING" if argument.binding_type=="String" else "")+")",argument.expression.span)
360
363
 
361
364
  func _render_call(node: Model.RenderCall) -> void:
362
365
  var cast: String = node.result_type
@@ -59,6 +59,7 @@ class Literal extends SyntaxNode:
59
59
  class Attribute extends RefCounted:
60
60
  var span: Span
61
61
  var binding_path: Array = []
62
+ var binding_type := "bool"
62
63
  var kind: String = "property"
63
64
  var name: String
64
65
  var name_span: Span
@@ -369,10 +369,11 @@ func _native_type(property: Dictionary) -> String:
369
369
 
370
370
  func _implicit_binding(attribute, properties: Dictionary, signals: Dictionary, script) -> void:
371
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
372
+ if not properties.has("value") or properties.value.type not in [TYPE_BOOL,TYPE_STRING] or int(properties.value.usage)&PROPERTY_USAGE_READ_ONLY: return
373
+ var kind: int = properties.value.type
374
+ if not properties.value.get("source_bindable",false) and not Binding.declared(script,"value",kind): return
374
375
  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
376
+ if args.size()!=2 or args.any(func(arg): return arg.type!=kind): return
376
377
  var tokens := _expression_tokens(attribute.value)
377
378
  if tokens.size()<3 or tokens.size()%2!=1: return
378
379
  var names: Array = []
@@ -382,6 +383,7 @@ func _implicit_binding(attribute, properties: Dictionary, signals: Dictionary, s
382
383
  attribute.kind = "binding"
383
384
  attribute.type_name = "Variant"
384
385
  attribute.binding_path = names
386
+ attribute.binding_type = "String" if kind==TYPE_STRING else "bool"
385
387
 
386
388
  func _length(attribute, domain: String) -> void:
387
389
  var value = attribute.value
@@ -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":"Input","canonical":"EstragonInput","script":preload("../runtime/node/input.gd"),"dimension":2,"origin":"Estragon native; explicit import"},
5
6
  {"alias":"Checkbox","canonical":"EstragonCheckbox","script":preload("../runtime/node/checkbox.gd"),"dimension":2,"origin":"Estragon native; explicit import"},
6
7
  {"alias":"Grid","canonical":"EstragonGrid","script":preload("../runtime/node/grid.gd"),"dimension":2,"origin":"native layout"},
7
8
  {"alias":"Spacer","canonical":"EstragonSpacer","script":preload("../runtime/node/spacer.gd"),"dimension":2,"origin":"native layout"},
@@ -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.31"
6
+ version="0.1.0-beta.33"
7
7
  script="plugin.gd"
@@ -11,13 +11,15 @@ var write: Callable
11
11
  var value: Variant
12
12
  var valid := false
13
13
  var observable := false
14
+ var kind := TYPE_BOOL
14
15
  var node: WeakRef
15
16
  var computation: WeakRef
16
17
  var connected := false
17
18
  var writing := false
18
- func _init(owner: Variant, reader: Callable, property: StringName, writer: Callable, identity: String, snapshot_value: Variant) -> void:
19
+ func _init(owner: Variant, reader: Callable, property: StringName, writer: Callable, identity: String, snapshot_value: Variant, value_type: int = TYPE_BOOL) -> void:
20
+ kind = value_type
19
21
  value = snapshot_value
20
- valid = typeof(value)==TYPE_BOOL
22
+ valid = kind in [TYPE_BOOL,TYPE_STRING] and typeof(value)==kind
21
23
  if not owner is Object or not is_instance_valid(owner): return
22
24
  route = identity
23
25
  root = weakref(owner)
@@ -28,14 +30,16 @@ func _init(owner: Variant, reader: Callable, property: StringName, writer: Calla
28
30
  if endpoint == null: return
29
31
  source = weakref(endpoint)
30
32
  if not valid: return
31
- observable = declared(endpoint.get_script(),str(field))
33
+ observable = declared(endpoint.get_script(),str(field),kind)
32
34
  if observable:
33
35
  valid = endpoint.has_signal(str(field)+"_changed")
34
- static func declared(script, property: String) -> bool:
36
+ static func declared(script, property: String, value_type: int = TYPE_BOOL) -> bool:
37
+ var type_name: String = {TYPE_BOOL:"bool",TYPE_STRING:"String"}.get(value_type,"")
38
+ if type_name.is_empty(): return false
35
39
  while script is Script:
36
40
  for name in script.get_script_constant_map():
37
41
  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
42
+ if str(name).begins_with("_GOGO_BINDABLE_PROPERTIES_") and contract is Dictionary and contract.get(property,"")==type_name: return true
39
43
  script = script.get_base_script()
40
44
  return false
41
45
  func current():
@@ -43,7 +47,7 @@ func current():
43
47
  var endpoint = read.call(owner) if is_instance_valid(owner) else null
44
48
  return endpoint if endpoint is Object and is_instance_valid(endpoint) else null
45
49
  func same(other) -> bool:
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
50
+ return other!=null and valid and other.valid and kind==other.kind and source.get_ref()==other.source.get_ref() and root.get_ref()==other.root.get_ref() and field==other.field and route==other.route
47
51
  func attach(target: Node, scope) -> void:
48
52
  node = weakref(target)
49
53
  computation = weakref(scope)
@@ -61,7 +65,8 @@ func _target_exit() -> void:
61
65
  disconnect_edit()
62
66
  var scope = computation.get_ref() if computation!=null else null
63
67
  if scope!=null and scope.active and not scope.disposed: scope.schedule()
64
- func edit(_previous: bool, next: bool) -> void:
68
+ func edit(_previous: Variant, next: Variant) -> void:
69
+ if typeof(next)!=kind: return
65
70
  var scope = computation.get_ref() if computation!=null else null
66
71
  var target = node.get_ref() if node!=null else null
67
72
  var endpoint = source.get_ref() if source!=null else null
@@ -73,7 +78,7 @@ func edit(_previous: bool, next: bool) -> void:
73
78
  # Reentrant model callbacks can restore the old value; commit must still
74
79
  # restore a control whose local user value diverged from its snapshot.
75
80
  scope.schedule()
76
- func project(target: Node, next: bool) -> void:
81
+ func project(target: Node, next: Variant) -> void:
77
82
  writing = true
78
83
  target.set("value",next)
79
84
  writing = false
@@ -91,4 +96,5 @@ func snapshot():
91
96
  result.value = value
92
97
  result.valid = valid
93
98
  result.observable = observable
99
+ result.kind = kind
94
100
  return result
@@ -251,7 +251,7 @@ func _valid(desired: Element, previous: Mounted) -> bool:
251
251
  for key in desired.bindings:
252
252
  var binding = desired.bindings[key]
253
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"
254
+ validation_error = desired.location(str(key))+": invalid observable "+("String" if binding is Binding and binding.kind==TYPE_STRING else "Bool")+" binding endpoint; previous tree retained"
255
255
  return false
256
256
  for event in desired.handlers:
257
257
  var handler = desired.handlers[event]
@@ -405,7 +405,7 @@ func _apply(desired: Element, record: Mounted) -> void:
405
405
  if Profile.is_enabled(): Profile.add("property_writes")
406
406
  for key in desired.properties:
407
407
  if scroll and key=="scroll_offset": continue
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]):
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",typeof(desired.properties[key])) and not is_same(node.get(key),desired.properties[key]):
409
409
  if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
410
410
  writes += 1
411
411
  if Profile.is_enabled(): Profile.add("property_writes")
@@ -702,13 +702,13 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
702
702
  var expected: String = str(properties[key].get("class_name",""))
703
703
  if ClassDB.class_exists(expected) and not value.is_class(expected): return _invalid_attribute(desired,str(key),"incompatible native Object class "+expected)
704
704
  for key in desired.bindings:
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")
705
+ if key!="value" or desired.properties.has(key) or not properties.has(key) or properties[key].type not in [TYPE_BOOL,TYPE_STRING] or desired.bindings[key].kind!=properties[key].type or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return _invalid_attribute(desired,str(key),"invalid or conflicting controlled binding")
706
706
  var args: Array = signals.get("value_changed",{}).get("args",[])
707
707
 
708
708
  # 4.0 lacks signal argument type metadata. Compiler source proof and
709
709
  # native typed callback still apply; optional introspection cannot
710
710
  # reject a valid input on that engine.
711
- if args.size()!=2 or args.any(func(arg): return arg.type not in [TYPE_NIL,TYPE_BOOL]): return false
711
+ if args.size()!=2 or args.any(func(arg): return arg.type!=TYPE_NIL and arg.type!=properties[key].type): return false
712
712
  for key in desired.handlers:
713
713
  if not signals.has(key): return _invalid_attribute(desired,str(key),"unknown native signal")
714
714
  var message := _handler_error(desired.handlers[key],signals[key].get("args",[]).size())
@@ -44,6 +44,11 @@ func update(view: Node) -> void:
44
44
  if target != null: target.model.invalidated.connect(_configure)
45
45
  layout._sync()
46
46
  _configure()
47
+ # A root may become a participant after an initially empty/plain boundary.
48
+ # Parent gap counts follow that logical participation, not the host Node.
49
+ if layout._dimension==2:
50
+ var parent = layout.parent_coordinator()
51
+ if parent!=null: parent._sync()
47
52
  func _configure() -> void:
48
53
  if layout == null or not layout.active: return
49
54
  var requested := Vector3(-1,-1,0) if layout._dimension==2 else Vector3(-1,-1,-1)
@@ -303,7 +303,7 @@ func _default_padding() -> Vector4:
303
303
  return Vector4.ZERO
304
304
 
305
305
  func _padding_insets() -> Vector4:
306
- layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
306
+ layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size,layout.model.dimension_reference)
307
307
  return layout.model.padding
308
308
 
309
309
  func get_content_rect() -> Rect2:
@@ -387,7 +387,8 @@ func get_layout_stats() -> Dictionary:
387
387
  return {"measure": layout.model.measure_count, "arrange": layout.model.arrange_count, "flush": layout.flush_count, "active": get_layout_root() != null}
388
388
 
389
389
  func apply_layout_position(offset: Vector3) -> void:
390
- position = Vector2(offset.x, offset.y)
390
+ var next := Vector2(offset.x,offset.y)
391
+ if position!=next: position = next
391
392
 
392
393
  func apply_layout_size(size: Vector3) -> void:
393
394
  var next := Vector2(size.x,size.y)
@@ -402,7 +403,7 @@ func apply_layout_size(size: Vector3) -> void:
402
403
  layout_applied.emit(_layout_size)
403
404
 
404
405
  func _margin_insets() -> Vector4:
405
- layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
406
+ layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size,layout.model.dimension_reference)
406
407
  return layout.model.margin
407
408
 
408
409
  func _queue_style_redraw() -> void:
@@ -0,0 +1,161 @@
1
+ @tool
2
+ class_name EstragonInput
3
+ extends "component_2d.gd"
4
+ ## Node2D layout/skin with one private native single-line editing endpoint.
5
+ signal value_changed(previous: String, value: String)
6
+ signal submitted(value: String)
7
+ signal cancelled
8
+ signal focus_entered
9
+ signal focus_exited
10
+ const Editor = preload("internal/input_control.gd")
11
+ const Focus = preload("internal/focus.tres")
12
+ const State = preload("../composition/state.tres")
13
+ const _GOGO_BINDABLE_PROPERTIES_NATIVE := {"value":"String"}
14
+ @export var value: String = "":
15
+ set(next):
16
+ if value==next: return
17
+ var previous := value
18
+ value = next
19
+ _project_value()
20
+ value_changed.emit(previous,next)
21
+ get:
22
+ State.observe(self,&"value_changed")
23
+ return value
24
+ @export var placeholder: String = "":
25
+ set(next):
26
+ if placeholder==next: return
27
+ placeholder = next
28
+ _sync_editor()
29
+ @export var disabled := false:
30
+ set(next):
31
+ if disabled==next: return
32
+ disabled = next
33
+ _sync_editor()
34
+ queue_redraw()
35
+ @export var read_only := false:
36
+ set(next):
37
+ if read_only==next: return
38
+ read_only = next
39
+ _sync_editor()
40
+ @export var invalid := false:
41
+ set(next):
42
+ if invalid==next: return
43
+ invalid = next
44
+ queue_redraw()
45
+ @export_enum("None", "Click", "All") var focus_mode: int = Control.FOCUS_ALL:
46
+ set(next):
47
+ if next<Control.FOCUS_NONE or next>Control.FOCUS_ALL: return
48
+ focus_mode = next
49
+ _sync_editor()
50
+ @export var font: Font = ThemeDB.fallback_font:
51
+ set(next):
52
+ if next==null or next==font: return
53
+ _disconnect_font()
54
+ font = next
55
+ _connect_font()
56
+ _style_changed()
57
+ @export var font_size: int = 20:
58
+ set(next):
59
+ if next<=0 or font_size==next: return
60
+ font_size = next
61
+ _style_changed()
62
+ @export var color := Color.WHITE:
63
+ set(next):
64
+ if color==next: return
65
+ color = next
66
+ _sync_theme()
67
+ @export var focus_color := Color("#9cdcff"):
68
+ set(next):
69
+ focus_color = next
70
+ queue_redraw()
71
+ @export var invalid_color := Color("#f17b83"):
72
+ set(next):
73
+ invalid_color = next
74
+ queue_redraw()
75
+ var _editor: LineEdit
76
+ var _editor_skin := StyleBoxEmpty.new()
77
+ func _init() -> void:
78
+ background_color = Color("#383838")
79
+ padding = 8.0
80
+ func _measure_native() -> Vector2:
81
+ # A stable single-line viewport, not a text-dependent expanding field.
82
+ return Vector2(200,font.get_height(font_size))
83
+ func _enter_tree() -> void:
84
+ _connect_font()
85
+ super._enter_tree()
86
+ if Engine.is_editor_hint(): return
87
+ _editor = Editor.new()
88
+ _editor.name = "_EstragonInput"
89
+ _editor.text = value
90
+ add_child(_editor,false,Node.INTERNAL_MODE_BACK)
91
+ _editor.text_changed.connect(_edited)
92
+ _editor.text_submitted.connect(_submitted)
93
+ layout_applied.connect(_sync_editor)
94
+ _sync_theme()
95
+ _sync_editor()
96
+ func _exit_tree() -> void:
97
+ if is_instance_valid(_editor):
98
+ layout_applied.disconnect(_sync_editor)
99
+ remove_child(_editor)
100
+ _editor.free()
101
+ _editor = null
102
+ _disconnect_font()
103
+ super._exit_tree()
104
+ func _composition_is_private(child: Node) -> bool:
105
+ return child==_editor or super._composition_is_private(child)
106
+ func _connect_font() -> void:
107
+ if is_inside_tree() and not font.changed.is_connected(_style_changed): font.changed.connect(_style_changed)
108
+ func _disconnect_font() -> void:
109
+ if font!=null and font.changed.is_connected(_style_changed): font.changed.disconnect(_style_changed)
110
+ func _style_changed() -> void:
111
+ _changed()
112
+ _sync_theme()
113
+ func _sync_theme() -> void:
114
+ if not is_instance_valid(_editor): return
115
+ # Native text/caret/selection draw in the real content rect; the host
116
+ # supplies the local surface, border and focus/invalid outline.
117
+ for state in ["normal","read_only","focus"]: _editor.add_theme_stylebox_override(state,_editor_skin)
118
+ _editor.add_theme_constant_override("minimum_character_width",0)
119
+ _editor.add_theme_font_override("font",font)
120
+ _editor.add_theme_font_size_override("font_size",font_size)
121
+ for key in ["font_color","font_uneditable_color","caret_color"]: _editor.add_theme_color_override(key,color)
122
+ _editor.add_theme_color_override("font_placeholder_color",Color(color,0.5))
123
+ _sync_editor()
124
+ func _sync_editor(_size: Vector2 = Vector2.ZERO) -> void:
125
+ if not is_instance_valid(_editor): return
126
+ var content := get_content_rect()
127
+ _editor.visible = content.size.x>0 and content.size.y>=font.get_height(font_size)
128
+ _editor_skin.content_margin_left = content.position.x
129
+ _editor_skin.content_margin_top = content.position.y
130
+ _editor_skin.content_margin_right = maxf(0,layout_size.x-content.end.x)
131
+ _editor_skin.content_margin_bottom = maxf(0,layout_size.y-content.end.y)
132
+ _editor.position = Vector2.ZERO
133
+ _editor.size = layout_size
134
+ _editor.placeholder_text = placeholder
135
+ _editor.editable = not disabled and not read_only
136
+ _editor.selecting_enabled = not disabled
137
+ _editor.shortcut_keys_enabled = not disabled
138
+ _editor.context_menu_enabled = not disabled
139
+ _editor.focus_mode = Control.FOCUS_NONE if disabled else focus_mode
140
+ _editor.modulate = Color(1,1,1,0.5) if disabled else Color.WHITE
141
+ if not Focus.eligible(_editor): _editor.release_focus()
142
+ func _project_value() -> void:
143
+ if not is_instance_valid(_editor) or _editor.text==value: return
144
+ var caret := _editor.caret_column
145
+ var selected := _editor.has_selection()
146
+ var start := _editor.get_selection_from_column() if selected else 0
147
+ var end := _editor.get_selection_to_column() if selected else 0
148
+ _editor.text = value
149
+ _editor.caret_column = mini(caret,value.length())
150
+ if selected: _editor.select(mini(start,value.length()),mini(end,value.length()))
151
+ func _edited(next: String) -> void: value = next
152
+ func _submitted(next: String) -> void: submitted.emit(next)
153
+ func grab_focus() -> void:
154
+ if is_instance_valid(_editor) and Focus.eligible(_editor): _editor.grab_focus()
155
+ func release_focus() -> void:
156
+ if is_instance_valid(_editor): _editor.release_focus()
157
+ func has_focus() -> bool: return is_instance_valid(_editor) and _editor.has_focus()
158
+ func get_focus_control() -> Control: return _editor
159
+ func _draw() -> void:
160
+ if (has_focus() or invalid) and layout_size.x>4 and layout_size.y>4:
161
+ draw_rect(Rect2(Vector2(2,2),layout_size-Vector2(4,4)),invalid_color if invalid else focus_color,false,2)
@@ -0,0 +1 @@
1
+ uid://dmgpinqaglofu
@@ -22,6 +22,7 @@ func _init(host: Node, dimension: int, mode: int = Mode.PROOF) -> void:
22
22
  _mode = mode
23
23
  _host = weakref(host)
24
24
  _dimension = dimension
25
+ model.dimension_budget_enabled = dimension==2
25
26
  if _mode == Mode.PROOF: host.set_meta(META, weakref(self))
26
27
  model.invalidated.connect(_invalidated)
27
28
  model.placed.connect(_place)
@@ -104,7 +105,21 @@ func stop() -> void:
104
105
 
105
106
  func _visibility_changed() -> void:
106
107
  var parent = parent_coordinator()
107
- if parent!=null and parent.model.strategy in ["wrap","grid"]: parent._sync()
108
+ while parent!=null:
109
+ parent._sync()
110
+ if parent._mode!=Mode.COMPOSITION: break
111
+ parent = parent.parent_coordinator()
112
+
113
+ func participates() -> bool:
114
+ var host = _host.get_ref()
115
+ if host==null or _dimension==2 and host is CanvasItem and not host.is_visible_in_tree(): return false
116
+ if _mode==Mode.ENTRY: return false
117
+ if _mode==Mode.CONTROL: return control_adapter.participates()
118
+ if _mode==Mode.COMPOSITION:
119
+ var root = managed_root.get_ref() if managed_root!=null else null
120
+ var target = participant(root)
121
+ return target!=null and target.participates()
122
+ return true
108
123
 
109
124
  func _child_entered(child: Node) -> void:
110
125
  if child is Control: CompositionHosts.enter_control(child)
@@ -129,14 +144,18 @@ func _sync() -> void:
129
144
  # Native child-entered signals can precede internal-child bookkeeping.
130
145
  # Runtime GUI endpoints/decorations never become layout participants.
131
146
  if host.has_method("_composition_is_private") and host._composition_is_private(child): continue
132
- if _dimension==2 and model.strategy in ["wrap","grid"] and child is CanvasItem and not child.is_visible_in_tree(): continue
147
+ if _dimension==2 and child is CanvasItem and not child.is_visible_in_tree(): continue
133
148
  var found = participant(child,true)
134
149
  if found != null and found._mode != Mode.ENTRY:
135
- if found._mode == Mode.CONTROL and not found.control_adapter.participates(): continue
150
+ if _dimension==2 and not found.participates(): continue
136
151
  found.model.set_placement(CompositionHosts.get_placement(child))
137
152
  values.append(found.model)
153
+ var participation_changed := model.children != values
138
154
  var error := model.set_children(values)
139
155
  if error != OK: push_error("Estragon layout model ownership: " + error_string(error))
156
+ if participation_changed and _mode==Mode.COMPOSITION:
157
+ var parent = parent_coordinator()
158
+ if parent!=null: parent._sync()
140
159
 
141
160
  func changed() -> void:
142
161
  var host = _host.get_ref()
@@ -19,10 +19,17 @@ static func tracks(specs: Array, items: Array, placements: Array, axis: int, ref
19
19
  var span: int = rect.column_span if axis==0 else rect.row_span
20
20
  var occupied := gap*(span-1)
21
21
  var eligible: Array = []
22
+ var fractions_only := true
22
23
  for index in range(start,start+span):
23
24
  occupied += sizes[index]
24
25
  if specs[index].unit in ["auto","fr"]: eligible.append(index)
25
- var deficit: float = maxf(0,maxf(items[i].get("contribution",items[i].preferred)[axis],items[i].minimum[axis])+items[i].outer[axis]-occupied)
26
+ if specs[index].unit!="fr": fractions_only = false
27
+ var contribution: float = items[i].get("contribution",items[i].preferred)[axis]
28
+ var viewport_floor: float = items[i].get("scroll_floor",Vector3(-1,-1,-1))[axis]
29
+ # A definite fraction cell assigns a scrolling viewport. Its hidden
30
+ # content is not a minimum viewport size; auto rows remain intrinsic.
31
+ if reference>=0 and fractions_only and viewport_floor>=0: contribution = viewport_floor
32
+ var deficit: float = maxf(0,maxf(contribution,items[i].minimum[axis])+items[i].outer[axis]-occupied)
26
33
  for index in eligible: sizes[index] += deficit/eligible.size()
27
34
  if reference>=0:
28
35
  var budget := reference-gap*maxi(0,sizes.size()-1)
@@ -0,0 +1,25 @@
1
+ @tool
2
+ extends LineEdit
3
+ ## Native editing, selection and platform text input in the host's actual rect.
4
+ const Focus = preload("focus.tres")
5
+ func _estragon_focus_host(): return get_parent()
6
+ func _ready() -> void:
7
+ clip_contents = true
8
+ expand_to_text_length = false
9
+ focus_entered.connect(_entered)
10
+ focus_exited.connect(_exited)
11
+ func _entered() -> void:
12
+ var host = _estragon_focus_host()
13
+ if not Focus.eligible(self): release_focus(); return
14
+ host.queue_redraw()
15
+ host.focus_entered.emit()
16
+ func _exited() -> void:
17
+ var host = _estragon_focus_host()
18
+ host.queue_redraw()
19
+ host.focus_exited.emit()
20
+ func _gui_input(event: InputEvent) -> void:
21
+ if event is InputEventKey and event.is_action("ui_cancel") and event.pressed and not event.echo:
22
+ accept_event()
23
+ var host = _estragon_focus_host()
24
+ host.release_focus()
25
+ host.cancelled.emit()
@@ -0,0 +1 @@
1
+ uid://dfb5e8colfuh7
@@ -18,6 +18,14 @@ var pixels_per_unit: float = 1.0
18
18
  var length_offset := Vector3.ZERO
19
19
  var viewport_size := Vector2.ZERO
20
20
  var parent_reference := Vector3(-1,-1,-1)
21
+ # Width/height percentages alone use this parent-policy budget. Other Length
22
+ # domains retain parent_reference; spatial coordinators keep their old contract.
23
+ var dimension_reference := Vector3(-1,-1,-1)
24
+ var dimension_budget_enabled := true
25
+ var _dimension_axes := Vector3.ZERO
26
+ var _budget_context: Array = []
27
+ var _budget := Vector3(-1,-1,-1)
28
+ var dimension_budget_count := 0
21
29
  var resolution_count := 0
22
30
  var _length_context: Array = []
23
31
  var _parent_axes := Vector3.ZERO
@@ -86,6 +94,9 @@ func set_lengths(specs: Dictionary, growth: float, cross: int, scale: float, sta
86
94
  var dependencies := Length.dependencies(length_specs,stack_axis)
87
95
  _parent_axes = dependencies[0]
88
96
  _viewport_axes = dependencies[1]
97
+ _dimension_axes = Vector3.ZERO
98
+ for index in range(2):
99
+ if length_specs.get(["width","height"][index],{}).get("unit","")=="%": _dimension_axes[index] = 1
89
100
  _length_context = []
90
101
  invalidate()
91
102
 
@@ -120,7 +131,8 @@ func set_align_self(value: String) -> void:
120
131
  func _length(name: String, axis_index: int, fallback: float) -> float:
121
132
  if not length_specs.has(name): return fallback
122
133
  var spec: Dictionary = length_specs[name]
123
- return Length.resolve(spec,parent_reference[axis_index],viewport_size,pixels_per_unit)
134
+ var reference: float = dimension_reference[axis_index] if name in ["width","height"] and spec.unit=="%" else parent_reference[axis_index]
135
+ return Length.resolve(spec,reference,viewport_size,pixels_per_unit)
124
136
 
125
137
  func _warn_unanchored() -> void:
126
138
  if _reported_unanchored: return
@@ -144,20 +156,23 @@ func _edges(prefix: String) -> Vector4:
144
156
 
145
157
  # Resolve specs only on a changed parent/viewport/spec context. No property
146
158
  # writeback, parsing in arrange, subscriptions per length, or frame polling.
147
- func prepare(reference: Vector3, viewport: Vector2) -> void:
148
- if transparent and _forward_context!=[reference,viewport] or viewport_size!=viewport and not children.is_empty():
159
+ func prepare(reference: Vector3, viewport: Vector2, dimensions: Variant = null) -> void:
160
+ var budget: Vector3 = reference if dimensions==null else dimensions
161
+ if transparent and _forward_context!=[reference,viewport,budget] or viewport_size!=viewport and not children.is_empty():
149
162
  _measure_dirty = true
150
163
  _arrange_dirty = true
151
- _forward_context = [reference,viewport] if transparent else []
164
+ _forward_context = [reference,viewport,budget] if transparent else []
152
165
  for index in range(3):
153
166
  if parent_reference[index]!=reference[index] and measurement_allocation[index]>=0:
154
167
  measurement_allocation[index] = -1
155
168
  _measure_dirty = true
156
169
  parent_reference = reference
170
+ dimension_reference = budget
157
171
  viewport_size = viewport
158
- var context := [reference*_parent_axes,viewport*_viewport_axes]
172
+ var context := [reference*_parent_axes,viewport*_viewport_axes,budget*_dimension_axes]
159
173
  if _length_context==context: return
160
174
  _length_context = context
175
+ if dimension_budget_enabled: measurement_allocation = Vector3(-1,-1,-1)
161
176
  resolution_count += 1
162
177
  var before := [requested,gap,physical_gaps,padding,border,margin,length_offset,authored_minimum,authored_maximum]
163
178
  if not length_specs.is_empty():
@@ -228,7 +243,7 @@ func configure(extent: Vector3, spacing: float, centered: bool, stack_axis: int
228
243
  intrinsic = content
229
244
  requested = extent
230
245
  gap = spacing
231
- physical_gaps = Vector2(spacing,spacing)
246
+ if length_specs.is_empty(): physical_gaps = Vector2(spacing,spacing)
232
247
  center = centered
233
248
  invalidate()
234
249
  return OK
@@ -255,6 +270,7 @@ func set_children(values: Array) -> Error:
255
270
  return OK
256
271
 
257
272
  func invalidate() -> void:
273
+ if dimension_budget_enabled: measurement_allocation = Vector3(-1,-1,-1)
258
274
  _measure_dirty = true
259
275
  _arrange_dirty = true
260
276
  var parent = _parent.get_ref() if _parent != null else null
@@ -283,16 +299,48 @@ func track_contribution() -> Vector3:
283
299
  func _items() -> Array:
284
300
  var items: Array = []
285
301
  for child in children:
286
- items.append({"preferred":child.measured,"contribution":child.track_contribution(),"minimum":child.minimum(),"maximum":child.maximum(),"requested":child.requested,"grow":child.grow,"stretch":child.stretch,"align_self":child.align_self,"fill":child.fill,"outer":child.outer_extent(),"leading":leading(child.margin),"placement":child.placement})
302
+ items.append({"preferred":child.measured,"contribution":child.track_contribution(),"scroll_floor":child.scroll_track_floor(),"minimum":child.minimum(),"maximum":child.maximum(),"requested":child.requested,"grow":child.grow,"stretch":child.stretch,"align_self":child.align_self,"fill":child.fill,"outer":child.outer_extent(),"leading":leading(child.margin),"placement":child.placement})
287
303
  return items
288
304
 
289
- func _grid(items: Array, content: Vector3) -> Dictionary:
305
+ func scroll_track_floor() -> Vector3:
306
+ if transparent and children.size()==1: return children[0].scroll_track_floor()
307
+ var result := Vector3(-1,-1,-1)
308
+ for index in range(2):
309
+ if scroll_axes[index]>0 and requested[index]<0:
310
+ result[index] = maxf(minimum()[index],intrinsic[index]+leading(padding+border)[index]+trailing(padding+border)[index])
311
+ return result
312
+
313
+ func _prepare_grid() -> void:
290
314
  var placements: Array = []
291
- for item in items: placements.append(item.placement)
315
+ for child in children: placements.append(child.placement)
292
316
  if grid_definition.get("source_placements",[])!=placements or grid_definition.is_empty():
293
317
  grid_definition = GridDefinition.configuration(grid_config,placements)
294
318
  grid_definition.source_placements = placements.duplicate(true)
295
319
  if grid_definition.has("error"): push_error("Estragon Grid: "+grid_definition.error+"; previous native slots retained")
320
+
321
+ func dimension_budget(reference: Vector3) -> Vector3:
322
+ if not dimension_budget_enabled or transparent or strategy=="wrap": return reference
323
+ var result := reference
324
+ var counts := Vector2i.ONE
325
+ if strategy=="grid":
326
+ _prepare_grid()
327
+ if grid_definition.has("error"): return reference
328
+ counts = Vector2i(grid_definition.columns.size(),grid_definition.rows.size())
329
+ elif axis<2: counts[axis] = children.size()
330
+ var context := [reference,physical_gaps,counts]
331
+ if _budget_context==context: return _budget
332
+ _budget_context = context
333
+ dimension_budget_count += 1
334
+ for index in range(2):
335
+ if reference[index]>=0: result[index] = maxf(0,reference[index]-physical_gaps[index]*maxi(0,counts[index]-1))
336
+ _budget = result
337
+ return result
338
+
339
+ func _main_gap() -> float:
340
+ return physical_gaps[axis] if axis<2 else gap
341
+
342
+ func _grid(items: Array, content: Vector3) -> Dictionary:
343
+ _prepare_grid()
296
344
  if grid_definition.has("error"):
297
345
  # Native children may exceed an explicitly bounded grid after direct edits.
298
346
  # Reject the layout as a whole, preserving the previous allocated slots.
@@ -333,7 +381,7 @@ func measure_allocated(extent: Vector3, authority: Vector3) -> void:
333
381
  if transparent and children.size()==1:
334
382
  children[0].measure_allocated(extent,authority)
335
383
  _measure_dirty = true
336
- elif strategy in ["wrap","grid"] or scroll_axes!=Vector2.ZERO:
384
+ elif strategy in ["wrap","grid"] or scroll_axes!=Vector2.ZERO or dimension_budget_enabled and not children.is_empty():
337
385
  var next := measurement_allocation
338
386
  for index in range(2):
339
387
  if requested[index]<0 and authority[index]>0: next[index] = extent[index]
@@ -341,7 +389,13 @@ func measure_allocated(extent: Vector3, authority: Vector3) -> void:
341
389
  measurement_allocation = next
342
390
  _measure_dirty = true
343
391
  else: return
392
+ var preferred := measured
344
393
  measure()
394
+ # Allocated axes are not a new intrinsic growth basis. Only the dependent
395
+ # unallocated (e.g. wrapped cross) axes feed back into this bounded pass.
396
+ if dimension_budget_enabled:
397
+ for index in range(2):
398
+ if requested[index]<0 and authority[index]>0: measured[index] = preferred[index]
345
399
 
346
400
  func overflow_extent() -> Vector3:
347
401
  # Ancestors see the clipped participant's viewport, not its hidden content.
@@ -356,7 +410,7 @@ func overflow_extent() -> Vector3:
356
410
  func _slots(items: Array, content: Vector3, definite: Vector3) -> Array:
357
411
  if strategy=="grid": return _grid(items,content).slots
358
412
  if strategy=="wrap": return WrapPolicy.layout(items,content,axis,physical_gaps,alignment,align_content,Vector2(definite.x,definite.y)).slots
359
- return StackPolicy.slots(items,content,axis,physical_gaps[axis] if axis<2 and not length_specs.is_empty() else gap,alignment)
413
+ return StackPolicy.slots(items,content,axis,_main_gap(),alignment)
360
414
 
361
415
  func _authority(child, item: Dictionary, basis: Vector3) -> Vector3:
362
416
  var authority := Vector3.ZERO
@@ -372,7 +426,7 @@ func _authority(child, item: Dictionary, basis: Vector3) -> Vector3:
372
426
  func measure() -> Vector3:
373
427
  if transparent and children.size()==1:
374
428
  var child = children[0]
375
- child.prepare(parent_reference,viewport_size)
429
+ child.prepare(parent_reference,viewport_size,dimension_reference)
376
430
  child.set_capacity(available_capacity)
377
431
  child.measure()
378
432
  if child.requested!=requested or child.grow!=grow or child.stretch!=stretch or child.align_self!=align_self or child.margin!=margin or child.fill!=fill or child.length_offset!=length_offset:
@@ -389,8 +443,9 @@ func measure() -> Vector3:
389
443
  if Profile.is_enabled(): Profile.add("layout_measures")
390
444
  if not transparent:
391
445
  var basis := _content_basis()
446
+ var budget := dimension_budget(basis)
392
447
  for child in children:
393
- child.prepare(basis,viewport_size)
448
+ child.prepare(basis,viewport_size,budget)
394
449
  var capacity := basis
395
450
  for index in range(3):
396
451
  if capacity[index]>=0: capacity[index] = maxf(0,capacity[index]-child.outer_extent()[index])
@@ -404,13 +459,12 @@ func measure() -> Vector3:
404
459
  for index in range(children.size()): children[index].measure_allocated(allocations[index].extent,_authority(children[index],items[index],basis))
405
460
  var natural := Vector3.ZERO
406
461
  for child in children:
407
- if not transparent: child.prepare(_content_basis(),viewport_size)
408
462
  var child_size: Vector3 = child.measure()
409
463
  if not transparent: child_size += child.outer_extent()
410
464
  for index in range(3):
411
465
  if index == axis: natural[index] += child_size[index]
412
466
  else: natural[index] = maxf(natural[index],child_size[index])
413
- if children.size() > 1: natural[axis] += (physical_gaps[axis] if axis<2 and length_specs.has("column_gap") else gap) * (children.size() - 1)
467
+ if children.size() > 1: natural[axis] += _main_gap() * (children.size() - 1)
414
468
  if strategy=="wrap" and not transparent:
415
469
  var basis := _wrap_basis()
416
470
  natural = WrapPolicy.layout(_items(),basis,axis,physical_gaps,alignment,align_content,Vector2(1 if basis.x>=0 else 0,1 if basis.y>=0 else 0)).extent
@@ -484,9 +538,9 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
484
538
  push_warning("Estragon explicit main-axis dimension overrides grow; use auto height/width on a remaining-space Spacer")
485
539
  # Assigned content is authoritative, including grow allocations. Resolve the
486
540
  # immediate children against this box before measuring their slots.
541
+ var budget := dimension_budget(reference)
487
542
  for child in children:
488
- var child_reference := reference
489
- child.prepare(child_reference,viewport_size)
543
+ child.prepare(reference,viewport_size,budget)
490
544
  child.measure()
491
545
  if not _reported_full_percent and children.size()>1:
492
546
  var main_name: String = ["width","height","depth"][axis]
@@ -494,7 +548,7 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
494
548
  var spec: Dictionary = child.length_specs.get(main_name,{})
495
549
  if spec.get("unit","")=="%" and spec.get("value",0)>=100:
496
550
  _reported_full_percent = true
497
- push_warning("Estragon "+main_name+"=100% consumes the full definite parent content axis, not remaining space; siblings may overflow. Use an auto-sized Spacer with grow=1 for remaining space")
551
+ push_warning("Estragon "+main_name+"=100% consumes the full definite parent "+("dimension budget" if dimension_budget_enabled and strategy!="wrap" and axis<2 else "content axis")+", not remaining space; siblings may overflow. Use an auto-sized Spacer with grow=1 for remaining space")
498
552
  break
499
553
  var layout_content := content
500
554
  for index in range(2):
@@ -506,7 +560,7 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
506
560
  var wrap_basis := _wrap_basis()
507
561
  slots = WrapPolicy.layout(items,layout_content,axis,physical_gaps,policy,align_content,Vector2(1 if reference.x>=0 or axis==0 and wrap_basis.x>=0 else 0,1 if reference.y>=0 or axis==1 and wrap_basis.y>=0 else 0)).slots
508
562
  else:
509
- slots = StackPolicy.slots(items,layout_content,axis,physical_gaps[axis] if axis<2 and length_specs.has("column_gap") else gap,policy)
563
+ slots = StackPolicy.slots(items,layout_content,axis,_main_gap(),policy)
510
564
  if strategy=="grid":
511
565
  policy_result = _grid(items,reference)
512
566
  if policy_result.has("error"): return
@@ -523,7 +577,8 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
523
577
  if strategy=="grid" and cross<2 and policy[cross]=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
524
578
  elif strategy!="grid" and cross!=axis and StackPolicy.cross_alignment(items[index],policy[cross],cross)=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
525
579
  for scrolling_axis in range(2):
526
- if scroll_axes[scrolling_axis]>0: authority[scrolling_axis] = 0
580
+ if scroll_axes[scrolling_axis]>0:
581
+ authority[scrolling_axis] = 1 if independent_axis(scrolling_axis) and child.requested[scrolling_axis]<0 and (child.grow>0 or child.fill[scrolling_axis]>0) else 0
527
582
  child.arrange(slot.extent,authority)
528
583
  arranged.emit(size)
529
584
 
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  "tag": "beta",
30
30
  "registry": "https://registry.npmjs.org/"
31
31
  },
32
- "version": "0.1.0-beta.31"
32
+ "version": "0.1.0-beta.33"
33
33
  }