@papercraftgames/estragon 0.1.0-beta.36 → 0.1.0-beta.38

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.
@@ -57,6 +57,12 @@ func _component(node: Model.Component) -> void:
57
57
  script = script.get_base_script()
58
58
  properties.merge(resolved.get("properties",{}),true)
59
59
  signals.merge(resolved.get("signals",{}),true)
60
+ if VisualStyle.marked(resolved.script,"ESTRAGON_RADIO") and not node.attributes.any(func(attribute): return attribute.name=="value" or attribute.kind=="spread"):
61
+ _error("Radio requires a nonempty String value identifier",node.name_span)
62
+ return
63
+ if VisualStyle.marked(resolved.script,"ESTRAGON_RADIO_GROUP"):
64
+ _static_radio_identities(node,{})
65
+ if not file.diagnostics.is_empty(): return
60
66
  var stack_direction := StackContract.initial(resolved.script)
61
67
  for attribute in node.attributes:
62
68
  if attribute.name=="direction": stack_direction = str(attribute.value.value) if attribute.value is Model.Literal else StackContract.preset(resolved.script)
@@ -71,6 +77,9 @@ func _component(node: Model.Component) -> void:
71
77
  _node(attribute.value)
72
78
  continue
73
79
  var name := attribute.name
80
+ if name=="value" and VisualStyle.marked(resolved.script,"ESTRAGON_RADIO") and attribute.value is Model.Literal and str(attribute.value.value).is_empty():
81
+ _error("Radio requires a nonempty String value identifier",attribute.value.span)
82
+ return
74
83
  if VisualStyle.marked(resolved.script,"ESTRAGON_SCROLL_2D") and name in ["scroll_range","content_extent"]:
75
84
  _error("Read-only scrolling measurement: "+name,attribute.name_span)
76
85
  return
@@ -430,3 +439,22 @@ func _body_whitespace(value: String) -> String:
430
439
  if index<lines.size()-1: line = line.strip_edges(false,true)
431
440
  if not line.is_empty(): words.append(line)
432
441
  return " ".join(words)
442
+
443
+ func _static_radio_identities(node: Model.Component, identities: Dictionary) -> void:
444
+ # Only unconditional native descendants. Dynamic islands/conditional branches
445
+ # are checked together by the desired-description transaction at runtime.
446
+ for child in node.children:
447
+ if not child is Model.Component: continue
448
+ var resolved: Dictionary = resolver.resolve(child.name,child.name_span)
449
+ if resolved.is_empty(): return
450
+ if VisualStyle.marked(resolved.script,"ESTRAGON_RADIO_GROUP"): continue
451
+ if VisualStyle.marked(resolved.script,"ESTRAGON_RADIO"):
452
+ if child.attributes.any(func(attribute): return attribute.kind=="spread"): continue
453
+ for attribute in child.attributes:
454
+ if attribute.name!="value" or not attribute.value is Model.Literal: continue
455
+ var identity = attribute.value.value
456
+ if identities.has(identity):
457
+ _error("Duplicate Radio option identifier "+str(identity),attribute.value.span)
458
+ return
459
+ identities[identity] = true
460
+ else: _static_radio_identities(child,identities)
@@ -2,6 +2,8 @@
2
2
  extends RefCounted
3
3
  ## Trusted installed resources, not guessed global classes or installation roots.
