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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ const Element = preload("../runtime/composition/element.gd")
5
5
  const Model = preload("model.gd")
6
6
  const Source = preload("source.gd")
7
7
  const Resolver = preload("native/resolver.gd")
8
+ const StackContract = preload("../runtime/node/internal/stack_contract.gd")
8
9
  const Length = preload("../runtime/node/internal/length.gd")
9
10
  const Lexer = preload("lexer.gd")
10
11
  var file: Source
@@ -42,6 +43,10 @@ func _component(node: Model.Component) -> void:
42
43
  script = script.get_base_script()
43
44
  properties.merge(resolved.get("properties",{}),true)
44
45
  signals.merge(resolved.get("signals",{}),true)
46
+ var stack_direction := StackContract.preset(resolved.script)
47
+ if stack_direction.is_empty(): stack_direction = "row"
48
+ for attribute in node.attributes:
49
+ if attribute.name=="direction": stack_direction = str(attribute.value.value) if attribute.value is Model.Literal else StackContract.preset(resolved.script)
45
50
  var seen: Dictionary = {}
46
51
  for attribute in node.attributes:
47
52
  var name := attribute.name
@@ -81,8 +86,13 @@ func _component(node: Model.Component) -> void:
81
86
  _error("Unsupported Node property metadata: " + name, attribute.name_span)
82
87
  return
83
88
  else:
84
- _error("Removed layout API "+name+": use unit dimensions, flex and stretch" if name in ["fill_width","fill_height","viewport_width_scale","viewport_height_scale"] else "Unknown, read-only or reserved Node property/signal " + name, attribute.name_span)
89
+ _error("Removed layout API "+name+": use unit dimensions, grow and stretch" if name in ["flex","fill_width","fill_height","viewport_width_scale","viewport_height_scale"] else "Unknown, read-only or reserved Node property/signal " + name, attribute.name_span)
85
90
  return
91
+ if StackContract.registered(resolved.script) and attribute.value is Model.Literal:
92
+ var message := StackContract.error(name,attribute.value.value,stack_direction,StackContract.preset(resolved.script))
93
+ if not message.is_empty():
94
+ _error(message,attribute.value.span)
95
+ return
86
96
  var is_length := Length.registered(resolved.script,name)
87
97
  if is_length:
88
98
  _length(attribute,Length.domain(name))
@@ -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":"Spacer","canonical":"EstragonSpacer","script":preload("../runtime/node/spacer.gd"),"dimension":2,"origin":"native layout"},
5
6
  {"alias":"Box","canonical":"EstragonBox","script":preload("../runtime/node/box.gd"),"dimension":2,"origin":"native layout"},
6
7
  {"alias":"Text","canonical":"EstragonText","script":preload("../runtime/node/text.gd"),"dimension":2,"origin":"native widget"},
7
8
  {"alias":"Rect","canonical":"EstragonRect","script":preload("../runtime/node/rect.gd"),"dimension":2,"origin":"native widget"},
@@ -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.17"
6
+ version="0.1.0-beta.18"
7
7
  script="plugin.gd"
@@ -1,4 +1,5 @@
1
1
  extends RefCounted
2
+ const StackContract = preload("../node/internal/stack_contract.gd")
2
3
  const Length = preload("../node/internal/length.gd")
3
4
  const Profile = preload("profile.tres")
4
5
  ## F01 computation and retained static-shape records external to native objects.
@@ -320,9 +321,11 @@ func _apply(desired: Element, record: Mounted) -> void:
320
321
  writes += 1
321
322
  if Profile.is_enabled(): Profile.add("property_writes")
322
323
  binding.attach(node,self)
324
+ var stack := StackContract.registered(desired.type)
325
+ if stack: node._apply_stack_policy(desired.properties)
323
326
  for key in desired.properties:
324
327
  if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
325
- node.set(key,desired.properties[key])
328
+ if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
326
329
  writes += 1
327
330
  if Profile.is_enabled(): Profile.add("property_writes")
