@papercraftgames/estragon 0.1.0-beta.19 → 0.1.0-beta.20
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 +23 -2
- package/addons/estragon/editor/color_property.gd +37 -0
- package/addons/estragon/editor/color_property.gd.uid +1 -0
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/editor/scene_inspector.gd +5 -0
- package/addons/estragon/runtime/composition/computation.gd +17 -0
- package/addons/estragon/runtime/node/component_2d.gd +67 -2
- package/addons/estragon/runtime/node/internal/coordinator.gd +1 -1
- package/addons/estragon/runtime/node/internal/layout_core.gd +11 -8
- package/addons/estragon/runtime/node/internal/length.gd +8 -2
- package/addons/estragon/runtime/node/internal/visual_style_2d.gd +65 -0
- package/addons/estragon/runtime/node/internal/visual_style_2d.gd.uid +1 -0
- package/addons/estragon/runtime/node/rect.gd +1 -0
- package/addons/estragon/runtime/node/text.gd +1 -0
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ const Model = preload("model.gd")
|
|
|
6
6
|
const Source = preload("source.gd")
|
|
7
7
|
const Resolver = preload("native/resolver.gd")
|
|
8
8
|
const StackContract = preload("../runtime/node/internal/stack_contract.gd")
|
|
9
|
+
const VisualStyle = preload("../runtime/node/internal/visual_style_2d.gd")
|
|
9
10
|
const Length = preload("../runtime/node/internal/length.gd")
|
|
10
11
|
const Lexer = preload("lexer.gd")
|
|
11
12
|
var file: Source
|
|
@@ -50,6 +51,9 @@ func _component(node: Model.Component) -> void:
|
|
|
50
51
|
var seen: Dictionary = {}
|
|
51
52
|
for attribute in node.attributes:
|
|
52
53
|
var name := attribute.name
|
|
54
|
+
if VisualStyle.property(name) and VisualStyle.has_api(resolved.script) and not VisualStyle.supported(resolved.script):
|
|
55
|
+
_error("Shared visual styling on Text/Rect/Button is deferred to S02; use the existing local widget properties",attribute.name_span)
|
|
56
|
+
return
|
|
53
57
|
if seen.has(name):
|
|
54
58
|
_error("Duplicate Node property or signal " + name, attribute.name_span)
|
|
55
59
|
return
|
|
@@ -81,7 +85,7 @@ func _component(node: Model.Component) -> void:
|
|
|
81
85
|
return
|
|
82
86
|
index = token.span.end.index
|
|
83
87
|
elif properties.has(name) and name not in ["owner", "script"] and not name.contains("/") and not (int(properties[name].usage) & PROPERTY_USAGE_READ_ONLY):
|
|
84
|
-
attribute.type_name = "Variant" if Length.registered(resolved.script,name) else _native_type(properties[name])
|
|
88
|
+
attribute.type_name = "Variant" if Length.registered(resolved.script,name) or VisualStyle.registered(resolved.script,name) else _native_type(properties[name])
|
|
85
89
|
if attribute.type_name.is_empty():
|
|
86
90
|
_error("Unsupported Node property metadata: " + name, attribute.name_span)
|
|
87
91
|
return
|
|
@@ -93,12 +97,16 @@ func _component(node: Model.Component) -> void:
|
|
|
93
97
|
if not message.is_empty():
|
|
94
98
|
_error(message,attribute.value.span)
|
|
95
99
|
return
|
|
100
|
+
var is_color := VisualStyle.registered(resolved.script,name)
|
|
101
|
+
if is_color:
|
|
102
|
+
_color(attribute)
|
|
103
|
+
if not file.diagnostics.is_empty(): return
|
|
96
104
|
var is_length := Length.registered(resolved.script,name)
|
|
97
105
|
if is_length:
|
|
98
106
|
_length(attribute,Length.domain(name))
|
|
99
107
|
if not file.diagnostics.is_empty(): return
|
|
100
108
|
if attribute.value is Model.Literal:
|
|
101
|
-
if is_length:
|
|
109
|
+
if is_length or is_color:
|
|
102
110
|
attribute.value.kind = "string-literal"
|
|
103
111
|
continue
|
|
104
112
|
if attribute.type_name not in ["String", "StringName"]:
|
|
@@ -315,3 +323,16 @@ func _length(attribute, domain: String) -> void:
|
|
|
315
323
|
elif text.is_valid_float():
|
|
316
324
|
var parsed := Length.parse(float(text),domain)
|
|
317
325
|
if parsed.has("error"): _error(parsed.error,value.span)
|
|
326
|
+
|
|
327
|
+
func _color(attribute) -> void:
|
|
328
|
+
var value = attribute.value
|
|
329
|
+
if value is Model.Literal:
|
|
330
|
+
var parsed := VisualStyle.parse_color(value.value)
|
|
331
|
+
if parsed.has("error"): _error(parsed.error,value.span)
|
|
332
|
+
return
|
|
333
|
+
var tokens := _expression_tokens(value)
|
|
334
|
+
if tokens.size()==1 and tokens[0].kind=="string":
|
|
335
|
+
var parsed := VisualStyle.parse_color(tokens[0].text.substr(1,tokens[0].text.length()-2).c_unescape())
|
|
336
|
+
if parsed.has("error"): _error(parsed.error,value.span)
|
|
337
|
+
elif tokens.size()==1 and (tokens[0].kind=="number" or tokens[0].text in ["true","false","null","NAN","INF"]):
|
|
338
|
+
_error("Style color requires a native Color or validated hex/transparent string",value.span)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends EditorProperty
|
|
3
|
+
const Style = preload("../runtime/node/internal/visual_style_2d.gd")
|
|
4
|
+
var input := LineEdit.new()
|
|
5
|
+
var picker := ColorPickerButton.new()
|
|
6
|
+
var _updating := false
|
|
7
|
+
func _init() -> void:
|
|
8
|
+
var row := HBoxContainer.new()
|
|
9
|
+
input.placeholder_text = "#rrggbb or transparent"
|
|
10
|
+
input.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
11
|
+
row.add_child(input)
|
|
12
|
+
row.add_child(picker)
|
|
13
|
+
add_child(row)
|
|
14
|
+
add_focusable(input)
|
|
15
|
+
input.text_submitted.connect(_submit)
|
|
16
|
+
picker.color_changed.connect(_picked)
|
|
17
|
+
func _submit(text: String) -> void:
|
|
18
|
+
var parsed := Style.parse_color(text)
|
|
19
|
+
if parsed.has("error"):
|
|
20
|
+
input.tooltip_text = parsed.error
|
|
21
|
+
input.modulate = Color(1,0.5,0.5)
|
|
22
|
+
return
|
|
23
|
+
input.modulate = Color.WHITE
|
|
24
|
+
input.tooltip_text = ""
|
|
25
|
+
emit_changed(get_edited_property(),text)
|
|
26
|
+
func _picked(value: Color) -> void:
|
|
27
|
+
if not _updating: emit_changed(get_edited_property(),value)
|
|
28
|
+
func _update_property() -> void:
|
|
29
|
+
_updating = true
|
|
30
|
+
var value = get_edited_object().get(get_edited_property())
|
|
31
|
+
input.text = "#"+value.to_html() if value is Color else str(value)
|
|
32
|
+
var parsed := Style.parse_color(value)
|
|
33
|
+
if not parsed.has("error"):
|
|
34
|
+
picker.color = parsed.color
|
|
35
|
+
input.modulate = Color.WHITE
|
|
36
|
+
input.tooltip_text = ""
|
|
37
|
+
_updating = false
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://59799a75e034
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
extends EditorInspectorPlugin
|
|
3
3
|
## Authored-source presentation alongside the untouched native Script property.
|
|
4
|
+
const VisualStyle = preload("../runtime/node/internal/visual_style_2d.gd")
|
|
5
|
+
const ColorProperty = preload("color_property.gd")
|
|
4
6
|
const Length = preload("../runtime/node/internal/length.gd")
|
|
5
7
|
const LengthProperty = preload("length_property.gd")
|
|
6
8
|
var service: WeakRef
|
|
@@ -8,6 +10,9 @@ func _can_handle(object: Object) -> bool:
|
|
|
8
10
|
var owner = service.get_ref() if service != null else null
|
|
9
11
|
return owner != null and owner.active and object is Node and (owner.editable(object) or object.has_method("_get_layout_coordinator"))
|
|
10
12
|
func _parse_property(object: Object, _type: Variant.Type, name: String, _hint: PropertyHint, _hint_text: String, _usage: int, _wide: bool) -> bool:
|
|
13
|
+
if VisualStyle.registered(object.get_script(),name):
|
|
14
|
+
add_property_editor(name,ColorProperty.new())
|
|
15
|
+
return true
|
|
11
16
|
if not Length.registered(object.get_script(),name): return false
|
|
12
17
|
add_property_editor(name,LengthProperty.new())
|
|
13
18
|
return true
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
extends RefCounted
|
|
2
2
|
const StackContract = preload("../node/internal/stack_contract.gd")
|
|
3
|
+
const VisualStyle = preload("../node/internal/visual_style_2d.gd")
|
|
3
4
|
const Length = preload("../node/internal/length.gd")
|
|
4
5
|
const Profile = preload("profile.tres")
|
|
5
6
|
## F01 computation and retained static-shape records external to native objects.
|
|
@@ -323,6 +324,14 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
323
324
|
binding.attach(node,self)
|
|
324
325
|
var stack := StackContract.registered(desired.type)
|
|
325
326
|
if stack: node._apply_stack_policy(desired.properties)
|
|
327
|
+
# An omitted previously declared border side removes that local override;
|
|
328
|
+
# do not turn omission into permanent native state or change other props.
|
|
329
|
+
if VisualStyle.supported(desired.type):
|
|
330
|
+
for key in record.properties:
|
|
331
|
+
if key in Length.BORDER_EDGES and not desired.properties.has(key):
|
|
332
|
+
node.set(key,"auto")
|
|
333
|
+
writes += 1
|
|
334
|
+
if Profile.is_enabled(): Profile.add("property_writes")
|
|
326
335
|
for key in desired.properties:
|
|
327
336
|
if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
|
|
328
337
|
if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
|
|
@@ -476,9 +485,17 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
476
485
|
for key in desired.properties:
|
|
477
486
|
if not properties.has(key) or key in ["script","owner"] or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return false
|
|
478
487
|
var value = desired.properties[key]
|
|
488
|
+
if VisualStyle.property(str(key)) and VisualStyle.has_api(desired.type) and not VisualStyle.supported(desired.type):
|
|
489
|
+
validation_error = desired.source+": shared widget styling is deferred to S02; previous tree retained"
|
|
490
|
+
return false
|
|
479
491
|
if key=="grow" and Length.registered(desired.type,"width") and (not typeof(value) in [TYPE_INT,TYPE_FLOAT] or not is_finite(float(value)) or value<0):
|
|
480
492
|
validation_error = desired.source+": grow requires a finite nonnegative weight; previous tree retained"
|
|
481
493
|
return false
|
|
494
|
+
if VisualStyle.registered(desired.type,key):
|
|
495
|
+
var parsed := VisualStyle.parse_color(value)
|
|
496
|
+
if parsed.has("error"):
|
|
497
|
+
validation_error = desired.source+": invalid style '"+str(key)+"': "+parsed.error+"; previous tree retained"
|
|
498
|
+
return false
|
|
482
499
|
if Length.registered(desired.type,key):
|
|
483
500
|
var parsed := Length.parse(value,Length.domain(key))
|
|
484
501
|
if parsed.has("error"):
|
|
@@ -5,8 +5,51 @@ extends Node2D
|
|
|
5
5
|
signal layout_applied(size: Vector2)
|
|
6
6
|
const Coordinator = preload("internal/coordinator.gd")
|
|
7
7
|
const ESTRAGON_LENGTHS := true
|
|
8
|
+
const VisualStyle = preload("internal/visual_style_2d.gd")
|
|
9
|
+
var _visual_style = VisualStyle.new()
|
|
8
10
|
const Length = preload("internal/length.gd")
|
|
9
11
|
var lengths = Length.new()
|
|
12
|
+
const ESTRAGON_VISUAL_STYLE := true
|
|
13
|
+
var background_color: Variant = "transparent":
|
|
14
|
+
set(value):
|
|
15
|
+
if is_same(background_color,value) or not _style_supported() or not _visual_style.assign("background_color",value): return
|
|
16
|
+
background_color = value
|
|
17
|
+
_queue_style_redraw()
|
|
18
|
+
var border_color: Variant = "transparent":
|
|
19
|
+
set(value):
|
|
20
|
+
if is_same(border_color,value) or not _style_supported() or not _visual_style.assign("border_color",value): return
|
|
21
|
+
border_color = value
|
|
22
|
+
_queue_style_redraw()
|
|
23
|
+
var border_width: Variant = 0.0:
|
|
24
|
+
set(value):
|
|
25
|
+
if is_same(border_width,value) or not _style_supported() or not lengths.assign("border_width",value): return
|
|
26
|
+
border_width = value
|
|
27
|
+
_changed()
|
|
28
|
+
_queue_style_redraw()
|
|
29
|
+
var border_top_width: Variant = "auto":
|
|
30
|
+
set(value):
|
|
31
|
+
if is_same(border_top_width,value) or not _style_supported() or not lengths.assign("border_top_width",value): return
|
|
32
|
+
border_top_width = value
|
|
33
|
+
_changed()
|
|
34
|
+
_queue_style_redraw()
|
|
35
|
+
var border_right_width: Variant = "auto":
|
|
36
|
+
set(value):
|
|
37
|
+
if is_same(border_right_width,value) or not _style_supported() or not lengths.assign("border_right_width",value): return
|
|
38
|
+
border_right_width = value
|
|
39
|
+
_changed()
|
|
40
|
+
_queue_style_redraw()
|
|
41
|
+
var border_bottom_width: Variant = "auto":
|
|
42
|
+
set(value):
|
|
43
|
+
if is_same(border_bottom_width,value) or not _style_supported() or not lengths.assign("border_bottom_width",value): return
|
|
44
|
+
border_bottom_width = value
|
|
45
|
+
_changed()
|
|
46
|
+
_queue_style_redraw()
|
|
47
|
+
var border_left_width: Variant = "auto":
|
|
48
|
+
set(value):
|
|
49
|
+
if is_same(border_left_width,value) or not _style_supported() or not lengths.assign("border_left_width",value): return
|
|
50
|
+
border_left_width = value
|
|
51
|
+
_changed()
|
|
52
|
+
_queue_style_redraw()
|
|
10
53
|
var width: Variant = "auto":
|
|
11
54
|
set(value):
|
|
12
55
|
if is_same(width,value) or not lengths.assign("width",value): return
|
|
@@ -77,7 +120,9 @@ var layout_size: Vector2:
|
|
|
77
120
|
var _layout_size := Vector2.ZERO
|
|
78
121
|
var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
|
|
79
122
|
func _get_property_list() -> Array[Dictionary]:
|
|
80
|
-
|
|
123
|
+
var properties := Length.properties(["width","height","x","y","gap","margin","margin_top","margin_right","margin_bottom","margin_left"])
|
|
124
|
+
if VisualStyle.supported(get_script()): properties.append_array(Length.properties(["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width","background_color","border_color"]))
|
|
125
|
+
return properties
|
|
81
126
|
static func valid_length(value) -> bool:
|
|
82
127
|
return Length.valid(value,"extent")
|
|
83
128
|
|
|
@@ -112,10 +157,15 @@ func _notification(what: int) -> void:
|
|
|
112
157
|
if what == 12 and layout != null: layout.order_moved()
|
|
113
158
|
|
|
114
159
|
func _enter_tree() -> void:
|
|
160
|
+
# Native draw signal precedes script _draw, so derived Box foreground hooks
|
|
161
|
+
# cannot accidentally bypass the shared style. Legacy widget painters
|
|
162
|
+
# explicitly opt out of S01 styles and remain untouched until S02.
|
|
163
|
+
if VisualStyle.supported(get_script()) and not draw.is_connected(_paint_visual_style): draw.connect(_paint_visual_style)
|
|
115
164
|
layout.changed()
|
|
116
165
|
layout.start()
|
|
117
166
|
|
|
118
167
|
func _exit_tree() -> void:
|
|
168
|
+
if draw.is_connected(_paint_visual_style): draw.disconnect(_paint_visual_style)
|
|
119
169
|
layout.stop()
|
|
120
170
|
|
|
121
171
|
func invalidate_layout() -> void:
|
|
@@ -134,7 +184,9 @@ func apply_layout_position(offset: Vector3) -> void:
|
|
|
134
184
|
position = Vector2(offset.x, offset.y)
|
|
135
185
|
|
|
136
186
|
func apply_layout_size(size: Vector3) -> void:
|
|
137
|
-
|
|
187
|
+
var next := Vector2(size.x,size.y)
|
|
188
|
+
if next!=_layout_size: _queue_style_redraw()
|
|
189
|
+
_layout_size = next
|
|
138
190
|
# Explicit invalidation also restores a native position edited externally.
|
|
139
191
|
if layout.parent_coordinator() != null: layout._place(layout.model.offset)
|
|
140
192
|
layout_applied.emit(_layout_size)
|
|
@@ -142,3 +194,16 @@ func apply_layout_size(size: Vector3) -> void:
|
|
|
142
194
|
func _margin_insets() -> Vector4:
|
|
143
195
|
layout.model.prepare(layout.model.parent_reference,layout.model.viewport_size)
|
|
144
196
|
return layout.model.margin
|
|
197
|
+
|
|
198
|
+
func _queue_style_redraw() -> void:
|
|
199
|
+
_visual_style.redraw_count += 1
|
|
200
|
+
queue_redraw()
|
|
201
|
+
func _paint_visual_style() -> void:
|
|
202
|
+
_visual_style.paint(self,layout_size,layout.model.border)
|
|
203
|
+
func get_visual_style_stats() -> Dictionary:
|
|
204
|
+
return {"parse":_visual_style.parse_count,"draw":_visual_style.draw_count,"commands":_visual_style.command_count,"redraw":_visual_style.redraw_count}
|
|
205
|
+
|
|
206
|
+
func _style_supported() -> bool:
|
|
207
|
+
if VisualStyle.supported(get_script()): return true
|
|
208
|
+
push_error("Estragon style: Text/Rect/Button painters retain their local API until S02")
|
|
209
|
+
return false
|
|
@@ -135,7 +135,7 @@ func changed() -> void:
|
|
|
135
135
|
model.set_policy(options.get("alignment",["start","start","start"]))
|
|
136
136
|
if "lengths" in host:
|
|
137
137
|
for property in host._get_property_list():
|
|
138
|
-
if not host.lengths.specs.has(property.name): host.lengths.assign(property.name,host.get(property.name))
|
|
138
|
+
if not Core.Length.domain(property.name).is_empty() and not host.lengths.specs.has(property.name): host.lengths.assign(property.name,host.get(property.name))
|
|
139
139
|
model.set_lengths(host.lengths.specs,host.grow,host.stretch,host.pixels_per_unit if _dimension==3 else 1.0,options.axis)
|
|
140
140
|
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))
|
|
141
141
|
else: model.configure(host.requested_extent(), host.gap, host.center)
|
|
@@ -31,6 +31,7 @@ var intrinsic := Vector3.ZERO
|
|
|
31
31
|
# Native Control minimums constrain assigned slots, never read back from size.
|
|
32
32
|
var allocation_minimum := Vector3.ZERO
|
|
33
33
|
var padding := Vector4.ZERO # left, top, right, bottom; border-box insets
|
|
34
|
+
var border := Vector4.ZERO # inside the border-box, before padding
|
|
34
35
|
var margin := Vector4.ZERO # outside own geometry; consumed by the parent
|
|
35
36
|
var transparent: bool = false # composition proxy forwards one root slot
|
|
36
37
|
var alignment: Array = ["start","start","start"]
|
|
@@ -84,8 +85,9 @@ func _edges(prefix: String) -> Vector4:
|
|
|
84
85
|
var names := ["left","top","right","bottom"]
|
|
85
86
|
for edge in range(4):
|
|
86
87
|
var index: int = edge%2
|
|
87
|
-
var
|
|
88
|
-
|
|
88
|
+
var key: String = prefix+"_"+names[edge]+("_width" if prefix=="border" else "")
|
|
89
|
+
var value := _length(key,index,-1)
|
|
90
|
+
result[edge] = _length("border_width" if prefix=="border" else prefix,index,0) if value<0 else value
|
|
89
91
|
return result
|
|
90
92
|
|
|
91
93
|
# Resolve specs only on a changed parent/viewport/spec context. No property
|
|
@@ -101,22 +103,23 @@ func prepare(reference: Vector3, viewport: Vector2) -> void:
|
|
|
101
103
|
if _length_context==context: return
|
|
102
104
|
_length_context = context
|
|
103
105
|
resolution_count += 1
|
|
104
|
-
var before := [requested,gap,padding,margin,length_offset]
|
|
106
|
+
var before := [requested,gap,padding,border,margin,length_offset]
|
|
105
107
|
if not length_specs.is_empty():
|
|
106
108
|
for index in range(3):
|
|
107
109
|
requested[index] = _length(["width","height","depth"][index],index,requested[index])
|
|
108
110
|
length_offset[index] = _length(["x","y","z"][index],index,0)
|
|
109
111
|
gap = _length("gap",axis,0)
|
|
110
112
|
padding = _edges("padding")
|
|
113
|
+
border = _edges("border")
|
|
111
114
|
margin = _edges("margin")
|
|
112
|
-
if before!=[requested,gap,padding,margin,length_offset]:
|
|
115
|
+
if before!=[requested,gap,padding,border,margin,length_offset]:
|
|
113
116
|
_measure_dirty = true
|
|
114
117
|
_arrange_dirty = true
|
|
115
118
|
|
|
116
119
|
func _content_basis() -> Vector3:
|
|
117
120
|
var basis := Vector3(-1,-1,-1)
|
|
118
121
|
for index in range(3):
|
|
119
|
-
if requested[index]>=0: basis[index] = maxf(0,requested[index]-leading(padding)[index]-trailing(padding)[index])
|
|
122
|
+
if requested[index]>=0: basis[index] = maxf(0,requested[index]-leading(padding+border)[index]-trailing(padding+border)[index])
|
|
120
123
|
return basis
|
|
121
124
|
|
|
122
125
|
static func valid_extent(value: Vector3) -> bool:
|
|
@@ -203,7 +206,7 @@ func measure() -> Vector3:
|
|
|
203
206
|
else: natural[index] = maxf(natural[index],child_size[index])
|
|
204
207
|
if children.size() > 1: natural[axis] += gap * (children.size() - 1)
|
|
205
208
|
for index in range(3): natural[index] = maxf(natural[index],intrinsic[index])
|
|
206
|
-
if not transparent: natural += leading(padding)+trailing(padding)
|
|
209
|
+
if not transparent: natural += leading(padding+border)+trailing(padding+border)
|
|
207
210
|
measured = natural
|
|
208
211
|
for axis in range(3):
|
|
209
212
|
if requested[axis] >= 0: measured[axis] = requested[axis]
|
|
@@ -221,7 +224,7 @@ func independent_axis(index: int) -> bool:
|
|
|
221
224
|
func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
222
225
|
_external_axes = external_axes
|
|
223
226
|
_warn_unanchored()
|
|
224
|
-
var content := available-leading(padding)-trailing(padding)
|
|
227
|
+
var content := available-leading(padding+border)-trailing(padding+border)
|
|
225
228
|
var reference := Vector3(-1,-1,-1)
|
|
226
229
|
for index in range(3):
|
|
227
230
|
content[index] = maxf(0,content[index])
|
|
@@ -279,7 +282,7 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
279
282
|
for index in range(children.size()):
|
|
280
283
|
var child = children[index]
|
|
281
284
|
var slot: Dictionary = slots[index]
|
|
282
|
-
var next: Vector3 = leading(padding)+slot.position+child.length_offset
|
|
285
|
+
var next: Vector3 = leading(padding+border)+slot.position+child.length_offset
|
|
283
286
|
if child.offset != next or child.arrange_count == 0:
|
|
284
287
|
child.offset = next
|
|
285
288
|
child.placed.emit(next)
|
|
@@ -4,20 +4,26 @@ extends RefCounted
|
|
|
4
4
|
## Numeric values preserve native units; explicit pixel/reference strings use
|
|
5
5
|
## pixels_per_unit in 3D. Percent uses the containing layout content axis;
|
|
6
6
|
## independent 2D Entries receive their visible viewport as that context.
|
|
7
|
+
const VisualStyle = preload("visual_style_2d.gd")
|
|
7
8
|
const LIMIT := 1.0e12
|
|
8
9
|
const FACTORS := {"":1.0,"px":1.0,"in":96.0,"cm":96.0/2.54,"mm":96.0/25.4,"q":96.0/101.6,"pt":96.0/72.0,"pc":16.0}
|
|
9
10
|
const DIMENSIONS := ["width","height","depth"]
|
|
11
|
+
const BORDER_EDGES := ["border_top_width","border_right_width","border_bottom_width","border_left_width"]
|
|
10
12
|
const OFFSETS := ["x","y","z"]
|
|
11
13
|
const EDGES := ["padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"]
|
|
12
14
|
var specs: Dictionary = {}
|
|
13
15
|
var parse_count := 0
|
|
14
16
|
static func domain(name: String) -> String:
|
|
15
17
|
if name in DIMENSIONS: return "extent"
|
|
18
|
+
if name=="border_width": return "inset"
|
|
19
|
+
if name in BORDER_EDGES: return "edge"
|
|
16
20
|
if name in OFFSETS: return "offset"
|
|
17
21
|
if name in EDGES: return "edge" if name.contains("_") else "inset"
|
|
18
22
|
return "inset" if name=="gap" else ""
|
|
19
23
|
static func registered(type, name: String) -> bool:
|
|
20
24
|
if domain(name).is_empty() or not type is Script: return false
|
|
25
|
+
if name=="border_width" or name in BORDER_EDGES:
|
|
26
|
+
if not VisualStyle.supported(type): return false
|
|
21
27
|
while type != null:
|
|
22
28
|
# A declared native bridge marker avoids loading either adapter here.
|
|
23
29
|
if type.get_script_constant_map().get("ESTRAGON_LENGTHS",false): return true
|
|
@@ -72,8 +78,8 @@ static func dependencies(specs: Dictionary, stack_axis: int) -> Array:
|
|
|
72
78
|
for name in specs:
|
|
73
79
|
var unit: String = specs[name].unit
|
|
74
80
|
if unit=="%":
|
|
75
|
-
if name in ["width","x","margin_left","margin_right","padding_left","padding_right"]: parent_axes.x = 1
|
|
76
|
-
elif name in ["height","y","margin_top","margin_bottom","padding_top","padding_bottom"]: parent_axes.y = 1
|
|
81
|
+
if name in ["width","x","margin_left","margin_right","padding_left","padding_right","border_left_width","border_right_width"]: parent_axes.x = 1
|
|
82
|
+
elif name in ["height","y","margin_top","margin_bottom","padding_top","padding_bottom","border_top_width","border_bottom_width"]: parent_axes.y = 1
|
|
77
83
|
elif name in ["depth","z"]: parent_axes.z = 1
|
|
78
84
|
elif name=="gap": parent_axes[stack_axis] = 1
|
|
79
85
|
else: parent_axes = Vector3(1,1,parent_axes.z)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Local values and native paint only. No parent lookup, cascade or Nodes.
|
|
4
|
+
const COLORS := ["background_color","border_color"]
|
|
5
|
+
var colors := {"background_color":Color.TRANSPARENT,"border_color":Color.TRANSPARENT}
|
|
6
|
+
var parse_count := 0
|
|
7
|
+
var draw_count := 0
|
|
8
|
+
var command_count := 0
|
|
9
|
+
var redraw_count := 0
|
|
10
|
+
static func has_api(script) -> bool:
|
|
11
|
+
while script is Script:
|
|
12
|
+
if script.get_script_constant_map().get("ESTRAGON_VISUAL_STYLE",false): return true
|
|
13
|
+
script = script.get_base_script()
|
|
14
|
+
return false
|
|
15
|
+
static func supported(script) -> bool:
|
|
16
|
+
var current = script
|
|
17
|
+
while current is Script:
|
|
18
|
+
if current.get_script_constant_map().get("ESTRAGON_LEGACY_PAINT",false): return false
|
|
19
|
+
current = current.get_base_script()
|
|
20
|
+
return has_api(script)
|
|
21
|
+
static func property(name: String) -> bool:
|
|
22
|
+
return name in COLORS or name in ["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width"]
|
|
23
|
+
static func registered(script, name: String) -> bool:
|
|
24
|
+
return name in COLORS and supported(script)
|
|
25
|
+
static func parse_color(value) -> Dictionary:
|
|
26
|
+
if value is Color:
|
|
27
|
+
for channel in [value.r,value.g,value.b,value.a]:
|
|
28
|
+
if not is_finite(channel): return {"error":"Color channels must be finite"}
|
|
29
|
+
return {"color":value}
|
|
30
|
+
if value is String:
|
|
31
|
+
var text: String = value.strip_edges()
|
|
32
|
+
if text=="transparent": return {"color":Color.TRANSPARENT}
|
|
33
|
+
if text.begins_with("#") and text.length() in [4,5,7,9]:
|
|
34
|
+
var valid := true
|
|
35
|
+
for index in range(1,text.length()):
|
|
36
|
+
if not text[index].to_lower() in "0123456789abcdef": valid = false
|
|
37
|
+
if valid: return {"color":Color(text)}
|
|
38
|
+
return {"error":"Color requires a native Color, #rgb/#rgba/#rrggbb/#rrggbbaa or transparent"}
|
|
39
|
+
func assign(name: String, value) -> bool:
|
|
40
|
+
var parsed := parse_color(value)
|
|
41
|
+
parse_count += 1
|
|
42
|
+
if parsed.has("error"):
|
|
43
|
+
push_error("Estragon style '"+name+"': "+parsed.error)
|
|
44
|
+
return false
|
|
45
|
+
colors[name] = parsed.color
|
|
46
|
+
return true
|
|
47
|
+
func _rect(canvas: CanvasItem, rect: Rect2, color: Color) -> void:
|
|
48
|
+
if rect.size.x<=0 or rect.size.y<=0 or color.a<=0: return
|
|
49
|
+
canvas.draw_rect(rect,color)
|
|
50
|
+
command_count += 1
|
|
51
|
+
func paint(canvas: CanvasItem, extent: Vector2, border: Vector4) -> void:
|
|
52
|
+
draw_count += 1
|
|
53
|
+
if extent.x<=0 or extent.y<=0: return
|
|
54
|
+
_rect(canvas,Rect2(Vector2.ZERO,extent),colors.background_color)
|
|
55
|
+
# Filled strips stay inside the border-box, including fractional/huge edges.
|
|
56
|
+
# Top/bottom own the corners; side strips never double-blend those pixels.
|
|
57
|
+
var left := minf(border.x,extent.x)
|
|
58
|
+
var right := minf(border.z,maxf(0,extent.x-left))
|
|
59
|
+
var top := minf(border.y,extent.y)
|
|
60
|
+
var bottom := minf(border.w,maxf(0,extent.y-top))
|
|
61
|
+
var color: Color = colors.border_color
|
|
62
|
+
_rect(canvas,Rect2(0,0,extent.x,top),color)
|
|
63
|
+
_rect(canvas,Rect2(0,extent.y-bottom,extent.x,bottom),color)
|
|
64
|
+
_rect(canvas,Rect2(0,top,left,maxf(0,extent.y-top-bottom)),color)
|
|
65
|
+
_rect(canvas,Rect2(extent.x-right,top,right,maxf(0,extent.y-top-bottom)),color)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://942be491eebf
|
package/package.json
CHANGED