@papercraftgames/estragon 0.1.0-beta.25 → 0.1.0-beta.26
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 +2 -6
- package/addons/estragon/editor/components.gd +0 -1
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/runtime/composition/computation.gd +12 -18
- package/addons/estragon/runtime/node/component_2d.gd +58 -1
- package/addons/estragon/runtime/node/estragon_2d.gd +2 -0
- package/addons/estragon/runtime/node/internal/coordinator.gd +1 -0
- package/addons/estragon/runtime/node/internal/layout_core.gd +37 -34
- package/addons/estragon/runtime/node/internal/native_bounds.gd +5 -2
- package/addons/estragon/runtime/node/internal/scroll_2d.gd +175 -0
- package/addons/estragon/runtime/node/internal/scroll_2d.gd.uid +1 -0
- package/package.json +1 -1
- package/addons/estragon/runtime/node/scroll_view.gd +0 -193
- package/addons/estragon/runtime/node/scroll_view.gd.uid +0 -1
|
@@ -61,8 +61,8 @@ func _component(node: Model.Component) -> void:
|
|
|
61
61
|
_node(attribute.value)
|
|
62
62
|
continue
|
|
63
63
|
var name := attribute.name
|
|
64
|
-
if VisualStyle.marked(resolved.script,"
|
|
65
|
-
_error("Read-only
|
|
64
|
+
if VisualStyle.marked(resolved.script,"ESTRAGON_SCROLL_2D") and name in ["scroll_range","content_extent"]:
|
|
65
|
+
_error("Read-only scrolling measurement: "+name,attribute.name_span)
|
|
66
66
|
return
|
|
67
67
|
if VisualStyle.property(name) and VisualStyle.has_api(resolved.script) and not VisualStyle.supported(resolved.script):
|
|
68
68
|
_error("Shared visual styling is unsupported on this participant",attribute.name_span)
|
|
@@ -192,10 +192,6 @@ func _component(node: Model.Component) -> void:
|
|
|
192
192
|
else:
|
|
193
193
|
for index in range(node.children.size()-1,-1,-1):
|
|
194
194
|
if node.children[index] is Model.Literal: node.children.remove_at(index)
|
|
195
|
-
if VisualStyle.marked(resolved.script,"ESTRAGON_SCROLL_VIEW"):
|
|
196
|
-
if node.children.is_empty() or node.children.size()>1 and node.children.all(func(child): return child is Model.Component):
|
|
197
|
-
_error("ScrollView requires exactly one content root; use an explicit VBox or Grid",node.name_span)
|
|
198
|
-
return
|
|
199
195
|
var sibling_names := {}
|
|
200
196
|
for child in node.children:
|
|
201
197
|
if child is Model.GdExpression:
|
|
@@ -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":"ScrollView","canonical":"EstragonScrollView","script":preload("../runtime/node/scroll_view.gd"),"dimension":2,"origin":"native viewport"},
|
|
6
5
|
{"alias":"Grid","canonical":"EstragonGrid","script":preload("../runtime/node/grid.gd"),"dimension":2,"origin":"native layout"},
|
|
7
6
|
{"alias":"Spacer","canonical":"EstragonSpacer","script":preload("../runtime/node/spacer.gd"),"dimension":2,"origin":"native layout"},
|
|
8
7
|
{"alias":"Box","canonical":"EstragonBox","script":preload("../runtime/node/box.gd"),"dimension":2,"origin":"native layout"},
|
|
@@ -264,7 +264,7 @@ func _collect_foreign(record, result: Array) -> void:
|
|
|
264
264
|
var nested = manager.records[node.get_instance_id()].mounted
|
|
265
265
|
_collect_foreign(nested,result)
|
|
266
266
|
if nested!=null and nested.node.get_ref()!=null: known.append(nested.node.get_ref())
|
|
267
|
-
for child in node.get_children():
|
|
267
|
+
for child in (node._layout_children() if node.has_method("_layout_children") else node.get_children()):
|
|
268
268
|
if not known.has(child) and not result.has(child): result.append(child)
|
|
269
269
|
func _planned_foreign(desired, previous, result: Array) -> void:
|
|
270
270
|
if previous==null: return
|
|
@@ -282,7 +282,7 @@ func _rescue_clear(desired, previous, owner: Node) -> bool:
|
|
|
282
282
|
var rescued: Array = []
|
|
283
283
|
_planned_foreign(desired,previous,rescued)
|
|
284
284
|
var names := {}
|
|
285
|
-
for existing in owner.get_children():
|
|
285
|
+
for existing in (owner._layout_children() if owner.has_method("_layout_children") else owner.get_children()):
|
|
286
286
|
if previous!=null and existing==previous.node.get_ref(): continue
|
|
287
287
|
names[str(existing.name)] = true
|
|
288
288
|
var desired_name: String = str(desired.properties.get("name",str(previous.node.get_ref().name) if previous!=null and _compatible(desired,previous) else ""))
|
|
@@ -295,7 +295,7 @@ func _rescue_clear(desired, previous, owner: Node) -> bool:
|
|
|
295
295
|
func _boundary_clear(desired: Element, parent: Node) -> bool:
|
|
296
296
|
var name: String = str(desired.properties.get("name",""))
|
|
297
297
|
if name.is_empty(): return true
|
|
298
|
-
for child in parent.get_children():
|
|
298
|
+
for child in (parent._layout_children() if parent.has_method("_layout_children") else parent.get_children()):
|
|
299
299
|
if str(child.name)==name: return false
|
|
300
300
|
return true
|
|
301
301
|
func _mount(desired: Element, parent: Node, owner: Node) -> Mounted:
|
|
@@ -351,7 +351,7 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
351
351
|
if grid:
|
|
352
352
|
node._apply_grid(_grid_config(desired))
|
|
353
353
|
var stack := StackContract.registered(desired.type)
|
|
354
|
-
var scroll := VisualStyle.marked(desired.type,"
|
|
354
|
+
var scroll := VisualStyle.marked(desired.type,"ESTRAGON_SCROLL_2D")
|
|
355
355
|
if stack:
|
|
356
356
|
var policy := resets.duplicate()
|
|
357
357
|
policy.merge(desired.properties,true)
|
|
@@ -389,7 +389,7 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
389
389
|
writes += 1
|
|
390
390
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
391
391
|
# Apply the effective authored offset after geometry/axis flags. A dirty
|
|
392
|
-
#
|
|
392
|
+
# component retains it until the same core's next arrangement, so attribute
|
|
393
393
|
# order cannot clamp restoration against the previous viewport range.
|
|
394
394
|
if scroll:
|
|
395
395
|
var offset = desired.properties if desired.properties.has("scroll_offset") else resets
|
|
@@ -594,16 +594,10 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
594
594
|
if not message.is_empty():
|
|
595
595
|
validation_error = desired.location(key)+": "+message+"; previous tree retained"
|
|
596
596
|
return false
|
|
597
|
-
if VisualStyle.marked(desired.type,"
|
|
598
|
-
|
|
599
|
-
if content.size()!=1: return _invalid_attribute(desired,"children","ScrollView requires exactly one content root; use an explicit VBox or Grid")
|
|
600
|
-
if desired.properties.has("scroll_offset") and not preload("../node/scroll_view.gd").valid_offset(desired.properties.scroll_offset): return _invalid_attribute(desired,"scroll_offset","requires a finite nonnegative Vector2")
|
|
597
|
+
if VisualStyle.marked(desired.type,"ESTRAGON_SCROLL_2D"):
|
|
598
|
+
if desired.properties.has("scroll_offset") and not preload("../node/internal/scroll_2d.gd").valid_offset(desired.properties.scroll_offset): return _invalid_attribute(desired,"scroll_offset","requires a finite nonnegative Vector2")
|
|
601
599
|
for key in ["scroll_range","content_extent"]:
|
|
602
|
-
if desired.properties.has(key): return _invalid_attribute(desired,key,"read-only
|
|
603
|
-
var child = content[0]
|
|
604
|
-
var type = child.type if child.borrowed==null else child.borrowed.get_ref().get_script()
|
|
605
|
-
var native: String = (child.type if child.type is String else child.type.get_instance_base_type()) if child.borrowed==null else child.borrowed.get_ref().get_class()
|
|
606
|
-
if not ClassDB.is_parent_class(native,"Control") and not (ClassDB.is_parent_class(native,"Node2D") and (Length.registered(type,"width") or GridDefinition.component(type))): return _invalid_attribute(child,"children","ScrollView content needs a bounded native 2D participant, Control or Gogo component")
|
|
600
|
+
if desired.properties.has(key): return _invalid_attribute(desired,key,"read-only scrolling measurement")
|
|
607
601
|
if GridDefinition.marked(desired.type):
|
|
608
602
|
var config := _grid_config(desired)
|
|
609
603
|
var grid_matches := _matches(desired.children,previous.children if previous!=null and _compatible(desired,previous) else [])
|
|
@@ -694,7 +688,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
694
688
|
var node: Node = previous.node.get_ref() if _compatible(desired,previous) else null
|
|
695
689
|
if parent != null:
|
|
696
690
|
var name := _effective_name(desired,previous)
|
|
697
|
-
for existing in parent.get_children():
|
|
691
|
+
for existing in (parent._layout_children() if parent.has_method("_layout_children") else parent.get_children()):
|
|
698
692
|
if str(existing.name)==name and (previous==null or existing!=previous.node.get_ref()): return _invalid_attribute(desired,"name","native sibling name conflict "+name)
|
|
699
693
|
var known: Array = []
|
|
700
694
|
if node != null:
|
|
@@ -712,7 +706,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
712
706
|
if names.has(name): return _invalid_attribute(child,"name","duplicate effective sibling name "+name)
|
|
713
707
|
names[name] = true
|
|
714
708
|
if node != null:
|
|
715
|
-
for existing in node.get_children():
|
|
709
|
+
for existing in (node._layout_children() if node.has_method("_layout_children") else node.get_children()):
|
|
716
710
|
if str(existing.name)==name and not known.has(existing): return false
|
|
717
711
|
return true
|
|
718
712
|
func _free_managed(record: Mounted, rescue: Node = null) -> void:
|
|
@@ -731,10 +725,10 @@ func _free_managed(record: Mounted, rescue: Node = null) -> void:
|
|
|
731
725
|
var owner: Node = rescue if rescue != null else host.get_ref()
|
|
732
726
|
var manager = state.get_ref()
|
|
733
727
|
if manager != null and manager.records.has(node.get_instance_id()): manager.unmount(node,owner)
|
|
734
|
-
for child in node.get_children():
|
|
728
|
+
for child in (node._layout_children() if node.has_method("_layout_children") else node.get_children()):
|
|
735
729
|
if node.has_method("_composition_is_private") and node._composition_is_private(child): continue
|
|
736
730
|
var persisted_owner: Node = child.owner
|
|
737
|
-
|
|
731
|
+
child.get_parent().remove_child(child)
|
|
738
732
|
if owner != null:
|
|
739
733
|
owner.add_child(child)
|
|
740
734
|
if persisted_owner != null and persisted_owner.is_ancestor_of(child): child.owner = persisted_owner
|
|
@@ -4,10 +4,41 @@ class_name EstragonComponent2D
|
|
|
4
4
|
extends Node2D
|
|
5
5
|
## Native C1 participant. Needs a contiguous same-dimensional chain to an entry.
|
|
6
6
|
signal layout_applied(size: Vector2)
|
|
7
|
+
signal _layout_children_changed
|
|
7
8
|
const Coordinator = preload("internal/coordinator.gd")
|
|
8
9
|
const ESTRAGON_LENGTHS := true
|
|
9
10
|
const ESTRAGON_MINIMUMS_2D := true
|
|
10
11
|
const ESTRAGON_GAPS_2D := true
|
|
12
|
+
const ESTRAGON_SCROLL_2D := true
|
|
13
|
+
const Scroll = preload("internal/scroll_2d.gd")
|
|
14
|
+
var _scroll
|
|
15
|
+
@export var horizontal_scroll: bool = false:
|
|
16
|
+
set(value):
|
|
17
|
+
if horizontal_scroll==value: return
|
|
18
|
+
horizontal_scroll = value
|
|
19
|
+
_scroll_changed()
|
|
20
|
+
@export var vertical_scroll: bool = false:
|
|
21
|
+
set(value):
|
|
22
|
+
if vertical_scroll==value: return
|
|
23
|
+
vertical_scroll = value
|
|
24
|
+
_scroll_changed()
|
|
25
|
+
@export var scroll_offset := Vector2.ZERO:
|
|
26
|
+
set(value):
|
|
27
|
+
if not Scroll.valid_offset(value):
|
|
28
|
+
push_error("Estragon scrolling scroll_offset requires a finite nonnegative Vector2")
|
|
29
|
+
return
|
|
30
|
+
scroll_offset = value
|
|
31
|
+
if _scroll!=null: _scroll.offset_changed()
|
|
32
|
+
elif not horizontal_scroll and not vertical_scroll: scroll_offset = Vector2.ZERO
|
|
33
|
+
var scroll_range: Vector2:
|
|
34
|
+
get: return _scroll_range
|
|
35
|
+
set(_value): push_error("Estragon scrolling scroll_range is read-only")
|
|
36
|
+
var content_extent: Vector2:
|
|
37
|
+
get: return _content_extent
|
|
38
|
+
set(_value): push_error("Estragon scrolling content_extent is read-only")
|
|
39
|
+
var _scroll_range := Vector2.ZERO
|
|
40
|
+
var _content_extent := Vector2.ZERO
|
|
41
|
+
|
|
11
42
|
var row_gap: Variant = "auto":
|
|
12
43
|
set(value):
|
|
13
44
|
if is_same(row_gap,value) or not lengths.assign("row_gap",value): return
|
|
@@ -225,11 +256,32 @@ func get_content_rect() -> Rect2:
|
|
|
225
256
|
|
|
226
257
|
func _layout_options() -> Dictionary:
|
|
227
258
|
var natural := _measure_native()
|
|
228
|
-
return {"axis":_layout_axis(),"fill":Vector3.ZERO,"intrinsic":Vector3(natural.x,natural.y,0)}
|
|
259
|
+
return {"axis":_layout_axis(),"fill":Vector3.ZERO,"intrinsic":Vector3(natural.x,natural.y,0),"scroll_axes":Vector2(1 if horizontal_scroll else 0,1 if vertical_scroll else 0)}
|
|
229
260
|
|
|
230
261
|
func _is_layout_entry() -> bool:
|
|
231
262
|
return false
|
|
232
263
|
|
|
264
|
+
func _scroll_changed() -> void:
|
|
265
|
+
if _scroll==null and (horizontal_scroll or vertical_scroll): _scroll = Scroll.new(self)
|
|
266
|
+
_changed()
|
|
267
|
+
if _scroll!=null and is_inside_tree(): _scroll.start()
|
|
268
|
+
func _composition_child_parent() -> Node:
|
|
269
|
+
return _scroll.child_parent() if _scroll!=null and is_instance_valid(_scroll.child_parent()) else self
|
|
270
|
+
func _composition_is_private(child: Node) -> bool:
|
|
271
|
+
return _scroll!=null and _scroll.is_private(child)
|
|
272
|
+
func _layout_children() -> Array:
|
|
273
|
+
return _scroll.children() if _scroll!=null else get_children()
|
|
274
|
+
func get_layout_children() -> Array:
|
|
275
|
+
return _layout_children()
|
|
276
|
+
func get_layout_child(child_name: StringName) -> Node:
|
|
277
|
+
for child in _layout_children():
|
|
278
|
+
if child.name==child_name: return child
|
|
279
|
+
return null
|
|
280
|
+
func _content_pointer_allowed(point: Vector2) -> bool:
|
|
281
|
+
return _scroll==null or _scroll.pointer_allowed(point)
|
|
282
|
+
func _input(event: InputEvent) -> void:
|
|
283
|
+
if _scroll!=null: _scroll.input(event)
|
|
284
|
+
|
|
233
285
|
func _changed() -> void:
|
|
234
286
|
if layout != null: layout.changed()
|
|
235
287
|
|
|
@@ -242,10 +294,13 @@ func _enter_tree() -> void:
|
|
|
242
294
|
# cannot accidentally bypass the shared style. Legacy widget painters
|
|
243
295
|
# explicitly opt out of S01 styles and remain untouched until S02.
|
|
244
296
|
if VisualStyle.supported(get_script()) and not draw.is_connected(_paint_visual_style): draw.connect(_paint_visual_style)
|
|
297
|
+
if _scroll==null and (horizontal_scroll or vertical_scroll or get_node_or_null("_EstragonViewport")!=null): _scroll = Scroll.new(self)
|
|
298
|
+
if _scroll!=null: _scroll.start()
|
|
245
299
|
layout.changed()
|
|
246
300
|
layout.start()
|
|
247
301
|
|
|
248
302
|
func _exit_tree() -> void:
|
|
303
|
+
if _scroll!=null: _scroll.stop()
|
|
249
304
|
if draw.is_connected(_paint_visual_style): draw.disconnect(_paint_visual_style)
|
|
250
305
|
layout.stop()
|
|
251
306
|
|
|
@@ -268,8 +323,10 @@ func apply_layout_size(size: Vector3) -> void:
|
|
|
268
323
|
var next := Vector2(size.x,size.y)
|
|
269
324
|
if next!=_layout_size: _queue_style_redraw()
|
|
270
325
|
_layout_size = next
|
|
326
|
+
_content_extent = layout.model.content_extent()
|
|
271
327
|
# Explicit invalidation also restores a native position edited externally.
|
|
272
328
|
if layout.parent_coordinator() != null: layout._place(layout.model.offset)
|
|
329
|
+
if _scroll!=null: _scroll.refresh()
|
|
273
330
|
layout_applied.emit(_layout_size)
|
|
274
331
|
|
|
275
332
|
func _margin_insets() -> Vector4:
|
|
@@ -140,6 +140,7 @@ func changed() -> void:
|
|
|
140
140
|
if host == null: return
|
|
141
141
|
if host.has_method("_layout_options"):
|
|
142
142
|
var options: Dictionary = host._layout_options()
|
|
143
|
+
model.set_scroll_axes(options.get("scroll_axes",Vector2.ZERO) if _dimension==2 else Vector2.ZERO)
|
|
143
144
|
model.set_strategy(options.get("strategy","stack") if _dimension==2 else "stack",options.get("align_content","start"),options.get("grid",{}))
|
|
144
145
|
model.set_policy(options.get("alignment",["start","start","start"]))
|
|
145
146
|
model.set_align_self(host.align_self if _dimension==2 and "align_self" in host else "auto")
|
|
@@ -34,6 +34,8 @@ var grid_config: Dictionary = {}
|
|
|
34
34
|
var grid_definition: Dictionary = {}
|
|
35
35
|
var policy_result: Dictionary = {}
|
|
36
36
|
var strategy := "stack"
|
|
37
|
+
# Viewport decoration; never replaces Stack/Wrap/Grid.
|
|
38
|
+
var scroll_axes := Vector2.ZERO
|
|
37
39
|
var align_content := "start"
|
|
38
40
|
var physical_gaps := Vector2.ZERO
|
|
39
41
|
var gap: float = 0.0
|
|
@@ -99,6 +101,11 @@ func set_strategy(value: String, content_alignment: String = "start", config: Di
|
|
|
99
101
|
align_content = content_alignment
|
|
100
102
|
invalidate()
|
|
101
103
|
|
|
104
|
+
func set_scroll_axes(value: Vector2) -> void:
|
|
105
|
+
if scroll_axes==value: return
|
|
106
|
+
scroll_axes = value
|
|
107
|
+
invalidate()
|
|
108
|
+
|
|
102
109
|
func set_policy(values: Array) -> void:
|
|
103
110
|
if alignment==values: return
|
|
104
111
|
alignment = values.duplicate()
|
|
@@ -165,7 +172,7 @@ func prepare(reference: Vector3, viewport: Vector2) -> void:
|
|
|
165
172
|
padding = _edges("padding")
|
|
166
173
|
border = _edges("border")
|
|
167
174
|
margin = _edges("margin")
|
|
168
|
-
if before!=[requested,gap,physical_gaps,padding,border,margin,length_offset,authored_minimum]:
|
|
175
|
+
if before!=[requested,gap,physical_gaps,padding,border,margin,length_offset,authored_minimum,authored_maximum]:
|
|
169
176
|
_measure_dirty = true
|
|
170
177
|
_arrange_dirty = true
|
|
171
178
|
|
|
@@ -196,9 +203,8 @@ func _content_basis() -> Vector3:
|
|
|
196
203
|
for index in range(3):
|
|
197
204
|
var allocated: float = constrain(requested)[index] if requested[index]>=0 else measurement_allocation[index]
|
|
198
205
|
if allocated>=0: basis[index] = maxf(0,maxf(allocated,minimum()[index])-leading(padding+border)[index]-trailing(padding+border)[index])
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if grid_config.get(["horizontal_scroll","vertical_scroll"][index],false): basis[index] = -1
|
|
206
|
+
for index in range(2):
|
|
207
|
+
if scroll_axes[index]>0: basis[index] = -1
|
|
202
208
|
return basis
|
|
203
209
|
|
|
204
210
|
static func valid_extent(value: Vector3) -> bool:
|
|
@@ -267,7 +273,7 @@ func outer_extent() -> Vector3:
|
|
|
267
273
|
func track_contribution() -> Vector3:
|
|
268
274
|
if transparent and children.size()==1: return children[0].track_contribution()
|
|
269
275
|
var result := measured
|
|
270
|
-
if strategy=="wrap" and requested[axis]<0:
|
|
276
|
+
if strategy=="wrap" and scroll_axes[axis]==0 and requested[axis]<0:
|
|
271
277
|
result[axis] = intrinsic[axis]
|
|
272
278
|
for child in children: result[axis] = maxf(result[axis],maxf(child.measured[axis],child.minimum()[axis])+child.outer_extent()[axis])
|
|
273
279
|
result[axis] += leading(padding+border)[axis]+trailing(padding+border)[axis]
|
|
@@ -314,10 +320,10 @@ func set_capacity(value: Vector3) -> void:
|
|
|
314
320
|
|
|
315
321
|
func _wrap_basis() -> Vector3:
|
|
316
322
|
var basis := _content_basis()
|
|
317
|
-
if strategy=="wrap" and requested[axis]<0 and basis[axis]<0 and available_capacity[axis]>=0:
|
|
323
|
+
if strategy=="wrap" and scroll_axes[axis]==0 and requested[axis]<0 and basis[axis]<0 and available_capacity[axis]>=0:
|
|
318
324
|
basis[axis] = maxf(0,available_capacity[axis]-leading(padding+border)[axis]-trailing(padding+border)[axis])
|
|
319
325
|
var cap := maximum()
|
|
320
|
-
if strategy=="wrap" and cap[axis]>=0:
|
|
326
|
+
if strategy=="wrap" and scroll_axes[axis]==0 and cap[axis]>=0:
|
|
321
327
|
var available := maxf(0,maxf(cap[axis],minimum()[axis])-leading(padding+border)[axis]-trailing(padding+border)[axis])
|
|
322
328
|
basis[axis] = minf(basis[axis],available) if basis[axis]>=0 else available
|
|
323
329
|
return basis
|
|
@@ -326,7 +332,7 @@ func measure_allocated(extent: Vector3, authority: Vector3) -> void:
|
|
|
326
332
|
if transparent and children.size()==1:
|
|
327
333
|
children[0].measure_allocated(extent,authority)
|
|
328
334
|
_measure_dirty = true
|
|
329
|
-
elif strategy in ["wrap","grid"
|
|
335
|
+
elif strategy in ["wrap","grid"] or scroll_axes!=Vector2.ZERO:
|
|
330
336
|
var next := measurement_allocation
|
|
331
337
|
for index in range(2):
|
|
332
338
|
if requested[index]<0 and authority[index]>0: next[index] = extent[index]
|
|
@@ -336,17 +342,9 @@ func measure_allocated(extent: Vector3, authority: Vector3) -> void:
|
|
|
336
342
|
else: return
|
|
337
343
|
measure()
|
|
338
344
|
|
|
339
|
-
func _scroll_slots(items: Array, content: Vector3) -> Array:
|
|
340
|
-
var result: Array = []
|
|
341
|
-
for item in items:
|
|
342
|
-
var extent: Vector3 = item.preferred
|
|
343
|
-
for index in range(2):
|
|
344
|
-
if not grid_config.get(["horizontal_scroll","vertical_scroll"][index],false) and content[index]>=0 and item.requested[index]<0: extent[index] = maxf(item.minimum[index],content[index]-item.outer[index])
|
|
345
|
-
extent = StackPolicy.limit_extent(extent,item)
|
|
346
|
-
result.append({"position":item.leading-leading(padding+border),"extent":extent})
|
|
347
|
-
return result
|
|
348
|
-
|
|
349
345
|
func overflow_extent() -> Vector3:
|
|
346
|
+
# Ancestors see the clipped participant's viewport, not its hidden content.
|
|
347
|
+
if scroll_axes!=Vector2.ZERO: return size
|
|
350
348
|
var result := size
|
|
351
349
|
for index in range(3): result[index] = maxf(result[index],natural_extent[index])
|
|
352
350
|
for child in children:
|
|
@@ -355,7 +353,6 @@ func overflow_extent() -> Vector3:
|
|
|
355
353
|
return result
|
|
356
354
|
|
|
357
355
|
func _slots(items: Array, content: Vector3, definite: Vector3) -> Array:
|
|
358
|
-
if strategy=="scroll": return _scroll_slots(items,content)
|
|
359
356
|
if strategy=="grid": return _grid(items,content).slots
|
|
360
357
|
if strategy=="wrap": return WrapPolicy.layout(items,content,axis,physical_gaps,alignment,align_content,Vector2(definite.x,definite.y)).slots
|
|
361
358
|
return StackPolicy.slots(items,content,axis,physical_gaps[axis] if axis<2 and not length_specs.is_empty() else gap,alignment)
|
|
@@ -363,10 +360,8 @@ func _slots(items: Array, content: Vector3, definite: Vector3) -> Array:
|
|
|
363
360
|
func _authority(child, item: Dictionary, basis: Vector3) -> Vector3:
|
|
364
361
|
var authority := Vector3.ZERO
|
|
365
362
|
for index in range(3):
|
|
366
|
-
if basis[index]<0 or child.requested[index]>=0: continue
|
|
367
|
-
if strategy=="
|
|
368
|
-
if index<2 and not grid_config.get(["horizontal_scroll","vertical_scroll"][index],false): authority[index] = 1
|
|
369
|
-
elif strategy=="grid":
|
|
363
|
+
if basis[index]<0 or child.requested[index]>=0 or index<2 and scroll_axes[index]>0: continue
|
|
364
|
+
if strategy=="grid":
|
|
370
365
|
if index<2 and alignment[index]=="stretch": authority[index] = 1
|
|
371
366
|
elif index==axis:
|
|
372
367
|
if child.grow>0 or child.fill[index]>0: authority[index] = 1
|
|
@@ -435,12 +430,12 @@ func measure() -> Vector3:
|
|
|
435
430
|
# ignore this model's intrinsic extent and can inherit an independent basis.
|
|
436
431
|
func independent_axis(index: int) -> bool:
|
|
437
432
|
if requested[index] >= 0 or _external_axes[index] > 0: return true
|
|
438
|
-
if
|
|
433
|
+
if index<2 and scroll_axes[index]>0 and maximum()[index]>=0: return true
|
|
439
434
|
var parent = _parent.get_ref() if _parent != null else null
|
|
440
435
|
if parent == null: return false
|
|
441
436
|
var allocated := grow>0 or fill[index]>0
|
|
442
437
|
if index!=parent.axis: allocated = StackPolicy.cross_alignment({"align_self":align_self,"stretch":stretch,"fill":fill},parent.alignment[index],index)=="stretch"
|
|
443
|
-
if
|
|
438
|
+
if index<2 and parent.scroll_axes[index]>0: return false
|
|
444
439
|
if parent.strategy=="grid" and index<2: allocated = parent.alignment[index]=="stretch"
|
|
445
440
|
return parent.independent_axis(index) if requested[index] < 0 and allocated else false
|
|
446
441
|
|
|
@@ -453,6 +448,8 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
453
448
|
for index in range(3):
|
|
454
449
|
content[index] = maxf(0,content[index])
|
|
455
450
|
if independent_axis(index): reference[index] = content[index]
|
|
451
|
+
for index in range(2):
|
|
452
|
+
if scroll_axes[index]>0: reference[index] = -1
|
|
456
453
|
var changed: bool = reference != content_reference
|
|
457
454
|
if not _arrange_dirty and size == available and not changed: return
|
|
458
455
|
content_reference = reference
|
|
@@ -488,9 +485,6 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
488
485
|
# immediate children against this box before measuring their slots.
|
|
489
486
|
for child in children:
|
|
490
487
|
var child_reference := reference
|
|
491
|
-
if strategy=="scroll":
|
|
492
|
-
for index in range(2):
|
|
493
|
-
if grid_config.get(["horizontal_scroll","vertical_scroll"][index],false): child_reference[index] = -1
|
|
494
488
|
child.prepare(child_reference,viewport_size)
|
|
495
489
|
child.measure()
|
|
496
490
|
if not _reported_full_percent and children.size()>1:
|
|
@@ -501,16 +495,17 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
501
495
|
_reported_full_percent = true
|
|
502
496
|
push_warning("Estragon "+main_name+"=100% consumes the full definite parent content axis, not remaining space; siblings may overflow. Use an auto-sized Spacer with grow=1 for remaining space")
|
|
503
497
|
break
|
|
498
|
+
var layout_content := content
|
|
499
|
+
for index in range(2):
|
|
500
|
+
if scroll_axes[index]>0: layout_content[index] = maxf(content[index],natural_extent[index]-leading(padding+border)[index]-trailing(padding+border)[index])
|
|
504
501
|
var items := _items()
|
|
505
502
|
var policy := alignment.duplicate()
|
|
506
503
|
if center: policy[axis] = "center"
|
|
507
|
-
if strategy=="
|
|
508
|
-
slots = _scroll_slots(items,content)
|
|
509
|
-
elif strategy=="wrap":
|
|
504
|
+
if strategy=="wrap":
|
|
510
505
|
var wrap_basis := _wrap_basis()
|
|
511
|
-
slots = WrapPolicy.layout(items,
|
|
506
|
+
slots = WrapPolicy.layout(items,layout_content,axis,physical_gaps,policy,align_content,Vector2(1 if reference.x>=0 or axis==0 and wrap_basis.x>=0 else 0,1 if reference.y>=0 or axis==1 and wrap_basis.y>=0 else 0)).slots
|
|
512
507
|
else:
|
|
513
|
-
slots = StackPolicy.slots(items,
|
|
508
|
+
slots = StackPolicy.slots(items,layout_content,axis,physical_gaps[axis] if axis<2 and length_specs.has("column_gap") else gap,policy)
|
|
514
509
|
if strategy=="grid":
|
|
515
510
|
policy_result = _grid(items,reference)
|
|
516
511
|
if policy_result.has("error"): return
|
|
@@ -526,6 +521,14 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
526
521
|
for cross in range(3):
|
|
527
522
|
if strategy=="grid" and cross<2 and policy[cross]=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
|
|
528
523
|
elif strategy!="grid" and cross!=axis and StackPolicy.cross_alignment(items[index],policy[cross],cross)=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
|
|
529
|
-
|
|
524
|
+
for scrolling_axis in range(2):
|
|
525
|
+
if scroll_axes[scrolling_axis]>0: authority[scrolling_axis] = 0
|
|
530
526
|
child.arrange(slot.extent,authority)
|
|
531
527
|
arranged.emit(size)
|
|
528
|
+
|
|
529
|
+
func content_extent() -> Vector2:
|
|
530
|
+
var extent := Vector3.ZERO
|
|
531
|
+
for child in children:
|
|
532
|
+
var end: Vector3 = child.offset+child.overflow_extent()+trailing(child.margin)-leading(padding+border)
|
|
533
|
+
for index in range(2): extent[index] = maxf(extent[index],end[index])
|
|
534
|
+
return Vector2(extent.x,extent.y)
|
|
@@ -22,6 +22,7 @@ func start() -> void:
|
|
|
22
22
|
var host: Node = _host.get_ref()
|
|
23
23
|
host.child_entered_tree.connect(_child_changed)
|
|
24
24
|
host.child_exiting_tree.connect(_child_changed)
|
|
25
|
+
if host.has_signal("_layout_children_changed"): host.connect("_layout_children_changed",invalidate)
|
|
25
26
|
invalidate()
|
|
26
27
|
|
|
27
28
|
func stop() -> void:
|
|
@@ -30,6 +31,7 @@ func stop() -> void:
|
|
|
30
31
|
var host: Node = _host.get_ref()
|
|
31
32
|
if host.child_entered_tree.is_connected(_child_changed): host.child_entered_tree.disconnect(_child_changed)
|
|
32
33
|
if host.child_exiting_tree.is_connected(_child_changed): host.child_exiting_tree.disconnect(_child_changed)
|
|
34
|
+
if host.has_signal("_layout_children_changed") and host.is_connected("_layout_children_changed",invalidate): host.disconnect("_layout_children_changed",invalidate)
|
|
33
35
|
|
|
34
36
|
func _child_changed(_child: Node) -> void:
|
|
35
37
|
invalidate()
|
|
@@ -57,10 +59,11 @@ func _refresh() -> void:
|
|
|
57
59
|
extent = Vector3.ZERO
|
|
58
60
|
var host = _host.get_ref()
|
|
59
61
|
status = ERR_INVALID_PARAMETER
|
|
60
|
-
|
|
62
|
+
var native_children: Array = host.get_layout_children() if host!=null and host.has_method("get_layout_children") else (host.get_children() if host!=null else [])
|
|
63
|
+
if host == null or native_children.size() != 1:
|
|
61
64
|
_publish(host)
|
|
62
65
|
return
|
|
63
|
-
var child: Node =
|
|
66
|
+
var child: Node = native_children[0]
|
|
64
67
|
var points: Array[Vector3] = []
|
|
65
68
|
if _dimension == 2 and child is Polygon2D:
|
|
66
69
|
var basis: Transform2D = host.transform
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Lazy native viewport decoration. One owner coordinator; no child layout policy.
|
|
4
|
+
const Hosts = preload("composition_hosts.tres")
|
|
5
|
+
const Pointer = preload("pointer_2d.gd")
|
|
6
|
+
var owner_ref: WeakRef
|
|
7
|
+
var host:
|
|
8
|
+
get: return owner_ref.get_ref()
|
|
9
|
+
var _clip: Control
|
|
10
|
+
var _content: Node2D
|
|
11
|
+
var _horizontal: HScrollBar
|
|
12
|
+
var _vertical: VScrollBar
|
|
13
|
+
var _updating := false
|
|
14
|
+
var _input_guard = preload("scroll_input.gd").new()
|
|
15
|
+
func _init(owner: Node2D) -> void:
|
|
16
|
+
owner_ref = weakref(owner)
|
|
17
|
+
static func valid_offset(value) -> bool:
|
|
18
|
+
return value is Vector2 and is_finite(value.x) and is_finite(value.y) and value.x>=0 and value.y>=0
|
|
19
|
+
func _ensure_viewport() -> void:
|
|
20
|
+
if is_instance_valid(_clip):
|
|
21
|
+
Hosts.add(_content,host.layout)
|
|
22
|
+
if enabled(): _input_guard.start(_content)
|
|
23
|
+
return
|
|
24
|
+
_clip = host.get_node_or_null("_EstragonViewport")
|
|
25
|
+
if _clip==null:
|
|
26
|
+
_clip = Control.new()
|
|
27
|
+
_clip.name = "_EstragonViewport"
|
|
28
|
+
_clip.clip_contents = true
|
|
29
|
+
_clip.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
30
|
+
host.add_child(_clip,false,Node.INTERNAL_MODE_BACK)
|
|
31
|
+
_content = _clip.get_node_or_null("_EstragonContent")
|
|
32
|
+
if _content==null:
|
|
33
|
+
_content = Node2D.new()
|
|
34
|
+
_content.name = "_EstragonContent"
|
|
35
|
+
_clip.add_child(_content,false,Node.INTERNAL_MODE_BACK)
|
|
36
|
+
Hosts.add(_content,host.layout)
|
|
37
|
+
_input_guard.start(_content)
|
|
38
|
+
if not _content.child_entered_tree.is_connected(host.layout._child_entered): _content.child_entered_tree.connect(host.layout._child_entered)
|
|
39
|
+
if not _content.child_exiting_tree.is_connected(host.layout._child_exiting): _content.child_exiting_tree.connect(host.layout._child_exiting)
|
|
40
|
+
_content.child_entered_tree.connect(_children_changed)
|
|
41
|
+
_content.child_exiting_tree.connect(_children_changed)
|
|
42
|
+
_horizontal = HScrollBar.new()
|
|
43
|
+
_vertical = VScrollBar.new()
|
|
44
|
+
host.add_child(_horizontal,false,Node.INTERNAL_MODE_BACK)
|
|
45
|
+
# BACK appends internal children after the clip/content branch. FRONT is
|
|
46
|
+
# the beginning of SceneTree order and would let native Controls win GUI
|
|
47
|
+
# picking over this scrollbar, regardless of how the bar appears to paint.
|
|
48
|
+
host.add_child(_vertical,false,Node.INTERNAL_MODE_BACK)
|
|
49
|
+
_horizontal.step = 0
|
|
50
|
+
_vertical.step = 0
|
|
51
|
+
_horizontal.custom_step = 40
|
|
52
|
+
_vertical.custom_step = 40
|
|
53
|
+
_horizontal.value_changed.connect(_horizontal_changed)
|
|
54
|
+
_vertical.value_changed.connect(_vertical_changed)
|
|
55
|
+
func is_private(child: Node) -> bool:
|
|
56
|
+
return child==_clip or child==_horizontal or child==_vertical
|
|
57
|
+
func _children_changed(_child: Node) -> void:
|
|
58
|
+
if host!=null: host._layout_children_changed.emit()
|
|
59
|
+
func _remember_owners(node: Node, values: Dictionary) -> void:
|
|
60
|
+
if node.owner!=null: values[node] = node.owner
|
|
61
|
+
for child in node.get_children(): _remember_owners(child,values)
|
|
62
|
+
func _adopt_content(child: Node) -> void:
|
|
63
|
+
if child.get_parent()!=host or is_private(child): return
|
|
64
|
+
var owners := {}
|
|
65
|
+
_remember_owners(child,owners)
|
|
66
|
+
var scene_owner := child.owner
|
|
67
|
+
var focus: Control = host.get_viewport().gui_get_focus_owner() if host.is_inside_tree() else null
|
|
68
|
+
host.remove_child(child)
|
|
69
|
+
_content.add_child(child)
|
|
70
|
+
if scene_owner!=null:
|
|
71
|
+
# Native scene persistence includes the necessary private ancestry only
|
|
72
|
+
# for an authored persistent root. Generated owner-null views serialize
|
|
73
|
+
# neither helpers nor content; descriptions remount after reload.
|
|
74
|
+
_clip.owner = scene_owner
|
|
75
|
+
_content.owner = scene_owner
|
|
76
|
+
for node in owners:
|
|
77
|
+
if owners[node].is_ancestor_of(node): node.owner = owners[node]
|
|
78
|
+
if is_instance_valid(focus) and focus.is_inside_tree(): focus.grab_focus()
|
|
79
|
+
host.layout._sync()
|
|
80
|
+
func start() -> void:
|
|
81
|
+
if not enabled() and not is_instance_valid(_clip) and host.get_node_or_null("_EstragonViewport")==null: return
|
|
82
|
+
_ensure_viewport()
|
|
83
|
+
for child in host.get_children():
|
|
84
|
+
if not is_private(child): _adopt_content(child)
|
|
85
|
+
if not host.child_entered_tree.is_connected(_external_child): host.child_entered_tree.connect(_external_child)
|
|
86
|
+
_clip.clip_contents = enabled()
|
|
87
|
+
if enabled(): _input_guard.start(_content)
|
|
88
|
+
else: _input_guard.stop()
|
|
89
|
+
# Re-entry/scene reload must retain offsets until children and the existing
|
|
90
|
+
# coordinator are active again. Their arranged signal refreshes the viewport.
|
|
91
|
+
if host.layout.active: _refresh_viewport()
|
|
92
|
+
func children() -> Array:
|
|
93
|
+
var values: Array = _content.get_children() if is_instance_valid(_content) else []
|
|
94
|
+
for child in host.get_children():
|
|
95
|
+
if not is_private(child): values.append(child)
|
|
96
|
+
return values
|
|
97
|
+
func child_parent() -> Node:
|
|
98
|
+
return _content
|
|
99
|
+
func enabled() -> bool:
|
|
100
|
+
return host.horizontal_scroll or host.vertical_scroll
|
|
101
|
+
func _external_child(child: Node) -> void:
|
|
102
|
+
if not is_private(child): _adopt_later.call_deferred(weakref(child))
|
|
103
|
+
func _adopt_later(reference: WeakRef) -> void:
|
|
104
|
+
var child = reference.get_ref()
|
|
105
|
+
if child!=null and host!=null and host.is_inside_tree(): _adopt_content(child)
|
|
106
|
+
func stop() -> void:
|
|
107
|
+
_input_guard.stop()
|
|
108
|
+
if host.child_entered_tree.is_connected(_external_child): host.child_entered_tree.disconnect(_external_child)
|
|
109
|
+
if is_instance_valid(_content): Hosts.remove(_content,host.layout)
|
|
110
|
+
func refresh() -> void:
|
|
111
|
+
_refresh_viewport()
|
|
112
|
+
func offset_changed() -> void:
|
|
113
|
+
if not host.layout.model.is_layout_dirty(): _update_scroll()
|
|
114
|
+
func _refresh_viewport() -> void:
|
|
115
|
+
if not is_instance_valid(_clip): return
|
|
116
|
+
var rect: Rect2 = host.get_content_rect()
|
|
117
|
+
_clip.position = rect.position
|
|
118
|
+
_clip.size = rect.size
|
|
119
|
+
host._content_extent = host.layout.model.content_extent()
|
|
120
|
+
host._scroll_range = Vector2(maxf(0,host.content_extent.x-rect.size.x) if host.horizontal_scroll else 0,maxf(0,host.content_extent.y-rect.size.y) if host.vertical_scroll else 0)
|
|
121
|
+
_update_scroll()
|
|
122
|
+
func _update_scroll() -> void:
|
|
123
|
+
if _updating or not is_instance_valid(_content): return
|
|
124
|
+
_updating = true
|
|
125
|
+
host.scroll_offset = Vector2(clampf(host.scroll_offset.x,0,host.scroll_range.x),clampf(host.scroll_offset.y,0,host.scroll_range.y))
|
|
126
|
+
if _content.position!=-host.get_content_rect().position-host.scroll_offset:
|
|
127
|
+
_input_guard.cancel()
|
|
128
|
+
var entry = host.get_layout_root()
|
|
129
|
+
if entry!=null and entry.has_method("_get_pointer_router"): entry._get_pointer_router().cancel()
|
|
130
|
+
_content.position = -host.get_content_rect().position-host.scroll_offset
|
|
131
|
+
var rect: Rect2 = host.get_content_rect()
|
|
132
|
+
_horizontal.visible = host.scroll_range.x>0
|
|
133
|
+
_vertical.visible = host.scroll_range.y>0
|
|
134
|
+
_horizontal.position = rect.position+Vector2(0,maxf(0,rect.size.y-12))
|
|
135
|
+
_horizontal.size = Vector2(maxf(0,rect.size.x-(12 if _vertical.visible else 0)),12)
|
|
136
|
+
_vertical.position = rect.position+Vector2(maxf(0,rect.size.x-12),0)
|
|
137
|
+
_vertical.size = Vector2(12,maxf(0,rect.size.y-(12 if _horizontal.visible else 0)))
|
|
138
|
+
_horizontal.max_value = host.content_extent.x
|
|
139
|
+
_horizontal.page = rect.size.x
|
|
140
|
+
_horizontal.value = host.scroll_offset.x
|
|
141
|
+
_vertical.max_value = host.content_extent.y
|
|
142
|
+
_vertical.page = rect.size.y
|
|
143
|
+
_vertical.value = host.scroll_offset.y
|
|
144
|
+
_updating = false
|
|
145
|
+
func _horizontal_changed(value: float) -> void:
|
|
146
|
+
if not _updating: host.scroll_offset = Vector2(value,host.scroll_offset.y)
|
|
147
|
+
func _vertical_changed(value: float) -> void:
|
|
148
|
+
if not _updating: host.scroll_offset = Vector2(host.scroll_offset.x,value)
|
|
149
|
+
func pointer_allowed(position: Vector2) -> bool:
|
|
150
|
+
if not enabled(): return true
|
|
151
|
+
for bar in [_horizontal,_vertical]:
|
|
152
|
+
if is_instance_valid(bar) and bar.is_visible_in_tree():
|
|
153
|
+
var point: Vector2 = bar.get_global_transform_with_canvas().affine_inverse()*position
|
|
154
|
+
if Rect2(Vector2.ZERO,bar.size).has_point(point): return false
|
|
155
|
+
return true
|
|
156
|
+
func input(event: InputEvent) -> void:
|
|
157
|
+
if not enabled() or Engine.is_editor_hint() or not host.is_visible_in_tree() or not (event is InputEventMouse or event is InputEventPanGesture): return
|
|
158
|
+
var point: Vector2 = host.get_global_transform_with_canvas().affine_inverse()*event.position
|
|
159
|
+
if not host.get_content_rect().has_point(point) or not Pointer.inside_clips(host,event.position): return
|
|
160
|
+
var delta := Vector2.ZERO
|
|
161
|
+
if event is InputEventMouseButton and event.pressed:
|
|
162
|
+
match event.button_index:
|
|
163
|
+
MOUSE_BUTTON_WHEEL_DOWN: delta.y = 40*event.factor
|
|
164
|
+
MOUSE_BUTTON_WHEEL_UP: delta.y = -40*event.factor
|
|
165
|
+
MOUSE_BUTTON_WHEEL_RIGHT: delta.x = 40*event.factor
|
|
166
|
+
MOUSE_BUTTON_WHEEL_LEFT: delta.x = -40*event.factor
|
|
167
|
+
if event.shift_pressed: delta = Vector2(delta.y,delta.x)
|
|
168
|
+
elif event is InputEventPanGesture: delta = event.delta*40
|
|
169
|
+
else: return
|
|
170
|
+
var next := Vector2(clampf(host.scroll_offset.x+delta.x,0,host.scroll_range.x),clampf(host.scroll_offset.y+delta.y,0,host.scroll_range.y))
|
|
171
|
+
if next==host.scroll_offset: return # An exhausted nested viewport bubbles naturally.
|
|
172
|
+
host.scroll_offset = next
|
|
173
|
+
var entry = host.get_layout_root()
|
|
174
|
+
if entry!=null and entry.has_method("_get_pointer_router"): entry._get_pointer_router().cancel()
|
|
175
|
+
host.get_viewport().set_input_as_handled()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://b4qhcxualkktg
|
package/package.json
CHANGED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
@tool
|
|
2
|
-
class_name EstragonScrollView
|
|
3
|
-
extends "component_2d.gd"
|
|
4
|
-
## One authored content root, one existing layout model. Native Control supplies
|
|
5
|
-
## rectangular clipping/GUI exclusion; Node2D supplies local scroll translation.
|
|
6
|
-
const ESTRAGON_SCROLL_VIEW := true
|
|
7
|
-
const Hosts = preload("internal/composition_hosts.tres")
|
|
8
|
-
const Pointer = preload("internal/pointer_2d.gd")
|
|
9
|
-
@export var horizontal_scroll: bool = false:
|
|
10
|
-
set(value):
|
|
11
|
-
if horizontal_scroll==value: return
|
|
12
|
-
horizontal_scroll = value
|
|
13
|
-
_changed()
|
|
14
|
-
@export var vertical_scroll: bool = false:
|
|
15
|
-
set(value):
|
|
16
|
-
if vertical_scroll==value: return
|
|
17
|
-
vertical_scroll = value
|
|
18
|
-
_changed()
|
|
19
|
-
@export var scroll_offset := Vector2.ZERO:
|
|
20
|
-
set(value):
|
|
21
|
-
if not valid_offset(value):
|
|
22
|
-
push_error("Estragon ScrollView scroll_offset requires a finite nonnegative Vector2")
|
|
23
|
-
return
|
|
24
|
-
scroll_offset = value
|
|
25
|
-
# A new viewport/content allocation must resolve before restoring/clamping
|
|
26
|
-
# an authored offset. The existing arranged callback consumes it once.
|
|
27
|
-
if not layout.model.is_layout_dirty(): _update_scroll()
|
|
28
|
-
var scroll_range: Vector2:
|
|
29
|
-
get: return _scroll_range
|
|
30
|
-
set(_value): push_error("Estragon ScrollView scroll_range is read-only")
|
|
31
|
-
var content_extent: Vector2:
|
|
32
|
-
get: return _content_extent
|
|
33
|
-
set(_value): push_error("Estragon ScrollView content_extent is read-only")
|
|
34
|
-
var _scroll_range := Vector2.ZERO
|
|
35
|
-
var _content_extent := Vector2.ZERO
|
|
36
|
-
var _clip: Control
|
|
37
|
-
var _content: Node2D
|
|
38
|
-
var _horizontal: HScrollBar
|
|
39
|
-
var _vertical: VScrollBar
|
|
40
|
-
var _updating := false
|
|
41
|
-
var _input_guard = preload("internal/scroll_input.gd").new()
|
|
42
|
-
static func valid_offset(value) -> bool:
|
|
43
|
-
return value is Vector2 and is_finite(value.x) and is_finite(value.y) and value.x>=0 and value.y>=0
|
|
44
|
-
func _ensure_viewport() -> void:
|
|
45
|
-
if is_instance_valid(_clip):
|
|
46
|
-
Hosts.add(_content,layout)
|
|
47
|
-
_input_guard.start(_content)
|
|
48
|
-
return
|
|
49
|
-
_clip = get_node_or_null("_EstragonViewport")
|
|
50
|
-
if _clip==null:
|
|
51
|
-
_clip = Control.new()
|
|
52
|
-
_clip.name = "_EstragonViewport"
|
|
53
|
-
_clip.clip_contents = true
|
|
54
|
-
_clip.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
55
|
-
add_child(_clip,false,Node.INTERNAL_MODE_BACK)
|
|
56
|
-
_content = _clip.get_node_or_null("_EstragonContent")
|
|
57
|
-
if _content==null:
|
|
58
|
-
_content = Node2D.new()
|
|
59
|
-
_content.name = "_EstragonContent"
|
|
60
|
-
_clip.add_child(_content,false,Node.INTERNAL_MODE_BACK)
|
|
61
|
-
Hosts.add(_content,layout)
|
|
62
|
-
_input_guard.start(_content)
|
|
63
|
-
if not _content.child_entered_tree.is_connected(layout._child_entered): _content.child_entered_tree.connect(layout._child_entered)
|
|
64
|
-
if not _content.child_exiting_tree.is_connected(layout._child_exiting): _content.child_exiting_tree.connect(layout._child_exiting)
|
|
65
|
-
_horizontal = HScrollBar.new()
|
|
66
|
-
_vertical = VScrollBar.new()
|
|
67
|
-
add_child(_horizontal,false,Node.INTERNAL_MODE_BACK)
|
|
68
|
-
add_child(_vertical,false,Node.INTERNAL_MODE_FRONT)
|
|
69
|
-
_horizontal.step = 0
|
|
70
|
-
_vertical.step = 0
|
|
71
|
-
_horizontal.custom_step = 40
|
|
72
|
-
_vertical.custom_step = 40
|
|
73
|
-
_horizontal.value_changed.connect(_horizontal_changed)
|
|
74
|
-
_vertical.value_changed.connect(_vertical_changed)
|
|
75
|
-
func _composition_child_parent() -> Node:
|
|
76
|
-
_ensure_viewport()
|
|
77
|
-
return _content
|
|
78
|
-
func _layout_children() -> Array:
|
|
79
|
-
return _content.get_children() if is_instance_valid(_content) else []
|
|
80
|
-
func get_content_root() -> Node:
|
|
81
|
-
return _content.get_child(0) if is_instance_valid(_content) and _content.get_child_count()>0 else null
|
|
82
|
-
func _layout_options() -> Dictionary:
|
|
83
|
-
var result := super._layout_options()
|
|
84
|
-
result.strategy = "scroll"
|
|
85
|
-
result.grid = {"horizontal_scroll":horizontal_scroll,"vertical_scroll":vertical_scroll}
|
|
86
|
-
return result
|
|
87
|
-
func _composition_is_private(child: Node) -> bool:
|
|
88
|
-
return child==_clip or child==_horizontal or child==_vertical
|
|
89
|
-
func _remember_owners(node: Node, values: Dictionary) -> void:
|
|
90
|
-
if node.owner!=null: values[node] = node.owner
|
|
91
|
-
for child in node.get_children(): _remember_owners(child,values)
|
|
92
|
-
func _adopt_content(child: Node) -> void:
|
|
93
|
-
if child.get_parent()!=self or _composition_is_private(child): return
|
|
94
|
-
if _content.get_child_count()>0:
|
|
95
|
-
push_error("Estragon ScrollView requires one content root; wrap siblings in VBox/Grid")
|
|
96
|
-
return
|
|
97
|
-
var owners := {}
|
|
98
|
-
_remember_owners(child,owners)
|
|
99
|
-
var scene_owner := child.owner
|
|
100
|
-
remove_child(child)
|
|
101
|
-
_content.add_child(child)
|
|
102
|
-
if scene_owner!=null:
|
|
103
|
-
# Native scene persistence includes the necessary private ancestry only
|
|
104
|
-
# for an authored persistent root. Generated owner-null views serialize
|
|
105
|
-
# neither helpers nor content; descriptions remount after reload.
|
|
106
|
-
_clip.owner = scene_owner
|
|
107
|
-
_content.owner = scene_owner
|
|
108
|
-
for node in owners:
|
|
109
|
-
if owners[node].is_ancestor_of(node): node.owner = owners[node]
|
|
110
|
-
layout._sync()
|
|
111
|
-
func _enter_tree() -> void:
|
|
112
|
-
_ensure_viewport()
|
|
113
|
-
for child in get_children():
|
|
114
|
-
if not _composition_is_private(child): _adopt_content(child)
|
|
115
|
-
super._enter_tree()
|
|
116
|
-
if not child_entered_tree.is_connected(_external_child): child_entered_tree.connect(_external_child)
|
|
117
|
-
func _external_child(child: Node) -> void:
|
|
118
|
-
if not _composition_is_private(child): _adopt_later.call_deferred(weakref(child))
|
|
119
|
-
func _adopt_later(reference: WeakRef) -> void:
|
|
120
|
-
var child = reference.get_ref()
|
|
121
|
-
if child!=null and is_inside_tree(): _adopt_content(child)
|
|
122
|
-
func _exit_tree() -> void:
|
|
123
|
-
_input_guard.stop()
|
|
124
|
-
if child_entered_tree.is_connected(_external_child): child_entered_tree.disconnect(_external_child)
|
|
125
|
-
super._exit_tree()
|
|
126
|
-
if is_instance_valid(_content): Hosts.remove(_content,layout)
|
|
127
|
-
func apply_layout_size(extent: Vector3) -> void:
|
|
128
|
-
super.apply_layout_size(extent)
|
|
129
|
-
_refresh_viewport()
|
|
130
|
-
func _refresh_viewport() -> void:
|
|
131
|
-
if not is_instance_valid(_clip): return
|
|
132
|
-
var rect := get_content_rect()
|
|
133
|
-
_clip.position = rect.position
|
|
134
|
-
_clip.size = rect.size
|
|
135
|
-
_content_extent = Vector2.ZERO
|
|
136
|
-
if not layout.model.children.is_empty():
|
|
137
|
-
var extent: Vector3 = layout.model.children[0].overflow_extent()
|
|
138
|
-
_content_extent = Vector2(extent.x,extent.y)
|
|
139
|
-
_scroll_range = Vector2(maxf(0,content_extent.x-rect.size.x) if horizontal_scroll else 0,maxf(0,content_extent.y-rect.size.y) if vertical_scroll else 0)
|
|
140
|
-
_update_scroll()
|
|
141
|
-
func _update_scroll() -> void:
|
|
142
|
-
if _updating or not is_instance_valid(_content): return
|
|
143
|
-
_updating = true
|
|
144
|
-
scroll_offset = Vector2(clampf(scroll_offset.x,0,scroll_range.x),clampf(scroll_offset.y,0,scroll_range.y))
|
|
145
|
-
if _content.position!=-scroll_offset:
|
|
146
|
-
_input_guard.cancel()
|
|
147
|
-
var entry = get_layout_root()
|
|
148
|
-
if entry!=null and entry.has_method("_get_pointer_router"): entry._get_pointer_router().cancel()
|
|
149
|
-
_content.position = -scroll_offset
|
|
150
|
-
var rect := get_content_rect()
|
|
151
|
-
_horizontal.visible = scroll_range.x>0
|
|
152
|
-
_vertical.visible = scroll_range.y>0
|
|
153
|
-
_horizontal.position = rect.position+Vector2(0,maxf(0,rect.size.y-12))
|
|
154
|
-
_horizontal.size = Vector2(maxf(0,rect.size.x-(12 if _vertical.visible else 0)),12)
|
|
155
|
-
_vertical.position = rect.position+Vector2(maxf(0,rect.size.x-12),0)
|
|
156
|
-
_vertical.size = Vector2(12,maxf(0,rect.size.y-(12 if _horizontal.visible else 0)))
|
|
157
|
-
_horizontal.max_value = content_extent.x
|
|
158
|
-
_horizontal.page = rect.size.x
|
|
159
|
-
_horizontal.value = scroll_offset.x
|
|
160
|
-
_vertical.max_value = content_extent.y
|
|
161
|
-
_vertical.page = rect.size.y
|
|
162
|
-
_vertical.value = scroll_offset.y
|
|
163
|
-
_updating = false
|
|
164
|
-
func _horizontal_changed(value: float) -> void:
|
|
165
|
-
if not _updating: scroll_offset = Vector2(value,scroll_offset.y)
|
|
166
|
-
func _vertical_changed(value: float) -> void:
|
|
167
|
-
if not _updating: scroll_offset = Vector2(scroll_offset.x,value)
|
|
168
|
-
func _content_pointer_allowed(position: Vector2) -> bool:
|
|
169
|
-
for bar in [_horizontal,_vertical]:
|
|
170
|
-
if is_instance_valid(bar) and bar.is_visible_in_tree():
|
|
171
|
-
var point: Vector2 = bar.get_global_transform_with_canvas().affine_inverse()*position
|
|
172
|
-
if Rect2(Vector2.ZERO,bar.size).has_point(point): return false
|
|
173
|
-
return true
|
|
174
|
-
func _input(event: InputEvent) -> void:
|
|
175
|
-
if Engine.is_editor_hint() or not is_visible_in_tree() or not (event is InputEventMouse or event is InputEventPanGesture): return
|
|
176
|
-
var point: Vector2 = get_global_transform_with_canvas().affine_inverse()*event.position
|
|
177
|
-
if not get_content_rect().has_point(point) or not Pointer.inside_clips(self,event.position): return
|
|
178
|
-
var delta := Vector2.ZERO
|
|
179
|
-
if event is InputEventMouseButton and event.pressed:
|
|
180
|
-
match event.button_index:
|
|
181
|
-
MOUSE_BUTTON_WHEEL_DOWN: delta.y = 40*event.factor
|
|
182
|
-
MOUSE_BUTTON_WHEEL_UP: delta.y = -40*event.factor
|
|
183
|
-
MOUSE_BUTTON_WHEEL_RIGHT: delta.x = 40*event.factor
|
|
184
|
-
MOUSE_BUTTON_WHEEL_LEFT: delta.x = -40*event.factor
|
|
185
|
-
if event.shift_pressed: delta = Vector2(delta.y,delta.x)
|
|
186
|
-
elif event is InputEventPanGesture: delta = event.delta*40
|
|
187
|
-
else: return
|
|
188
|
-
var next := Vector2(clampf(scroll_offset.x+delta.x,0,scroll_range.x),clampf(scroll_offset.y+delta.y,0,scroll_range.y))
|
|
189
|
-
if next==scroll_offset: return # An exhausted nested viewport bubbles naturally.
|
|
190
|
-
scroll_offset = next
|
|
191
|
-
var entry = get_layout_root()
|
|
192
|
-
if entry!=null and entry.has_method("_get_pointer_router"): entry._get_pointer_router().cancel()
|
|
193
|
-
get_viewport().set_input_as_handled()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
uid://cqrqp33qeuh6g
|