328
331
  for event in record.handlers:
@@ -459,9 +462,23 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
459
462
  contracts[desired.type] = {"properties":properties,"signals":signals}
460
463
  var properties: Dictionary = contracts[desired.type].properties
461
464
  var signals: Dictionary = contracts[desired.type].signals
465
+ if StackContract.registered(desired.type):
466
+ var policy: Dictionary = previous.properties.duplicate() if previous!=null and _compatible(desired,previous) else {}
467
+ policy.merge(desired.properties,true)
468
+ var fixed := StackContract.preset(desired.type)
469
+ var direction = policy.get("direction",fixed if not fixed.is_empty() else "row")
470
+ for key in ["direction","horizontal_align","vertical_align"]:
471
+ var value = policy.get(key,direction if key=="direction" else "start")
472
+ var message := StackContract.error(key,value,str(direction),fixed)
473
+ if not message.is_empty():
474
+ validation_error = desired.source+": "+message+"; previous tree retained"
475
+ return false
462
476
  for key in desired.properties:
463
477
  if not properties.has(key) or key in ["script","owner"] or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return false
464
478
  var value = desired.properties[key]
479
+ if key=="grow" and Length.registered(desired.type,"width") and (not typeof(value) in [TYPE_INT,TYPE_FLOAT] or not is_finite(float(value)) or value<0):
480
+ validation_error = desired.source+": grow requires a finite nonnegative weight; previous tree retained"
481
+ return false
465
482
  if Length.registered(desired.type,key):
466
483
  var parsed := Length.parse(value,Length.domain(key))
467
484
  if parsed.has("error"):
@@ -2,6 +2,59 @@
2
2
  class_name EstragonBox
3
3
  extends "component_2d.gd"
4
4
  ## Constructible horizontal Box. VBox selects the vertical axis.
5
+ const ESTRAGON_STACK_POLICY := true
6
+ var _policy_commit := false
7
+ const StackContract = preload("internal/stack_contract.gd")
8
+ @export_enum("row", "column") var direction: String = "row":
9
+ set(value):
10
+ if value==direction: return
11
+ if _policy_commit:
12
+ direction = value
13
+ return
14
+ var message := StackContract.error("direction",value,value,StackContract.preset(get_script()))
15
+ if message.is_empty():
16
+ message = StackContract.error("horizontal_align",horizontal_align,value)
17
+ if message.is_empty(): message = StackContract.error("vertical_align",vertical_align,value)
18
+ if not message.is_empty():
19
+ push_error("Estragon Box: "+message)
20
+ return
21
+ direction = value
22
+ _changed()
23
+ @export_enum("start", "center", "end", "stretch") var horizontal_align: String = "start":
24
+ set(value):
25
+ if _policy_commit:
26
+ horizontal_align = value
27
+ return
28
+ if value==horizontal_align or not _valid_alignment("horizontal_align",value): return
29
+ horizontal_align = value
30
+ _changed()
31
+ @export_enum("start", "center", "end", "stretch") var vertical_align: String = "start":
32
+ set(value):
33
+ if _policy_commit:
34
+ vertical_align = value
35
+ return
36
+ if value==vertical_align or not _valid_alignment("vertical_align",value): return
37
+ vertical_align = value
38
+ _changed()
39
+ # Called only after whole-description preflight; avoids transient invalid states
40
+ # when direction and cross alignment change together in one reconciliation.
41
+ func _apply_stack_policy(values: Dictionary) -> void:
42
+ var before := [direction,horizontal_align,vertical_align]
43
+ _policy_commit = true
44
+ for key in ["direction","horizontal_align","vertical_align"]:
45
+ if values.has(key): set(key,values[key])
46
+ _policy_commit = false
47
+ if before!=[direction,horizontal_align,vertical_align]: _changed()
48
+ func _valid_alignment(property: String, value) -> bool:
49
+ var message := StackContract.error(property,value,"row" if _layout_axis()==0 else "column")
50
+ if not message.is_empty(): push_error("Estragon Box: "+message)
51
+ return message.is_empty()
52
+ func _layout_axis() -> int:
53
+ return 0 if direction=="row" else 1
54
+ func _layout_options() -> Dictionary:
55
+ var result := super._layout_options()
56
+ result["alignment"] = [horizontal_align,vertical_align,"start"]
57
+ return result
5
58
  var padding: Variant = 0.0:
6
59
  set(value):
7
60
  if is_same(padding,value) or not lengths.assign("padding",value): return
@@ -57,10 +57,10 @@ var margin_left: Variant = "auto":
57
57
  if is_same(margin_left,value) or not lengths.assign("margin_left",value): return
58
58
  margin_left = value
59
59
  _changed()
60
- @export var flex: float = 0.0:
60
+ @export var grow: float = 0.0:
61
61
  set(value):
62
- if not is_finite(value) or value<0 or value==flex: return
63
- flex = value
62
+ if not is_finite(value) or value<0 or value==grow: return
63
+ grow = value
64
64
  _changed()
65
65
  @export_enum("Natural", "Stretch") var stretch: int = 0:
66
66
  set(value):
@@ -42,10 +42,10 @@ var gap: Variant = 0.0:
42
42
  if is_same(gap,value) or not lengths.assign("gap",value): return
43
43
  gap = value
44
44
  _changed()
45
- @export var flex: float = 0.0:
45
+ @export var grow: float = 0.0:
46
46
  set(value):
47
- if not is_finite(value) or value<0 or value==flex: return
48
- flex = value
47
+ if not is_finite(value) or value<0 or value==grow: return
48
+ grow = value
49
49
  _changed()
50
50
  @export_enum("Natural", "Stretch") var stretch: int = 0:
51
51
  set(value):
@@ -1,6 +1,9 @@
1
1
  @tool
2
2
  class_name EstragonHBox
3
3
  extends "box.gd"
4
+ const STACK_DIRECTION := "row"
5
+ func _init() -> void:
6
+ direction = "row"
4
7
  ## Native stack participant using the shared composed layout algorithm.
5
8
  func _layout_axis() -> int:
6
9
  return 0
@@ -132,10 +132,11 @@ func changed() -> void:
132
132
  if host == null: return
133
133
  if host.has_method("_layout_options"):
134
134
  var options: Dictionary = host._layout_options()
135
+ model.set_policy(options.get("alignment",["start","start","start"]))
135
136
  if "lengths" in host:
136
137
  for property in host._get_property_list():
137
138
  if not host.lengths.specs.has(property.name): host.lengths.assign(property.name,host.get(property.name))
138
- model.set_lengths(host.lengths.specs,host.flex,host.stretch,host.pixels_per_unit if _dimension==3 else 1.0,options.axis)
139
+ model.set_lengths(host.lengths.specs,host.grow,host.stretch,host.pixels_per_unit if _dimension==3 else 1.0,options.axis)
139
140
  model.configure(host.requested_extent(),model.gap,host.center,options.axis,options.fill,options.intrinsic,model.padding if "lengths" in host else options.get("padding",Vector4.ZERO),model.margin if "lengths" in host else options.get("margin",Vector4.ZERO))
140
141
  else: model.configure(host.requested_extent(), host.gap, host.center)
141
142
 