4
4
  const ITEMS := [
5
+ {"alias":"RadioGroup","canonical":"EstragonRadioGroup","script":preload("../runtime/node/radio_group.gd"),"dimension":2,"origin":"Estragon native; explicit import"},
6
+ {"alias":"Radio","canonical":"EstragonRadio","script":preload("../runtime/node/radio.gd"),"dimension":2,"origin":"Estragon native; explicit import"},
5
7
  {"alias":"Input","canonical":"EstragonInput","script":preload("../runtime/node/input.gd"),"dimension":2,"origin":"Estragon native; explicit import"},
6
8
  {"alias":"Checkbox","canonical":"EstragonCheckbox","script":preload("../runtime/node/checkbox.gd"),"dimension":2,"origin":"Estragon native; explicit import"},
7
9
  {"alias":"Grid","canonical":"EstragonGrid","script":preload("../runtime/node/grid.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.36"
6
+ version="0.1.0-beta.38"
7
7
  script="plugin.gd"
@@ -412,7 +412,8 @@ func _apply(desired: Element, record: Mounted) -> void:
412
412
  for key in desired.properties:
413
413
  if scroll and key=="scroll_offset": continue
414
414
  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]):
415
- if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
415
+ if key=="value" and VisualStyle.marked(desired.type,"ESTRAGON_RADIO"): node._apply_radio_identity(desired.properties[key])
416
+ elif not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
416
417
  writes += 1
417
418
  if Profile.is_enabled(): Profile.add("property_writes")
418
419
  # Apply the effective authored offset after geometry/axis flags. A dirty
@@ -589,6 +590,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
589
590
  if Profile.is_enabled(): Profile.add("preflights")
590
591
  if desired == null: return true
591
592
  if desired.borrowed != null: return desired.borrowed.get_ref() != null
593
+ if parent!=null and not _radio_context(desired,previous,parent): return false
592
594
  # Cache only within this synchronous desired-tree validation. No Script
593
595
  # contracts survive a commit or hide editor reload/metadata changes.
594
596
  if contracts==null: contracts = {}
@@ -609,6 +611,12 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
609
611
  contracts[desired.type] = {"properties":properties,"signals":signals}
610
612
  var properties: Dictionary = contracts[desired.type].properties
611
613
  var signals: Dictionary = contracts[desired.type].signals
614
+ if VisualStyle.marked(desired.type,"ESTRAGON_RADIO"):
615
+ var identity = desired.properties.get("value","")
616
+ if not identity is String or identity.is_empty(): return _invalid_attribute(desired,"value","Radio requires a nonempty String identifier")
617
+ if VisualStyle.marked(desired.type,"ESTRAGON_RADIO_GROUP"):
618
+ if desired.properties.has("value") and not desired.properties.value is String: return _invalid_attribute(desired,"value","RadioGroup requires String")
619
+ if not _radio_identities(desired,{},previous): return false
612
620
  if StackContract.registered(desired.type):
613
621
  var policy: Dictionary = previous.properties.duplicate() if previous!=null and _compatible(desired,previous) else {}
614
622
  policy.merge(_spread_resets(desired,previous),true)
@@ -835,3 +843,51 @@ func _connect_observer(key: String, pair: Array) -> void:
835
843
  notification_callbacks[key] = callback
836
844
  if Profile.is_enabled(): Profile.add("subscription_connects")
837
845
  if source.connect(pair[1],callback)!=OK: push_error("Composition observation connection failed")
846
+
847
+ # Include retained opaque component output and foreign native children, while
848
+ # replacing only the old managed description region in the current transaction.
849
+ func _radio_native(node: Node, identities: Dictionary) -> bool:
850
+ if not is_instance_valid(node): return false
851
+ if node.has_method("_radio_group"): return true
852
+ if node.has_method("_radio_owner"):
853
+ if node.value.is_empty() or identities.has(node.value): return false
854
+ identities[node.value] = true
855
+ for child in (node._layout_children() if node.has_method("_layout_children") else node.get_children()):
856
+ if not _radio_native(child,identities): return false
857
+ return true
858
+ func _radio_context(desired, previous, parent: Node) -> bool:
859
+ var group = parent
860
+ while group!=null and not group.has_method("_radio_group"): group = group.get_parent()
861
+ if group==null or VisualStyle.marked(desired.type,"ESTRAGON_RADIO_GROUP"): return true
862
+ var old: Node = previous.node.get_ref() if previous!=null else null
863
+ var identities := {}
864
+ for option in group.options():
865
+ if old!=null and (option==old or old.is_ancestor_of(option)): continue
866
+ if option.value.is_empty() or identities.has(option.value): return _invalid_attribute(desired,"value","existing group has invalid Radio identifiers")
867
+ identities[option.value] = true
868
+ return _radio_desired(desired,previous,identities)
869
+ func _radio_desired(desired, previous, identities: Dictionary) -> bool:
870
+ if desired==null: return true
871
+ if desired.borrowed!=null: return _radio_native(desired.borrowed.get_ref(),identities)
872
+ if VisualStyle.marked(desired.type,"ESTRAGON_RADIO_GROUP"): return true
873
+ if VisualStyle.marked(desired.type,"ESTRAGON_RADIO"):
874
+ var identity = desired.properties.get("value","")
875
+ if not identity is String or identity.is_empty(): return _invalid_attribute(desired,"value","Radio requires a nonempty String identifier")
876
+ if identities.has(identity): return _invalid_attribute(desired,"value","duplicate Radio identifier "+identity)
877
+ identities[identity] = true
878
+ return _radio_identities(desired,identities,previous)
879
+ func _radio_identities(desired, identities: Dictionary, previous = null) -> bool:
880
+ var retained = previous if _compatible(desired,previous) else null
881
+ var old_children: Array = retained.children if retained!=null else []
882
+ var matches := _matches(desired.children,old_children)
883
+ for index in range(desired.children.size()):
884
+ if not _radio_desired(desired.children[index],matches[index],identities): return false
885
+ if retained!=null:
886
+ var node: Node = retained.node.get_ref()
887
+ var known: Array = []
888
+ for child in old_children:
889
+ if child!=null: known.append(child.node.get_ref())
890
+ for child in (node._layout_children() if node.has_method("_layout_children") else node.get_children()):
891
+ if known.has(child) or node.has_method("_composition_is_private") and node._composition_is_private(child): continue
892
+ if not _radio_native(child,identities): return _invalid_attribute(desired,"value","duplicate or empty retained native Radio identifier")
893
+ return true
@@ -84,11 +84,13 @@ func _exit_tree() -> void:
84
84
  super._exit_tree()
85
85
  func _composition_is_private(child: Node) -> bool:
86
86
  return child==_focus_control or super._composition_is_private(child)
87
+ func _input_disabled() -> bool:
88
+ return disabled
87
89
  func _sync_focus(_size: Vector2 = Vector2.ZERO) -> void:
88
90
  if not is_instance_valid(_focus_control): return
89
91
  _focus_control.position = Vector2.ZERO
90
92
  _focus_control.size = layout_size
91
- _focus_control.focus_mode = Control.FOCUS_NONE if disabled else focus_mode
93
+ _focus_control.focus_mode = Control.FOCUS_NONE if _input_disabled() else focus_mode
92
94
  if not Focus.eligible(_focus_control):
93
95
  _focus_control.cancel()
94
96
  _focus_control.release_focus()
@@ -2,6 +2,7 @@
2
2
  extends Resource
3
3
  ## One native GUI focus owner. This registry only joins native GUI roots for Tab.
4
4
  ## Weak Entries; no retained focus graph, Node metadata or frame callbacks.
5
+ signal geometry_changed
5
6
  const Pointer = preload("pointer_2d.gd")
6
7
  var viewports: Dictionary = {}
7
8
  var refreshes := 0
@@ -42,7 +43,9 @@ func _validate() -> void:
42
43
  var viewport = record.viewport.get_ref()
43
44
  if viewport==null: continue
44
45
  var owner = viewport.gui_get_focus_owner()
45
- if owner!=null and contains(owner) and not eligible(owner): owner.release_focus()
46
+ if owner!=null and contains(owner) and not eligible(owner):
47
+ owner.release_focus()
48
+ geometry_changed.emit()
46
49
  func contains(control: Control) -> bool:
47
50
  var record: Dictionary = viewports.get(control.get_viewport().get_instance_id(),{})
48
51
  for reference in record.get("entries",[]):
@@ -64,13 +67,13 @@ static func intersect(region: Array, boundary: PackedVector2Array) -> Array:
64
67
  for index in range(clipped.size()): area += clipped[index].cross(clipped[(index+1)%clipped.size()])
65
68
  if not is_zero_approx(area): result.append(clipped)
66
69
  return result
67
- static func eligible(control: Control, tab: bool = false) -> bool:
70
+ static func eligible(control: Control, tab: bool = false, require_focus: bool = true) -> bool:
68
71
  if not is_instance_valid(control) or not control.is_inside_tree() or control.is_queued_for_deletion() or not control.is_visible_in_tree() or not control.can_process(): return false
69
- if control.focus_mode==Control.FOCUS_NONE or tab and control.focus_mode!=Control.FOCUS_ALL: return false
72
+ if require_focus and (control.focus_mode==Control.FOCUS_NONE or tab and control.focus_mode!=Control.FOCUS_ALL): return false
70
73
  if control is BaseButton and control.disabled: return false
71
74
  if owns(control):
72
75
  var host = control._estragon_focus_host()
73
- if host==null or host.disabled or host.is_queued_for_deletion(): return false
76
+ if host==null or (host._input_disabled() if host.has_method("_input_disabled") else host.disabled) or host.is_queued_for_deletion(): return false
74
77
  if control.size.x<=0 or control.size.y<=0: return false
75
78
  var transform := control.get_global_transform_with_canvas()
76
79
  if is_zero_approx(transform.x.cross(transform.y)): return false
@@ -88,7 +91,9 @@ static func eligible(control: Control, tab: bool = false) -> bool:
88
91
  return true
89
92
  func _collect(node: Node, viewport: Viewport, output: Array) -> void:
90
93
  if node.get_viewport()!=viewport: return
91
- if node is Control and eligible(node,true) and not output.has(node): output.append(node)
94
+ if node is Control and eligible(node,true) and not output.has(node):
95
+ var host = node._estragon_focus_host() if owns(node) else null
96
+ if host==null or not host.has_method("_focus_tab_stop") or host._focus_tab_stop(): output.append(node)
92
97
  for child in node.get_children(true): _collect(child,viewport,output)
93
98
  func candidates(viewport: Viewport) -> Array:
94
99
  var output: Array = []
@@ -111,7 +116,11 @@ func key(viewport: Viewport, event: InputEvent) -> bool:
111
116
  if owner!=null and not path.is_empty():
112
117
  var explicit = owner.get_node_or_null(path)
113
118
  if explicit is Control and eligible(explicit,true): explicit.grab_focus(); return true
114
- var index := list.find(owner)
119
+ var logical_owner := owner
120
+ if owner!=null and owns(owner):
121
+ var host = owner._estragon_focus_host()
122
+ if host!=null and host.has_method("_focus_tab_control"): logical_owner = host._focus_tab_control()
123
+ var index := list.find(logical_owner)
115
124
  if index<0 and owner!=null:
116
125
  var ordered := list.duplicate()
117
126
  if event.shift_pressed: ordered.reverse()
@@ -30,6 +30,10 @@ func cancel() -> void:
30
30
  func _gui_input(event: InputEvent) -> void:
31
31
  if not event is InputEventKey: return
32
32
  if not Focus.eligible(self): cancel(); release_focus(); return
33
+ var target = _estragon_focus_host()
34
+ if target.has_method("_focus_key") and target._focus_key(event):
35
+ accept_event()
36
+ return
33
37
  if event.is_action("ui_cancel"):
34
38
  cancel()
35
39
  accept_event()
@@ -20,11 +20,16 @@ static func tracks(specs: Array, items: Array, placements: Array, axis: int, ref
20
20
  var occupied := gap*(span-1)
21
21
  var eligible: Array = []
22
22
  var fractions_only := true
23
+ var intrinsic_track := false
23
24
  for index in range(start,start+span):
24
25
  occupied += sizes[index]
25
26
  if specs[index].unit in ["auto","fr"]: eligible.append(index)
26
27
  if specs[index].unit!="fr": fractions_only = false
28
+ if specs[index].unit=="auto": intrinsic_track = true
27
29
  var contribution: float = items[i].get("contribution",items[i].preferred)[axis]
30
+ # Auto tracks request the natural preferred extent. The smaller
31
+ # unbreakable Wrap floor belongs to distributable fraction tracks.
32
+ if intrinsic_track: contribution = items[i].preferred[axis]
28
33
  var viewport_floor: float = items[i].get("scroll_floor",Vector3(-1,-1,-1))[axis]
29
34
  # A definite fraction cell assigns a scrolling viewport. Its hidden
30
35
  # content is not a minimum viewport size; auto rows remain intrinsic.
@@ -80,6 +80,7 @@ var arrange_count: int = 0
80
80
  var _measure_dirty: bool = true
81
81
  var _arrange_dirty: bool = true
82
82
  var _parent: WeakRef
83
+ var _parent_index := -1
83
84
 
84
85
  var default_padding := Vector4.ZERO
85
86
 
@@ -269,10 +270,12 @@ func set_children(values: Array) -> Error:
269
270
  for child in children:
270
271
  if not values.has(child):
271
272
  child._parent = null
273
+ child._parent_index = -1
272
274
  children = values.duplicate()
273
275
  grid_definition = {}
274
- for child in children:
275
- child._parent = weakref(self)
276
+ for index in range(children.size()):
277
+ children[index]._parent = weakref(self)
278
+ children[index]._parent_index = index
276
279
  invalidate()
277
280
  return OK
278
281
 
@@ -301,6 +304,16 @@ func track_contribution() -> Vector3:
301
304
  result[axis] = intrinsic[axis]
302
305
  for child in children: result[axis] = maxf(result[axis],maxf(child.measured[axis],child.minimum()[axis])+child.outer_extent()[axis])
303
306
  result[axis] += leading(padding+border)[axis]+trailing(padding+border)[axis]
307
+ elif strategy=="stack" and not children.is_empty():
308
+ var natural := Vector3.ZERO
309
+ for child in children:
310
+ var contribution: Vector3 = child.track_contribution()+child.outer_extent()
311
+ for index in range(3):
312
+ if index==axis: natural[index] += contribution[index]
313
+ else: natural[index] = maxf(natural[index],contribution[index])
314
+ natural[axis] += _main_gap()*maxi(0,children.size()-1)
315
+ for index in range(3):
316
+ if requested[index]<0 and (index>1 or scroll_axes[index]==0): result[index] = maxf(intrinsic[index],natural[index])+leading(padding+border)[index]+trailing(padding+border)[index]
304
317
  return constrain(result)
305
318
 
306
319
  func _items() -> Array:
@@ -362,18 +375,45 @@ func _grid(items: Array, content: Vector3) -> Dictionary:
362
375
 
363
376
  # Allocation-dependent measurement is a bounded second pass in this same core.
364
377
  # Only independently assigned axes may supply a basis; auto cycles stay absent.
378
+ func _uses_capacity(index: int) -> bool:
379
+ if requested[index]>=0 or index<2 and scroll_axes[index]>0: return false
380
+ if strategy=="wrap" and index==axis: return true
381
+ for child in children:
382
+ if child._uses_capacity(index): return true
383
+ return false
384
+
365
385
  func set_capacity(value: Vector3) -> void:
366
386
  if not transparent:
367
- if strategy!="wrap" or requested[axis]>=0: return
368
- var main: float = value[axis]
369
- value = Vector3(-1,-1,-1)
370
- value[axis] = main
387
+ if strategy=="wrap":
388
+ if requested[axis]>=0: return
389
+ var main: float = value[axis]
390
+ value = Vector3(-1,-1,-1)
391
+ value[axis] = main
392
+ elif children.is_empty(): return
393
+ else:
394
+ for index in range(3):
395
+ if requested[index]>=0: value[index] = -1
371
396
  if available_capacity==value: return
397
+ var dependent := false
398
+ for index in range(2):
399
+ if available_capacity[index]!=value[index] and measurement_allocation[index]<0 and _uses_capacity(index): dependent = true
372
400
  available_capacity = value
373
- _measure_dirty = true
374
- _arrange_dirty = true
401
+ if dependent:
402
+ _measure_dirty = true
403
+ _arrange_dirty = true
375
404
  if transparent and children.size()==1: children[0].set_capacity(value)
376
405
 
406
+ func _capacity_basis(basis: Vector3) -> Vector3:
407
+ # A natural wrapper forwards a ceiling without making its auto dimensions
408
+ # percentage/grow references. Scrolling leaves its content axis unbounded.
409
+ var ceiling := constrain(available_capacity)-leading(padding+border)-trailing(padding+border)
410
+ var inner := Vector2(ceiling.x if available_capacity.x>=0 else -1,ceiling.y if available_capacity.y>=0 else -1)
411
+ var strips := ScrollbarGeometry.thickness(inner,scroll_axes,length_specs,viewport_size)
412
+ for index in range(2):
413
+ if scroll_axes[index]>0: basis[index] = -1
414
+ elif basis[index]<0 and available_capacity[index]>=0: basis[index] = maxf(0,ceiling[index]-strips[index])
415
+ return basis
416
+
377
417
  func _wrap_basis() -> Vector3:
378
418
  var basis := _content_basis()
379
419
  if axis<2 and scroll_axes[axis]>0: basis[axis] = -1
@@ -387,13 +427,15 @@ func _wrap_basis() -> Vector3:
387
427
 
388
428
  func measure_allocated(extent: Vector3, authority: Vector3) -> void:
389
429
  if transparent and children.size()==1:
430
+ set_capacity(extent)
390
431
  children[0].measure_allocated(extent,authority)
391
432
  _measure_dirty = true
392
433
  elif strategy in ["wrap","grid"] or scroll_axes!=Vector2.ZERO or dimension_budget_enabled and not children.is_empty():
393
- var next := measurement_allocation
434
+ set_capacity(extent)
435
+ var next := Vector3(-1,-1,-1)
394
436
  for index in range(2):
395
437
  if requested[index]<0 and authority[index]>0: next[index] = extent[index]
396
- if next==measurement_allocation: return
438
+ if next==measurement_allocation and not _measure_dirty: return
397
439
  measurement_allocation = next
398
440
  _measure_dirty = true
399
441
  else: return
@@ -405,6 +447,18 @@ func measure_allocated(extent: Vector3, authority: Vector3) -> void:
405
447
  for index in range(2):
406
448
  if requested[index]<0 and authority[index]>0: measured[index] = preferred[index]
407
449
 
450
+ func _clear_allocation(authority: Vector3) -> void:
451
+ # Remove lost track/stretch authority before natural measurement chooses
452
+ # new slots; otherwise an old slot can become its own auto-track floor.
453
+ if transparent and children.size()==1:
454
+ children[0]._clear_allocation(authority)
455
+ if children[0]._measure_dirty: _measure_dirty = true
456
+ for index in range(2):
457
+ if authority[index]==0 and measurement_allocation[index]>=0:
458
+ measurement_allocation[index] = -1
459
+ _measure_dirty = true
460
+ _arrange_dirty = true
461
+
408
462
  func overflow_extent() -> Vector3:
409
463
  # Ancestors see the clipped participant's viewport, not its hidden content.
410
464
  if clips_content or scroll_axes!=Vector2.ZERO: return size
@@ -420,12 +474,30 @@ func _slots(items: Array, content: Vector3, definite: Vector3) -> Array:
420
474
  if strategy=="wrap": return WrapPolicy.layout(items,content,axis,physical_gaps,alignment,align_content,Vector2(definite.x,definite.y)).slots
421
475
  return StackPolicy.slots(items,content,axis,_main_gap(),alignment)
422
476
 
423
- func _authority(child, item: Dictionary, basis: Vector3) -> Vector3:
477
+ func _grid_track_definite(item_index: int, axis_index: int, basis: Vector3) -> bool:
478
+ # measure()/arrange() refresh placements once before walking child slots.
479
+ # Do not rescan every sibling for each child's two authority checks.
480
+ if grid_definition.is_empty(): _prepare_grid()
481
+ if grid_definition.has("error") or item_index<0 or item_index>=grid_definition.placements.size(): return false
482
+ var rect: Dictionary = grid_definition.placements[item_index]
483
+ var tracks: Array = grid_definition.columns if axis_index==0 else grid_definition.rows
484
+ var start: int = rect.column if axis_index==0 else rect.row
485
+ var span: int = rect.column_span if axis_index==0 else rect.row_span
486
+ for index in range(start,start+span):
487
+ var unit: String = tracks[index].unit
488
+ if unit=="auto" or unit in ["fr","%"] and basis[axis_index]<0: return false
489
+ return true
490
+
491
+ func _authority(child, item: Dictionary, basis: Vector3, item_index: int = -1) -> Vector3:
424
492
  var authority := Vector3.ZERO
425
493
  for index in range(3):
426
- if basis[index]<0 or child.requested[index]>=0 or index<2 and scroll_axes[index]>0: continue
494
+ if child.requested[index]>=0 or index<2 and scroll_axes[index]>0: continue
427
495
  if strategy=="grid":
428
- if index<2 and alignment[index]=="stretch": authority[index] = 1
496
+ # A fixed track is definite even in an auto Grid. Conversely, an
497
+ # auto track remains content-derived inside a definite-height Grid;
498
+ # its dependent cross contribution must survive remeasurement.
499
+ if index<2 and alignment[index]=="stretch" and _grid_track_definite(item_index,index,basis): authority[index] = 1
500
+ elif basis[index]<0: continue
429
501
  elif index==axis:
430
502
  if child.grow>0 or child.fill[index]>0: authority[index] = 1
431
503
  elif StackPolicy.cross_alignment(item,alignment[index],index)=="stretch": authority[index] = 1
@@ -452,19 +524,21 @@ func measure() -> Vector3:
452
524
  if not transparent:
453
525
  var basis := _content_basis()
454
526
  var budget := dimension_budget(basis)
455
- for child in children:
527
+ for child_index in range(children.size()):
528
+ var child = children[child_index]
456
529
  child.prepare(basis,viewport_size,budget)
457
- var capacity := basis
530
+ var capacity := _capacity_basis(basis)
458
531
  for index in range(3):
459
532
  if capacity[index]>=0: capacity[index] = maxf(0,capacity[index]-child.outer_extent()[index])
460
533
  child.set_capacity(capacity)
534
+ child._clear_allocation(_authority(child,{"align_self":child.align_self,"stretch":child.stretch,"fill":child.fill},basis,child_index))
461
535
  child.measure()
462
- if basis.x>=0 or basis.y>=0:
536
+ if basis.x>=0 or basis.y>=0 or strategy=="grid":
463
537
  var items := _items()
464
538
  var definite := Vector3(1 if basis.x>=0 else 0,1 if basis.y>=0 else 0,1 if basis.z>=0 else 0)
465
539
  var allocations := _slots(items,basis,definite)
466
540
  if allocations.size()==children.size():
467
- for index in range(children.size()): children[index].measure_allocated(allocations[index].extent,_authority(children[index],items[index],basis))
541
+ for index in range(children.size()): children[index].measure_allocated(allocations[index].extent,_authority(children[index],items[index],basis,index))
468
542
  var natural := Vector3.ZERO
469
543
  for child in children:
470
544
  var child_size: Vector3 = child.measure()
@@ -499,7 +573,8 @@ func independent_axis(index: int) -> bool:
499
573
  var allocated := grow>0 or fill[index]>0
500
574
  if index!=parent.axis: allocated = StackPolicy.cross_alignment({"align_self":align_self,"stretch":stretch,"fill":fill},parent.alignment[index],index)=="stretch"
501
575
  if index<2 and parent.scroll_axes[index]>0: return false
502
- if parent.strategy=="grid" and index<2: allocated = parent.alignment[index]=="stretch"
576
+ if parent.strategy=="grid" and index<2:
577
+ return parent.alignment[index]=="stretch" and parent._grid_track_definite(_parent_index,index,parent.content_reference)
503
578
  return parent.independent_axis(index) if requested[index] < 0 and allocated else false
504
579
 
505
580
  func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
@@ -585,7 +660,7 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
585
660
  child.placed.emit(next)
586
661
  var authority := Vector3.ZERO
587
662
  for cross in range(3):
588
- if strategy=="grid" and cross<2 and policy[cross]=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
663
+ if strategy=="grid" and cross<2 and policy[cross]=="stretch" and child.requested[cross]<0 and _grid_track_definite(index,cross,reference): authority[cross] = 1
589
664
  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
590
665
  for scrolling_axis in range(2):
591
666
  if scroll_axes[scrolling_axis]>0:
@@ -82,14 +82,14 @@ func input(event: InputEvent) -> bool:
82
82
  return held != null
83
83
  if not event is InputEventMouseButton or event.button_index != MOUSE_BUTTON_LEFT: return false
84
84
  if event.pressed:
85
- if held == null and hovered != null and not hovered.disabled:
85
+ if held == null and hovered != null and not hovered._input_disabled():
86
86
  hovered.grab_focus()
87
87
  _captured = weakref(hovered)
88
88
  hovered._set_pointer_state(true,true)
89
89
  return hovered != null
90
90
  if held == null: return hovered != null
91
91
  _captured = null
92
- var activate: bool = held==hovered and not held.disabled and held.is_visible_in_tree()
92
+ var activate: bool = held==hovered and not held._input_disabled() and held.is_visible_in_tree()
93
93
  held._set_pointer_state(held==hovered,false)
94
94
  if activate: held.pressed.emit()
95
95
  return true
@@ -24,6 +24,10 @@ static func grid_capable(script) -> bool:
24
24
  script = script.get_base_script()
25
25
  return false
26
26
  static func initial(script) -> String:
27
+ var base = script
28
+ while base is Script:
29
+ if base.get_script_constant_map().has("ESTRAGON_STACK_INITIAL"): return base.get_script_constant_map().ESTRAGON_STACK_INITIAL
30
+ base = base.get_base_script()
27
31
  return "grid" if grid_capable(script) else (preset(script) if not preset(script).is_empty() else "row")
28
32
  static func error(name: String, value, direction: String, fixed: String = "", grid: bool = false) -> String:
29
33
  if name=="align_content":
@@ -0,0 +1,103 @@
1
+ @tool
2
+ class_name EstragonRadio
3
+ extends "button.gd"
4
+ ## Option identity is separate from the enclosing group's observable selection.
5
+ const ESTRAGON_RADIO := true
6
+ var _leaving := false
7
+ var _identity_commit := false
8
+ @export var value: String = "":
9
+ set(next):
10
+ var group = _radio_owner()
11
+ if next.is_empty() or not _identity_commit and group!=null and not group.accepts(self,next):
12
+ push_error("Estragon Radio.value requires a nonempty unique String identifier")
13
+ return
14
+ if value==next: return
15
+ value = next
16
+ _identity_changed()
17
+ func _init() -> void:
18
+ super._init()
19
+ background_color = "transparent"
20
+ pressed.connect(_activate_radio)
21
+ focus_entered.connect(_radio_focused)
22
+ focus_exited.connect(_radio_blurred)
23
+ func _enter_tree() -> void:
24
+ _leaving = false
25
+ super._enter_tree()
26
+ visibility_changed.connect(_radio_visibility)
27
+ func _exit_tree() -> void:
28
+ _leaving = true
29
+ visibility_changed.disconnect(_radio_visibility)
30
+ super._exit_tree()
31
+ func _radio_visibility() -> void:
32
+ var group = _radio_owner()
33
+ if group!=null: group._queue_options()
34
+ func _radio_focused() -> void:
35
+ var group = _radio_owner()
36
+ if group!=null: group._option_focused(self)
37
+ func _radio_blurred() -> void:
38
+ var group = _radio_owner()
39
+ if group==null: return
40
+ if _radio_eligible() and not _leaving: group._focused = null
41
+ else: group._queue_options()
42
+ func _apply_radio_identity(next: String) -> void:
43
+ # The reconciler calls this only after whole desired-group validation. This
44
+ # permits valid swaps/replacements without testing obsolete sibling IDs.
45
+ _identity_commit = true
46
+ value = next
47
+ _identity_commit = false
48
+ func _identity_changed() -> void:
49
+ var group = _radio_owner()
50
+ if group!=null: group._queue_options()
51
+ _queue_style_redraw()
52
+ func _focus_tab_control():
53
+ var group = _radio_owner()
54
+ var option = group.tab_option() if group!=null else null
55
+ return option.get_focus_control() if option!=null else null
56
+ func _radio_owner():
57
+ var parent := get_parent()
58
+ while parent!=null:
59
+ if parent.has_method("_radio_group"): return parent
60
+ parent = parent.get_parent()
61
+ return null
62
+ func _input_disabled() -> bool:
63
+ var group = _radio_owner()
64
+ return _leaving or disabled or group==null or group.disabled or not group.accepts(self,value)
65
+ func _radio_participates() -> bool:
66
+ return not _input_disabled() and is_instance_valid(_focus_control) and Focus.eligible(_focus_control,false,false)
67
+ func _radio_eligible() -> bool:
68
+ return not _input_disabled() and is_instance_valid(_focus_control) and Focus.eligible(_focus_control)
69
+ func _focus_tab_stop() -> bool:
70
+ var group = _radio_owner()
71
+ return group!=null and group.tab_option()==self
72
+ func _focus_key(event: InputEventKey) -> bool:
73
+ var group = _radio_owner()
74
+ return group!=null and group.navigate(self,event)
75
+ func is_selected() -> bool:
76
+ var group = _radio_owner()
77
+ return group!=null and group.value==value and _radio_participates()
78
+ func _activate_radio() -> void:
79
+ if _radio_participates(): _radio_owner().value = value
80
+ func get_background_color() -> Color:
81
+ return _visual_style.colors.disabled_background_color if _input_disabled() else super.get_background_color()
82
+ func _indicator_size() -> float:
83
+ return maxf(16.0,float(font_size))
84
+ func _measure_native() -> Vector2:
85
+ var label := _measure_label() if not text.is_empty() else Vector2.ZERO
86
+ return Vector2(_indicator_size()+(8.0+label.x if not text.is_empty() else 0.0),maxf(_indicator_size(),label.y))
87
+ func get_label_origin() -> Vector2:
88
+ var content := get_content_rect()
89
+ return content.position+Vector2(_indicator_size()+8,maxf(0,(content.size.y-_measure_label().y)*0.5))
90
+ func _draw() -> void:
91
+ var content := get_content_rect()
92
+ var side := minf(_indicator_size(),minf(content.size.x,content.size.y))
93
+ if side<=0: return
94
+ var center := content.position+Vector2(side*0.5,content.size.y*0.5)
95
+ var tint := Color(0.5,0.5,0.5) if _input_disabled() else Color(0.85,0.85,0.85)
96
+ draw_circle(center,maxf(0,side*0.5-1.5),get_background_color())
97
+ draw_arc(center,maxf(0,side*0.5-0.75),0,TAU,40,tint,1.5,true)
98
+ if is_selected():
99
+ var accent: Color = _visual_style.colors.border_color
100
+ draw_circle(center,side*0.27,accent if accent.a>0 else tint)
101
+ _draw_label(get_label_origin(),tint)
102
+ if has_focus() and layout_size.x>4 and layout_size.y>4:
103
+ draw_rect(Rect2(Vector2(2,2),layout_size-Vector2(4,4)),Color("#cccccc"),false,2)
@@ -0,0 +1 @@
1
+ uid://d04jcjfnh8srq
@@ -0,0 +1,138 @@
1
+ @tool
2
+ class_name EstragonRadioGroup
3
+ extends "box.gd"
4
+ ## A String selection over native Radio options; Box remains the layout owner.
5
+ signal value_changed(previous: String, value: String)
6
+ const ESTRAGON_RADIO_GROUP := true
7
+ const ESTRAGON_STACK_INITIAL := "column"
8
+ const _GOGO_BINDABLE_PROPERTIES_NATIVE := {"value":"String"}
9
+ const Focus = preload("internal/focus.tres")
10
+ const State = preload("../composition/state.tres")
11
+ @export var value: String = "":
12
+ set(next):
13
+ if value==next: return
14
+ var previous := value
15
+ value = next
16
+ _refresh_options()
17
+ value_changed.emit(previous,next)
18
+ get:
19
+ State.observe(self,&"value_changed")
20
+ return value
21
+ @export var disabled: bool = false:
22
+ set(next):
23
+ if disabled==next: return
24
+ disabled = next
25
+ _refresh_options()
26
+ var _refresh_pending := false
27
+ var _options_dirty := true
28
+ var _options: Array[WeakRef] = []
29
+ var _identity_counts: Dictionary = {}
30
+ var _focused: WeakRef
31
+ var _focused_index := 0
32
+ var _duplicate_ids: Array = []
33
+ func _init() -> void:
34
+ direction = ESTRAGON_STACK_INITIAL
35
+ func _enter_tree() -> void:
36
+ super._enter_tree()
37
+ get_tree().tree_changed.connect(_queue_options)
38
+ if not Engine.is_editor_hint(): Focus.geometry_changed.connect(_queue_options)
39
+ visibility_changed.connect(_refresh_options)
40
+ layout_applied.connect(_arranged)
41
+ _queue_options()
42
+ func _exit_tree() -> void:
43
+ get_tree().tree_changed.disconnect(_queue_options)
44
+ if Focus.geometry_changed.is_connected(_queue_options): Focus.geometry_changed.disconnect(_queue_options)
45
+ visibility_changed.disconnect(_refresh_options)
46
+ layout_applied.disconnect(_arranged)
47
+ _options.clear()
48
+ _identity_counts.clear()
49
+ _options_dirty = true
50
+ _focused = null
51
+ super._exit_tree()
52
+ func _arranged(_size: Vector2) -> void:
53
+ _refresh_options()
54
+ func _queue_options() -> void:
55
+ _options_dirty = true
56
+ if _refresh_pending: return
57
+ _refresh_pending = true
58
+ _refresh_options.call_deferred()
59
+ func _collect_options(node: Node, output: Array) -> void:
60
+ for child in (node._layout_children() if node.has_method("_layout_children") else node.get_children()):
61
+ if child.has_method("_radio_group"): continue
62
+ if child.has_method("_radio_owner"): output.append(child)
63
+ _collect_options(child,output)
64
+ func _radio_group() -> Node:
65
+ return self
66
+ func options() -> Array:
67
+ if _options_dirty or not is_inside_tree():
68
+ _options_dirty = false
69
+ var current: Array = []
70
+ _collect_options(self,current)
71
+ _options.clear()
72
+ _identity_counts.clear()
73
+ for option in current:
74
+ _options.append(weakref(option))
75
+ _identity_counts[option.value] = _identity_counts.get(option.value,0)+1
76
+ var result: Array = []
77
+ for reference in _options:
78
+ var option = reference.get_ref()
79
+ if option!=null: result.append(option)
80
+ return result
81
+ func accepts(option: Node, identity: String) -> bool:
82
+ if identity.is_empty(): return false
83
+ if _options_dirty or not is_inside_tree(): options()
84
+ var count: int = _identity_counts.get(identity,0)
85
+ return count==0 or count==1 and option.value==identity
86
+ func _refresh_options() -> void:
87
+ _refresh_pending = false
88
+ if not is_inside_tree(): return
89
+ var list := options()
90
+ var duplicates: Array = []
91
+ var identities := {}
92
+ for option in list:
93
+ if option.value.is_empty() or identities.has(option.value): duplicates.append(option.value)
94
+ identities[option.value] = true
95
+ if duplicates!=_duplicate_ids:
96
+ _duplicate_ids = duplicates
97
+ if not duplicates.is_empty(): push_error("Estragon RadioGroup: option identifiers must be nonempty and unique: "+str(duplicates))
98
+ for option in list:
99
+ if not option._radio_participates(): option._cancel_pointer()
100
+ option._sync_focus()
101
+ option._queue_style_redraw()
102
+ if _focused!=null:
103
+ var previous = _focused.get_ref()
104
+ if previous!=null and list.has(previous) and previous._radio_eligible(): _focused_index = list.find(previous)
105
+ else:
106
+ _focused = null
107
+ var focus_owner := get_viewport().gui_get_focus_owner()
108
+ if focus_owner!=null and Focus.eligible(focus_owner): return
109
+ for offset in range(list.size()):
110
+ var candidate = list[posmod(_focused_index+offset,list.size())]
111
+ if candidate._radio_eligible():
112
+ candidate.grab_focus()
113
+ break
114
+ func _option_focused(option: Node) -> void:
115
+ _focused = weakref(option)
116
+ _focused_index = options().find(option)
117
+ func tab_option():
118
+ var first
119
+ for option in options():
120
+ if not option._radio_eligible() or option.get_focus_control().focus_mode!=Control.FOCUS_ALL: continue
121
+ if first==null: first = option
122
+ if option.value==value: return option
123
+ return first
124
+ func navigate(option: Node, event: InputEventKey) -> bool:
125
+ var backwards: int = KEY_LEFT if direction=="row" else KEY_UP
126
+ var forwards: int = KEY_RIGHT if direction=="row" else KEY_DOWN
127
+ if not event.keycode in [backwards,forwards,KEY_HOME,KEY_END] or event.alt_pressed or event.ctrl_pressed or event.meta_pressed: return false
128
+ if not event.pressed or event.echo: return true
129
+ var eligible: Array = []
130
+ for candidate in options():
131
+ if candidate._radio_eligible(): eligible.append(candidate)
132
+ if eligible.is_empty(): return true
133
+ var index: int = eligible.find(option)
134
+ index = 0 if event.keycode==KEY_HOME else eligible.size()-1 if event.keycode==KEY_END else posmod(index+(-1 if event.keycode==backwards else 1),eligible.size())
135
+ var next = eligible[index]
136
+ value = next.value
137
+ next.grab_focus()
138
+ return true
@@ -0,0 +1 @@
1
+ uid://bsecwnvqe1xd1
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.36"
32
+ "version": "0.1.0-beta.38"
33
33
  }