@papercraftgames/estragon 0.1.0-beta.22 → 0.1.0-beta.23

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.
@@ -106,6 +106,11 @@ func _component(node: Model.Component) -> void:
106
106
  if not message.is_empty():
107
107
  _error(message,attribute.value.span)
108
108
  return
109
+ if name=="align_self" and StackContract.self_registered(resolved.script) and attribute.value is Model.Literal:
110
+ var message := StackContract.error(name,attribute.value.value,"")
111
+ if not message.is_empty():
112
+ _error(message,attribute.value.span)
113
+ return
109
114
  var is_color := VisualStyle.registered(resolved.script,name)
110
115
  if is_color:
111
116
  _color(attribute)
@@ -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.22"
6
+ version="0.1.0-beta.23"
7
7
  script="plugin.gd"
@@ -365,6 +365,10 @@ func _apply(desired: Element, record: Mounted) -> void:
365
365
  node.set(key,0.0)
366
366
  writes += 1
367
367
  if Profile.is_enabled(): Profile.add("property_writes")
368
+ if StackContract.self_registered(desired.type) and record.properties.has("align_self") and not desired.properties.has("align_self"):
369
+ node.set("align_self","auto")
370
+ writes += 1
371
+ if Profile.is_enabled(): Profile.add("property_writes")
368
372
  for key in desired.properties:
369
373
  if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
370
374
  if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
@@ -391,7 +395,7 @@ func _spread_resets(desired: Element, record) -> Dictionary:
391
395
  if record==null or not _compatible(desired,record): return result
392
396
  var node = record.node.get_ref()
393
397
  for key in record.spread_applied:
394
- if desired.properties.has(key) or key in Length.BORDER_EDGES or key in Length.MINIMUMS: continue
398
+ if desired.properties.has(key) or (key=="align_self" and StackContract.self_registered(desired.type)) or key in Length.BORDER_EDGES or key in Length.MINIMUMS: continue
395
399
  # Do not overwrite imperative native changes made since our last commit.
396
400
  if is_same(node.get(key),record.spread_applied[key]) and not is_same(node.get(key),record.defaults[key]): result[key] = record.defaults[key]
397
401
  return result
@@ -565,6 +569,9 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
565
569
  var native: String = desired.type if desired.type is String else desired.type.get_instance_base_type()
566
570
  if not properties.has(key) or not NativeAttributes.writable(native,desired.type,str(key),properties[key]): return _invalid_attribute(desired,str(key),"unknown, read-only or reserved native property")
567
571
  var value = desired.properties[key]
572
+ if key=="align_self" and StackContract.self_registered(desired.type):
573
+ var message := StackContract.error(key,value,"")
574
+ if not message.is_empty(): return _invalid_attribute(desired,str(key),message)
568
575
  if VisualStyle.property(str(key)) and VisualStyle.has_api(desired.type) and not VisualStyle.supported(desired.type):
569
576
  validation_error = desired.location(str(key))+": shared visual styling is unsupported on this participant; previous tree retained"
570
577
  return false
@@ -20,7 +20,7 @@ const StackContract = preload("internal/stack_contract.gd")
20
20
  return
21
21
  direction = value
22
22
  _changed()
23
- @export_enum("start", "center", "end", "stretch") var horizontal_align: String = "start":
23
+ @export_enum("start", "center", "end", "stretch", "space-between", "space-around", "space-evenly") var horizontal_align: String = "start":
24
24
  set(value):
25
25
  if _policy_commit:
26
26
  horizontal_align = value
@@ -28,7 +28,7 @@ const StackContract = preload("internal/stack_contract.gd")
28
28
  if value==horizontal_align or not _valid_alignment("horizontal_align",value): return
29
29
  horizontal_align = value
30
30
  _changed()
31
- @export_enum("start", "center", "end", "stretch") var vertical_align: String = "start":
31
+ @export_enum("start", "center", "end", "stretch", "space-between", "space-around", "space-evenly") var vertical_align: String = "start":
32
32
  set(value):
33
33
  if _policy_commit:
34
34
  vertical_align = value
@@ -7,6 +7,8 @@ signal layout_applied(size: Vector2)
7
7
  const Coordinator = preload("internal/coordinator.gd")
8
8
  const ESTRAGON_LENGTHS := true
9
9
  const ESTRAGON_MINIMUMS_2D := true
10
+ const ESTRAGON_ALIGN_SELF_2D := true
11
+ const AlignmentContract = preload("internal/stack_contract.gd")
10
12
  const VisualStyle = preload("internal/visual_style_2d.gd")
11
13
  var _visual_style = VisualStyle.new()
12
14
  const Length = preload("internal/length.gd")
@@ -147,6 +149,15 @@ var margin_left: Variant = "auto":
147
149
  if value not in [0,1] or value==stretch: return
148
150
  stretch = value
149
151
  _changed()