@@ -0,0 +1,75 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Pure future Grid input normalization, not an executable layout component.
4
+ ## Serializable dictionaries only. Track fractions never enter Length dimensions.
5
+ const Length = preload("length.gd")
6
+ static func tracks(values) -> Dictionary:
7
+ if values is int:
8
+ if values<1 or values>256: return {"error":"track count must be 1..256"}
9
+ var result: Array = []
10
+ for index in range(values): result.append({"unit":"fr","value":1.0})
11
+ return {"tracks":result}
12
+ if not values is Array or values.is_empty() or values.size()>256: return {"error":"tracks require a nonempty array or count (maximum 256)"}
13
+ var result: Array = []
14
+ for value in values:
15
+ if value is String and value.ends_with("fr"):
16
+ var number: String = value.trim_suffix("fr")
17
+ if not number.is_valid_float() or not is_finite(float(number)) or float(number)<=0 or float(number)>Length.LIMIT: return {"error":"fr track weight must be finite and positive"}
18
+ result.append({"unit":"fr","value":float(number)})
19
+ else:
20
+ var spec := Length.parse(value,"extent")
21
+ if spec.has("error"): return {"error":"invalid track: "+spec.error}
22
+ result.append(spec)
23
+ return {"tracks":result}
24
+ static func normalize(columns, rows, areas: Array = [], placements: Array = []) -> Dictionary:
25
+ var cols := tracks(columns)
26
+ if cols.has("error"): return cols
27
+ var lines := tracks(rows)
28
+ if lines.has("error"): return lines
29
+ var matrix: Array = []
30
+ var bounds := {}
31
+ if not areas.is_empty() and areas.size()!=lines.tracks.size(): return {"error":"area row count must match row tracks"}
32
+ for row in range(areas.size()):
33
+ if not areas[row] is String: return {"error":"each area row must be a space-separated string"}
34
+ var cells: Array = []
35
+ for cell in areas[row].replace("\t"," ").split(" ",false): cells.append(cell)
36
+ if cells.size()!=cols.tracks.size(): return {"error":"uneven area row or column track count mismatch"}
37
+ matrix.append(cells)
38
+ for col in range(cells.size()):
39
+ var name: String = cells[col]
40
+ if name==".": continue
41
+ if not name.is_valid_identifier(): return {"error":"area names must be identifiers or ."}
42
+ if not bounds.has(name): bounds[name] = {"row":row,"column":col,"row_span":1,"column_span":1}
43
+ var rect: Dictionary = bounds[name]
44
+ rect.row_span = row-rect.row+1
45
+ var end: int = maxi(rect.column+rect.column_span,col+1)
46
+ rect.column = mini(rect.column,col)
47
+ rect.column_span = end-rect.column
48
+ for name in bounds:
49
+ var rect: Dictionary = bounds[name]
50
+ for row in range(rect.row,rect.row+rect.row_span):
51
+ for col in range(rect.column,rect.column+rect.column_span):
52
+ if matrix[row][col]!=name: return {"error":"area '"+name+"' must form one rectangle"}
53
+ var normalized: Array = []
54
+ var occupied := {}
55
+ for placement in placements:
56
+ if not placement is Dictionary: return {"error":"placement must be a dictionary"}
57
+ var rect: Dictionary
58
+ if placement.has("area"):
59
+ if placement.size()!=1: return {"error":"area conflicts with explicit row/column placement"}
60
+ if not bounds.has(placement.area): return {"error":"unknown placement area: "+str(placement.area)}
61
+ rect = bounds[placement.area].duplicate()
62
+ else:
63
+ for key in placement:
64
+ if key not in ["row","column","row_span","column_span"]: return {"error":"unknown placement field: "+str(key)}
65
+ rect = {"row":placement.get("row",0),"column":placement.get("column",0),"row_span":placement.get("row_span",1),"column_span":placement.get("column_span",1)}
66
+ for key in rect:
67
+ if not rect[key] is int or rect[key]<(1 if key.ends_with("span") else 0): return {"error":"placement indices must be nonnegative integers and spans positive"}
68
+ if rect.row+rect.row_span>lines.tracks.size() or rect.column+rect.column_span>cols.tracks.size(): return {"error":"placement exceeds track bounds"}
69
+ for row in range(rect.row,rect.row+rect.row_span):
70
+ for col in range(rect.column,rect.column+rect.column_span):
71
+ var key := str(row)+":"+str(col)
72
+ if occupied.has(key): return {"error":"duplicate/conflicting child placement at "+key}
73
+ occupied[key] = true
74
+ normalized.append(rect)
75
+ return {"columns":cols.tracks,"rows":lines.tracks,"areas":matrix,"bounds":bounds,"placements":normalized}
@@ -0,0 +1 @@
1
+ uid://6f643551992c
@@ -1,5 +1,6 @@
1
1
  @tool
