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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.32"
6
+ version="0.1.0-beta.33"
7
7
  script="plugin.gd"
@@ -44,6 +44,11 @@ func update(view: Node) -> void:
44
44
  if target != null: target.model.invalidated.connect(_configure)
45
45
  layout._sync()
46
46
  _configure()
47
+ # A root may become a participant after an initially empty/plain boundary.
48
+ # Parent gap counts follow that logical participation, not the host Node.
49
+ if layout._dimension==2:
50
+ var parent = layout.parent_coordinator()
51
+ if parent!=null: parent._sync()
47
52
  func _configure() -> void:
48
53
  if layout == null or not layout.active: return
49
54
  var requested := Vector3(-1,-1,0) if layout._dimension==2 else Vector3(-1,-1,-1)
@@ -303,7 +303,7 @@ func _default_padding() -> Vector4:
303
303
  return Vector4.ZERO
304
304
 
305
305
  func _padding_insets() -> Vector4:
306
- layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
306
+ layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size,layout.model.dimension_reference)
307
307
  return layout.model.padding
308
308
 
309
309
  func get_content_rect() -> Rect2:
@@ -387,7 +387,8 @@ func get_layout_stats() -> Dictionary:
387
387
  return {"measure": layout.model.measure_count, "arrange": layout.model.arrange_count, "flush": layout.flush_count, "active": get_layout_root() != null}
388
388
 
389
389
  func apply_layout_position(offset: Vector3) -> void:
390
- position = Vector2(offset.x, offset.y)
390
+ var next := Vector2(offset.x,offset.y)
391
+ if position!=next: position = next
391
392
 
392
393
  func apply_layout_size(size: Vector3) -> void:
393
394
  var next := Vector2(size.x,size.y)
@@ -402,7 +403,7 @@ func apply_layout_size(size: Vector3) -> void:
402
403
  layout_applied.emit(_layout_size)
403
404
 
404
405
  func _margin_insets() -> Vector4:
405
- layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
406
+ layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size,layout.model.dimension_reference)
406
407
  return layout.model.margin
407
408
 
408
409
  func _queue_style_redraw() -> void:
@@ -75,7 +75,7 @@ const _GOGO_BINDABLE_PROPERTIES_NATIVE := {"value":"String"}
75
75
  var _editor: LineEdit
76
76
  var _editor_skin := StyleBoxEmpty.new()
77
77
  func _init() -> void:
78
- background_color = Color("#252d38")
78
+ background_color = Color("#383838")
79
79
  padding = 8.0
80
80
  func _measure_native() -> Vector2:
81
81
  # A stable single-line viewport, not a text-dependent expanding field.
@@ -22,6 +22,7 @@ func _init(host: Node, dimension: int, mode: int = Mode.PROOF) -> void:
22
22
  _mode = mode
23
23
  _host = weakref(host)
24
24
  _dimension = dimension
25
+ model.dimension_budget_enabled = dimension==2
25
26
  if _mode == Mode.PROOF: host.set_meta(META, weakref(self))
26
27
  model.invalidated.connect(_invalidated)
27
28
  model.placed.connect(_place)
@@ -104,7 +105,21 @@ func stop() -> void:
104
105
 
105
106
  func _visibility_changed() -> void:
106
107
  var parent = parent_coordinator()
107
- if parent!=null and parent.model.strategy in ["wrap","grid"]: parent._sync()
108
+ while parent!=null:
109
+ parent._sync()
110
+ if parent._mode!=Mode.COMPOSITION: break
111
+ parent = parent.parent_coordinator()
112
+
113
+ func participates() -> bool:
114
+ var host = _host.get_ref()
115
+ if host==null or _dimension==2 and host is CanvasItem and not host.is_visible_in_tree(): return false
116
+ if _mode==Mode.ENTRY: return false
117
+ if _mode==Mode.CONTROL: return control_adapter.participates()
118
+ if _mode==Mode.COMPOSITION:
119
+ var root = managed_root.get_ref() if managed_root!=null else null
120
+ var target = participant(root)
121
+ return target!=null and target.participates()
122
+ return true
108
123
 
109
124
  func _child_entered(child: Node) -> void:
110
125
  if child is Control: CompositionHosts.enter_control(child)
@@ -129,14 +144,18 @@ func _sync() -> void:
129
144
  # Native child-entered signals can precede internal-child bookkeeping.
130
145
  # Runtime GUI endpoints/decorations never become layout participants.
131
146
  if host.has_method("_composition_is_private") and host._composition_is_private(child): continue