152
+ @export_enum("auto", "start", "center", "end", "stretch") var align_self: String = "auto":
153
+ set(value):
154
+ if value==align_self: return
155
+ var message := AlignmentContract.error("align_self",value,"")
156
+ if not message.is_empty():
157
+ push_error("Estragon alignment: "+message)
158
+ return
159
+ align_self = value
160
+ _changed()
150
161
  @export var center: bool = false:
151
162
  set(value):
152
163
  if center == value: return
@@ -133,6 +133,7 @@ func changed() -> void:
133
133
  if host.has_method("_layout_options"):
134
134
  var options: Dictionary = host._layout_options()
135
135
  model.set_policy(options.get("alignment",["start","start","start"]))
136
+ model.set_align_self(host.align_self if _dimension==2 and "align_self" in host else "auto")
136
137
  if "lengths" in host:
137
138
  for property in host._get_property_list():
138
139
  if not Core.Length.domain(property.name).is_empty() and not host.lengths.specs.has(property.name): host.lengths.assign(property.name,host.get(property.name),Core.Length.domain(property.name,host.get_script()))
@@ -10,6 +10,7 @@ signal arranged(size)
10
10
  var length_specs: Dictionary = {}
11
11
  var grow: float = 0.0
12
12
  var stretch: int = 0
13
+ var align_self := "auto"
13
14
  var pixels_per_unit: float = 1.0
14
15
  var length_offset := Vector3.ZERO
15
16
  var viewport_size := Vector2.ZERO
@@ -72,6 +73,11 @@ func set_policy(values: Array) -> void:
72
73
  alignment = values.duplicate()
73
74
  invalidate()
74
75
 
76
+ func set_align_self(value: String) -> void:
77
+ if align_self==value: return
78
+ align_self = value
79
+ invalidate()
80
+
75
81
  func _length(name: String, axis_index: int, fallback: float) -> float:
76
82
  if not length_specs.has(name): return fallback
77
83
  var spec: Dictionary = length_specs[name]
@@ -204,10 +210,11 @@ func measure() -> Vector3:
204
210
  var child = children[0]
205
211
  child.prepare(parent_reference,viewport_size)
206
212
  child.measure()
207
- 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:
213
+ 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:
208
214
  requested = child.requested
209
215
  grow = child.grow
210
216
  stretch = child.stretch
217
+ align_self = child.align_self
211
218
  fill = child.fill
212
219
  margin = child.margin
213
220
  length_offset = child.length_offset
@@ -239,7 +246,9 @@ func independent_axis(index: int) -> bool:
239
246
  if requested[index] >= 0 or _external_axes[index] > 0: return true
240
247
  var parent = _parent.get_ref() if _parent != null else null
241
248
  if parent == null: return false
242
- 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
249
+ var allocated := grow>0 or fill[index]>0
250
+ if index!=parent.axis: allocated = StackPolicy.cross_alignment({"align_self":align_self,"stretch":stretch,"fill":fill},parent.alignment[index],index)=="stretch"
251
+ return parent.independent_axis(index) if requested[index] < 0 and allocated else false
243
252
 
244
253
  func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
245
254
  available = constrain(available)
@@ -296,7 +305,7 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
296
305
  break
297
306
  var items: Array = []
298
307
  for child in children:
299
- items.append({"preferred":child.measured,"minimum":child.minimum(),"requested":child.requested,"grow":child.grow,"stretch":child.stretch,"fill":child.fill,"outer":child.outer_extent(),"leading":leading(child.margin)})
308
+ items.append({"preferred":child.measured,"minimum":child.minimum(),"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)})
300
309
  var policy := alignment.duplicate()
301
310
  if center: policy[axis] = "center"
302
311
  slots = StackPolicy.slots(items,content,axis,gap,policy)
@@ -309,6 +318,6 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
309
318
  child.placed.emit(next)
310
319
  var authority := Vector3.ZERO
311
320
  for cross in range(3):
312
- if cross!=axis and policy[cross]=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
321
+ if cross!=axis and StackPolicy.cross_alignment(items[index],policy[cross],cross)=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
313
322
  child.arrange(slot.extent,authority)
314
323
  arranged.emit(size)
@@ -1,5 +1,12 @@
1
1
  @tool
2
2
  extends RefCounted
3
+ const DISTRIBUTION := ["space-between","space-around","space-evenly"]
4
+ const SELF := ["auto","start","center","end","stretch"]
5
+ static func self_registered(script) -> bool:
6
+ while script is Script:
7
+ if script.get_script_constant_map().has("ESTRAGON_ALIGN_SELF_2D"): return true
8
+ script = script.get_base_script()
9
+ return false
3
10
  ## Shared static/preflight/native validation for the delivered Box policy.
4
11
  static func registered(script) -> bool:
5
12
  while script is Script:
@@ -12,10 +19,15 @@ static func preset(script) -> String:
12
19
  script = script.get_base_script()
13
20
  return ""
14
21
  static func error(name: String, value, direction: String, fixed: String = "") -> String:
15
- if name=="direction":
22
+ if name=="align_self":
23
+ if value not in SELF: return "align_self requires auto, start, center, end or stretch"
24
+ elif name=="direction":
16
25
  if value not in ["row","column"]: return "direction requires row or column"
17
26
  if not fixed.is_empty() and value!=fixed: return "HBox/VBox direction is fixed; use Box to change direction"
18
27
  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"
28
+ if value not in ["start","center","end","stretch"]+DISTRIBUTION: return name+" requires start, center, end, main-axis space-between/around/evenly or cross-axis stretch"
29
+ if direction in ["row","column"]:
30
+ var main := name==("horizontal_align" if direction=="row" else "vertical_align")
31
+ if main and value=="stretch": return "stretch is cross-axis only; use grow for remaining main-axis space"
32
+ if not main and value in DISTRIBUTION: return name+": space distribution is main-axis only"
21
33
  return ""
@@ -12,7 +12,7 @@ static func slots(items: Array, content: Vector3, axis: int, gap: float, alignme
12
12
  var extent: Vector3 = item.preferred
13
13
  for index in range(3): extent[index] = maxf(extent[index],item.minimum[index])
14
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"):
15
+ if index != axis and item.requested[index]<0 and cross_alignment(item,alignment[index],index)=="stretch":
16
16
  extent[index] = maxf(item.minimum[index],content[index]-item.outer[index])
17
17
  # Native fill remains a zero-basis allocation with a native minimum floor.
18
18
  if item.fill[axis]>0 and item.requested[axis]<0: extent[axis] = 0.0
@@ -23,7 +23,6 @@ static func slots(items: Array, content: Vector3, axis: int, gap: float, alignme
23
23
  flexible.append(extents.size()-1)
24
24
  var remaining := maxf(0,content[axis]-occupied)
25
25
  var shares := {}
26
- var total_weight := weight
27
26
  # Preserve native expand minimum water-filling (70/20 minima in 100 ->70/30).
28
27
  while not flexible.is_empty():
29
28
  var constrained := false
@@ -42,18 +41,39 @@ static func slots(items: Array, content: Vector3, axis: int, gap: float, alignme
42
41
  var item: Dictionary = items[index]
43
42
  shares[index] = remaining*(item.grow if item.grow>0 else 1.0)/weight
44
43
  break
45
- var cursor := maxf(0,content[axis]-occupied) * factor(alignment[axis]) if total_weight==0 else 0.0
44
+ # Growth/native minimum water-filling is complete before distribution. Count
45
+ # final extents and margins afresh: none of the allocated shares is free twice.
46
+ occupied = gap * maxi(0,items.size()-1)
47
+ for index in range(items.size()):
48
+ var extent: Vector3 = extents[index]
49
+ if shares.has(index): extent[axis] += shares[index]
50
+ extents[index] = extent
51
+ occupied += extent[axis]+items[index].outer[axis]
52
+ var free := maxf(0,content[axis]-occupied)
53
+ var cursor := free * factor(alignment[axis])
54
+ var extra_gap := 0.0
55
+ var count := items.size()
56
+ if alignment[axis]=="space-between" and count>1: extra_gap = free/(count-1)
57
+ elif alignment[axis]=="space-around" and count>0:
58
+ extra_gap = free/count
59
+ cursor = extra_gap/2
60
+ elif alignment[axis]=="space-evenly" and count>0:
61
+ extra_gap = free/(count+1)
62
+ cursor = extra_gap
46
63
  var result: Array = []
47
64
  for index in range(items.size()):
48
65
  var item: Dictionary = items[index]
49
66
  var extent: Vector3 = extents[index]
50
- if shares.has(index): extent[axis] += shares[index]
51
67
  var position: Vector3 = item.leading
52
68
  position[axis] += cursor
53
69
  for cross in range(3):
54
- if cross != axis: position[cross] += maxf(0,content[cross]-extent[cross]-item.outer[cross])*factor(alignment[cross])
70
+ if cross != axis: position[cross] += maxf(0,content[cross]-extent[cross]-item.outer[cross])*factor(cross_alignment(item,alignment[cross],cross))
55
71
  result.append({"position":position,"extent":extent})
56
- cursor += extent[axis]+item.outer[axis]+gap
72
+ cursor += extent[axis]+item.outer[axis]+gap+extra_gap
57
73
  return result
74
+ static func cross_alignment(item: Dictionary, parent: String, index: int) -> String:
75
+ var own: String = item.get("align_self","auto")
76
+ if own!="auto": return own
77
+ return "stretch" if item.stretch>0 or item.fill[index]>0 else parent
58
78
  static func factor(value: String) -> float:
59
79
  return 0.5 if value=="center" else (1.0 if value=="end" else 0.0)
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.22"
32
+ "version": "0.1.0-beta.23"
33
33
  }