2
2
  extends RefCounted
3
+ const StackPolicy = preload("stack_policy.gd")
3
4
  const Length = preload("length.gd")
4
5
  const Profile = preload("../../composition/profile.tres")
5
6
  ## Shared B2/C1 mathematical row layout. No Nodes, rendering or SceneTree dependencies.
@@ -7,7 +8,7 @@ signal invalidated
7
8
  signal placed(offset)
8
9
  signal arranged(size)
9
10
  var length_specs: Dictionary = {}
10
- var flex: float = 0.0
11
+ var grow: float = 0.0
11
12
  var stretch: int = 0
12
13
  var pixels_per_unit: float = 1.0
13
14
  var length_offset := Vector3.ZERO
@@ -19,6 +20,8 @@ var _parent_axes := Vector3.ZERO
19
20
  var _viewport_axes := Vector2.ZERO
20
21
  var _forward_context: Array = []
21
22
  var _reported_unanchored := false
23
+ var _reported_full_percent := false
24
+ var _reported_fixed_growth := false
22
25
  var requested := Vector3(-1, -1, -1)
23
26
  var gap: float = 0.0
24
27
  var center: bool = false
@@ -30,6 +33,9 @@ var allocation_minimum := Vector3.ZERO
30
33
  var padding := Vector4.ZERO # left, top, right, bottom; border-box insets
31
34
  var margin := Vector4.ZERO # outside own geometry; consumed by the parent
32
35
  var transparent: bool = false # composition proxy forwards one root slot
36
+ var alignment: Array = ["start","start","start"]
37
+ # Parent-owned border-box placements; no Node references or additive offsets.
38
+ var slots: Array = []
33
39
  var children: Array = []
34
40
  var measured := Vector3.ZERO
35
41
  # -1 is an unavailable/cyclic reference axis, distinct from an arranged zero.
@@ -44,9 +50,9 @@ var _arrange_dirty: bool = true
44
50
  var _parent: WeakRef
45
51
 
46
52
  func set_lengths(specs: Dictionary, growth: float, cross: int, scale: float, stack_axis: int) -> void:
47
- if length_specs==specs and flex==growth and stretch==cross and pixels_per_unit==scale and axis==stack_axis: return
53
+ if length_specs==specs and grow==growth and stretch==cross and pixels_per_unit==scale and axis==stack_axis: return
48
54
  length_specs = specs.duplicate(true)
49
- flex = growth
55
+ grow = growth
50
56
  stretch = cross
51
57
  pixels_per_unit = scale
52
58
  var dependencies := Length.dependencies(length_specs,stack_axis)
