@papercraftgames/estragon 0.1.0-beta.2 → 0.1.0-beta.21
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.
- package/CHANGELOG.md +7 -3
- package/README.md +11 -8
- package/addons/estragon/compiler/bindable.gd +3 -3
- package/addons/estragon/compiler/compiler.gd +8 -8
- package/addons/estragon/compiler/composition.gd +5 -4
- package/addons/estragon/compiler/emitter.gd +34 -8
- package/addons/estragon/compiler/frontend.gd +8 -8
- package/addons/estragon/compiler/lexer.gd +2 -2
- package/addons/estragon/compiler/model.gd +2 -0
- package/addons/estragon/compiler/native/resolver.gd +125 -29
- package/addons/estragon/compiler/parser.gd +3 -3
- package/addons/estragon/compiler/project_sources.gd +91 -0
- package/addons/estragon/compiler/project_sources.gd.uid +1 -0
- package/addons/estragon/compiler/script_validation.gd +3 -3
- package/addons/estragon/compiler/source.gd +19 -2
- package/addons/estragon/compiler/source_map.gd +3 -3
- package/addons/estragon/compiler/validator.gd +74 -10
- package/addons/estragon/editor/build_service.gd +91 -72
- package/addons/estragon/editor/color_property.gd +37 -0
- package/addons/estragon/editor/color_property.gd.uid +1 -0
- package/addons/estragon/editor/completion.gd +531 -0
- package/addons/estragon/editor/completion.gd.uid +1 -0
- package/addons/estragon/editor/completion_edit.gd +7 -0
- package/addons/estragon/editor/completion_edit.gd.uid +1 -0
- package/addons/estragon/editor/components.gd +20 -0
- package/addons/estragon/editor/components.gd.uid +1 -0
- package/addons/estragon/editor/creation_menu.gd.txt +14 -0
- package/addons/estragon/editor/generated_editors.gd +256 -0
- package/addons/estragon/editor/generated_editors.gd.uid +1 -0
- package/addons/estragon/editor/highlighter.gd +62 -103
- package/addons/estragon/editor/highlighter_association.gd +11 -2
- package/addons/estragon/editor/imports.gd +47 -0
- package/addons/estragon/editor/imports.gd.uid +1 -0
- package/addons/estragon/editor/language_services.gd +288 -0
- package/addons/estragon/editor/language_services.gd.uid +1 -0
- package/addons/estragon/editor/length_property.gd +22 -0
- package/addons/estragon/editor/length_property.gd.uid +1 -0
- package/addons/estragon/editor/lexical_context.gd +159 -0
- package/addons/estragon/editor/lexical_context.gd.uid +1 -0
- package/addons/estragon/editor/navigation.gd +30 -0
- package/addons/estragon/editor/navigation.gd.uid +1 -0
- package/addons/estragon/editor/new_script.gd +77 -0
- package/addons/estragon/editor/new_script.gd.uid +1 -0
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/editor/plugin.gd +113 -40
- package/addons/estragon/editor/scene_components.gd +267 -0
- package/addons/estragon/editor/scene_components.gd.uid +1 -0
- package/addons/estragon/editor/scene_inspector.gd +42 -0
- package/addons/estragon/editor/scene_inspector.gd.uid +1 -0
- package/addons/estragon/editor/script_dependencies.gd +5 -3
- package/addons/estragon/runtime/composition/binding.gd +1 -1
- package/addons/estragon/runtime/composition/computation.gd +141 -9
- package/addons/estragon/runtime/composition/element.gd +3 -1
- package/addons/estragon/runtime/composition/layout_host.gd +58 -0
- package/addons/estragon/runtime/composition/layout_host.gd.uid +1 -0
- package/addons/estragon/runtime/composition/profile.tres +1 -1
- package/addons/estragon/runtime/composition/projection.gd +32 -0
- package/addons/estragon/runtime/composition/projection.gd.uid +1 -0
- package/addons/estragon/runtime/composition/state.gd +13 -2
- package/addons/estragon/runtime/composition/state.tres +1 -1
- package/addons/estragon/runtime/node/box.gd +57 -0
- package/addons/estragon/runtime/node/box.gd.uid +1 -0
- package/addons/estragon/runtime/node/button.gd +44 -15
- package/addons/estragon/runtime/node/component_2d.gd +167 -24
- package/addons/estragon/runtime/node/component_3d.gd +54 -18
- package/addons/estragon/runtime/node/estragon_2d.gd +2 -11
- package/addons/estragon/runtime/node/estragon_3d.gd +1 -10
- package/addons/estragon/runtime/node/hbox.gd +4 -1
- package/addons/estragon/runtime/node/internal/component_2d_icon.tres +4 -0
- package/addons/estragon/runtime/node/internal/composition_hosts.gd +159 -0
- package/addons/estragon/runtime/node/internal/composition_hosts.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/composition_hosts.tres +6 -0
- package/addons/estragon/runtime/node/internal/control_participant.gd +164 -0
- package/addons/estragon/runtime/node/internal/control_participant.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/coordinator.gd +79 -27
- package/addons/estragon/runtime/node/internal/grid_definition.gd +75 -0
- package/addons/estragon/runtime/node/internal/grid_definition.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/layout_core.gd +205 -22
- package/addons/estragon/runtime/node/internal/length.gd +94 -0
- package/addons/estragon/runtime/node/internal/length.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/stack_contract.gd +21 -0
- package/addons/estragon/runtime/node/internal/stack_contract.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/stack_policy.gd +59 -0
- package/addons/estragon/runtime/node/internal/stack_policy.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/visual_style_2d.gd +75 -0
- package/addons/estragon/runtime/node/internal/visual_style_2d.gd.uid +1 -0
- package/addons/estragon/runtime/node/native_2d.gd +5 -5
- package/addons/estragon/runtime/node/native_3d.gd +5 -5
- package/addons/estragon/runtime/node/rect.gd +13 -13
- package/addons/estragon/runtime/node/spacer.gd +4 -0
- package/addons/estragon/runtime/node/spacer.gd.uid +1 -0
- package/addons/estragon/runtime/node/text.gd +5 -3
- package/addons/estragon/runtime/node/toggle.gd +18 -5
- package/addons/estragon/runtime/node/vbox.gd +4 -1
- package/package.json +1 -1
|
@@ -1,18 +1,47 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
extends RefCounted
|
|
3
|
-
const
|
|
3
|
+
const StackPolicy = preload("stack_policy.gd")
|
|
4
|
+
const Length = preload("length.gd")
|
|
5
|
+
const Profile = preload("../../composition/profile.tres")
|
|
4
6
|
## Shared B2/C1 mathematical row layout. No Nodes, rendering or SceneTree dependencies.
|
|
5
7
|
signal invalidated
|
|
6
8
|
signal placed(offset)
|
|
7
9
|
signal arranged(size)
|
|
10
|
+
var length_specs: Dictionary = {}
|
|
11
|
+
var grow: float = 0.0
|
|
12
|
+
var stretch: int = 0
|
|
13
|
+
var pixels_per_unit: float = 1.0
|
|
14
|
+
var length_offset := Vector3.ZERO
|
|
15
|
+
var viewport_size := Vector2.ZERO
|
|
16
|
+
var parent_reference := Vector3(-1,-1,-1)
|
|
17
|
+
var resolution_count := 0
|
|
18
|
+
var _length_context: Array = []
|
|
19
|
+
var _parent_axes := Vector3.ZERO
|
|
20
|
+
var _viewport_axes := Vector2.ZERO
|
|
21
|
+
var _forward_context: Array = []
|
|
22
|
+
var _reported_unanchored := false
|
|
23
|
+
var _reported_full_percent := false
|
|
24
|
+
var _reported_fixed_growth := false
|
|
8
25
|
var requested := Vector3(-1, -1, -1)
|
|
9
26
|
var gap: float = 0.0
|
|
10
27
|
var center: bool = false
|
|
11
28
|
var axis: int = 0
|
|
12
29
|
var fill := Vector3.ZERO
|
|
13
30
|
var intrinsic := Vector3.ZERO
|
|
31
|
+
# Native Control minimums constrain assigned slots, never read back from size.
|
|
32
|
+
var allocation_minimum := Vector3.ZERO
|
|
33
|
+
var padding := Vector4.ZERO # left, top, right, bottom; border-box insets
|
|
34
|
+
var border := Vector4.ZERO # inside the border-box, before padding
|
|
35
|
+
var margin := Vector4.ZERO # outside own geometry; consumed by the parent
|
|
36
|
+
var transparent: bool = false # composition proxy forwards one root slot
|
|
37
|
+
var alignment: Array = ["start","start","start"]
|
|
38
|
+
# Parent-owned border-box placements; no Node references or additive offsets.
|
|
39
|
+
var slots: Array = []
|
|
14
40
|
var children: Array = []
|
|
15
41
|
var measured := Vector3.ZERO
|
|
42
|
+
# -1 is an unavailable/cyclic reference axis, distinct from an arranged zero.
|
|
43
|
+
var content_reference := Vector3(-1,-1,-1)
|
|
44
|
+
var _external_axes := Vector3.ZERO
|
|
16
45
|
var size := Vector3.ZERO
|
|
17
46
|
var offset := Vector3.ZERO
|
|
18
47
|
var measure_count: int = 0
|
|
@@ -21,16 +50,98 @@ var _measure_dirty: bool = true
|
|
|
21
50
|
var _arrange_dirty: bool = true
|
|
22
51
|
var _parent: WeakRef
|
|
23
52
|
|
|
53
|
+
var default_padding := Vector4.ZERO
|
|
54
|
+
|
|
55
|
+
func set_lengths(specs: Dictionary, growth: float, cross: int, scale: float, stack_axis: int, padding_fallback: Vector4 = Vector4.ZERO) -> void:
|
|
56
|
+
if default_padding==padding_fallback and length_specs==specs and grow==growth and stretch==cross and pixels_per_unit==scale and axis==stack_axis: return
|
|
57
|
+
default_padding = padding_fallback
|
|
58
|
+
length_specs = specs.duplicate(true)
|
|
59
|
+
grow = growth
|
|
60
|
+
stretch = cross
|
|
61
|
+
pixels_per_unit = scale
|
|
62
|
+
var dependencies := Length.dependencies(length_specs,stack_axis)
|
|
63
|
+
_parent_axes = dependencies[0]
|
|
64
|
+
_viewport_axes = dependencies[1]
|
|
65
|
+
_length_context = []
|
|
66
|
+
invalidate()
|
|
67
|
+
|
|
68
|
+
func set_policy(values: Array) -> void:
|
|
69
|
+
if alignment==values: return
|
|
70
|
+
alignment = values.duplicate()
|
|
71
|
+
invalidate()
|
|
72
|
+
|
|
73
|
+
func _length(name: String, axis_index: int, fallback: float) -> float:
|
|
74
|
+
if not length_specs.has(name): return fallback
|
|
75
|
+
var spec: Dictionary = length_specs[name]
|
|
76
|
+
return Length.resolve(spec,parent_reference[axis_index],viewport_size,pixels_per_unit)
|
|
77
|
+
|
|
78
|
+
func _warn_unanchored() -> void:
|
|
79
|
+
if _reported_unanchored: return
|
|
80
|
+
for index in range(3):
|
|
81
|
+
if _parent_axes[index]>0 and parent_reference[index]<0:
|
|
82
|
+
_reported_unanchored = true
|
|
83
|
+
push_warning("Estragon percentage has no definite containing content axis and resolves to zero; give the containing auto layout axis an independent extent or grow allocation; independent 2D Entries use their visible viewport")
|
|
84
|
+
return
|
|
85
|
+
|
|
86
|
+
func _edges(prefix: String) -> Vector4:
|
|
87
|
+
var result := Vector4.ZERO
|
|
88
|
+
var names := ["left","top","right","bottom"]
|
|
89
|
+
for edge in range(4):
|
|
90
|
+
var index: int = edge%2
|
|
91
|
+
var key: String = prefix+"_"+names[edge]+("_width" if prefix=="border" else "")
|
|
92
|
+
var value := _length(key,index,-1)
|
|
93
|
+
var uniform := _length("border_width" if prefix=="border" else prefix,index,0)
|
|
94
|
+
if prefix=="padding" and uniform<0: uniform = default_padding[edge]
|
|
95
|
+
result[edge] = uniform if value<0 else value
|
|
96
|
+
return result
|
|
97
|
+
|
|
98
|
+
# Resolve specs only on a changed parent/viewport/spec context. No property
|
|
99
|
+
# writeback, parsing in arrange, subscriptions per length, or frame polling.
|
|
100
|
+
func prepare(reference: Vector3, viewport: Vector2) -> void:
|
|
101
|
+
if transparent and _forward_context!=[reference,viewport] or viewport_size!=viewport and not children.is_empty():
|
|
102
|
+
_measure_dirty = true
|
|
103
|
+
_arrange_dirty = true
|
|
104
|
+
_forward_context = [reference,viewport] if transparent else []
|
|
105
|
+
parent_reference = reference
|
|
106
|
+
viewport_size = viewport
|
|
107
|
+
var context := [reference*_parent_axes,viewport*_viewport_axes]
|
|
108
|
+
if _length_context==context: return
|
|
109
|
+
_length_context = context
|
|
110
|
+
resolution_count += 1
|
|
111
|
+
var before := [requested,gap,padding,border,margin,length_offset]
|
|
112
|
+
if not length_specs.is_empty():
|
|
113
|
+
for index in range(3):
|
|
114
|
+
requested[index] = _length(["width","height","depth"][index],index,requested[index])
|
|
115
|
+
length_offset[index] = _length(["x","y","z"][index],index,0)
|
|
116
|
+
gap = _length("gap",axis,0)
|
|
117
|
+
padding = _edges("padding")
|
|
118
|
+
border = _edges("border")
|
|
119
|
+
margin = _edges("margin")
|
|
120
|
+
if before!=[requested,gap,padding,border,margin,length_offset]:
|
|
121
|
+
_measure_dirty = true
|
|
122
|
+
_arrange_dirty = true
|
|
123
|
+
|
|
124
|
+
func _content_basis() -> Vector3:
|
|
125
|
+
var basis := Vector3(-1,-1,-1)
|
|
126
|
+
for index in range(3):
|
|
127
|
+
if requested[index]>=0: basis[index] = maxf(0,requested[index]-leading(padding+border)[index]-trailing(padding+border)[index])
|
|
128
|
+
return basis
|
|
129
|
+
|
|
24
130
|
static func valid_extent(value: Vector3) -> bool:
|
|
25
131
|
for axis in range(3):
|
|
26
132
|
if not is_finite(value[axis]) or value[axis] < 0 and value[axis] != -1: return false
|
|
27
133
|
return true
|
|
28
134
|
|
|
29
|
-
func configure(extent: Vector3, spacing: float, centered: bool, stack_axis: int = 0, fills: Vector3 = Vector3.ZERO, content: Vector3 = Vector3.ZERO) -> Error:
|
|
135
|
+
func configure(extent: Vector3, spacing: float, centered: bool, stack_axis: int = 0, fills: Vector3 = Vector3.ZERO, content: Vector3 = Vector3.ZERO, inner: Vector4 = Vector4.ZERO, outer: Vector4 = Vector4.ZERO, passthrough: bool = false) -> Error:
|
|
30
136
|
if not valid_extent(extent) or not is_finite(spacing) or spacing < 0 or stack_axis < 0 or stack_axis > 2: return ERR_INVALID_PARAMETER
|
|
31
137
|
for index in range(3):
|
|
32
138
|
if fills[index] not in [0.0,1.0] or not is_finite(content[index]) or content[index] < 0: return ERR_INVALID_PARAMETER
|
|
33
|
-
|
|
139
|
+
for edge in range(4):
|
|
140
|
+
if not is_finite(inner[edge]) or inner[edge] < 0 or not is_finite(outer[edge]) or outer[edge] < 0: return ERR_INVALID_PARAMETER
|
|
141
|
+
if requested == extent and gap == spacing and center == centered and axis == stack_axis and fill == fills and intrinsic == content and padding == inner and margin == outer and transparent == passthrough: return OK
|
|
142
|
+
padding = inner
|
|
143
|
+
margin = outer
|
|
144
|
+
transparent = passthrough
|
|
34
145
|
axis = stack_axis
|
|
35
146
|
fill = fills
|
|
36
147
|
intrinsic = content
|
|
@@ -52,9 +163,11 @@ func set_children(values: Array) -> Error:
|
|
|
52
163
|
seen.append(child)
|
|
53
164
|
if children == values: return OK
|
|
54
165
|
for child in children:
|
|
55
|
-
if not values.has(child):
|
|
166
|
+
if not values.has(child):
|
|
167
|
+
child._parent = null
|
|
56
168
|
children = values.duplicate()
|
|
57
|
-
for child in children:
|
|
169
|
+
for child in children:
|
|
170
|
+
child._parent = weakref(self)
|
|
58
171
|
invalidate()
|
|
59
172
|
return OK
|
|
60
173
|
|
|
@@ -65,26 +178,65 @@ func invalidate() -> void:
|
|
|
65
178
|
if parent != null: parent.invalidate()
|
|
66
179
|
invalidated.emit()
|
|
67
180
|
|
|
181
|
+
static func leading(edges: Vector4) -> Vector3:
|
|
182
|
+
return Vector3(edges.x,edges.y,0)
|
|
183
|
+
static func trailing(edges: Vector4) -> Vector3:
|
|
184
|
+
return Vector3(edges.z,edges.w,0)
|
|
185
|
+
func outer_extent() -> Vector3:
|
|
186
|
+
return leading(margin)+trailing(margin)
|
|
187
|
+
|
|
68
188
|
func measure() -> Vector3:
|
|
189
|
+
if transparent and children.size()==1:
|
|
190
|
+
var child = children[0]
|
|
191
|
+
child.prepare(parent_reference,viewport_size)
|
|
192
|
+
child.measure()
|
|
193
|
+
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:
|
|
194
|
+
requested = child.requested
|
|
195
|
+
grow = child.grow
|
|
196
|
+
stretch = child.stretch
|
|
197
|
+
fill = child.fill
|
|
198
|
+
margin = child.margin
|
|
199
|
+
length_offset = child.length_offset
|
|
200
|
+
_measure_dirty = true
|
|
69
201
|
if not _measure_dirty: return measured
|
|
70
202
|
measure_count += 1
|
|
71
203
|
if Profile.is_enabled(): Profile.add("layout_measures")
|
|
72
204
|
var natural := Vector3.ZERO
|
|
73
205
|
for child in children:
|
|
206
|
+
if not transparent: child.prepare(_content_basis(),viewport_size)
|
|
74
207
|
var child_size: Vector3 = child.measure()
|
|
208
|
+
if not transparent: child_size += child.outer_extent()
|
|
75
209
|
for index in range(3):
|
|
76
210
|
if index == axis: natural[index] += child_size[index]
|
|
77
211
|
else: natural[index] = maxf(natural[index],child_size[index])
|
|
78
212
|
if children.size() > 1: natural[axis] += gap * (children.size() - 1)
|
|
79
213
|
for index in range(3): natural[index] = maxf(natural[index],intrinsic[index])
|
|
214
|
+
if not transparent: natural += leading(padding+border)+trailing(padding+border)
|
|
80
215
|
measured = natural
|
|
81
216
|
for axis in range(3):
|
|
82
217
|
if requested[axis] >= 0: measured[axis] = requested[axis]
|
|
83
218
|
_measure_dirty = false
|
|
84
219
|
return measured
|
|
85
220
|
|
|
86
|
-
|
|
87
|
-
|
|
221
|
+
# An auto axis cannot be a reference to its own descendants. Fill allocations
|
|
222
|
+
# ignore this model's intrinsic extent and can inherit an independent basis.
|
|
223
|
+
func independent_axis(index: int) -> bool:
|
|
224
|
+
if requested[index] >= 0 or _external_axes[index] > 0: return true
|
|
225
|
+
var parent = _parent.get_ref() if _parent != null else null
|
|
226
|
+
if parent == null: return false
|
|
227
|
+
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
|
|
228
|
+
|
|
229
|
+
func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
230
|
+
_external_axes = external_axes
|
|
231
|
+
_warn_unanchored()
|
|
232
|
+
var content := available-leading(padding+border)-trailing(padding+border)
|
|
233
|
+
var reference := Vector3(-1,-1,-1)
|
|
234
|
+
for index in range(3):
|
|
235
|
+
content[index] = maxf(0,content[index])
|
|
236
|
+
if independent_axis(index): reference[index] = content[index]
|
|
237
|
+
var changed: bool = reference != content_reference
|
|
238
|
+
if not _arrange_dirty and size == available and not changed: return
|
|
239
|
+
content_reference = reference
|
|
88
240
|
measure()
|
|
89
241
|
arrange_count += 1
|
|
90
242
|
if Profile.is_enabled(): Profile.add("layout_arranges")
|
|
@@ -92,24 +244,55 @@ func arrange(available: Vector3) -> void:
|
|
|
92
244
|
# Clear before callbacks so a signal-triggered change queues a genuine
|
|
93
245
|
# follow-up instead of being overwritten when this pass finishes.
|
|
94
246
|
_arrange_dirty = false
|
|
95
|
-
|
|
96
|
-
|
|
247
|
+
if transparent:
|
|
248
|
+
for child in children:
|
|
249
|
+
if child.offset != Vector3.ZERO or child.arrange_count == 0:
|
|
250
|
+
child.offset = Vector3.ZERO
|
|
251
|
+
child.placed.emit(Vector3.ZERO)
|
|
252
|
+
child.viewport_size = viewport_size
|
|
253
|
+
# Forward actual allocation authority through transparent hosts. Their
|
|
254
|
+
# internal X axis must not reinterpret the outer Box's grow axis.
|
|
255
|
+
var authority := Vector3.ZERO
|
|
256
|
+
for index in range(3):
|
|
257
|
+
if independent_axis(index): authority[index] = 1
|
|
258
|
+
child.arrange(available,authority)
|
|
259
|
+
arranged.emit(size)
|
|
260
|
+
return
|
|
261
|
+
if not _reported_fixed_growth and grow>0 and _parent!=null and _parent.get_ref()!=null:
|
|
262
|
+
var containing = _parent.get_ref()
|
|
263
|
+
while containing.transparent and containing._parent!=null and containing._parent.get_ref()!=null: containing = containing._parent.get_ref()
|
|
264
|
+
var main: int = containing.axis
|
|
265
|
+
if requested[main]>=0:
|
|
266
|
+
_reported_fixed_growth = true
|
|
267
|
+
push_warning("Estragon explicit main-axis dimension overrides grow; use auto height/width on a remaining-space Spacer")
|
|
268
|
+
# Assigned content is authoritative, including grow allocations. Resolve the
|
|
269
|
+
# immediate children against this box before measuring their slots.
|
|
97
270
|
for child in children:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
271
|
+
child.prepare(reference,viewport_size)
|
|
272
|
+
child.measure()
|
|
273
|
+
if not _reported_full_percent and children.size()>1:
|
|
274
|
+
var main_name: String = ["width","height","depth"][axis]
|
|
275
|
+
for child in children:
|
|
276
|
+
var spec: Dictionary = child.length_specs.get(main_name,{})
|
|
277
|
+
if spec.get("unit","")=="%" and spec.get("value",0)>=100:
|
|
278
|
+
_reported_full_percent = true
|
|
279
|
+
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")
|
|
280
|
+
break
|
|
281
|
+
var items: Array = []
|
|
103
282
|
for child in children:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
283
|
+
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)})
|
|
284
|
+
var policy := alignment.duplicate()
|
|
285
|
+
if center: policy[axis] = "center"
|
|
286
|
+
slots = StackPolicy.slots(items,content,axis,gap,policy)
|
|
287
|
+
for index in range(children.size()):
|
|
288
|
+
var child = children[index]
|
|
289
|
+
var slot: Dictionary = slots[index]
|
|
290
|
+
var next: Vector3 = leading(padding+border)+slot.position+child.length_offset
|
|
110
291
|
if child.offset != next or child.arrange_count == 0:
|
|
111
292
|
child.offset = next
|
|
112
293
|
child.placed.emit(next)
|
|
113
|
-
|
|
114
|
-
|
|
294
|
+
var authority := Vector3.ZERO
|
|
295
|
+
for cross in range(3):
|
|
296
|
+
if cross!=axis and policy[cross]=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
|
|
297
|
+
child.arrange(slot.extent,authority)
|
|
115
298
|
arranged.emit(size)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Sole length grammar, property domains, conversion and dependency contract.
|
|
4
|
+
## Numeric values preserve native units; explicit pixel/reference strings use
|
|
5
|
+
## pixels_per_unit in 3D. Percent uses the containing layout content axis;
|
|
6
|
+
## independent 2D Entries receive their visible viewport as that context.
|
|
7
|
+
const VisualStyle = preload("visual_style_2d.gd")
|
|
8
|
+
const LIMIT := 1.0e12
|
|
9
|
+
const FACTORS := {"":1.0,"px":1.0,"in":96.0,"cm":96.0/2.54,"mm":96.0/25.4,"q":96.0/101.6,"pt":96.0/72.0,"pc":16.0}
|
|
10
|
+
const DIMENSIONS := ["width","height","depth"]
|
|
11
|
+
const BORDER_EDGES := ["border_top_width","border_right_width","border_bottom_width","border_left_width"]
|
|
12
|
+
const OFFSETS := ["x","y","z"]
|
|
13
|
+
const EDGES := ["padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"]
|
|
14
|
+
var specs: Dictionary = {}
|
|
15
|
+
var parse_count := 0
|
|
16
|
+
static func domain(name: String, script = null) -> String:
|
|
17
|
+
if name=="padding" and VisualStyle.marked(script,"ESTRAGON_BUTTON_STYLE"): return "edge"
|
|
18
|
+
if name in DIMENSIONS: return "extent"
|
|
19
|
+
if name=="border_width": return "inset"
|
|
20
|
+
if name in BORDER_EDGES: return "edge"
|
|
21
|
+
if name in OFFSETS: return "offset"
|
|
22
|
+
if name in EDGES: return "edge" if name.contains("_") else "inset"
|
|
23
|
+
return "inset" if name=="gap" else ""
|
|
24
|
+
static func registered(type, name: String) -> bool:
|
|
25
|
+
if domain(name).is_empty() or not type is Script: return false
|
|
26
|
+
if name=="border_width" or name in BORDER_EDGES:
|
|
27
|
+
if not VisualStyle.supported(type): return false
|
|
28
|
+
while type != null:
|
|
29
|
+
# A declared native bridge marker avoids loading either adapter here.
|
|
30
|
+
if type.get_script_constant_map().get("ESTRAGON_LENGTHS",false): return true
|
|
31
|
+
type = type.get_base_script()
|
|
32
|
+
return false
|
|
33
|
+
static func parse(value, kind: String) -> Dictionary:
|
|
34
|
+
if typeof(value) in [TYPE_INT,TYPE_FLOAT]:
|
|
35
|
+
var number := float(value)
|
|
36
|
+
if not is_finite(number) or absf(number)>LIMIT or number<0 and kind!="offset": return {"error":"Expected a finite nonnegative length (negative offsets are allowed)"}
|
|
37
|
+
return {"unit":"native","value":number}
|
|
38
|
+
if not value is String: return {"error":"Length requires int, float or a unit string"}
|
|
39
|
+
var text: String = value.strip_edges()
|
|
40
|
+
if text=="auto":
|
|
41
|
+
return {"unit":"auto","value":0.0} if kind in ["extent","edge"] else {"error":"auto is only valid for dimensions and unset inset edges"}
|
|
42
|
+
# This is a scalar value grammar, never a mixed Gogo/GGX syntax parser.
|
|
43
|
+
var matcher := RegEx.new()
|
|
44
|
+
matcher.compile("^([+-]?(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)(?:[eE][+-]?[0-9]+)?)(px|%|vw|vh|vmin|vmax|in|cm|mm|q|pt|pc)?$")
|
|
45
|
+
var found := matcher.search(text)
|
|
46
|
+
if found==null: return {"error":"Invalid length: use a number, px, %, vw/vh/vmin/vmax, in/cm/mm/q/pt/pc or eligible auto; font units and calc are unsupported"}
|
|
47
|
+
var number := float(found.get_string(1))
|
|
48
|
+
var unit := found.get_string(2)
|
|
49
|
+
if not is_finite(number) or absf(number)>LIMIT or number<0 and kind!="offset": return {"error":"Length is negative, nonfinite or outside the supported range"}
|
|
50
|
+
if FACTORS.has(unit) and absf(number*FACTORS[unit])>LIMIT: return {"error":"Converted length exceeds supported range"}
|
|
51
|
+
return {"unit":unit,"value":number}
|
|
52
|
+
static func valid(value, kind: String) -> bool:
|
|
53
|
+
return not parse(value,kind).has("error")
|
|
54
|
+
func assign(name: String, value, kind: String = "") -> bool:
|
|
55
|
+
var parsed := parse(value,domain(name) if kind.is_empty() else kind)
|
|
56
|
+
parse_count += 1
|
|
57
|
+
if parsed.has("error"):
|
|
58
|
+
push_error("Estragon length '"+name+"': "+parsed.error)
|
|
59
|
+
return false
|
|
60
|
+
specs[name] = parsed
|
|
61
|
+
return true
|
|
62
|
+
static func resolve(spec: Dictionary, reference: float, viewport: Vector2, pixels_per_unit: float = 1.0) -> float:
|
|
63
|
+
var unit: String = spec.unit
|
|
64
|
+
var value: float = spec.value
|
|
65
|
+
if unit=="auto": return -1.0
|
|
66
|
+
if unit=="native": return clampf(value/pixels_per_unit,-LIMIT,LIMIT)
|
|
67
|
+
if unit=="%": return clampf(value*maxf(0,reference)/100.0,-LIMIT,LIMIT)
|
|
68
|
+
var pixels: float
|
|
69
|
+
match unit:
|
|
70
|
+
"vw": pixels = viewport.x*value/100.0
|
|
71
|
+
"vh": pixels = viewport.y*value/100.0
|
|
72
|
+
"vmin": pixels = minf(viewport.x,viewport.y)*value/100.0
|
|
73
|
+
"vmax": pixels = maxf(viewport.x,viewport.y)*value/100.0
|
|
74
|
+
_: pixels = value*FACTORS[unit]
|
|
75
|
+
return clampf(pixels/pixels_per_unit,-LIMIT,LIMIT)
|
|
76
|
+
static func dependencies(specs: Dictionary, stack_axis: int) -> Array:
|
|
77
|
+
var parent_axes := Vector3.ZERO
|
|
78
|
+
var viewport_axes := Vector2.ZERO
|
|
79
|
+
for name in specs:
|
|
80
|
+
var unit: String = specs[name].unit
|
|
81
|
+
if unit=="%":
|
|
82
|
+
if name in ["width","x","margin_left","margin_right","padding_left","padding_right","border_left_width","border_right_width"]: parent_axes.x = 1
|
|
83
|
+
elif name in ["height","y","margin_top","margin_bottom","padding_top","padding_bottom","border_top_width","border_bottom_width"]: parent_axes.y = 1
|
|
84
|
+
elif name in ["depth","z"]: parent_axes.z = 1
|
|
85
|
+
elif name=="gap": parent_axes[stack_axis] = 1
|
|
86
|
+
else: parent_axes = Vector3(1,1,parent_axes.z)
|
|
87
|
+
elif unit=="vw": viewport_axes.x = 1
|
|
88
|
+
elif unit=="vh": viewport_axes.y = 1
|
|
89
|
+
elif unit in ["vmin","vmax"]: viewport_axes = Vector2.ONE
|
|
90
|
+
return [parent_axes,viewport_axes]
|
|
91
|
+
static func properties(names: Array) -> Array[Dictionary]:
|
|
92
|
+
var result: Array[Dictionary] = []
|
|
93
|
+
for name in names: result.append({"name":name,"type":TYPE_NIL,"usage":PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_NIL_IS_VARIANT})
|
|
94
|
+
return result
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://c4qeit8py8f76
|
|
@@ -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,75 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Local values and native paint only. No parent lookup, cascade or Nodes.
|
|
4
|
+
const COLORS := ["background_color","border_color","hover_background_color","pressed_background_color","disabled_background_color","checked_background_color"]
|
|
5
|
+
var colors := {"background_color":Color.TRANSPARENT,"border_color":Color.TRANSPARENT,"hover_background_color":Color("#705a9e"),"pressed_background_color":Color("#302440"),"disabled_background_color":Color("#38343f"),"checked_background_color":Color("#227a60")}
|
|
6
|
+
var parse_count := 0
|
|
7
|
+
var draw_count := 0
|
|
8
|
+
var command_count := 0
|
|
9
|
+
var redraw_count := 0
|
|
10
|
+
static func marked(script, marker: String) -> bool:
|
|
11
|
+
while script is Script:
|
|
12
|
+
if script.get_script_constant_map().get(marker,false): return true
|
|
13
|
+
script = script.get_base_script()
|
|
14
|
+
return false
|
|
15
|
+
static func has_api(script) -> bool:
|
|
16
|
+
while script is Script:
|
|
17
|
+
if script.get_script_constant_map().get("ESTRAGON_VISUAL_STYLE",false): return true
|
|
18
|
+
script = script.get_base_script()
|
|
19
|
+
return false
|
|
20
|
+
static func supported(script) -> bool:
|
|
21
|
+
var current = script
|
|
22
|
+
while current is Script:
|
|
23
|
+
if current.get_script_constant_map().get("ESTRAGON_LEGACY_PAINT",false): return false
|
|
24
|
+
current = current.get_base_script()
|
|
25
|
+
return has_api(script)
|
|
26
|
+
static func property(name: String) -> bool:
|
|
27
|
+
return name in COLORS or name in ["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width"]
|
|
28
|
+
static func registered(script, name: String) -> bool:
|
|
29
|
+
if not supported(script): return false
|
|
30
|
+
if name in ["background_color","border_color"]: return true
|
|
31
|
+
if name=="checked_background_color": return marked(script,"ESTRAGON_TOGGLE_STYLE")
|
|
32
|
+
return name in COLORS and marked(script,"ESTRAGON_BUTTON_STYLE")
|
|
33
|
+
static func rect_conflict(script, names: Array) -> bool:
|
|
34
|
+
return marked(script,"ESTRAGON_RECT_STYLE") and "fill" in names and "background_color" in names
|
|
35
|
+
static func parse_color(value) -> Dictionary:
|
|
36
|
+
if value is Color:
|
|
37
|
+
for channel in [value.r,value.g,value.b,value.a]:
|
|
38
|
+
if not is_finite(channel): return {"error":"Color channels must be finite"}
|
|
39
|
+
return {"color":value}
|
|
40
|
+
if value is String:
|
|
41
|
+
var text: String = value.strip_edges()
|
|
42
|
+
if text=="transparent": return {"color":Color.TRANSPARENT}
|
|
43
|
+
if text.begins_with("#") and text.length() in [4,5,7,9]:
|
|
44
|
+
var valid := true
|
|
45
|
+
for index in range(1,text.length()):
|
|
46
|
+
if not text[index].to_lower() in "0123456789abcdef": valid = false
|
|
47
|
+
if valid: return {"color":Color(text)}
|
|
48
|
+
return {"error":"Color requires a native Color, #rgb/#rgba/#rrggbb/#rrggbbaa or transparent"}
|
|
49
|
+
func assign(name: String, value) -> bool:
|
|
50
|
+
var parsed := parse_color(value)
|
|
51
|
+
parse_count += 1
|
|
52
|
+
if parsed.has("error"):
|
|
53
|
+
push_error("Estragon style '"+name+"': "+parsed.error)
|
|
54
|
+
return false
|
|
55
|
+
colors[name] = parsed.color
|
|
56
|
+
return true
|
|
57
|
+
func _rect(canvas: CanvasItem, rect: Rect2, color: Color) -> void:
|
|
58
|
+
if rect.size.x<=0 or rect.size.y<=0 or color.a<=0: return
|
|
59
|
+
canvas.draw_rect(rect,color)
|
|
60
|
+
command_count += 1
|
|
61
|
+
func paint(canvas: CanvasItem, extent: Vector2, border: Vector4, background: Color) -> void:
|
|
62
|
+
draw_count += 1
|
|
63
|
+
if extent.x<=0 or extent.y<=0: return
|
|
64
|
+
_rect(canvas,Rect2(Vector2.ZERO,extent),background)
|
|
65
|
+
# Filled strips stay inside the border-box, including fractional/huge edges.
|
|
66
|
+
# Top/bottom own the corners; side strips never double-blend those pixels.
|
|
67
|
+
var left := minf(border.x,extent.x)
|
|
68
|
+
var right := minf(border.z,maxf(0,extent.x-left))
|
|
69
|
+
var top := minf(border.y,extent.y)
|
|
70
|
+
var bottom := minf(border.w,maxf(0,extent.y-top))
|
|
71
|
+
var color: Color = colors.border_color
|
|
72
|
+
_rect(canvas,Rect2(0,0,extent.x,top),color)
|
|
73
|
+
_rect(canvas,Rect2(0,extent.y-bottom,extent.x,bottom),color)
|
|
74
|
+
_rect(canvas,Rect2(0,top,left,maxf(0,extent.y-top-bottom)),color)
|
|
75
|
+
_rect(canvas,Rect2(extent.x-right,top,right,maxf(0,extent.y-top-bottom)),color)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://942be491eebf
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
class_name EstragonNative2D
|
|
3
|
-
extends "
|
|
3
|
+
extends "component_2d.gd"
|
|
4
4
|
## C1 bounded native visual participant; allocation never stretches geometry.
|
|
5
|
-
const Bounds = preload("
|
|
5
|
+
const Bounds = preload("internal/native_bounds.gd")
|
|
6
6
|
@export var observe_native: bool = false:
|
|
7
7
|
set(value):
|
|
8
8
|
observe_native = value
|
|
@@ -20,9 +20,9 @@ func _exit_tree() -> void:
|
|
|
20
20
|
func invalidate_native() -> void:
|
|
21
21
|
bounds.invalidate()
|
|
22
22
|
|
|
23
|
-
func
|
|
23
|
+
func _measure_native() -> Vector2:
|
|
24
24
|
var natural: Vector3 = bounds.extent if bounds != null else Vector3.ZERO
|
|
25
|
-
return
|
|
25
|
+
return Vector2(natural.x,natural.y)
|
|
26
26
|
|
|
27
27
|
func apply_layout_position(offset: Vector3) -> void:
|
|
28
28
|
var value: Vector3 = offset - bounds.origin
|
|
@@ -30,7 +30,7 @@ func apply_layout_position(offset: Vector3) -> void:
|
|
|
30
30
|
|
|
31
31
|
func apply_layout_size(size: Vector3) -> void:
|
|
32
32
|
_layout_size = Vector2(size.x, size.y)
|
|
33
|
-
if layout.parent_coordinator() != null:
|
|
33
|
+
if layout.parent_coordinator() != null: layout._place(layout.model.offset)
|
|
34
34
|
layout_applied.emit(_layout_size)
|
|
35
35
|
|
|
36
36
|
func get_native_bounds() -> Rect2:
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
class_name EstragonNative3D
|
|
3
|
-
extends "
|
|
3
|
+
extends "component_3d.gd"
|
|
4
4
|
## C1 bounded native visual participant; allocation never stretches geometry.
|
|
5
|
-
const Bounds = preload("
|
|
5
|
+
const Bounds = preload("internal/native_bounds.gd")
|
|
6
6
|
@export var observe_native: bool = false:
|
|
7
7
|
set(value):
|
|
8
8
|
observe_native = value
|
|
@@ -20,9 +20,9 @@ func _exit_tree() -> void:
|
|
|
20
20
|
func invalidate_native() -> void:
|
|
21
21
|
bounds.invalidate()
|
|
22
22
|
|
|
23
|
-
func
|
|
23
|
+
func _measure_native() -> Vector3:
|
|
24
24
|
var natural: Vector3 = bounds.extent if bounds != null else Vector3.ZERO
|
|
25
|
-
return
|
|
25
|
+
return natural
|
|
26
26
|
|
|
27
27
|
func apply_layout_position(offset: Vector3) -> void:
|
|
28
28
|
var value: Vector3 = offset - bounds.origin
|
|
@@ -30,7 +30,7 @@ func apply_layout_position(offset: Vector3) -> void:
|
|
|
30
30
|
|
|
31
31
|
func apply_layout_size(size: Vector3) -> void:
|
|
32
32
|
_layout_size = size
|
|
33
|
-
if layout.parent_coordinator() != null:
|
|
33
|
+
if layout.parent_coordinator() != null: layout._place(layout.model.offset)
|
|
34
34
|
layout_applied.emit(_layout_size)
|
|
35
35
|
|
|
36
36
|
func get_native_bounds() -> AABB:
|