@papercraftgames/estragon 0.1.0-beta.37 → 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.37"
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()
@@ -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.37"
32
+ "version": "0.1.0-beta.38"
33
33
  }