@@ -55,6 +61,11 @@ func set_lengths(specs: Dictionary, growth: float, cross: int, scale: float, sta
55
61
  _length_context = []
56
62
  invalidate()
57
63
 
64
+ func set_policy(values: Array) -> void:
65
+ if alignment==values: return
66
+ alignment = values.duplicate()
67
+ invalidate()
68
+
58
69
  func _length(name: String, axis_index: int, fallback: float) -> float:
59
70
  if not length_specs.has(name): return fallback
60
71
  var spec: Dictionary = length_specs[name]
@@ -65,7 +76,7 @@ func _warn_unanchored() -> void:
65
76
  for index in range(3):
66
77
  if _parent_axes[index]>0 and parent_reference[index]<0:
67
78
  _reported_unanchored = true
68
- push_warning("Estragon unanchored/cyclic percentage resolves to zero; give the containing layout axis an independent extent")
79
+ push_warning("Estragon percentage has no definite containing content axis and resolves to zero; root Entry uses 100vw/100vh, not 100%; give auto parents an independent extent or grow allocation")
69
80
  return
70
81
 
71
82
  func _edges(prefix: String) -> Vector4:
@@ -171,9 +182,9 @@ func measure() -> Vector3:
171
182
  var child = children[0]
172
183
  child.prepare(parent_reference,viewport_size)
173
184
  child.measure()
174
- if child.requested!=requested or child.flex!=flex or child.stretch!=stretch or child.margin!=margin or child.fill!=fill or child.length_offset!=length_offset:
185
+ if child.requested!=requested or child.grow!=grow or child.stretch!=stretch or child.margin!=margin or child.fill!=fill or child.length_offset!=length_offset:
175
186
  requested = child.requested
176
- flex = child.flex
187
+ grow = child.grow
177
188
  stretch = child.stretch
178
189
  fill = child.fill
179
190
  margin = child.margin
@@ -205,7 +216,7 @@ func independent_axis(index: int) -> bool:
205
216
  if requested[index] >= 0 or _external_axes[index] > 0: return true
206
217
  var parent = _parent.get_ref() if _parent != null else null
207
218
  if parent == null: return false
208
- return parent.independent_axis(index) if requested[index] < 0 and (fill[index] > 0 or (flex>0 if index==parent.axis else stretch>0)) else false
219
+ return parent.independent_axis(index) if requested[index] < 0 and (fill[index] > 0 or (grow>0 if index==parent.axis else stretch>0)) else false
209
220
 
210
221
  func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
211
222
  _external_axes = external_axes
@@ -232,56 +243,48 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
232
243
  child.placed.emit(Vector3.ZERO)
233
244
  child.viewport_size = viewport_size
234
245
  # Forward actual allocation authority through transparent hosts. Their
235
- # internal X axis must not reinterpret the outer Box's flex axis.
246
+ # internal X axis must not reinterpret the outer Box's grow axis.
236
247
  var authority := Vector3.ZERO
237
248
  for index in range(3):
238
249
  if independent_axis(index): authority[index] = 1
239
250
  child.arrange(available,authority)
240
251
  arranged.emit(size)
241
252
  return
242
- # Assigned content is authoritative, including flex allocations. Resolve the
253
+ if not _reported_fixed_growth and grow>0 and _parent!=null and _parent.get_ref()!=null:
254
+ var containing = _parent.get_ref()
255
+ while containing.transparent and containing._parent!=null and containing._parent.get_ref()!=null: containing = containing._parent.get_ref()
256
+ var main: int = containing.axis
257
+ if requested[main]>=0:
258
+ _reported_fixed_growth = true
259
+ push_warning("Estragon explicit main-axis dimension overrides grow; use auto height/width on a remaining-space Spacer")
260
+ # Assigned content is authoritative, including grow allocations. Resolve the
243
261
  # immediate children against this box before measuring their slots.
244
262
  for child in children:
245
263
  child.prepare(reference,viewport_size)
246
264
  child.measure()
247
- var fixed: float = gap * maxi(0, children.size() - 1)
248
- var flexible: Array = []
249
- for child in children:
250
- fixed += child.outer_extent()[axis]
251
- if (child.flex>0 or child.fill[axis]>0) and child.requested[axis] < 0: flexible.append(child)
252
- else: fixed += child.measured[axis]
253
- var remaining: float = maxf(0,content[axis] - fixed)
254
- var shares: Dictionary = {}
255
- # Reserve constrained native minimums, then share the remaining space.
256
- # Zero floors preserve the existing equal-share Box behavior.
257
- while not flexible.is_empty():
258
- var weight := 0.0
259
- for child in flexible: weight += child.flex if child.flex>0 else 1.0
260
- var share: float = remaining / weight
261
- var constrained := false
262
- for child in flexible.duplicate():
263
- if child.allocation_minimum[axis] > share*(child.flex if child.flex>0 else 1.0):
264
- shares[child] = child.allocation_minimum[axis]
265
- remaining = maxf(0,remaining-child.allocation_minimum[axis])
266
- flexible.erase(child)
267
- constrained = true
268
- if not constrained:
269
- for child in flexible: shares[child] = share*(child.flex if child.flex>0 else 1.0)
270
- break
271
- var row_extent: float = fixed
272
- for share in shares.values(): row_extent += share
273
- var cursor: float = (content[axis] - row_extent) * 0.5 if center else 0.0
265
+ if not _reported_full_percent and children.size()>1:
266
+ var main_name: String = ["width","height","depth"][axis]
267
+ for child in children:
268
+ var spec: Dictionary = child.length_specs.get(main_name,{})
269
+ if spec.get("unit","")=="%" and spec.get("value",0)>=100:
270
+ _reported_full_percent = true
271
+ 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")
272
+ break
273
+ var items: Array = []
274
274
  for child in children:
275
- var allocation: Vector3 = child.measured
276
- for index in range(3):
277
- if (child.fill[index]>0 or (child.flex>0 if index==axis else child.stretch>0)) and child.requested[index] < 0:
278
- allocation[index] = shares[child] if index == axis else maxf(0,content[index]-child.outer_extent()[index])
279
- allocation[index] = maxf(allocation[index],child.allocation_minimum[index])
280
- var next: Vector3 = leading(padding)+leading(child.margin)+child.length_offset
281
- next[axis] += cursor
275
+ items.append({"preferred":child.measured,"minimum":child.allocation_minimum,"requested":child.requested,"grow":child.grow,"stretch":child.stretch,"fill":child.fill,"outer":child.outer_extent(),"leading":leading(child.margin)})
276
+ var policy := alignment.duplicate()
277
+ if center: policy[axis] = "center"
278
+ slots = StackPolicy.slots(items,content,axis,gap,policy)
279
+ for index in range(children.size()):
280
+ var child = children[index]
281
+ var slot: Dictionary = slots[index]
282
+ var next: Vector3 = leading(padding)+slot.position+child.length_offset
282
283
  if child.offset != next or child.arrange_count == 0:
283
284
  child.offset = next
284
285
  child.placed.emit(next)
285
- child.arrange(allocation)
286
- cursor += allocation[axis] + child.outer_extent()[axis] + gap
286
+ var authority := Vector3.ZERO
287
+ for cross in range(3):
288
+ if cross!=axis and policy[cross]=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
289
+ child.arrange(slot.extent,authority)
287
290
  arranged.emit(size)
@@ -0,0 +1,21 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Shared static/preflight/native validation for the delivered Box policy.
4
+ static func registered(script) -> bool:
5
+ while script is Script:
6
+ if script.get_script_constant_map().has("ESTRAGON_STACK_POLICY"): return true
7
+ script = script.get_base_script()
8
+ return false
9
+ static func preset(script) -> String:
10
+ while script is Script:
11
+ if script.get_script_constant_map().has("STACK_DIRECTION"): return script.get_script_constant_map().STACK_DIRECTION
12
+ script = script.get_base_script()
13
+ return ""
14
+ static func error(name: String, value, direction: String, fixed: String = "") -> String:
15
+ if name=="direction":
16
+ if value not in ["row","column"]: return "direction requires row or column"
17
+ if not fixed.is_empty() and value!=fixed: return "HBox/VBox direction is fixed; use Box to change direction"
18
+ elif name in ["horizontal_align","vertical_align"]:
19
+ if value not in ["start","center","end","stretch"]: return name+" requires start, center, end or cross-axis stretch; distribution is deferred to #161"
20
+ if value=="stretch" and direction in ["row","column"] and name==("horizontal_align" if direction=="row" else "vertical_align"): return "stretch is cross-axis only; use grow for remaining main-axis space"
21
+ return ""
@@ -0,0 +1 @@
1
+ uid://242ae24481ad
@@ -0,0 +1,59 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Pure parent-owned sequential slot strategy. Input is measured placement data;
4
+ ## output is border-box slots, before child-authored additive transforms.
5
+ ## Wrap/Grid will assign the same slots without using this cursor algorithm.
6
+ static func slots(items: Array, content: Vector3, axis: int, gap: float, alignment: Array) -> Array:
7
+ var extents: Array = []
8
+ var occupied := gap * maxi(0,items.size()-1)
9
+ var weight := 0.0
10
+ var flexible: Array = []
11
+ for item in items:
12
+ var extent: Vector3 = item.preferred
13
+ for index in range(3): extent[index] = maxf(extent[index],item.minimum[index])
14
+ for index in range(3):
15
+ if index != axis and item.requested[index]<0 and (item.stretch>0 or item.fill[index]>0 or alignment[index]=="stretch"):
16
+ extent[index] = maxf(item.minimum[index],content[index]-item.outer[index])
17
+ # Native fill remains a zero-basis allocation with a native minimum floor.
18
+ if item.fill[axis]>0 and item.requested[axis]<0: extent[axis] = 0.0
19
+ extents.append(extent)
20
+ occupied += extent[axis]+item.outer[axis]
21
+ if item.requested[axis]<0 and (item.grow>0 or item.fill[axis]>0):
22
+ weight += item.grow if item.grow>0 else 1.0
23
+ flexible.append(extents.size()-1)
24
+ var remaining := maxf(0,content[axis]-occupied)
25
+ var shares := {}
26
+ var total_weight := weight
27
+ # Preserve native expand minimum water-filling (70/20 minima in 100 ->70/30).
28
+ while not flexible.is_empty():
29
+ var constrained := false
30
+ for index in flexible.duplicate():
31
+ var item: Dictionary = items[index]
32
+ var part: float = remaining*(item.grow if item.grow>0 else 1.0)/weight
33
+ var floor_extra: float = maxf(0,item.minimum[axis]-extents[index][axis])
34
+ if floor_extra>part:
35
+ shares[index] = floor_extra
36
+ remaining = maxf(0,remaining-floor_extra)
37
+ weight -= item.grow if item.grow>0 else 1.0
38
+ flexible.erase(index)
39
+ constrained = true
40
+ if not constrained:
41
+ for index in flexible:
42
+ var item: Dictionary = items[index]
43
+ shares[index] = remaining*(item.grow if item.grow>0 else 1.0)/weight
44
+ break
45
+ var cursor := maxf(0,content[axis]-occupied) * factor(alignment[axis]) if total_weight==0 else 0.0
46
+ var result: Array = []
47
+ for index in range(items.size()):
48
+ var item: Dictionary = items[index]
49
+ var extent: Vector3 = extents[index]
50
+ if shares.has(index): extent[axis] += shares[index]
51
+ var position: Vector3 = item.leading
52
+ position[axis] += cursor
53
+ for cross in range(3):
54
+ if cross != axis: position[cross] += maxf(0,content[cross]-extent[cross]-item.outer[cross])*factor(alignment[cross])
55
+ result.append({"position":position,"extent":extent})
56
+ cursor += extent[axis]+item.outer[axis]+gap
57
+ return result
58
+ static func factor(value: String) -> float:
59
+ return 0.5 if value=="center" else (1.0 if value=="end" else 0.0)
@@ -0,0 +1 @@
1
+ uid://92ed730c24b4
@@ -0,0 +1,4 @@
1
+ @tool
2
+ class_name EstragonSpacer
3
+ extends "component_2d.gd"
4
+ ## Zero-natural-size, non-drawing participant. Use grow for remaining space.
@@ -0,0 +1 @@
1
+ uid://25ac39971b06
@@ -1,6 +1,9 @@
1
1
  @tool
2
2
  class_name EstragonVBox
3
3
  extends "box.gd"
4
+ const STACK_DIRECTION := "column"
5
+ func _init() -> void:
6
+ direction = "column"
4
7
  ## Native stack participant using the shared composed layout algorithm.
5
8
  func _layout_axis() -> int:
6
9
  return 1
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.17"
32
+ "version": "0.1.0-beta.18"
33
33
  }