132
- if _dimension==2 and model.strategy in ["wrap","grid"] and child is CanvasItem and not child.is_visible_in_tree(): continue
147
+ if _dimension==2 and child is CanvasItem and not child.is_visible_in_tree(): continue
133
148
  var found = participant(child,true)
134
149
  if found != null and found._mode != Mode.ENTRY:
135
- if found._mode == Mode.CONTROL and not found.control_adapter.participates(): continue
150
+ if _dimension==2 and not found.participates(): continue
136
151
  found.model.set_placement(CompositionHosts.get_placement(child))
137
152
  values.append(found.model)
153
+ var participation_changed := model.children != values
138
154
  var error := model.set_children(values)
139
155
  if error != OK: push_error("Estragon layout model ownership: " + error_string(error))
156
+ if participation_changed and _mode==Mode.COMPOSITION:
157
+ var parent = parent_coordinator()
158
+ if parent!=null: parent._sync()
140
159
 
141
160
  func changed() -> void:
142
161
  var host = _host.get_ref()
@@ -19,10 +19,17 @@ static func tracks(specs: Array, items: Array, placements: Array, axis: int, ref
19
19
  var span: int = rect.column_span if axis==0 else rect.row_span
20
20
  var occupied := gap*(span-1)
21
21
  var eligible: Array = []
22
+ var fractions_only := true
22
23
  for index in range(start,start+span):
23
24
  occupied += sizes[index]
24
25
  if specs[index].unit in ["auto","fr"]: eligible.append(index)
25
- var deficit: float = maxf(0,maxf(items[i].get("contribution",items[i].preferred)[axis],items[i].minimum[axis])+items[i].outer[axis]-occupied)
26
+ if specs[index].unit!="fr": fractions_only = false
27
+ var contribution: float = items[i].get("contribution",items[i].preferred)[axis]
28
+ var viewport_floor: float = items[i].get("scroll_floor",Vector3(-1,-1,-1))[axis]
29
+ # A definite fraction cell assigns a scrolling viewport. Its hidden
30
+ # content is not a minimum viewport size; auto rows remain intrinsic.
31
+ if reference>=0 and fractions_only and viewport_floor>=0: contribution = viewport_floor
32
+ var deficit: float = maxf(0,maxf(contribution,items[i].minimum[axis])+items[i].outer[axis]-occupied)
26
33
  for index in eligible: sizes[index] += deficit/eligible.size()
27
34
  if reference>=0:
28
35
  var budget := reference-gap*maxi(0,sizes.size()-1)
@@ -18,6 +18,14 @@ var pixels_per_unit: float = 1.0
18
18
  var length_offset := Vector3.ZERO
19
19
  var viewport_size := Vector2.ZERO
20
20
  var parent_reference := Vector3(-1,-1,-1)
21
+ # Width/height percentages alone use this parent-policy budget. Other Length
22
+ # domains retain parent_reference; spatial coordinators keep their old contract.
23
+ var dimension_reference := Vector3(-1,-1,-1)
24
+ var dimension_budget_enabled := true
25
+ var _dimension_axes := Vector3.ZERO
26
+ var _budget_context: Array = []
27
+ var _budget := Vector3(-1,-1,-1)
28
+ var dimension_budget_count := 0
21
29
  var resolution_count := 0
22
30
  var _length_context: Array = []
23
31
  var _parent_axes := Vector3.ZERO
@@ -86,6 +94,9 @@ func set_lengths(specs: Dictionary, growth: float, cross: int, scale: float, sta
86
94
  var dependencies := Length.dependencies(length_specs,stack_axis)
87
95
  _parent_axes = dependencies[0]
88
96
  _viewport_axes = dependencies[1]
97
+ _dimension_axes = Vector3.ZERO
98
+ for index in range(2):
99
+ if length_specs.get(["width","height"][index],{}).get("unit","")=="%": _dimension_axes[index] = 1
89
100
  _length_context = []
90
101
  invalidate()
91
102
 
@@ -120,7 +131,8 @@ func set_align_self(value: String) -> void:
120
131
  func _length(name: String, axis_index: int, fallback: float) -> float:
121
132
  if not length_specs.has(name): return fallback
122
133
  var spec: Dictionary = length_specs[name]
123
- return Length.resolve(spec,parent_reference[axis_index],viewport_size,pixels_per_unit)
134
+ var reference: float = dimension_reference[axis_index] if name in ["width","height"] and spec.unit=="%" else parent_reference[axis_index]
135
+ return Length.resolve(spec,reference,viewport_size,pixels_per_unit)
124
136
 
125
137
  func _warn_unanchored() -> void:
126
138
  if _reported_unanchored: return
@@ -144,20 +156,23 @@ func _edges(prefix: String) -> Vector4:
144
156
 
145
157
  # Resolve specs only on a changed parent/viewport/spec context. No property
146
158
  # writeback, parsing in arrange, subscriptions per length, or frame polling.
147
- func prepare(reference: Vector3, viewport: Vector2) -> void:
148
- if transparent and _forward_context!=[reference,viewport] or viewport_size!=viewport and not children.is_empty():
159
+ func prepare(reference: Vector3, viewport: Vector2, dimensions: Variant = null) -> void:
160
+ var budget: Vector3 = reference if dimensions==null else dimensions
161
+ if transparent and _forward_context!=[reference,viewport,budget] or viewport_size!=viewport and not children.is_empty():
149
162
  _measure_dirty = true
150
163
  _arrange_dirty = true
151
- _forward_context = [reference,viewport] if transparent else []
164
+ _forward_context = [reference,viewport,budget] if transparent else []
152
165
  for index in range(3):
153
166
  if parent_reference[index]!=reference[index] and measurement_allocation[index]>=0:
154
167
  measurement_allocation[index] = -1
155
168
  _measure_dirty = true
156
169
  parent_reference = reference
170
+ dimension_reference = budget
157
171
  viewport_size = viewport
158
- var context := [reference*_parent_axes,viewport*_viewport_axes]
172
+ var context := [reference*_parent_axes,viewport*_viewport_axes,budget*_dimension_axes]
159
173
  if _length_context==context: return
160
174
  _length_context = context
175
+ if dimension_budget_enabled: measurement_allocation = Vector3(-1,-1,-1)
161
176
  resolution_count += 1
162
177
  var before := [requested,gap,physical_gaps,padding,border,margin,length_offset,authored_minimum,authored_maximum]
163
178
  if not length_specs.is_empty():
@@ -228,7 +243,7 @@ func configure(extent: Vector3, spacing: float, centered: bool, stack_axis: int
228
243
  intrinsic = content
229
244
  requested = extent
230
245
  gap = spacing
231
- physical_gaps = Vector2(spacing,spacing)
246
+ if length_specs.is_empty(): physical_gaps = Vector2(spacing,spacing)
232
247
  center = centered
233
248
  invalidate()
234
249
  return OK
@@ -255,6 +270,7 @@ func set_children(values: Array) -> Error:
255
270
  return OK
256
271
 
257
272
  func invalidate() -> void:
273
+ if dimension_budget_enabled: measurement_allocation = Vector3(-1,-1,-1)
258
274
  _measure_dirty = true
259
275
  _arrange_dirty = true
260
276
  var parent = _parent.get_ref() if _parent != null else null
@@ -283,16 +299,48 @@ func track_contribution() -> Vector3:
283
299
  func _items() -> Array:
284
300
  var items: Array = []
285
301
  for child in children:
286
- items.append({"preferred":child.measured,"contribution":child.track_contribution(),"minimum":child.minimum(),"maximum":child.maximum(),"requested":child.requested,"grow":child.grow,"stretch":child.stretch,"align_self":child.align_self,"fill":child.fill,"outer":child.outer_extent(),"leading":leading(child.margin),"placement":child.placement})
302
+ items.append({"preferred":child.measured,"contribution":child.track_contribution(),"scroll_floor":child.scroll_track_floor(),"minimum":child.minimum(),"maximum":child.maximum(),"requested":child.requested,"grow":child.grow,"stretch":child.stretch,"align_self":child.align_self,"fill":child.fill,"outer":child.outer_extent(),"leading":leading(child.margin),"placement":child.placement})
287
303
  return items
288
304
 
289
- func _grid(items: Array, content: Vector3) -> Dictionary:
305
+ func scroll_track_floor() -> Vector3:
306
+ if transparent and children.size()==1: return children[0].scroll_track_floor()
307
+ var result := Vector3(-1,-1,-1)
308
+ for index in range(2):
309
+ if scroll_axes[index]>0 and requested[index]<0:
310
+ result[index] = maxf(minimum()[index],intrinsic[index]+leading(padding+border)[index]+trailing(padding+border)[index])
311
+ return result
312
+
313
+ func _prepare_grid() -> void:
290
314
  var placements: Array = []
291
- for item in items: placements.append(item.placement)
315
+ for child in children: placements.append(child.placement)
292
316
  if grid_definition.get("source_placements",[])!=placements or grid_definition.is_empty():
293
317
  grid_definition = GridDefinition.configuration(grid_config,placements)
294
318
  grid_definition.source_placements = placements.duplicate(true)
295
319
  if grid_definition.has("error"): push_error("Estragon Grid: "+grid_definition.error+"; previous native slots retained")
320
+
321
+ func dimension_budget(reference: Vector3) -> Vector3:
322
+ if not dimension_budget_enabled or transparent or strategy=="wrap": return reference
323
+ var result := reference
324
+ var counts := Vector2i.ONE
325
+ if strategy=="grid":
326
+ _prepare_grid()
327
+ if grid_definition.has("error"): return reference
328
+ counts = Vector2i(grid_definition.columns.size(),grid_definition.rows.size())
329
+ elif axis<2: counts[axis] = children.size()
330
+ var context := [reference,physical_gaps,counts]
331
+ if _budget_context==context: return _budget
332
+ _budget_context = context
333
+ dimension_budget_count += 1
334
+ for index in range(2):
335
+ if reference[index]>=0: result[index] = maxf(0,reference[index]-physical_gaps[index]*maxi(0,counts[index]-1))
336
+ _budget = result
337
+ return result
338
+
339
+ func _main_gap() -> float:
340
+ return physical_gaps[axis] if axis<2 else gap
341
+
342
+ func _grid(items: Array, content: Vector3) -> Dictionary:
343
+ _prepare_grid()
296
344
  if grid_definition.has("error"):
297
345
  # Native children may exceed an explicitly bounded grid after direct edits.
298
346
  # Reject the layout as a whole, preserving the previous allocated slots.
@@ -333,7 +381,7 @@ func measure_allocated(extent: Vector3, authority: Vector3) -> void:
333
381
  if transparent and children.size()==1:
334
382
  children[0].measure_allocated(extent,authority)
335
383
  _measure_dirty = true
336
- elif strategy in ["wrap","grid"] or scroll_axes!=Vector2.ZERO:
384
+ elif strategy in ["wrap","grid"] or scroll_axes!=Vector2.ZERO or dimension_budget_enabled and not children.is_empty():
337
385
  var next := measurement_allocation
338
386
  for index in range(2):
339
387
  if requested[index]<0 and authority[index]>0: next[index] = extent[index]
@@ -341,7 +389,13 @@ func measure_allocated(extent: Vector3, authority: Vector3) -> void:
341
389
  measurement_allocation = next
342
390
  _measure_dirty = true
343
391
  else: return
392
+ var preferred := measured
344
393
  measure()
394
+ # Allocated axes are not a new intrinsic growth basis. Only the dependent
395
+ # unallocated (e.g. wrapped cross) axes feed back into this bounded pass.
396
+ if dimension_budget_enabled:
397
+ for index in range(2):
398
+ if requested[index]<0 and authority[index]>0: measured[index] = preferred[index]
345
399
 
346
400
  func overflow_extent() -> Vector3:
347
401
  # Ancestors see the clipped participant's viewport, not its hidden content.
@@ -356,7 +410,7 @@ func overflow_extent() -> Vector3:
356
410
  func _slots(items: Array, content: Vector3, definite: Vector3) -> Array:
357
411
  if strategy=="grid": return _grid(items,content).slots
358
412
  if strategy=="wrap": return WrapPolicy.layout(items,content,axis,physical_gaps,alignment,align_content,Vector2(definite.x,definite.y)).slots
359
- return StackPolicy.slots(items,content,axis,physical_gaps[axis] if axis<2 and not length_specs.is_empty() else gap,alignment)
413
+ return StackPolicy.slots(items,content,axis,_main_gap(),alignment)
360
414
 
361
415
  func _authority(child, item: Dictionary, basis: Vector3) -> Vector3:
362
416
  var authority := Vector3.ZERO
@@ -372,7 +426,7 @@ func _authority(child, item: Dictionary, basis: Vector3) -> Vector3:
372
426
  func measure() -> Vector3:
373
427
  if transparent and children.size()==1:
374
428
  var child = children[0]
375
- child.prepare(parent_reference,viewport_size)
429
+ child.prepare(parent_reference,viewport_size,dimension_reference)
376
430
  child.set_capacity(available_capacity)
377
431
  child.measure()
378
432
  if child.requested!=requested or child.grow!=grow or child.stretch!=stretch or child.align_self!=align_self or child.margin!=margin or child.fill!=fill or child.length_offset!=length_offset:
@@ -389,8 +443,9 @@ func measure() -> Vector3:
389
443
  if Profile.is_enabled(): Profile.add("layout_measures")
390
444
  if not transparent:
391
445
  var basis := _content_basis()
446
+ var budget := dimension_budget(basis)
392
447
  for child in children:
393
- child.prepare(basis,viewport_size)
448
+ child.prepare(basis,viewport_size,budget)
394
449
  var capacity := basis
395
450
  for index in range(3):
396
451
  if capacity[index]>=0: capacity[index] = maxf(0,capacity[index]-child.outer_extent()[index])
@@ -404,13 +459,12 @@ func measure() -> Vector3:
404
459
  for index in range(children.size()): children[index].measure_allocated(allocations[index].extent,_authority(children[index],items[index],basis))
405
460
  var natural := Vector3.ZERO
406
461
  for child in children:
407
- if not transparent: child.prepare(_content_basis(),viewport_size)
408
462
  var child_size: Vector3 = child.measure()
409
463
  if not transparent: child_size += child.outer_extent()
410
464
  for index in range(3):
411
465
  if index == axis: natural[index] += child_size[index]
412
466
  else: natural[index] = maxf(natural[index],child_size[index])
413
- if children.size() > 1: natural[axis] += (physical_gaps[axis] if axis<2 and length_specs.has("column_gap") else gap) * (children.size() - 1)
467
+ if children.size() > 1: natural[axis] += _main_gap() * (children.size() - 1)
414
468
  if strategy=="wrap" and not transparent:
415
469
  var basis := _wrap_basis()
416
470
  natural = WrapPolicy.layout(_items(),basis,axis,physical_gaps,alignment,align_content,Vector2(1 if basis.x>=0 else 0,1 if basis.y>=0 else 0)).extent
@@ -484,9 +538,9 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
484
538
  push_warning("Estragon explicit main-axis dimension overrides grow; use auto height/width on a remaining-space Spacer")
485
539
  # Assigned content is authoritative, including grow allocations. Resolve the
486
540
  # immediate children against this box before measuring their slots.
541
+ var budget := dimension_budget(reference)
487
542
  for child in children:
488
- var child_reference := reference
489
- child.prepare(child_reference,viewport_size)
543
+ child.prepare(reference,viewport_size,budget)
490
544
  child.measure()
491
545
  if not _reported_full_percent and children.size()>1:
492
546
  var main_name: String = ["width","height","depth"][axis]
@@ -494,7 +548,7 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
494
548
  var spec: Dictionary = child.length_specs.get(main_name,{})
495
549
  if spec.get("unit","")=="%" and spec.get("value",0)>=100:
496
550
  _reported_full_percent = true
497
- push_warning("Estragon "+main_name+"=100% consumes the full definite parent content axis, not remaining space; siblings may overflow. Use an auto-sized Spacer with grow=1 for remaining space")
551
+ push_warning("Estragon "+main_name+"=100% consumes the full definite parent "+("dimension budget" if dimension_budget_enabled and strategy!="wrap" and axis<2 else "content axis")+", not remaining space; siblings may overflow. Use an auto-sized Spacer with grow=1 for remaining space")
498
552
  break
499
553
  var layout_content := content
500
554
  for index in range(2):
@@ -506,7 +560,7 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
506
560
  var wrap_basis := _wrap_basis()
507
561
  slots = WrapPolicy.layout(items,layout_content,axis,physical_gaps,policy,align_content,Vector2(1 if reference.x>=0 or axis==0 and wrap_basis.x>=0 else 0,1 if reference.y>=0 or axis==1 and wrap_basis.y>=0 else 0)).slots
508
562
  else:
509
- slots = StackPolicy.slots(items,layout_content,axis,physical_gaps[axis] if axis<2 and length_specs.has("column_gap") else gap,policy)
563
+ slots = StackPolicy.slots(items,layout_content,axis,_main_gap(),policy)
510
564
  if strategy=="grid":
511
565
  policy_result = _grid(items,reference)
512
566
  if policy_result.has("error"): return
@@ -523,7 +577,8 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
523
577
  if strategy=="grid" and cross<2 and policy[cross]=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
524
578
  elif strategy!="grid" and cross!=axis and StackPolicy.cross_alignment(items[index],policy[cross],cross)=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
525
579
  for scrolling_axis in range(2):
526
- if scroll_axes[scrolling_axis]>0: authority[scrolling_axis] = 0
580
+ if scroll_axes[scrolling_axis]>0:
581
+ authority[scrolling_axis] = 1 if independent_axis(scrolling_axis) and child.requested[scrolling_axis]<0 and (child.grow>0 or child.fill[scrolling_axis]>0) else 0
527
582
  child.arrange(slot.extent,authority)
528
583
  arranged.emit(size)
529
584
 
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  "tag": "beta",
30
30
  "registry": "https://registry.npmjs.org/"
31
31
  },
32
- "version": "0.1.0-beta.32"
32
+ "version": "0.1.0-beta.33"
33
33
  }