@papercraftgames/estragon 0.1.0-beta.14 → 0.1.0-beta.17
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/addons/estragon/compiler/validator.gd +31 -2
- package/addons/estragon/editor/completion.gd +6 -1
- package/addons/estragon/editor/components.gd +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/plugin.cfg +1 -1
- package/addons/estragon/editor/scene_inspector.gd +8 -2
- package/addons/estragon/runtime/composition/computation.gd +9 -1
- package/addons/estragon/runtime/composition/layout_host.gd +1 -1
- package/addons/estragon/runtime/node/box.gd +37 -0
- package/addons/estragon/runtime/node/box.gd.uid +1 -0
- package/addons/estragon/runtime/node/component_2d.gd +60 -21
- package/addons/estragon/runtime/node/component_3d.gd +52 -16
- package/addons/estragon/runtime/node/estragon_2d.gd +1 -16
- package/addons/estragon/runtime/node/estragon_3d.gd +0 -15
- package/addons/estragon/runtime/node/hbox.gd +1 -1
- package/addons/estragon/runtime/node/internal/coordinator.gd +13 -11
- package/addons/estragon/runtime/node/internal/layout_core.gd +170 -17
- package/addons/estragon/runtime/node/internal/length.gd +86 -0
- package/addons/estragon/runtime/node/internal/length.gd.uid +1 -0
- package/addons/estragon/runtime/node/native_2d.gd +2 -2
- package/addons/estragon/runtime/node/native_3d.gd +2 -2
- package/addons/estragon/runtime/node/vbox.gd +1 -1
- package/package.json +1 -1
|
@@ -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 Length = preload("../runtime/node/internal/length.gd")
|
|
8
9
|
const Lexer = preload("lexer.gd")
|
|
9
10
|
var file: Source
|
|
10
11
|
var resolver
|
|
@@ -75,14 +76,21 @@ func _component(node: Model.Component) -> void:
|
|
|
75
76
|
return
|
|
76
77
|
index = token.span.end.index
|
|
77
78
|
elif properties.has(name) and name not in ["owner", "script"] and not name.contains("/") and not (int(properties[name].usage) & PROPERTY_USAGE_READ_ONLY):
|
|
78
|
-
attribute.type_name = _native_type(properties[name])
|
|
79
|
+
attribute.type_name = "Variant" if Length.registered(resolved.script,name) else _native_type(properties[name])
|
|
79
80
|
if attribute.type_name.is_empty():
|
|
80
81
|
_error("Unsupported Node property metadata: " + name, attribute.name_span)
|
|
81
82
|
return
|
|
82
83
|
else:
|
|
83
|
-
_error("Unknown, read-only or reserved Node property/signal " + name, attribute.name_span)
|
|
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)
|
|
84
85
|
return
|
|
86
|
+
var is_length := Length.registered(resolved.script,name)
|
|
87
|
+
if is_length:
|
|
88
|
+
_length(attribute,Length.domain(name))
|
|
89
|
+
if not file.diagnostics.is_empty(): return
|
|
85
90
|
if attribute.value is Model.Literal:
|
|
91
|
+
if is_length:
|
|
92
|
+
attribute.value.kind = "string-literal"
|
|
93
|
+
continue
|
|
86
94
|
if attribute.type_name not in ["String", "StringName"]:
|
|
87
95
|
_error("Typed Node values require {GDScript expressions}; only strings may be quoted", attribute.value.span)
|
|
88
96
|
return
|
|
@@ -276,3 +284,24 @@ func _binding(attribute, node, properties: Dictionary, signals: Dictionary) -> v
|
|
|
276
284
|
attribute.kind = "binding"
|
|
277
285
|
attribute.type_name = "Variant"
|
|
278
286
|
attribute.binding_path = names
|
|
287
|
+
|
|
288
|
+
func _length(attribute, domain: String) -> void:
|
|
289
|
+
var value = attribute.value
|
|
290
|
+
if value is Model.Literal:
|
|
291
|
+
var parsed := Length.parse(value.value,domain)
|
|
292
|
+
if parsed.has("error"): _error(parsed.error,value.span)
|
|
293
|
+
return
|
|
294
|
+
var tokens := _expression_tokens(value)
|
|
295
|
+
var text := ""
|
|
296
|
+
if tokens.size()==1: text = tokens[0].text
|
|
297
|
+
elif tokens.size()==2 and tokens[0].text in ["+","-"] and tokens[1].kind=="number": text = tokens[0].text+tokens[1].text
|
|
298
|
+
if tokens.size()==1 and tokens[0].kind=="string":
|
|
299
|
+
var parsed := Length.parse(text.substr(1,text.length()-2).c_unescape(),domain)
|
|
300
|
+
if parsed.has("error"): _error(parsed.error,value.span)
|
|
301
|
+
elif text in ["true","false","null"]:
|
|
302
|
+
_error("Length requires int, float or a unit string",value.span)
|
|
303
|
+
elif text in ["NAN","INF","-INF","+INF"]:
|
|
304
|
+
_error("Length must be finite",value.span)
|
|
305
|
+
elif text.is_valid_float():
|
|
306
|
+
var parsed := Length.parse(float(text),domain)
|
|
307
|
+
if parsed.has("error"): _error(parsed.error,value.span)
|
|
@@ -241,7 +241,12 @@ func _chain(tokens: Array, end: int, row: int, depth: int = 0) -> Dictionary:
|
|
|
241
241
|
return {"start":receiver.start,"value":members[token.text]}
|
|
242
242
|
if token.text=="self": return {"start":end,"value":{"self":true,"row":row}}
|
|
243
243
|
var scope := _scope_members(row)
|
|
244
|
-
if scope.has(token.text):
|
|
244
|
+
if scope.has(token.text):
|
|
245
|
+
# A preload alias is also a const declaration. Its empty value type must
|
|
246
|
+
# not hide the Script receiver; local/typed shadows remain authoritative.
|
|
247
|
+
if _aliases.has(token.text) and scope[token.text].kind == CodeEdit.KIND_CONSTANT and scope[token.text].get("owner","").is_empty() and scope[token.text].get("type","").is_empty():
|
|
248
|
+
return {"start":end,"value":{"type":token.text}}
|
|
249
|
+
return {"start":end,"value":scope[token.text]}
|
|
245
250
|
if ClassDB.class_exists(token.text) or _aliases.has(token.text): return {"start":end,"value":{"type":token.text}}
|
|
246
251
|
return {}
|
|
247
252
|
func _receiver_members(tokens: Array, end: int, row: int) -> Dictionary:
|
|
@@ -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":"Box","canonical":"EstragonBox","script":preload("../runtime/node/box.gd"),"dimension":2,"origin":"native layout"},
|
|
5
6
|
{"alias":"Text","canonical":"EstragonText","script":preload("../runtime/node/text.gd"),"dimension":2,"origin":"native widget"},
|
|
6
7
|
{"alias":"Rect","canonical":"EstragonRect","script":preload("../runtime/node/rect.gd"),"dimension":2,"origin":"native widget"},
|
|
7
8
|
{"alias":"UiButton","canonical":"EstragonButton","script":preload("../runtime/node/button.gd"),"dimension":2,"origin":"native widget"},
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends EditorProperty
|
|
3
|
+
const Length = preload("../runtime/node/internal/length.gd")
|
|
4
|
+
var input := LineEdit.new()
|
|
5
|
+
func _init() -> void:
|
|
6
|
+
input.placeholder_text = "200, 50%, 2.5in, auto"
|
|
7
|
+
add_child(input)
|
|
8
|
+
add_focusable(input)
|
|
9
|
+
input.text_submitted.connect(_submit)
|
|
10
|
+
func _submit(text: String) -> void:
|
|
11
|
+
var name := str(get_edited_property())
|
|
12
|
+
var value: Variant = float(text) if text.is_valid_float() else text
|
|
13
|
+
var parsed := Length.parse(value,Length.domain(name))
|
|
14
|
+
if parsed.has("error"):
|
|
15
|
+
input.tooltip_text = parsed.error
|
|
16
|
+
input.modulate = Color(1,0.5,0.5)
|
|
17
|
+
return
|
|
18
|
+
input.modulate = Color.WHITE
|
|
19
|
+
input.tooltip_text = ""
|
|
20
|
+
emit_changed(get_edited_property(),value)
|
|
21
|
+
func _update_property() -> void:
|
|
22
|
+
input.text = str(get_edited_object().get(get_edited_property()))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://b36hmqsxprn3d
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
extends EditorInspectorPlugin
|
|
3
3
|
## Authored-source presentation alongside the untouched native Script property.
|
|
4
|
+
const Length = preload("../runtime/node/internal/length.gd")
|
|
5
|
+
const LengthProperty = preload("length_property.gd")
|
|
4
6
|
var service: WeakRef
|
|
5
7
|
func _can_handle(object: Object) -> bool:
|
|
6
8
|
var owner = service.get_ref() if service != null else null
|
|
7
|
-
return owner != null and owner.active and object is Node and owner.editable(object)
|
|
9
|
+
return owner != null and owner.active and object is Node and (owner.editable(object) or object.has_method("_get_layout_coordinator"))
|
|
10
|
+
func _parse_property(object: Object, _type: Variant.Type, name: String, _hint: PropertyHint, _hint_text: String, _usage: int, _wide: bool) -> bool:
|
|
11
|
+
if not Length.registered(object.get_script(),name): return false
|
|
12
|
+
add_property_editor(name,LengthProperty.new())
|
|
13
|
+
return true
|
|
8
14
|
func _parse_begin(object: Object) -> void:
|
|
9
15
|
var owner = service.get_ref() if service != null else null
|
|
10
|
-
if owner == null: return
|
|
16
|
+
if owner == null or not owner.editable(object): return
|
|
11
17
|
var panel := VBoxContainer.new()
|
|
12
18
|
panel.name = "GogoSceneComponent"
|
|
13
19
|
var label := Label.new()
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
extends RefCounted
|
|
2
|
+
const Length = preload("../node/internal/length.gd")
|
|
2
3
|
const Profile = preload("profile.tres")
|
|
3
4
|
## F01 computation and retained static-shape records external to native objects.
|
|
4
5
|
const Binding = preload("binding.gd")
|
|
@@ -36,6 +37,7 @@ var moves := 0
|
|
|
36
37
|
var _rendering := false
|
|
37
38
|
var _again := false
|
|
38
39
|
var _consecutive := 0
|
|
40
|
+
var validation_error := ""
|
|
39
41
|
func _init(owner: Node, manager: Resource) -> void:
|
|
40
42
|
host = weakref(owner)
|
|
41
43
|
state = weakref(manager)
|
|
@@ -115,10 +117,11 @@ func _flush() -> void:
|
|
|
115
117
|
if Profile.is_enabled(): Profile.elapsed("view",started)
|
|
116
118
|
_borrow_seen.clear()
|
|
117
119
|
_observes_children = false
|
|
120
|
+
validation_error = ""
|
|
118
121
|
desired = _normalize(desired)
|
|
119
122
|
_rendering = false
|
|
120
123
|
if not desired is Element or not _valid(desired,mounted) or not _preflight(desired,mounted,owner) or not _rescue_clear(desired,mounted,owner):
|
|
121
|
-
push_error("Invalid composition output or foreign boundary conflict; previous tree retained")
|
|
124
|
+
push_error(validation_error if not validation_error.is_empty() else "Invalid composition output or foreign boundary conflict; previous tree retained")
|
|
122
125
|
return
|
|
123
126
|
# A nested array may be an empty get_children() result. Observe native
|
|
124
127
|
# changes without inspecting the expression source or polling the tree.
|
|
@@ -459,6 +462,11 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
459
462
|
for key in desired.properties:
|
|
460
463
|
if not properties.has(key) or key in ["script","owner"] or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return false
|
|
461
464
|
var value = desired.properties[key]
|
|
465
|
+
if Length.registered(desired.type,key):
|
|
466
|
+
var parsed := Length.parse(value,Length.domain(key))
|
|
467
|
+
if parsed.has("error"):
|
|
468
|
+
validation_error = desired.source+": invalid length '"+str(key)+"': "+parsed.error+"; previous tree retained"
|
|
469
|
+
return false
|
|
462
470
|
var kind: int = properties[key].type
|
|
463
471
|
if kind!=TYPE_NIL and typeof(value)!=kind and not (kind==TYPE_FLOAT and typeof(value)==TYPE_INT) and not (kind==TYPE_OBJECT and value==null) and not (kind in [TYPE_STRING,TYPE_STRING_NAME] and typeof(value) in [TYPE_STRING,TYPE_STRING_NAME]): return false
|
|
464
472
|
if kind==TYPE_OBJECT and value!=null:
|
|
@@ -55,4 +55,4 @@ func _configure() -> void:
|
|
|
55
55
|
layout.model.allocation_minimum = target.model.allocation_minimum if included else Vector3.ZERO
|
|
56
56
|
# One child, at zero local offset. Parent places the native host once;
|
|
57
57
|
# root constraints determine both proxy allocation and root allocation.
|
|
58
|
-
layout.model.configure(requested,0,false,0,fills)
|
|
58
|
+
layout.model.configure(requested,0,false,0,fills,Vector3.ZERO,Vector4.ZERO,target.model.margin if included else Vector4.ZERO,true)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
class_name EstragonBox
|
|
3
|
+
extends "component_2d.gd"
|
|
4
|
+
## Constructible horizontal Box. VBox selects the vertical axis.
|
|
5
|
+
var padding: Variant = 0.0:
|
|
6
|
+
set(value):
|
|
7
|
+
if is_same(padding,value) or not lengths.assign("padding",value): return
|
|
8
|
+
padding = value
|
|
9
|
+
_changed()
|
|
10
|
+
var padding_top: Variant = "auto":
|
|
11
|
+
set(value):
|
|
12
|
+
if is_same(padding_top,value) or not lengths.assign("padding_top",value): return
|
|
13
|
+
padding_top = value
|
|
14
|
+
_changed()
|
|
15
|
+
var padding_right: Variant = "auto":
|
|
16
|
+
set(value):
|
|
17
|
+
if is_same(padding_right,value) or not lengths.assign("padding_right",value): return
|
|
18
|
+
padding_right = value
|
|
19
|
+
_changed()
|
|
20
|
+
var padding_bottom: Variant = "auto":
|
|
21
|
+
set(value):
|
|
22
|
+
if is_same(padding_bottom,value) or not lengths.assign("padding_bottom",value): return
|
|
23
|
+
padding_bottom = value
|
|
24
|
+
_changed()
|
|
25
|
+
var padding_left: Variant = "auto":
|
|
26
|
+
set(value):
|
|
27
|
+
if is_same(padding_left,value) or not lengths.assign("padding_left",value): return
|
|
28
|
+
padding_left = value
|
|
29
|
+
_changed()
|
|
30
|
+
func _get_property_list() -> Array[Dictionary]:
|
|
31
|
+
var result: Array[Dictionary] = super._get_property_list()
|
|
32
|
+
result.append_array(Length.properties(["padding","padding_top","padding_right","padding_bottom","padding_left"]))
|
|
33
|
+
return result
|
|
34
|
+
|
|
35
|
+
func _padding_insets() -> Vector4:
|
|
36
|
+
layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
|
|
37
|
+
return layout.model.padding
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://beab4bf1a259
|
|
@@ -4,31 +4,69 @@ extends Node2D
|
|
|
4
4
|
## Native C1 participant. Needs a contiguous same-dimensional chain to an entry.
|
|
5
5
|
signal layout_applied(size: Vector2)
|
|
6
6
|
const Coordinator = preload("internal/coordinator.gd")
|
|
7
|
-
|
|
7
|
+
const ESTRAGON_LENGTHS := true
|
|
8
|
+
const Length = preload("internal/length.gd")
|
|
9
|
+
var lengths = Length.new()
|
|
10
|
+
var width: Variant = "auto":
|
|
8
11
|
set(value):
|
|
9
|
-
if
|
|
12
|
+
if is_same(width,value) or not lengths.assign("width",value): return
|
|
10
13
|
width = value
|
|
11
14
|
_changed()
|
|
12
|
-
|
|
15
|
+
var height: Variant = "auto":
|
|
13
16
|
set(value):
|
|
14
|
-
if
|
|
17
|
+
if is_same(height,value) or not lengths.assign("height",value): return
|
|
15
18
|
height = value
|
|
16
19
|
_changed()
|
|
17
|
-
|
|
20
|
+
var x: Variant = 0.0:
|
|
18
21
|
set(value):
|
|
19
|
-
if
|
|
20
|
-
|
|
22
|
+
if is_same(x,value) or not lengths.assign("x",value): return
|
|
23
|
+
x = value
|
|
21
24
|
_changed()
|
|
22
|
-
|
|
25
|
+
var y: Variant = 0.0:
|
|
23
26
|
set(value):
|
|
24
|
-
if
|
|
25
|
-
|
|
27
|
+
if is_same(y,value) or not lengths.assign("y",value): return
|
|
28
|
+
y = value
|
|
26
29
|
_changed()
|
|
27
|
-
|
|
30
|
+
var gap: Variant = 0.0:
|
|
28
31
|
set(value):
|
|
29
|
-
if
|
|
32
|
+
if is_same(gap,value) or not lengths.assign("gap",value): return
|
|
30
33
|
gap = value
|
|
31
34
|
_changed()
|
|
35
|
+
var margin: Variant = 0.0:
|
|
36
|
+
set(value):
|
|
37
|
+
if is_same(margin,value) or not lengths.assign("margin",value): return
|
|
38
|
+
margin = value
|
|
39
|
+
_changed()
|
|
40
|
+
var margin_top: Variant = "auto":
|
|
41
|
+
set(value):
|
|
42
|
+
if is_same(margin_top,value) or not lengths.assign("margin_top",value): return
|
|
43
|
+
margin_top = value
|
|
44
|
+
_changed()
|
|
45
|
+
var margin_right: Variant = "auto":
|
|
46
|
+
set(value):
|
|
47
|
+
if is_same(margin_right,value) or not lengths.assign("margin_right",value): return
|
|
48
|
+
margin_right = value
|
|
49
|
+
_changed()
|
|
50
|
+
var margin_bottom: Variant = "auto":
|
|
51
|
+
set(value):
|
|
52
|
+
if is_same(margin_bottom,value) or not lengths.assign("margin_bottom",value): return
|
|
53
|
+
margin_bottom = value
|
|
54
|
+
_changed()
|
|
55
|
+
var margin_left: Variant = "auto":
|
|
56
|
+
set(value):
|
|
57
|
+
if is_same(margin_left,value) or not lengths.assign("margin_left",value): return
|
|
58
|
+
margin_left = value
|
|
59
|
+
_changed()
|
|
60
|
+
@export var flex: float = 0.0:
|
|
61
|
+
set(value):
|
|
62
|
+
if not is_finite(value) or value<0 or value==flex: return
|
|
63
|
+
flex = value
|
|
64
|
+
_changed()
|
|
65
|
+
@export_enum("Natural", "Stretch") var stretch: int = 0:
|
|
66
|
+
set(value):
|
|
67
|
+
if value not in [0,1] or value==stretch: return
|
|
68
|
+
stretch = value
|
|
69
|
+
_changed()
|
|
32
70
|
@export var center: bool = false:
|
|
33
71
|
set(value):
|
|
34
72
|
if center == value: return
|
|
@@ -37,11 +75,11 @@ const Coordinator = preload("internal/coordinator.gd")
|
|
|
37
75
|
var layout_size: Vector2:
|
|
38
76
|
get: return _layout_size
|
|
39
77
|
var _layout_size := Vector2.ZERO
|
|
40
|
-
# Internal bridge, deliberately not the public authoring API.
|
|
41
78
|
var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
79
|
+
func _get_property_list() -> Array[Dictionary]:
|
|
80
|
+
return Length.properties(["width","height","x","y","gap","margin","margin_top","margin_right","margin_bottom","margin_left"])
|
|
81
|
+
static func valid_length(value) -> bool:
|
|
82
|
+
return Length.valid(value,"extent")
|
|
45
83
|
|
|
46
84
|
func set_extent(value: Vector2) -> Error:
|
|
47
85
|
for axis in range(2):
|
|
@@ -51,7 +89,7 @@ func set_extent(value: Vector2) -> Error:
|
|
|
51
89
|
return OK
|
|
52
90
|
|
|
53
91
|
func requested_extent() -> Vector3:
|
|
54
|
-
return
|
|
92
|
+
return layout.model.requested
|
|
55
93
|
|
|
56
94
|
func _layout_axis() -> int:
|
|
57
95
|
return 0
|
|
@@ -61,14 +99,11 @@ func _measure_native() -> Vector2:
|
|
|
61
99
|
|
|
62
100
|
func _layout_options() -> Dictionary:
|
|
63
101
|
var natural := _measure_native()
|
|
64
|
-
return {"axis":_layout_axis(),"fill":Vector3
|
|
102
|
+
return {"axis":_layout_axis(),"fill":Vector3.ZERO,"intrinsic":Vector3(natural.x,natural.y,0)}
|
|
65
103
|
|
|
66
104
|
func _is_layout_entry() -> bool:
|
|
67
105
|
return false
|
|
68
106
|
|
|
69
|
-
func _layout_viewport_scale() -> Vector2:
|
|
70
|
-
return Vector2.ZERO
|
|
71
|
-
|
|
72
107
|
func _changed() -> void:
|
|
73
108
|
if layout != null: layout.changed()
|
|
74
109
|
|
|
@@ -103,3 +138,7 @@ func apply_layout_size(size: Vector3) -> void:
|
|
|
103
138
|
# Explicit invalidation also restores a native position edited externally.
|
|
104
139
|
if layout.parent_coordinator() != null: layout._place(layout.model.offset)
|
|
105
140
|
layout_applied.emit(_layout_size)
|
|
141
|
+
|
|
142
|
+
func _margin_insets() -> Vector4:
|
|
143
|
+
layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
|
|
144
|
+
return layout.model.margin
|
|
@@ -4,26 +4,59 @@ extends Node3D
|
|
|
4
4
|
## Native C1 participant. Needs a contiguous same-dimensional chain to an entry.
|
|
5
5
|
signal layout_applied(size: Vector3)
|
|
6
6
|
const Coordinator = preload("internal/coordinator.gd")
|
|
7
|
-
|
|
7
|
+
const ESTRAGON_LENGTHS := true
|
|
8
|
+
const Length = preload("internal/length.gd")
|
|
9
|
+
var lengths = Length.new()
|
|
10
|
+
var width: Variant = "auto":
|
|
8
11
|
set(value):
|
|
9
|
-
if
|
|
12
|
+
if is_same(width,value) or not lengths.assign("width",value): return
|
|
10
13
|
width = value
|
|
11
14
|
_changed()
|
|
12
|
-
|
|
15
|
+
var height: Variant = "auto":
|
|
13
16
|
set(value):
|
|
14
|
-
if
|
|
17
|
+
if is_same(height,value) or not lengths.assign("height",value): return
|
|
15
18
|
height = value
|
|
16
19
|
_changed()
|
|
17
|
-
|
|
20
|
+
var depth: Variant = "auto":
|
|
18
21
|
set(value):
|
|
19
|
-
if
|
|
22
|
+
if is_same(depth,value) or not lengths.assign("depth",value): return
|
|
20
23
|
depth = value
|
|
21
24
|
_changed()
|
|
22
|
-
|
|
25
|
+
var x: Variant = 0.0:
|
|
23
26
|
set(value):
|
|
24
|
-
if
|
|
27
|
+
if is_same(x,value) or not lengths.assign("x",value): return
|
|
28
|
+
x = value
|
|
29
|
+
_changed()
|
|
30
|
+
var y: Variant = 0.0:
|
|
31
|
+
set(value):
|
|
32
|
+
if is_same(y,value) or not lengths.assign("y",value): return
|
|
33
|
+
y = value
|
|
34
|
+
_changed()
|
|
35
|
+
var z: Variant = 0.0:
|
|
36
|
+
set(value):
|
|
37
|
+
if is_same(z,value) or not lengths.assign("z",value): return
|
|
38
|
+
z = value
|
|
39
|
+
_changed()
|
|
40
|
+
var gap: Variant = 0.0:
|
|
41
|
+
set(value):
|
|
42
|
+
if is_same(gap,value) or not lengths.assign("gap",value): return
|
|
25
43
|
gap = value
|
|
26
44
|
_changed()
|
|
45
|
+
@export var flex: float = 0.0:
|
|
46
|
+
set(value):
|
|
47
|
+
if not is_finite(value) or value<0 or value==flex: return
|
|
48
|
+
flex = value
|
|
49
|
+
_changed()
|
|
50
|
+
@export_enum("Natural", "Stretch") var stretch: int = 0:
|
|
51
|
+
set(value):
|
|
52
|
+
if value not in [0,1] or value==stretch: return
|
|
53
|
+
stretch = value
|
|
54
|
+
_changed()
|
|
55
|
+
@export var pixels_per_unit: float = 100.0:
|
|
56
|
+
set(value):
|
|
57
|
+
if not is_finite(value) or value<=0 or pixels_per_unit==value: return
|
|
58
|
+
pixels_per_unit = value
|
|
59
|
+
_changed()
|
|
27
60
|
@export var center: bool = false:
|
|
28
61
|
set(value):
|
|
29
62
|
if center == value: return
|
|
@@ -32,11 +65,11 @@ const Coordinator = preload("internal/coordinator.gd")
|
|
|
32
65
|
var layout_size: Vector3:
|
|
33
66
|
get: return _layout_size
|
|
34
67
|
var _layout_size := Vector3.ZERO
|
|
35
|
-
# Internal bridge, deliberately not the public authoring API.
|
|
36
68
|
var layout = Coordinator.new(self, 3, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
69
|
+
func _get_property_list() -> Array[Dictionary]:
|
|
70
|
+
return Length.properties(["width","height","depth","x","y","z","gap"])
|
|
71
|
+
static func valid_length(value) -> bool:
|
|
72
|
+
return Length.valid(value,"extent")
|
|
40
73
|
|
|
41
74
|
func set_extent(value: Vector3) -> Error:
|
|
42
75
|
for axis in range(3):
|
|
@@ -47,14 +80,17 @@ func set_extent(value: Vector3) -> Error:
|
|
|
47
80
|
return OK
|
|
48
81
|
|
|
49
82
|
func requested_extent() -> Vector3:
|
|
50
|
-
return
|
|
83
|
+
return layout.model.requested
|
|
84
|
+
|
|
85
|
+
func _measure_native() -> Vector3:
|
|
86
|
+
return Vector3.ZERO
|
|
87
|
+
|
|
88
|
+
func _layout_options() -> Dictionary:
|
|
89
|
+
return {"axis":0,"fill":Vector3.ZERO,"intrinsic":_measure_native()}
|
|
51
90
|
|
|
52
91
|
func _is_layout_entry() -> bool:
|
|
53
92
|
return false
|
|
54
93
|
|
|
55
|
-
func _layout_viewport_scale() -> Vector2:
|
|
56
|
-
return Vector2.ZERO
|
|
57
|
-
|
|
58
94
|
func _changed() -> void:
|
|
59
95
|
if layout != null: layout.changed()
|
|
60
96
|
|
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
class_name Estragon2D
|
|
3
|
-
extends "
|
|
3
|
+
extends "box.gd"
|
|
4
4
|
## Explicit independent layout scope; does not assign native scene owner.
|
|
5
|
-
@export var viewport_width_scale: float = 0.0:
|
|
6
|
-
set(value):
|
|
7
|
-
if not is_finite(value) or value < 0 or viewport_width_scale == value: return
|
|
8
|
-
viewport_width_scale = value
|
|
9
|
-
if layout != null: layout._invalidated()
|
|
10
|
-
|
|
11
|
-
@export var viewport_height_scale: float = 0.0:
|
|
12
|
-
set(value):
|
|
13
|
-
if not is_finite(value) or value < 0 or viewport_height_scale == value: return
|
|
14
|
-
viewport_height_scale = value
|
|
15
|
-
if layout != null: layout._invalidated()
|
|
16
|
-
|
|
17
5
|
func _is_layout_entry() -> bool:
|
|
18
6
|
return true
|
|
19
7
|
|
|
20
|
-
func _layout_viewport_scale() -> Vector2:
|
|
21
|
-
return Vector2(viewport_width_scale,viewport_height_scale)
|
|
22
|
-
|
|
23
8
|
const Pointer = preload("internal/pointer_2d.gd")
|
|
24
9
|
var _pointer = Pointer.new(self)
|
|
25
10
|
|
|
@@ -2,20 +2,5 @@
|
|
|
2
2
|
class_name Estragon3D
|
|
3
3
|
extends "component_3d.gd"
|
|
4
4
|
## Explicit independent layout scope; does not assign native scene owner.
|
|
5
|
-
@export var viewport_width_scale: float = 0.0:
|
|
6
|
-
set(value):
|
|
7
|
-
if not is_finite(value) or value < 0 or viewport_width_scale == value: return
|
|
8
|
-
viewport_width_scale = value
|
|
9
|
-
if layout != null: layout._invalidated()
|
|
10
|
-
|
|
11
|
-
@export var viewport_height_scale: float = 0.0:
|
|
12
|
-
set(value):
|
|
13
|
-
if not is_finite(value) or value < 0 or viewport_height_scale == value: return
|
|
14
|
-
viewport_height_scale = value
|
|
15
|
-
if layout != null: layout._invalidated()
|
|
16
|
-
|
|
17
5
|
func _is_layout_entry() -> bool:
|
|
18
6
|
return true
|
|
19
|
-
|
|
20
|
-
func _layout_viewport_scale() -> Vector2:
|
|
21
|
-
return Vector2(viewport_width_scale,viewport_height_scale)
|
|
@@ -16,6 +16,7 @@ var _host: WeakRef
|
|
|
16
16
|
var _dimension: int
|
|
17
17
|
var _queued: bool = false
|
|
18
18
|
var _viewport: Viewport
|
|
19
|
+
var _root_offset := Vector3.ZERO
|
|
19
20
|
|
|
20
21
|
func _init(host: Node, dimension: int, mode: int = Mode.PROOF) -> void:
|
|
21
22
|
_mode = mode
|
|
@@ -62,9 +63,6 @@ func root_host() -> Node:
|
|
|
62
63
|
var found = scope_root()
|
|
63
64
|
return found._host.get_ref() if found != null else null
|
|
64
65
|
|
|
65
|
-
func _viewport_scale(host: Node) -> Vector2:
|
|
66
|
-
return Vector2(host.viewport_width_scale,0) if _mode == Mode.PROOF else host._layout_viewport_scale()
|
|
67
|
-
|
|
68
66
|
func start() -> void:
|
|
69
67
|
active = true
|
|
70
68
|
var host: Node = _host.get_ref()
|
|
@@ -134,14 +132,17 @@ func changed() -> void:
|
|
|
134
132
|
if host == null: return
|
|
135
133
|
if host.has_method("_layout_options"):
|
|
136
134
|
var options: Dictionary = host._layout_options()
|
|
137
|
-
|
|
135
|
+
if "lengths" in host:
|
|
136
|
+
for property in host._get_property_list():
|
|
137
|
+
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.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))
|
|
138
140
|
else: model.configure(host.requested_extent(), host.gap, host.center)
|
|
139
141
|
|
|
140
142
|
func _viewport_changed() -> void:
|
|
141
143
|
var host = _host.get_ref()
|
|
142
144
|
if host == null or parent_coordinator() != null: return
|
|
143
|
-
|
|
144
|
-
if scale.x > 0 or scale.y > 0: _invalidated()
|
|
145
|
+
model.invalidate()
|
|
145
146
|
|
|
146
147
|
func _invalidated() -> void:
|
|
147
148
|
if Profile.is_enabled(): Profile.add("layout_invalidations")
|
|
@@ -156,13 +157,14 @@ func _flush() -> void:
|
|
|
156
157
|
if host == null or host.is_queued_for_deletion(): return
|
|
157
158
|
flush_count += 1
|
|
158
159
|
if Profile.is_enabled(): Profile.add("layout_flushes")
|
|
160
|
+
var visible := _viewport.get_visible_rect().size if _viewport!=null else Vector2.ZERO
|
|
161
|
+
model.prepare(Vector3(-1,-1,-1),visible)
|
|
159
162
|
var available: Vector3 = model.measure()
|
|
160
|
-
if _viewport != null:
|
|
161
|
-
var scale := _viewport_scale(host)
|
|
162
|
-
var visible := _viewport.get_visible_rect().size
|
|
163
|
-
if scale.x > 0: available.x = visible.x * scale.x
|
|
164
|
-
if scale.y > 0: available.y = visible.y * scale.y
|
|
165
163
|
model.arrange(available)
|
|
164
|
+
if host is Node2D:
|
|
165
|
+
host.position += Vector2(model.length_offset.x-_root_offset.x,model.length_offset.y-_root_offset.y)
|
|
166
|
+
elif host is Node3D: host.position += model.length_offset-_root_offset
|
|
167
|
+
_root_offset = model.length_offset
|
|
166
168
|
CompositionHosts.refresh_positions(self)
|
|
167
169
|
|
|
168
170
|
func _place(offset: Vector3) -> void:
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
extends RefCounted
|
|
3
|
+
const Length = preload("length.gd")
|
|
3
4
|
const Profile = preload("../../composition/profile.tres")
|
|
4
5
|
## Shared B2/C1 mathematical row layout. No Nodes, rendering or SceneTree dependencies.
|
|
5
6
|
signal invalidated
|
|
6
7
|
signal placed(offset)
|
|
7
8
|
signal arranged(size)
|
|
9
|
+
var length_specs: Dictionary = {}
|
|
10
|
+
var flex: float = 0.0
|
|
11
|
+
var stretch: int = 0
|
|
12
|
+
var pixels_per_unit: float = 1.0
|
|
13
|
+
var length_offset := Vector3.ZERO
|
|
14
|
+
var viewport_size := Vector2.ZERO
|
|
15
|
+
var parent_reference := Vector3(-1,-1,-1)
|
|
16
|
+
var resolution_count := 0
|
|
17
|
+
var _length_context: Array = []
|
|
18
|
+
var _parent_axes := Vector3.ZERO
|
|
19
|
+
var _viewport_axes := Vector2.ZERO
|
|
20
|
+
var _forward_context: Array = []
|
|
21
|
+
var _reported_unanchored := false
|
|
8
22
|
var requested := Vector3(-1, -1, -1)
|
|
9
23
|
var gap: float = 0.0
|
|
10
24
|
var center: bool = false
|
|
@@ -13,8 +27,14 @@ var fill := Vector3.ZERO
|
|
|
13
27
|
var intrinsic := Vector3.ZERO
|
|
14
28
|
# Native Control minimums constrain assigned slots, never read back from size.
|
|
15
29
|
var allocation_minimum := Vector3.ZERO
|
|
30
|
+
var padding := Vector4.ZERO # left, top, right, bottom; border-box insets
|
|
31
|
+
var margin := Vector4.ZERO # outside own geometry; consumed by the parent
|
|
32
|
+
var transparent: bool = false # composition proxy forwards one root slot
|
|
16
33
|
var children: Array = []
|
|
17
34
|
var measured := Vector3.ZERO
|
|
35
|
+
# -1 is an unavailable/cyclic reference axis, distinct from an arranged zero.
|
|
36
|
+
var content_reference := Vector3(-1,-1,-1)
|
|
37
|
+
var _external_axes := Vector3.ZERO
|
|
18
38
|
var size := Vector3.ZERO
|
|
19
39
|
var offset := Vector3.ZERO
|
|
20
40
|
var measure_count: int = 0
|
|
@@ -23,16 +43,86 @@ var _measure_dirty: bool = true
|
|
|
23
43
|
var _arrange_dirty: bool = true
|
|
24
44
|
var _parent: WeakRef
|
|
25
45
|
|
|
46
|
+
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
|
|
48
|
+
length_specs = specs.duplicate(true)
|
|
49
|
+
flex = growth
|
|
50
|
+
stretch = cross
|
|
51
|
+
pixels_per_unit = scale
|
|
52
|
+
var dependencies := Length.dependencies(length_specs,stack_axis)
|
|
53
|
+
_parent_axes = dependencies[0]
|
|
54
|
+
_viewport_axes = dependencies[1]
|
|
55
|
+
_length_context = []
|
|
56
|
+
invalidate()
|
|
57
|
+
|
|
58
|
+
func _length(name: String, axis_index: int, fallback: float) -> float:
|
|
59
|
+
if not length_specs.has(name): return fallback
|
|
60
|
+
var spec: Dictionary = length_specs[name]
|
|
61
|
+
return Length.resolve(spec,parent_reference[axis_index],viewport_size,pixels_per_unit)
|
|
62
|
+
|
|
63
|
+
func _warn_unanchored() -> void:
|
|
64
|
+
if _reported_unanchored: return
|
|
65
|
+
for index in range(3):
|
|
66
|
+
if _parent_axes[index]>0 and parent_reference[index]<0:
|
|
67
|
+
_reported_unanchored = true
|
|
68
|
+
push_warning("Estragon unanchored/cyclic percentage resolves to zero; give the containing layout axis an independent extent")
|
|
69
|
+
return
|
|
70
|
+
|
|
71
|
+
func _edges(prefix: String) -> Vector4:
|
|
72
|
+
var result := Vector4.ZERO
|
|
73
|
+
var names := ["left","top","right","bottom"]
|
|
74
|
+
for edge in range(4):
|
|
75
|
+
var index: int = edge%2
|
|
76
|
+
var value := _length(prefix+"_"+names[edge],index,-1)
|
|
77
|
+
result[edge] = _length(prefix,index,0) if value<0 else value
|
|
78
|
+
return result
|
|
79
|
+
|
|
80
|
+
# Resolve specs only on a changed parent/viewport/spec context. No property
|
|
81
|
+
# writeback, parsing in arrange, subscriptions per length, or frame polling.
|
|
82
|
+
func prepare(reference: Vector3, viewport: Vector2) -> void:
|
|
83
|
+
if transparent and _forward_context!=[reference,viewport] or viewport_size!=viewport and not children.is_empty():
|
|
84
|
+
_measure_dirty = true
|
|
85
|
+
_arrange_dirty = true
|
|
86
|
+
_forward_context = [reference,viewport] if transparent else []
|
|
87
|
+
parent_reference = reference
|
|
88
|
+
viewport_size = viewport
|
|
89
|
+
var context := [reference*_parent_axes,viewport*_viewport_axes]
|
|
90
|
+
if _length_context==context: return
|
|
91
|
+
_length_context = context
|
|
92
|
+
resolution_count += 1
|
|
93
|
+
var before := [requested,gap,padding,margin,length_offset]
|
|
94
|
+
if not length_specs.is_empty():
|
|
95
|
+
for index in range(3):
|
|
96
|
+
requested[index] = _length(["width","height","depth"][index],index,requested[index])
|
|
97
|
+
length_offset[index] = _length(["x","y","z"][index],index,0)
|
|
98
|
+
gap = _length("gap",axis,0)
|
|
99
|
+
padding = _edges("padding")
|
|
100
|
+
margin = _edges("margin")
|
|
101
|
+
if before!=[requested,gap,padding,margin,length_offset]:
|
|
102
|
+
_measure_dirty = true
|
|
103
|
+
_arrange_dirty = true
|
|
104
|
+
|
|
105
|
+
func _content_basis() -> Vector3:
|
|
106
|
+
var basis := Vector3(-1,-1,-1)
|
|
107
|
+
for index in range(3):
|
|
108
|
+
if requested[index]>=0: basis[index] = maxf(0,requested[index]-leading(padding)[index]-trailing(padding)[index])
|
|
109
|
+
return basis
|
|
110
|
+
|
|
26
111
|
static func valid_extent(value: Vector3) -> bool:
|
|
27
112
|
for axis in range(3):
|
|
28
113
|
if not is_finite(value[axis]) or value[axis] < 0 and value[axis] != -1: return false
|
|
29
114
|
return true
|
|
30
115
|
|
|
31
|
-
func configure(extent: Vector3, spacing: float, centered: bool, stack_axis: int = 0, fills: Vector3 = Vector3.ZERO, content: Vector3 = Vector3.ZERO) -> Error:
|
|
116
|
+
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:
|
|
32
117
|
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
|
|
33
118
|
for index in range(3):
|
|
34
119
|
if fills[index] not in [0.0,1.0] or not is_finite(content[index]) or content[index] < 0: return ERR_INVALID_PARAMETER
|
|
35
|
-
|
|
120
|
+
for edge in range(4):
|
|
121
|
+
if not is_finite(inner[edge]) or inner[edge] < 0 or not is_finite(outer[edge]) or outer[edge] < 0: return ERR_INVALID_PARAMETER
|
|
122
|
+
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
|
|
123
|
+
padding = inner
|
|
124
|
+
margin = outer
|
|
125
|
+
transparent = passthrough
|
|
36
126
|
axis = stack_axis
|
|
37
127
|
fill = fills
|
|
38
128
|
intrinsic = content
|
|
@@ -54,9 +144,11 @@ func set_children(values: Array) -> Error:
|
|
|
54
144
|
seen.append(child)
|
|
55
145
|
if children == values: return OK
|
|
56
146
|
for child in children:
|
|
57
|
-
if not values.has(child):
|
|
147
|
+
if not values.has(child):
|
|
148
|
+
child._parent = null
|
|
58
149
|
children = values.duplicate()
|
|
59
|
-
for child in children:
|
|
150
|
+
for child in children:
|
|
151
|
+
child._parent = weakref(self)
|
|
60
152
|
invalidate()
|
|
61
153
|
return OK
|
|
62
154
|
|
|
@@ -67,26 +159,65 @@ func invalidate() -> void:
|
|
|
67
159
|
if parent != null: parent.invalidate()
|
|
68
160
|
invalidated.emit()
|
|
69
161
|
|
|
162
|
+
static func leading(edges: Vector4) -> Vector3:
|
|
163
|
+
return Vector3(edges.x,edges.y,0)
|
|
164
|
+
static func trailing(edges: Vector4) -> Vector3:
|
|
165
|
+
return Vector3(edges.z,edges.w,0)
|
|
166
|
+
func outer_extent() -> Vector3:
|
|
167
|
+
return leading(margin)+trailing(margin)
|
|
168
|
+
|
|
70
169
|
func measure() -> Vector3:
|
|
170
|
+
if transparent and children.size()==1:
|
|
171
|
+
var child = children[0]
|
|
172
|
+
child.prepare(parent_reference,viewport_size)
|
|
173
|
+
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:
|
|
175
|
+
requested = child.requested
|
|
176
|
+
flex = child.flex
|
|
177
|
+
stretch = child.stretch
|
|
178
|
+
fill = child.fill
|
|
179
|
+
margin = child.margin
|
|
180
|
+
length_offset = child.length_offset
|
|
181
|
+
_measure_dirty = true
|
|
71
182
|
if not _measure_dirty: return measured
|
|
72
183
|
measure_count += 1
|
|
73
184
|
if Profile.is_enabled(): Profile.add("layout_measures")
|
|
74
185
|
var natural := Vector3.ZERO
|
|
75
186
|
for child in children:
|
|
187
|
+
if not transparent: child.prepare(_content_basis(),viewport_size)
|
|
76
188
|
var child_size: Vector3 = child.measure()
|
|
189
|
+
if not transparent: child_size += child.outer_extent()
|
|
77
190
|
for index in range(3):
|
|
78
191
|
if index == axis: natural[index] += child_size[index]
|
|
79
192
|
else: natural[index] = maxf(natural[index],child_size[index])
|
|
80
193
|
if children.size() > 1: natural[axis] += gap * (children.size() - 1)
|
|
81
194
|
for index in range(3): natural[index] = maxf(natural[index],intrinsic[index])
|
|
195
|
+
if not transparent: natural += leading(padding)+trailing(padding)
|
|
82
196
|
measured = natural
|
|
83
197
|
for axis in range(3):
|
|
84
198
|
if requested[axis] >= 0: measured[axis] = requested[axis]
|
|
85
199
|
_measure_dirty = false
|
|
86
200
|
return measured
|
|
87
201
|
|
|
88
|
-
|
|
89
|
-
|
|
202
|
+
# An auto axis cannot be a reference to its own descendants. Fill allocations
|
|
203
|
+
# ignore this model's intrinsic extent and can inherit an independent basis.
|
|
204
|
+
func independent_axis(index: int) -> bool:
|
|
205
|
+
if requested[index] >= 0 or _external_axes[index] > 0: return true
|
|
206
|
+
var parent = _parent.get_ref() if _parent != null else null
|
|
207
|
+
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
|
|
209
|
+
|
|
210
|
+
func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
211
|
+
_external_axes = external_axes
|
|
212
|
+
_warn_unanchored()
|
|
213
|
+
var content := available-leading(padding)-trailing(padding)
|
|
214
|
+
var reference := Vector3(-1,-1,-1)
|
|
215
|
+
for index in range(3):
|
|
216
|
+
content[index] = maxf(0,content[index])
|
|
217
|
+
if independent_axis(index): reference[index] = content[index]
|
|
218
|
+
var changed: bool = reference != content_reference
|
|
219
|
+
if not _arrange_dirty and size == available and not changed: return
|
|
220
|
+
content_reference = reference
|
|
90
221
|
measure()
|
|
91
222
|
arrange_count += 1
|
|
92
223
|
if Profile.is_enabled(): Profile.add("layout_arranges")
|
|
@@ -94,41 +225,63 @@ func arrange(available: Vector3) -> void:
|
|
|
94
225
|
# Clear before callbacks so a signal-triggered change queues a genuine
|
|
95
226
|
# follow-up instead of being overwritten when this pass finishes.
|
|
96
227
|
_arrange_dirty = false
|
|
228
|
+
if transparent:
|
|
229
|
+
for child in children:
|
|
230
|
+
if child.offset != Vector3.ZERO or child.arrange_count == 0:
|
|
231
|
+
child.offset = Vector3.ZERO
|
|
232
|
+
child.placed.emit(Vector3.ZERO)
|
|
233
|
+
child.viewport_size = viewport_size
|
|
234
|
+
# Forward actual allocation authority through transparent hosts. Their
|
|
235
|
+
# internal X axis must not reinterpret the outer Box's flex axis.
|
|
236
|
+
var authority := Vector3.ZERO
|
|
237
|
+
for index in range(3):
|
|
238
|
+
if independent_axis(index): authority[index] = 1
|
|
239
|
+
child.arrange(available,authority)
|
|
240
|
+
arranged.emit(size)
|
|
241
|
+
return
|
|
242
|
+
# Assigned content is authoritative, including flex allocations. Resolve the
|
|
243
|
+
# immediate children against this box before measuring their slots.
|
|
244
|
+
for child in children:
|
|
245
|
+
child.prepare(reference,viewport_size)
|
|
246
|
+
child.measure()
|
|
97
247
|
var fixed: float = gap * maxi(0, children.size() - 1)
|
|
98
248
|
var flexible: Array = []
|
|
99
249
|
for child in children:
|
|
100
|
-
|
|
250
|
+
fixed += child.outer_extent()[axis]
|
|
251
|
+
if (child.flex>0 or child.fill[axis]>0) and child.requested[axis] < 0: flexible.append(child)
|
|
101
252
|
else: fixed += child.measured[axis]
|
|
102
|
-
var remaining: float = maxf(0,
|
|
253
|
+
var remaining: float = maxf(0,content[axis] - fixed)
|
|
103
254
|
var shares: Dictionary = {}
|
|
104
255
|
# Reserve constrained native minimums, then share the remaining space.
|
|
105
256
|
# Zero floors preserve the existing equal-share Box behavior.
|
|
106
257
|
while not flexible.is_empty():
|
|
107
|
-
var
|
|
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
|
|
108
261
|
var constrained := false
|
|
109
262
|
for child in flexible.duplicate():
|
|
110
|
-
if child.allocation_minimum[axis] > share:
|
|
263
|
+
if child.allocation_minimum[axis] > share*(child.flex if child.flex>0 else 1.0):
|
|
111
264
|
shares[child] = child.allocation_minimum[axis]
|
|
112
265
|
remaining = maxf(0,remaining-child.allocation_minimum[axis])
|
|
113
266
|
flexible.erase(child)
|
|
114
267
|
constrained = true
|
|
115
268
|
if not constrained:
|
|
116
|
-
for child in flexible: shares[child] = share
|
|
269
|
+
for child in flexible: shares[child] = share*(child.flex if child.flex>0 else 1.0)
|
|
117
270
|
break
|
|
118
271
|
var row_extent: float = fixed
|
|
119
272
|
for share in shares.values(): row_extent += share
|
|
120
|
-
var cursor: float = (
|
|
273
|
+
var cursor: float = (content[axis] - row_extent) * 0.5 if center else 0.0
|
|
121
274
|
for child in children:
|
|
122
275
|
var allocation: Vector3 = child.measured
|
|
123
276
|
for index in range(3):
|
|
124
|
-
if child.fill[index] > 0 and child.requested[index] < 0:
|
|
125
|
-
allocation[index] = shares[child] if index == axis else
|
|
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])
|
|
126
279
|
allocation[index] = maxf(allocation[index],child.allocation_minimum[index])
|
|
127
|
-
var next
|
|
128
|
-
next[axis]
|
|
280
|
+
var next: Vector3 = leading(padding)+leading(child.margin)+child.length_offset
|
|
281
|
+
next[axis] += cursor
|
|
129
282
|
if child.offset != next or child.arrange_count == 0:
|
|
130
283
|
child.offset = next
|
|
131
284
|
child.placed.emit(next)
|
|
132
285
|
child.arrange(allocation)
|
|
133
|
-
cursor += allocation[axis] + gap
|
|
286
|
+
cursor += allocation[axis] + child.outer_extent()[axis] + gap
|
|
134
287
|
arranged.emit(size)
|
|
@@ -0,0 +1,86 @@
|
|
|
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 always uses an immediate layout content axis.
|
|
6
|
+
const LIMIT := 1.0e12
|
|
7
|
+
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}
|
|
8
|
+
const DIMENSIONS := ["width","height","depth"]
|
|
9
|
+
const OFFSETS := ["x","y","z"]
|
|
10
|
+
const EDGES := ["padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"]
|
|
11
|
+
var specs: Dictionary = {}
|
|
12
|
+
var parse_count := 0
|
|
13
|
+
static func domain(name: String) -> String:
|
|
14
|
+
if name in DIMENSIONS: return "extent"
|
|
15
|
+
if name in OFFSETS: return "offset"
|
|
16
|
+
if name in EDGES: return "edge" if name.contains("_") else "inset"
|
|
17
|
+
return "inset" if name=="gap" else ""
|
|
18
|
+
static func registered(type, name: String) -> bool:
|
|
19
|
+
if domain(name).is_empty() or not type is Script: return false
|
|
20
|
+
while type != null:
|
|
21
|
+
# A declared native bridge marker avoids loading either adapter here.
|
|
22
|
+
if type.get_script_constant_map().get("ESTRAGON_LENGTHS",false): return true
|
|
23
|
+
type = type.get_base_script()
|
|
24
|
+
return false
|
|
25
|
+
static func parse(value, kind: String) -> Dictionary:
|
|
26
|
+
if typeof(value) in [TYPE_INT,TYPE_FLOAT]:
|
|
27
|
+
var number := float(value)
|
|
28
|
+
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)"}
|
|
29
|
+
return {"unit":"native","value":number}
|
|
30
|
+
if not value is String: return {"error":"Length requires int, float or a unit string"}
|
|
31
|
+
var text: String = value.strip_edges()
|
|
32
|
+
if text=="auto":
|
|
33
|
+
return {"unit":"auto","value":0.0} if kind in ["extent","edge"] else {"error":"auto is only valid for dimensions and unset inset edges"}
|
|
34
|
+
# This is a scalar value grammar, never a mixed Gogo/GGX syntax parser.
|
|
35
|
+
var matcher := RegEx.new()
|
|
36
|
+
matcher.compile("^([+-]?(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)(?:[eE][+-]?[0-9]+)?)(px|%|vw|vh|vmin|vmax|in|cm|mm|q|pt|pc)?$")
|
|
37
|
+
var found := matcher.search(text)
|
|
38
|
+
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"}
|
|
39
|
+
var number := float(found.get_string(1))
|
|
40
|
+
var unit := found.get_string(2)
|
|
41
|
+
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"}
|
|
42
|
+
if FACTORS.has(unit) and absf(number*FACTORS[unit])>LIMIT: return {"error":"Converted length exceeds supported range"}
|
|
43
|
+
return {"unit":unit,"value":number}
|
|
44
|
+
static func valid(value, kind: String) -> bool:
|
|
45
|
+
return not parse(value,kind).has("error")
|
|
46
|
+
func assign(name: String, value) -> bool:
|
|
47
|
+
var parsed := parse(value,domain(name))
|
|
48
|
+
parse_count += 1
|
|
49
|
+
if parsed.has("error"):
|
|
50
|
+
push_error("Estragon length '"+name+"': "+parsed.error)
|
|
51
|
+
return false
|
|
52
|
+
specs[name] = parsed
|
|
53
|
+
return true
|
|
54
|
+
static func resolve(spec: Dictionary, reference: float, viewport: Vector2, pixels_per_unit: float = 1.0) -> float:
|
|
55
|
+
var unit: String = spec.unit
|
|
56
|
+
var value: float = spec.value
|
|
57
|
+
if unit=="auto": return -1.0
|
|
58
|
+
if unit=="native": return clampf(value/pixels_per_unit,-LIMIT,LIMIT)
|
|
59
|
+
if unit=="%": return clampf(value*maxf(0,reference)/100.0,-LIMIT,LIMIT)
|
|
60
|
+
var pixels: float
|
|
61
|
+
match unit:
|
|
62
|
+
"vw": pixels = viewport.x*value/100.0
|
|
63
|
+
"vh": pixels = viewport.y*value/100.0
|
|
64
|
+
"vmin": pixels = minf(viewport.x,viewport.y)*value/100.0
|
|
65
|
+
"vmax": pixels = maxf(viewport.x,viewport.y)*value/100.0
|
|
66
|
+
_: pixels = value*FACTORS[unit]
|
|
67
|
+
return clampf(pixels/pixels_per_unit,-LIMIT,LIMIT)
|
|
68
|
+
static func dependencies(specs: Dictionary, stack_axis: int) -> Array:
|
|
69
|
+
var parent_axes := Vector3.ZERO
|
|
70
|
+
var viewport_axes := Vector2.ZERO
|
|
71
|
+
for name in specs:
|
|
72
|
+
var unit: String = specs[name].unit
|
|
73
|
+
if unit=="%":
|
|
74
|
+
if name in ["width","x","margin_left","margin_right","padding_left","padding_right"]: parent_axes.x = 1
|
|
75
|
+
elif name in ["height","y","margin_top","margin_bottom","padding_top","padding_bottom"]: parent_axes.y = 1
|
|
76
|
+
elif name in ["depth","z"]: parent_axes.z = 1
|
|
77
|
+
elif name=="gap": parent_axes[stack_axis] = 1
|
|
78
|
+
else: parent_axes = Vector3(1,1,parent_axes.z)
|
|
79
|
+
elif unit=="vw": viewport_axes.x = 1
|
|
80
|
+
elif unit=="vh": viewport_axes.y = 1
|
|
81
|
+
elif unit in ["vmin","vmax"]: viewport_axes = Vector2.ONE
|
|
82
|
+
return [parent_axes,viewport_axes]
|
|
83
|
+
static func properties(names: Array) -> Array[Dictionary]:
|
|
84
|
+
var result: Array[Dictionary] = []
|
|
85
|
+
for name in names: result.append({"name":name,"type":TYPE_NIL,"usage":PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_NIL_IS_VARIANT})
|
|
86
|
+
return result
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://c4qeit8py8f76
|
|
@@ -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
|
|
@@ -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
|
package/package.json
CHANGED