@papercraftgames/estragon 0.1.0-beta.15 → 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/emitter.gd +1 -1
- package/addons/estragon/compiler/validator.gd +22 -16
- package/addons/estragon/editor/components.gd +0 -1
- 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 +10 -5
- package/addons/estragon/runtime/composition/state.gd +1 -7
- package/addons/estragon/runtime/node/box.gd +16 -17
- package/addons/estragon/runtime/node/component_2d.gd +54 -45
- package/addons/estragon/runtime/node/component_3d.gd +52 -16
- package/addons/estragon/runtime/node/estragon_2d.gd +0 -15
- package/addons/estragon/runtime/node/estragon_3d.gd +0 -15
- package/addons/estragon/runtime/node/internal/coordinator.gd +14 -17
- package/addons/estragon/runtime/node/internal/layout_core.gd +115 -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/package.json +1 -1
- package/addons/estragon/runtime/composition/pixels.gd +0 -38
- package/addons/estragon/runtime/composition/pixels.gd.uid +0 -1
- package/addons/estragon/runtime/node/internal/pixel_contract.gd +0 -20
- package/addons/estragon/runtime/node/internal/pixel_contract.gd.uid +0 -1
|
@@ -86,7 +86,7 @@ static func _string(value: String) -> String:
|
|
|
86
86
|
return output + '"'
|
|
87
87
|
|
|
88
88
|
static func literal(value: Model.Literal) -> String:
|
|
89
|
-
return
|
|
89
|
+
return _string(value.value)
|
|
90
90
|
|
|
91
91
|
func _argument(expression: Model.GdExpression, type_name: String, factory: Factory) -> void:
|
|
92
92
|
var argument := Argument.new()
|
|
@@ -5,7 +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
|
|
8
|
+
const Length = preload("../runtime/node/internal/length.gd")
|
|
9
9
|
const Lexer = preload("lexer.gd")
|
|
10
10
|
var file: Source
|
|
11
11
|
var resolver
|
|
@@ -76,19 +76,21 @@ func _component(node: Model.Component) -> void:
|
|
|
76
76
|
return
|
|
77
77
|
index = token.span.end.index
|
|
78
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):
|
|
79
|
-
attribute.type_name = _native_type(properties[name])
|
|
79
|
+
attribute.type_name = "Variant" if Length.registered(resolved.script,name) else _native_type(properties[name])
|
|
80
80
|
if attribute.type_name.is_empty():
|
|
81
81
|
_error("Unsupported Node property metadata: " + name, attribute.name_span)
|
|
82
82
|
return
|
|
83
83
|
else:
|
|
84
|
-
_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)
|
|
85
85
|
return
|
|
86
|
-
var
|
|
87
|
-
if
|
|
88
|
-
|
|
86
|
+
var is_length := Length.registered(resolved.script,name)
|
|
87
|
+
if is_length:
|
|
88
|
+
_length(attribute,Length.domain(name))
|
|
89
89
|
if not file.diagnostics.is_empty(): return
|
|
90
90
|
if attribute.value is Model.Literal:
|
|
91
|
-
if
|
|
91
|
+
if is_length:
|
|
92
|
+
attribute.value.kind = "string-literal"
|
|
93
|
+
continue
|
|
92
94
|
if attribute.type_name not in ["String", "StringName"]:
|
|
93
95
|
_error("Typed Node values require {GDScript expressions}; only strings may be quoted", attribute.value.span)
|
|
94
96
|
return
|
|
@@ -283,19 +285,23 @@ func _binding(attribute, node, properties: Dictionary, signals: Dictionary) -> v
|
|
|
283
285
|
attribute.type_name = "Variant"
|
|
284
286
|
attribute.binding_path = names
|
|
285
287
|
|
|
286
|
-
func
|
|
288
|
+
func _length(attribute, domain: String) -> void:
|
|
287
289
|
var value = attribute.value
|
|
288
290
|
if value is Model.Literal:
|
|
289
|
-
var
|
|
290
|
-
if
|
|
291
|
-
value.value = -1.0 if text == "auto" else float(text)
|
|
292
|
-
value.kind = "pixel-literal"
|
|
293
|
-
return
|
|
294
|
-
_error("Pixel lengths require finite nonnegative numbers; only width/height allow quoted numbers or auto",value.span)
|
|
291
|
+
var parsed := Length.parse(value.value,domain)
|
|
292
|
+
if parsed.has("error"): _error(parsed.error,value.span)
|
|
295
293
|
return
|
|
296
294
|
var tokens := _expression_tokens(value)
|
|
297
295
|
var text := ""
|
|
298
296
|
if tokens.size()==1: text = tokens[0].text
|
|
299
297
|
elif tokens.size()==2 and tokens[0].text in ["+","-"] and tokens[1].kind=="number": text = tokens[0].text+tokens[1].text
|
|
300
|
-
if
|
|
301
|
-
|
|
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)
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
extends RefCounted
|
|
3
3
|
## Trusted installed resources, not guessed global classes or installation roots.
|
|
4
4
|
const ITEMS := [
|
|
5
|
-
{"alias":"Pixels","canonical":"EstragonPixels","script":preload("../runtime/composition/pixels.gd"),"dimension":0,"origin":"observed pixel helper"},
|
|
6
5
|
{"alias":"Box","canonical":"EstragonBox","script":preload("../runtime/node/box.gd"),"dimension":2,"origin":"native layout"},
|
|
7
6
|
{"alias":"Text","canonical":"EstragonText","script":preload("../runtime/node/text.gd"),"dimension":2,"origin":"native widget"},
|
|
8
7
|
{"alias":"Rect","canonical":"EstragonRect","script":preload("../runtime/node/rect.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,5 +1,5 @@
|
|
|
1
1
|
extends RefCounted
|
|
2
|
-
const
|
|
2
|
+
const Length = preload("../node/internal/length.gd")
|
|
3
3
|
const Profile = preload("profile.tres")
|
|
4
4
|
## F01 computation and retained static-shape records external to native objects.
|
|
5
5
|
const Binding = preload("binding.gd")
|
|
@@ -37,6 +37,7 @@ var moves := 0
|
|
|
37
37
|
var _rendering := false
|
|
38
38
|
var _again := false
|
|
39
39
|
var _consecutive := 0
|
|
40
|
+
var validation_error := ""
|
|
40
41
|
func _init(owner: Node, manager: Resource) -> void:
|
|
41
42
|
host = weakref(owner)
|
|
42
43
|
state = weakref(manager)
|
|
@@ -110,16 +111,17 @@ func _flush() -> void:
|
|
|
110
111
|
if Profile.is_enabled(): Profile.add("views")
|
|
111
112
|
_rendering = true
|
|
112
113
|
_again = false
|
|
113
|
-
manager.begin(
|
|
114
|
+
manager.begin()
|
|
114
115
|
var desired = owner.call("build_view")
|
|
115
116
|
var reads: Dictionary = manager.finish()
|
|
116
117
|
if Profile.is_enabled(): Profile.elapsed("view",started)
|
|
117
118
|
_borrow_seen.clear()
|
|
118
119
|
_observes_children = false
|
|
120
|
+
validation_error = ""
|
|
119
121
|
desired = _normalize(desired)
|
|
120
122
|
_rendering = false
|
|
121
123
|
if not desired is Element or not _valid(desired,mounted) or not _preflight(desired,mounted,owner) or not _rescue_clear(desired,mounted,owner):
|
|
122
|
-
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")
|
|
123
125
|
return
|
|
124
126
|
# A nested array may be an empty get_children() result. Observe native
|
|
125
127
|
# changes without inspecting the expression source or polling the tree.
|
|
@@ -460,8 +462,11 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
460
462
|
for key in desired.properties:
|
|
461
463
|
if not properties.has(key) or key in ["script","owner"] or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return false
|
|
462
464
|
var value = desired.properties[key]
|
|
463
|
-
|
|
464
|
-
|
|
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
|
|
465
470
|
var kind: int = properties[key].type
|
|
466
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
|
|
467
472
|
if kind==TYPE_OBJECT and value!=null:
|
|
@@ -3,7 +3,6 @@ extends Resource
|
|
|
3
3
|
const Profile = preload("profile.tres")
|
|
4
4
|
## Framework-owned shared scope stack; never stored on application objects.
|
|
5
5
|
var scopes: Array = []
|
|
6
|
-
var composing_hosts: Array = []
|
|
7
6
|
var records: Dictionary = {}
|
|
8
7
|
var managed: Dictionary = {}
|
|
9
8
|
var dirty: Array = []
|
|
@@ -40,19 +39,14 @@ func drain() -> void:
|
|
|
40
39
|
break
|
|
41
40
|
flushing = false
|
|
42
41
|
if Profile.is_enabled() and passes>0: Profile.elapsed("drain",started)
|
|
43
|
-
func begin(
|
|
42
|
+
func begin() -> void:
|
|
44
43
|
scopes.append({})
|
|
45
|
-
composing_hosts.append(weakref(host) if host != null else null)
|
|
46
|
-
func current_host() -> Node:
|
|
47
|
-
if composing_hosts.is_empty() or composing_hosts.back() == null: return null
|
|
48
|
-
return composing_hosts.back().get_ref()
|
|
49
44
|
func observe(source: Object, event: StringName) -> void:
|
|
50
45
|
if scopes.is_empty(): return
|
|
51
46
|
if Profile.is_enabled(): Profile.add("getter_reads")
|
|
52
47
|
var key := str(source.get_instance_id())+":"+str(event)
|
|
53
48
|
scopes.back()[key] = [weakref(source),event]
|
|
54
49
|
func finish() -> Dictionary:
|
|
55
|
-
composing_hosts.pop_back()
|
|
56
50
|
return scopes.pop_back()
|
|
57
51
|
func lifecycle(host: Node, what: int) -> void:
|
|
58
52
|
if Engine.is_editor_hint(): return
|
|
@@ -2,37 +2,36 @@
|
|
|
2
2
|
class_name EstragonBox
|
|
3
3
|
extends "component_2d.gd"
|
|
4
4
|
## Constructible horizontal Box. VBox selects the vertical axis.
|
|
5
|
-
|
|
6
|
-
@export var padding: float = 0.0:
|
|
5
|
+
var padding: Variant = 0.0:
|
|
7
6
|
set(value):
|
|
8
|
-
if
|
|
7
|
+
if is_same(padding,value) or not lengths.assign("padding",value): return
|
|
9
8
|
padding = value
|
|
10
9
|
_changed()
|
|
11
|
-
|
|
10
|
+
var padding_top: Variant = "auto":
|
|
12
11
|
set(value):
|
|
13
|
-
if
|
|
12
|
+
if is_same(padding_top,value) or not lengths.assign("padding_top",value): return
|
|
14
13
|
padding_top = value
|
|
15
14
|
_changed()
|
|
16
|
-
|
|
15
|
+
var padding_right: Variant = "auto":
|
|
17
16
|
set(value):
|
|
18
|
-
if
|
|
17
|
+
if is_same(padding_right,value) or not lengths.assign("padding_right",value): return
|
|
19
18
|
padding_right = value
|
|
20
19
|
_changed()
|
|
21
|
-
|
|
20
|
+
var padding_bottom: Variant = "auto":
|
|
22
21
|
set(value):
|
|
23
|
-
if
|
|
22
|
+
if is_same(padding_bottom,value) or not lengths.assign("padding_bottom",value): return
|
|
24
23
|
padding_bottom = value
|
|
25
24
|
_changed()
|
|
26
|
-
|
|
25
|
+
var padding_left: Variant = "auto":
|
|
27
26
|
set(value):
|
|
28
|
-
if
|
|
27
|
+
if is_same(padding_left,value) or not lengths.assign("padding_left",value): return
|
|
29
28
|
padding_left = value
|
|
30
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
|
|
31
34
|
|
|
32
35
|
func _padding_insets() -> Vector4:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
func _layout_options() -> Dictionary:
|
|
36
|
-
var options := super._layout_options()
|
|
37
|
-
options.padding = _padding_insets()
|
|
38
|
-
return options
|
|
36
|
+
layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
|
|
37
|
+
return layout.model.padding
|
|
@@ -4,74 +4,82 @@ 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()
|
|
32
|
-
|
|
35
|
+
var margin: Variant = 0.0:
|
|
33
36
|
set(value):
|
|
34
|
-
if
|
|
35
|
-
center = value
|
|
36
|
-
_changed()
|
|
37
|
-
var layout_size: Vector2:
|
|
38
|
-
get: return _layout_size
|
|
39
|
-
var _layout_size := Vector2.ZERO
|
|
40
|
-
# Internal bridge, deliberately not the public authoring API.
|
|
41
|
-
var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
|
|
42
|
-
|
|
43
|
-
# -1 means an unset edge; explicit edges always override the shorthand.
|
|
44
|
-
@export var margin: float = 0.0:
|
|
45
|
-
set(value):
|
|
46
|
-
if not is_finite(value) or value < 0 or value == margin: return
|
|
37
|
+
if is_same(margin,value) or not lengths.assign("margin",value): return
|
|
47
38
|
margin = value
|
|
48
39
|
_changed()
|
|
49
|
-
|
|
40
|
+
var margin_top: Variant = "auto":
|
|
50
41
|
set(value):
|
|
51
|
-
if
|
|
42
|
+
if is_same(margin_top,value) or not lengths.assign("margin_top",value): return
|
|
52
43
|
margin_top = value
|
|
53
44
|
_changed()
|
|
54
|
-
|
|
45
|
+
var margin_right: Variant = "auto":
|
|
55
46
|
set(value):
|
|
56
|
-
if
|
|
47
|
+
if is_same(margin_right,value) or not lengths.assign("margin_right",value): return
|
|
57
48
|
margin_right = value
|
|
58
49
|
_changed()
|
|
59
|
-
|
|
50
|
+
var margin_bottom: Variant = "auto":
|
|
60
51
|
set(value):
|
|
61
|
-
if
|
|
52
|
+
if is_same(margin_bottom,value) or not lengths.assign("margin_bottom",value): return
|
|
62
53
|
margin_bottom = value
|
|
63
54
|
_changed()
|
|
64
|
-
|
|
55
|
+
var margin_left: Variant = "auto":
|
|
65
56
|
set(value):
|
|
66
|
-
if
|
|
57
|
+
if is_same(margin_left,value) or not lengths.assign("margin_left",value): return
|
|
67
58
|
margin_left = value
|
|
68
59
|
_changed()
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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()
|
|
70
|
+
@export var center: bool = false:
|
|
71
|
+
set(value):
|
|
72
|
+
if center == value: return
|
|
73
|
+
center = value
|
|
74
|
+
_changed()
|
|
75
|
+
var layout_size: Vector2:
|
|
76
|
+
get: return _layout_size
|
|
77
|
+
var _layout_size := Vector2.ZERO
|
|
78
|
+
var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
|
|
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")
|
|
75
83
|
|
|
76
84
|
func set_extent(value: Vector2) -> Error:
|
|
77
85
|
for axis in range(2):
|
|
@@ -81,7 +89,7 @@ func set_extent(value: Vector2) -> Error:
|
|
|
81
89
|
return OK
|
|
82
90
|
|
|
83
91
|
func requested_extent() -> Vector3:
|
|
84
|
-
return
|
|
92
|
+
return layout.model.requested
|
|
85
93
|
|
|
86
94
|
func _layout_axis() -> int:
|
|
87
95
|
return 0
|
|
@@ -91,14 +99,11 @@ func _measure_native() -> Vector2:
|
|
|
91
99
|
|
|
92
100
|
func _layout_options() -> Dictionary:
|
|
93
101
|
var natural := _measure_native()
|
|
94
|
-
return {"
|
|
102
|
+
return {"axis":_layout_axis(),"fill":Vector3.ZERO,"intrinsic":Vector3(natural.x,natural.y,0)}
|
|
95
103
|
|
|
96
104
|
func _is_layout_entry() -> bool:
|
|
97
105
|
return false
|
|
98
106
|
|
|
99
|
-
func _layout_viewport_scale() -> Vector2:
|
|
100
|
-
return Vector2.ZERO
|
|
101
|
-
|
|
102
107
|
func _changed() -> void:
|
|
103
108
|
if layout != null: layout.changed()
|
|
104
109
|
|
|
@@ -133,3 +138,7 @@ func apply_layout_size(size: Vector3) -> void:
|
|
|
133
138
|
# Explicit invalidation also restores a native position edited externally.
|
|
134
139
|
if layout.parent_coordinator() != null: layout._place(layout.model.offset)
|
|
135
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
|
|
|
@@ -2,24 +2,9 @@
|
|
|
2
2
|
class_name Estragon2D
|
|
3
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,18 +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
|
-
|
|
161
|
-
if
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
available.x = visible.x * scale.x
|
|
166
|
-
external_axes.x = 1
|
|
167
|
-
if scale.y > 0:
|
|
168
|
-
available.y = visible.y * scale.y
|
|
169
|
-
external_axes.y = 1
|
|
170
|
-
model.arrange(available,external_axes)
|
|
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
|
|
171
168
|
CompositionHosts.refresh_positions(self)
|
|
172
169
|
|
|
173
170
|
func _place(offset: Vector3) -> void:
|
|
@@ -1,12 +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)
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
10
22
|
var requested := Vector3(-1, -1, -1)
|
|
11
23
|
var gap: float = 0.0
|
|
12
24
|
var center: bool = false
|
|
@@ -31,6 +43,71 @@ var _measure_dirty: bool = true
|
|
|
31
43
|
var _arrange_dirty: bool = true
|
|
32
44
|
var _parent: WeakRef
|
|
33
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
|
+
|
|
34
111
|
static func valid_extent(value: Vector3) -> bool:
|
|
35
112
|
for axis in range(3):
|
|
36
113
|
if not is_finite(value[axis]) or value[axis] < 0 and value[axis] != -1: return false
|
|
@@ -66,17 +143,13 @@ func set_children(values: Array) -> Error:
|
|
|
66
143
|
if child._parent != null and child._parent.get_ref() != null and child._parent.get_ref() != self: return ERR_ALREADY_IN_USE
|
|
67
144
|
seen.append(child)
|
|
68
145
|
if children == values: return OK
|
|
69
|
-
var moved: Array = []
|
|
70
146
|
for child in children:
|
|
71
147
|
if not values.has(child):
|
|
72
148
|
child._parent = null
|
|
73
|
-
moved.append(child)
|
|
74
149
|
children = values.duplicate()
|
|
75
150
|
for child in children:
|
|
76
|
-
if child._parent == null or child._parent.get_ref() != self: moved.append(child)
|
|
77
151
|
child._parent = weakref(self)
|
|
78
152
|
invalidate()
|
|
79
|
-
for child in moved: child.parent_changed.emit()
|
|
80
153
|
return OK
|
|
81
154
|
|
|
82
155
|
func invalidate() -> void:
|
|
@@ -94,11 +167,24 @@ func outer_extent() -> Vector3:
|
|
|
94
167
|
return leading(margin)+trailing(margin)
|
|
95
168
|
|
|
96
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
|
|
97
182
|
if not _measure_dirty: return measured
|
|
98
183
|
measure_count += 1
|
|
99
184
|
if Profile.is_enabled(): Profile.add("layout_measures")
|
|
100
185
|
var natural := Vector3.ZERO
|
|
101
186
|
for child in children:
|
|
187
|
+
if not transparent: child.prepare(_content_basis(),viewport_size)
|
|
102
188
|
var child_size: Vector3 = child.measure()
|
|
103
189
|
if not transparent: child_size += child.outer_extent()
|
|
104
190
|
for index in range(3):
|
|
@@ -116,13 +202,14 @@ func measure() -> Vector3:
|
|
|
116
202
|
# An auto axis cannot be a reference to its own descendants. Fill allocations
|
|
117
203
|
# ignore this model's intrinsic extent and can inherit an independent basis.
|
|
118
204
|
func independent_axis(index: int) -> bool:
|
|
119
|
-
if
|
|
205
|
+
if requested[index] >= 0 or _external_axes[index] > 0: return true
|
|
120
206
|
var parent = _parent.get_ref() if _parent != null else null
|
|
121
207
|
if parent == null: return false
|
|
122
|
-
return parent.independent_axis(index) if requested[index] < 0 and fill[index] > 0 else 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
|
|
123
209
|
|
|
124
210
|
func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
125
211
|
_external_axes = external_axes
|
|
212
|
+
_warn_unanchored()
|
|
126
213
|
var content := available-leading(padding)-trailing(padding)
|
|
127
214
|
var reference := Vector3(-1,-1,-1)
|
|
128
215
|
for index in range(3):
|
|
@@ -143,31 +230,43 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
143
230
|
if child.offset != Vector3.ZERO or child.arrange_count == 0:
|
|
144
231
|
child.offset = Vector3.ZERO
|
|
145
232
|
child.placed.emit(Vector3.ZERO)
|
|
146
|
-
child.
|
|
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)
|
|
147
240
|
arranged.emit(size)
|
|
148
|
-
if changed: reference_changed.emit()
|
|
149
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()
|
|
150
247
|
var fixed: float = gap * maxi(0, children.size() - 1)
|
|
151
248
|
var flexible: Array = []
|
|
152
249
|
for child in children:
|
|
153
250
|
fixed += child.outer_extent()[axis]
|
|
154
|
-
if child.fill[axis]
|
|
251
|
+
if (child.flex>0 or child.fill[axis]>0) and child.requested[axis] < 0: flexible.append(child)
|
|
155
252
|
else: fixed += child.measured[axis]
|
|
156
253
|
var remaining: float = maxf(0,content[axis] - fixed)
|
|
157
254
|
var shares: Dictionary = {}
|
|
158
255
|
# Reserve constrained native minimums, then share the remaining space.
|
|
159
256
|
# Zero floors preserve the existing equal-share Box behavior.
|
|
160
257
|
while not flexible.is_empty():
|
|
161
|
-
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
|
|
162
261
|
var constrained := false
|
|
163
262
|
for child in flexible.duplicate():
|
|
164
|
-
if child.allocation_minimum[axis] > share:
|
|
263
|
+
if child.allocation_minimum[axis] > share*(child.flex if child.flex>0 else 1.0):
|
|
165
264
|
shares[child] = child.allocation_minimum[axis]
|
|
166
265
|
remaining = maxf(0,remaining-child.allocation_minimum[axis])
|
|
167
266
|
flexible.erase(child)
|
|
168
267
|
constrained = true
|
|
169
268
|
if not constrained:
|
|
170
|
-
for child in flexible: shares[child] = share
|
|
269
|
+
for child in flexible: shares[child] = share*(child.flex if child.flex>0 else 1.0)
|
|
171
270
|
break
|
|
172
271
|
var row_extent: float = fixed
|
|
173
272
|
for share in shares.values(): row_extent += share
|
|
@@ -175,10 +274,10 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
175
274
|
for child in children:
|
|
176
275
|
var allocation: Vector3 = child.measured
|
|
177
276
|
for index in range(3):
|
|
178
|
-
if child.fill[index] > 0 and child.requested[index] < 0:
|
|
277
|
+
if (child.fill[index]>0 or (child.flex>0 if index==axis else child.stretch>0)) and child.requested[index] < 0:
|
|
179
278
|
allocation[index] = shares[child] if index == axis else maxf(0,content[index]-child.outer_extent()[index])
|
|
180
279
|
allocation[index] = maxf(allocation[index],child.allocation_minimum[index])
|
|
181
|
-
var next
|
|
280
|
+
var next: Vector3 = leading(padding)+leading(child.margin)+child.length_offset
|
|
182
281
|
next[axis] += cursor
|
|
183
282
|
if child.offset != next or child.arrange_count == 0:
|
|
184
283
|
child.offset = next
|
|
@@ -186,4 +285,3 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
186
285
|
child.arrange(allocation)
|
|
187
286
|
cursor += allocation[axis] + child.outer_extent()[axis] + gap
|
|
188
287
|
arranged.emit(size)
|
|
189
|
-
if changed: reference_changed.emit()
|
|
@@ -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
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
@tool
|
|
2
|
-
class_name EstragonPixels
|
|
3
|
-
extends RefCounted
|
|
4
|
-
## Opt-in ordinary numeric pixel helpers. Read during the child's build_view;
|
|
5
|
-
## the existing composition manager observes the parent core's native signal.
|
|
6
|
-
const State = preload("state.tres")
|
|
7
|
-
const Hosts = preload("../node/internal/composition_hosts.tres")
|
|
8
|
-
static func parent_width(context: Node, percent: float) -> float:
|
|
9
|
-
return _parent_pixels(context,percent,0)
|
|
10
|
-
static func parent_height(context: Node, percent: float) -> float:
|
|
11
|
-
return _parent_pixels(context,percent,1)
|
|
12
|
-
static func _parent_pixels(context: Node, percent: float, axis: int) -> float:
|
|
13
|
-
if not is_finite(percent) or percent < 0:
|
|
14
|
-
push_warning("EstragonPixels requires a finite nonnegative percentage; using 0 pixels")
|
|
15
|
-
return 0.0
|
|
16
|
-
if context == null or context != State.current_host():
|
|
17
|
-
push_warning("EstragonPixels context must be self in the current Gogo build_view; using 0 pixels")
|
|
18
|
-
return 0.0
|
|
19
|
-
var layout = context._get_layout_coordinator() if context.has_method("_get_layout_coordinator") else Hosts.find(context)
|
|
20
|
-
if layout == null or layout._dimension != 2: return 0.0
|
|
21
|
-
State.observe(layout.model,&"parent_changed")
|
|
22
|
-
if layout.scope_root() == null or layout._mode == layout.Mode.ENTRY: return 0.0
|
|
23
|
-
var parent = layout.parent_coordinator()
|
|
24
|
-
# Structural Gogo proxies add no content box; use the containing participant.
|
|
25
|
-
while parent != null and parent._mode == parent.Mode.COMPOSITION:
|
|
26
|
-
State.observe(parent.model,&"parent_changed")
|
|
27
|
-
parent = parent.parent_coordinator()
|
|
28
|
-
if parent == null or parent._mode == parent.Mode.CONTROL: return 0.0
|
|
29
|
-
State.observe(parent.model,&"reference_changed")
|
|
30
|
-
# Unarranged references bootstrap at zero. Intrinsic/auto parent axes stay
|
|
31
|
-
# unavailable instead of repeatedly solving a child/parent fixed point.
|
|
32
|
-
var extent: float = parent.model.content_reference[axis]
|
|
33
|
-
if extent < 0: return 0.0
|
|
34
|
-
var pixels: float = extent * (percent / 100.0)
|
|
35
|
-
if not is_finite(pixels) or not is_finite(Vector2(pixels,0).x):
|
|
36
|
-
push_warning("EstragonPixels result exceeds native finite pixel range; using 0 pixels")
|
|
37
|
-
return 0.0
|
|
38
|
-
return pixels
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
uid://e7b3c54c9f3a
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
@tool
|
|
2
|
-
extends RefCounted
|
|
3
|
-
## Shared GGX pixel domain, used before native description commits as well as
|
|
4
|
-
## by static validation. Ordinary native properties keep their own contracts.
|
|
5
|
-
const Participant = preload("../component_2d.gd")
|
|
6
|
-
const Box = preload("../box.gd")
|
|
7
|
-
static func _derives(type, base: Script) -> bool:
|
|
8
|
-
if not type is Script: return false
|
|
9
|
-
while type != null:
|
|
10
|
-
if type == base: return true
|
|
11
|
-
type = type.get_base_script()
|
|
12
|
-
return false
|
|
13
|
-
static func kind(type, name: String) -> String:
|
|
14
|
-
if not _derives(type,Participant): return ""
|
|
15
|
-
if name in ["width","height"]: return "length"
|
|
16
|
-
if name == "gap" or name in ["margin","margin_top","margin_right","margin_bottom","margin_left"]: return "inset"
|
|
17
|
-
if name in ["padding","padding_top","padding_right","padding_bottom","padding_left"] and _derives(type,Box): return "inset"
|
|
18
|
-
return ""
|
|
19
|
-
static func valid(value, domain: String) -> bool:
|
|
20
|
-
return (value is int or value is float) and is_finite(float(value)) and (value >= 0 or domain == "length" and value == -1)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
uid://758ca164d812
|