@papercraftgames/estragon 0.1.0-beta.25 → 0.1.0-beta.27

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.
@@ -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,"ESTRAGON_SCROLL_VIEW") and name in ["scroll_range","content_extent"]:
65
- _error("Read-only ScrollView measurement: "+name,attribute.name_span)
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)
@@ -137,6 +137,11 @@ func _component(node: Model.Component) -> void:
137
137
  _error("Grid "+name+" requires start, center, end or stretch",attribute.value.span)
138
138
  return
139
139
  var is_color := VisualStyle.registered(resolved.script,name)
140
+ if VisualStyle.supported(resolved.script) and name=="background_texture_mode" and attribute.value is Model.Literal:
141
+ var message := VisualStyle.surface_error(name,attribute.value.value)
142
+ if not message.is_empty():
143
+ _error(message,attribute.value.span)
144
+ return
140
145
  if is_color:
141
146
  _color(attribute)
142
147
  if not file.diagnostics.is_empty(): return
@@ -192,10 +197,6 @@ func _component(node: Model.Component) -> void:
192
197
  else:
193
198
  for index in range(node.children.size()-1,-1,-1):
194
199
  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
200
  var sibling_names := {}
200
201
  for child in node.children:
201
202
  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"},
@@ -3,5 +3,5 @@
3
3
  name="Estragon"
4
4
  description="Native Gogo/GGX highlighting, compilation and validation before Play."
5
5
  author="Resist Design"
6
- version="0.1.0-beta.25"
6
+ version="0.1.0-beta.27"
7
7
  script="plugin.gd"
@@ -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,"ESTRAGON_SCROLL_VIEW")
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)
@@ -365,7 +365,7 @@ func _apply(desired: Element, record: Mounted) -> void:
365
365
  # do not turn omission into permanent native state or change other props.
366
366
  if VisualStyle.supported(desired.type):
367
367
  for key in record.properties:
368
- if key in Length.BORDER_EDGES and not desired.properties.has(key):
368
+ if (key in Length.BORDER_EDGES or key in VisualStyle.RADII.slice(1)) and not desired.properties.has(key):
369
369
  node.set(key,"auto")
370
370
  writes += 1
371
371
  if Profile.is_enabled(): Profile.add("property_writes")
@@ -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
- # ScrollView retains it until the same core's next arrangement, so attribute
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,"ESTRAGON_SCROLL_VIEW"):
598
- var content: Array = desired.children.filter(func(child): return child!=null)
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 ScrollView measurement")
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 [])
@@ -651,6 +645,9 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
651
645
  var native: String = desired.type if desired.type is String else desired.type.get_instance_base_type()
652
646
  if not properties.has(key) or not NativeAttributes.writable(native,desired.type,str(key),properties[key]): return _invalid_attribute(desired,str(key),"unknown, read-only or reserved native property")
653
647
  var value = desired.properties[key]
648
+ if VisualStyle.supported(desired.type) and key in VisualStyle.SURFACE:
649
+ var message := VisualStyle.surface_error(key,value)
650
+ if not message.is_empty(): return _invalid_attribute(desired,str(key),message)
654
651
  if key=="align_self" and StackContract.self_registered(desired.type):
655
652
  var message := StackContract.error(key,value,"")
656
653
  if not message.is_empty(): return _invalid_attribute(desired,str(key),message)
@@ -694,7 +691,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
694
691
  var node: Node = previous.node.get_ref() if _compatible(desired,previous) else null
695
692
  if parent != null:
696
693
  var name := _effective_name(desired,previous)
697
- for existing in parent.get_children():
694
+ for existing in (parent._layout_children() if parent.has_method("_layout_children") else parent.get_children()):
698
695
  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
696
  var known: Array = []
700
697
  if node != null:
@@ -712,7 +709,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
712
709
  if names.has(name): return _invalid_attribute(child,"name","duplicate effective sibling name "+name)
713
710
  names[name] = true
714
711
  if node != null:
715
- for existing in node.get_children():
712
+ for existing in (node._layout_children() if node.has_method("_layout_children") else node.get_children()):
716
713
  if str(existing.name)==name and not known.has(existing): return false
717
714
  return true
718
715
  func _free_managed(record: Mounted, rescue: Node = null) -> void:
@@ -731,10 +728,10 @@ func _free_managed(record: Mounted, rescue: Node = null) -> void:
731
728
  var owner: Node = rescue if rescue != null else host.get_ref()
732
729
  var manager = state.get_ref()
733
730
  if manager != null and manager.records.has(node.get_instance_id()): manager.unmount(node,owner)
734
- for child in node.get_children():
731
+ for child in (node._layout_children() if node.has_method("_layout_children") else node.get_children()):
735
732
  if node.has_method("_composition_is_private") and node._composition_is_private(child): continue
736
733
  var persisted_owner: Node = child.owner
737
- node.remove_child(child)
734
+ child.get_parent().remove_child(child)
738
735
  if owner != null:
739
736
  owner.add_child(child)
740
737
  if persisted_owner != null and persisted_owner.is_ancestor_of(child): child.owner = persisted_owner
@@ -4,10 +4,46 @@ 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 clip_content: bool = false:
16
+ set(value):
17
+ if clip_content==value: return
18
+ clip_content = value
19
+ _clip_changed()
20
+ @export var horizontal_scroll: bool = false:
21
+ set(value):
22
+ if horizontal_scroll==value: return
23
+ horizontal_scroll = value
24
+ _scroll_changed()
25
+ @export var vertical_scroll: bool = false:
26
+ set(value):
27
+ if vertical_scroll==value: return
28
+ vertical_scroll = value
29
+ _scroll_changed()
30
+ @export var scroll_offset := Vector2.ZERO:
31
+ set(value):
32
+ if not Scroll.valid_offset(value):
33
+ push_error("Estragon scrolling scroll_offset requires a finite nonnegative Vector2")
34
+ return
35
+ scroll_offset = value
36
+ if _scroll!=null: _scroll.offset_changed()
37
+ elif not horizontal_scroll and not vertical_scroll: scroll_offset = Vector2.ZERO
38
+ var scroll_range: Vector2:
39
+ get: return _scroll_range
40
+ set(_value): push_error("Estragon scrolling scroll_range is read-only")
41
+ var content_extent: Vector2:
42
+ get: return _content_extent
43
+ set(_value): push_error("Estragon scrolling content_extent is read-only")
44
+ var _scroll_range := Vector2.ZERO
45
+ var _content_extent := Vector2.ZERO
46
+
11
47
  var row_gap: Variant = "auto":
12
48
  set(value):
13
49
  if is_same(row_gap,value) or not lengths.assign("row_gap",value): return
@@ -25,6 +61,56 @@ var _visual_style = VisualStyle.new()
25
61
  const Length = preload("internal/length.gd")
26
62
  var lengths = Length.new()
27
63
  const ESTRAGON_VISUAL_STYLE := true
64
+ @export var background_texture: Texture2D:
65
+ set(value):
66
+ if value==background_texture: return
67
+ background_texture = value
68
+ _visual_style.set_texture(value)
69
+ _queue_style_redraw()
70
+ @export_enum("stretch", "tile") var background_texture_mode: String = "stretch":
71
+ set(value):
72
+ if value==background_texture_mode: return
73
+ var message := VisualStyle.surface_error("background_texture_mode",value)
74
+ if not message.is_empty():
75
+ push_error("Estragon surface: "+message)
76
+ return
77
+ background_texture_mode = value
78
+ _visual_style.set_texture_mode(value)
79
+ _queue_style_redraw()
80
+ var corner_radius: Variant = 0.0:
81
+ set(value):
82
+ if is_same(corner_radius,value) or not _assign_radius("corner_radius",value): return
83
+ corner_radius = value
84
+ _queue_style_redraw()
85
+ var corner_radius_top_left: Variant = "auto":
86
+ set(value):
87
+ if is_same(corner_radius_top_left,value) or not _assign_radius("corner_radius_top_left",value): return
88
+ corner_radius_top_left = value
89
+ _queue_style_redraw()
90
+ var corner_radius_top_right: Variant = "auto":
91
+ set(value):
92
+ if is_same(corner_radius_top_right,value) or not _assign_radius("corner_radius_top_right",value): return
93
+ corner_radius_top_right = value
94
+ _queue_style_redraw()
95
+ var corner_radius_bottom_right: Variant = "auto":
96
+ set(value):
97
+ if is_same(corner_radius_bottom_right,value) or not _assign_radius("corner_radius_bottom_right",value): return
98
+ corner_radius_bottom_right = value
99
+ _queue_style_redraw()
100
+ var corner_radius_bottom_left: Variant = "auto":
101
+ set(value):
102
+ if is_same(corner_radius_bottom_left,value) or not _assign_radius("corner_radius_bottom_left",value): return
103
+ corner_radius_bottom_left = value
104
+ _queue_style_redraw()
105
+ func _assign_radius(name: String, value) -> bool:
106
+ var parsed := Length.parse(value,Length.domain(name))
107
+ _visual_style.parse_count += 1
108
+ if parsed.has("error"):
109
+ push_error("Estragon surface '"+name+"': "+parsed.error)
110
+ return false
111
+ _visual_style.radii[name] = parsed
112
+ _visual_style.sync_viewport()
113
+ return true
28
114
  var background_color: Variant = "transparent":
29
115
  set(value):
30
116
  if is_same(background_color,value) or not _style_supported() or not _visual_style.assign("background_color",value): return
@@ -192,6 +278,7 @@ func _get_property_list() -> Array[Dictionary]:
192
278
  var properties := Length.properties(["width","height","min_width","min_height","max_width","max_height","x","y","gap","padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"])
193
279
  properties.append_array(Length.properties(["row_gap","column_gap"]))
194
280
  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"]))
281
+ if VisualStyle.supported(get_script()): properties.append_array(Length.properties(VisualStyle.RADII))
195
282
  return properties
196
283
  static func valid_length(value) -> bool:
197
284
  return Length.valid(value,"extent")
@@ -225,11 +312,43 @@ func get_content_rect() -> Rect2:
225
312
 
226
313
  func _layout_options() -> Dictionary:
227
314
  var natural := _measure_native()
228
- return {"axis":_layout_axis(),"fill":Vector3.ZERO,"intrinsic":Vector3(natural.x,natural.y,0)}
315
+ 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
316
 
230
317
  func _is_layout_entry() -> bool:
231
318
  return false
232
319
 
320
+ func _scroll_changed() -> void:
321
+ if _scroll==null and (horizontal_scroll or vertical_scroll): _scroll = Scroll.new(self)
322
+ _changed()
323
+ if _scroll!=null and is_inside_tree(): _scroll.start()
324
+ func _clip_changed() -> void:
325
+ if _scroll==null and clip_content: _scroll = Scroll.new(self)
326
+ if layout==null: return
327
+ layout.model.clips_content = clip_content
328
+ if _scroll!=null and is_inside_tree(): _scroll.start()
329
+ # Only overflow observers need a refresh, not the existing layout slots.
330
+ var coordinator = layout.parent_coordinator()
331
+ while coordinator!=null:
332
+ var node = coordinator._host.get_ref()
333
+ if node!=null and "_scroll" in node and node._scroll!=null: node._scroll.refresh()
334
+ coordinator = coordinator.parent_coordinator()
335
+ func _composition_child_parent() -> Node:
336
+ return _scroll.child_parent() if _scroll!=null and is_instance_valid(_scroll.child_parent()) else self
337
+ func _composition_is_private(child: Node) -> bool:
338
+ return _scroll!=null and _scroll.is_private(child)
339
+ func _layout_children() -> Array:
340
+ return _scroll.children() if _scroll!=null else get_children()
341
+ func get_layout_children() -> Array:
342
+ return _layout_children()
343
+ func get_layout_child(child_name: StringName) -> Node:
344
+ for child in _layout_children():
345
+ if child.name==child_name: return child
346
+ return null
347
+ func _content_pointer_allowed(point: Vector2) -> bool:
348
+ return _scroll==null or _scroll.pointer_allowed(point)
349
+ func _input(event: InputEvent) -> void:
350
+ if _scroll!=null: _scroll.input(event)
351
+
233
352
  func _changed() -> void:
234
353
  if layout != null: layout.changed()
235
354
 
@@ -242,10 +361,16 @@ func _enter_tree() -> void:
242
361
  # cannot accidentally bypass the shared style. Legacy widget painters
243
362
  # explicitly opt out of S01 styles and remain untouched until S02.
244
363
  if VisualStyle.supported(get_script()) and not draw.is_connected(_paint_visual_style): draw.connect(_paint_visual_style)
364
+ _visual_style.start(self)
365
+ layout.model.clips_content = clip_content
366
+ if _scroll==null and (clip_content or horizontal_scroll or vertical_scroll or get_node_or_null("_EstragonViewport")!=null): _scroll = Scroll.new(self)
367
+ if _scroll!=null: _scroll.start()
245
368
  layout.changed()
246
369
  layout.start()
247
370
 
248
371
  func _exit_tree() -> void:
372
+ _visual_style.stop()
373
+ if _scroll!=null: _scroll.stop()
249
374
  if draw.is_connected(_paint_visual_style): draw.disconnect(_paint_visual_style)
250
375
  layout.stop()
251
376
 
@@ -266,10 +391,14 @@ func apply_layout_position(offset: Vector3) -> void:
266
391
 
267
392
  func apply_layout_size(size: Vector3) -> void:
268
393
  var next := Vector2(size.x,size.y)
269
- if next!=_layout_size: _queue_style_redraw()
394
+ var size_changed := next!=_layout_size
270
395
  _layout_size = next
396
+ var surface_changed := _prepare_surface()
397
+ if size_changed or surface_changed: _queue_style_redraw()
398
+ _content_extent = layout.model.content_extent()
271
399
  # Explicit invalidation also restores a native position edited externally.
272
400
  if layout.parent_coordinator() != null: layout._place(layout.model.offset)
401
+ if _scroll!=null: _scroll.refresh()
273
402
  layout_applied.emit(_layout_size)
274
403
 
275
404
  func _margin_insets() -> Vector4:
@@ -277,8 +406,17 @@ func _margin_insets() -> Vector4:
277
406
  return layout.model.margin
278
407
 
279
408
  func _queue_style_redraw() -> void:
409
+ if layout!=null: _prepare_surface()
280
410
  _visual_style.redraw_count += 1
281
411
  queue_redraw()
412
+ func _prepare_surface() -> bool:
413
+ var resolved := Vector4.ZERO
414
+ var viewport: Vector2 = get_viewport_rect().size if is_inside_tree() else layout.model.viewport_size
415
+ for index in range(4):
416
+ var spec: Dictionary = _visual_style.radii.get(VisualStyle.RADII[index+1],{"unit":"auto","value":0.0})
417
+ if spec.unit=="auto": spec = _visual_style.radii.get("corner_radius",{"unit":"native","value":0.0})
418
+ resolved[index] = Length.resolve(spec,minf(layout_size.x,layout_size.y),viewport)
419
+ return _visual_style.prepare(layout_size,layout.model.border,resolved)
282
420
  func _paint_visual_style() -> void:
283
421
  _visual_style.paint(self,layout_size,layout.model.border,get_background_color())
284
422
  func get_background_color() -> Color:
@@ -20,4 +20,6 @@ func _exit_tree() -> void:
20
20
  super._exit_tree()
21
21
 
22
22
  func _input(event: InputEvent) -> void:
23
+ super._input(event)
24
+ if get_viewport().is_input_handled(): return
23
25
  if _pointer.input(event): get_viewport().set_input_as_handled()
@@ -140,12 +140,13 @@ 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")
146
147
  if "lengths" in host:
147
148
  for property in host._get_property_list():
148
- 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),Core.Length.domain(property.name,host.get_script()))
149
+ if not property.name in Core.Length.VisualStyle.RADII and 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),Core.Length.domain(property.name,host.get_script()))
149
150
  model.set_lengths(host.lengths.specs,host.grow,host.stretch,host.pixels_per_unit if _dimension==3 else 1.0,options.axis,host._default_padding() if host.has_method("_default_padding") else Vector4.ZERO)
150
151
  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))
151
152
  else: model.configure(host.requested_extent(), host.gap, host.center)
@@ -34,6 +34,9 @@ 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
39
+ var clips_content := false
37
40
  var align_content := "start"
38
41
  var physical_gaps := Vector2.ZERO
39
42
  var gap: float = 0.0
@@ -99,6 +102,11 @@ func set_strategy(value: String, content_alignment: String = "start", config: Di
99
102
  align_content = content_alignment
100
103
  invalidate()
101
104
 
105
+ func set_scroll_axes(value: Vector2) -> void:
106
+ if scroll_axes==value: return
107
+ scroll_axes = value
108
+ invalidate()
109
+
102
110
  func set_policy(values: Array) -> void:
103
111
  if alignment==values: return
104
112
  alignment = values.duplicate()
@@ -165,7 +173,7 @@ func prepare(reference: Vector3, viewport: Vector2) -> void:
165
173
  padding = _edges("padding")
166
174
  border = _edges("border")
167
175
  margin = _edges("margin")
168
- if before!=[requested,gap,physical_gaps,padding,border,margin,length_offset,authored_minimum]:
176
+ if before!=[requested,gap,physical_gaps,padding,border,margin,length_offset,authored_minimum,authored_maximum]:
169
177
  _measure_dirty = true
170
178
  _arrange_dirty = true
171
179
 
@@ -196,9 +204,8 @@ func _content_basis() -> Vector3:
196
204
  for index in range(3):
197
205
  var allocated: float = constrain(requested)[index] if requested[index]>=0 else measurement_allocation[index]
198
206
  if allocated>=0: basis[index] = maxf(0,maxf(allocated,minimum()[index])-leading(padding+border)[index]-trailing(padding+border)[index])
199
- if strategy=="scroll":
200
- for index in range(2):
201
- if grid_config.get(["horizontal_scroll","vertical_scroll"][index],false): basis[index] = -1
207
+ for index in range(2):
208
+ if scroll_axes[index]>0: basis[index] = -1
202
209
  return basis
203
210
 
204
211
  static func valid_extent(value: Vector3) -> bool:
@@ -267,7 +274,7 @@ func outer_extent() -> Vector3:
267
274
  func track_contribution() -> Vector3:
268
275
  if transparent and children.size()==1: return children[0].track_contribution()
269
276
  var result := measured
270
- if strategy=="wrap" and requested[axis]<0:
277
+ if strategy=="wrap" and scroll_axes[axis]==0 and requested[axis]<0:
271
278
  result[axis] = intrinsic[axis]
272
279
  for child in children: result[axis] = maxf(result[axis],maxf(child.measured[axis],child.minimum()[axis])+child.outer_extent()[axis])
273
280
  result[axis] += leading(padding+border)[axis]+trailing(padding+border)[axis]
@@ -314,10 +321,10 @@ func set_capacity(value: Vector3) -> void:
314
321
 
315
322
  func _wrap_basis() -> Vector3:
316
323
  var basis := _content_basis()
317
- if strategy=="wrap" and requested[axis]<0 and basis[axis]<0 and available_capacity[axis]>=0:
324
+ if strategy=="wrap" and scroll_axes[axis]==0 and requested[axis]<0 and basis[axis]<0 and available_capacity[axis]>=0:
318
325
  basis[axis] = maxf(0,available_capacity[axis]-leading(padding+border)[axis]-trailing(padding+border)[axis])
319
326
  var cap := maximum()
320
- if strategy=="wrap" and cap[axis]>=0:
327
+ if strategy=="wrap" and scroll_axes[axis]==0 and cap[axis]>=0:
321
328
  var available := maxf(0,maxf(cap[axis],minimum()[axis])-leading(padding+border)[axis]-trailing(padding+border)[axis])
322
329
  basis[axis] = minf(basis[axis],available) if basis[axis]>=0 else available
323
330
  return basis
@@ -326,7 +333,7 @@ func measure_allocated(extent: Vector3, authority: Vector3) -> void:
326
333
  if transparent and children.size()==1:
327
334
  children[0].measure_allocated(extent,authority)
328
335
  _measure_dirty = true
329
- elif strategy in ["wrap","grid","scroll"]:
336
+ elif strategy in ["wrap","grid"] or scroll_axes!=Vector2.ZERO:
330
337
  var next := measurement_allocation
331
338
  for index in range(2):
332
339
  if requested[index]<0 and authority[index]>0: next[index] = extent[index]
@@ -336,17 +343,9 @@ func measure_allocated(extent: Vector3, authority: Vector3) -> void:
336
343
  else: return
337
344
  measure()
338
345
 
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
346
  func overflow_extent() -> Vector3:
347
+ # Ancestors see the clipped participant's viewport, not its hidden content.
348
+ if clips_content or scroll_axes!=Vector2.ZERO: return size
350
349
  var result := size
351
350
  for index in range(3): result[index] = maxf(result[index],natural_extent[index])
352
351
  for child in children:
@@ -355,7 +354,6 @@ func overflow_extent() -> Vector3:
355
354
  return result
356
355
 
357
356
  func _slots(items: Array, content: Vector3, definite: Vector3) -> Array:
358
- if strategy=="scroll": return _scroll_slots(items,content)
359
357
  if strategy=="grid": return _grid(items,content).slots
360
358
  if strategy=="wrap": return WrapPolicy.layout(items,content,axis,physical_gaps,alignment,align_content,Vector2(definite.x,definite.y)).slots
361
359
  return StackPolicy.slots(items,content,axis,physical_gaps[axis] if axis<2 and not length_specs.is_empty() else gap,alignment)
@@ -363,10 +361,8 @@ func _slots(items: Array, content: Vector3, definite: Vector3) -> Array:
363
361
  func _authority(child, item: Dictionary, basis: Vector3) -> Vector3:
364
362
  var authority := Vector3.ZERO
365
363
  for index in range(3):
366
- if basis[index]<0 or child.requested[index]>=0: continue
367
- if strategy=="scroll":
368
- if index<2 and not grid_config.get(["horizontal_scroll","vertical_scroll"][index],false): authority[index] = 1
369
- elif strategy=="grid":
364
+ if basis[index]<0 or child.requested[index]>=0 or index<2 and scroll_axes[index]>0: continue
365
+ if strategy=="grid":
370
366
  if index<2 and alignment[index]=="stretch": authority[index] = 1
371
367
  elif index==axis:
372
368
  if child.grow>0 or child.fill[index]>0: authority[index] = 1
@@ -435,12 +431,12 @@ func measure() -> Vector3:
435
431
  # ignore this model's intrinsic extent and can inherit an independent basis.
436
432
  func independent_axis(index: int) -> bool:
437
433
  if requested[index] >= 0 or _external_axes[index] > 0: return true
438
- if strategy=="scroll" and maximum()[index]>=0: return true
434
+ if index<2 and scroll_axes[index]>0 and maximum()[index]>=0: return true
439
435
  var parent = _parent.get_ref() if _parent != null else null
440
436
  if parent == null: return false
441
437
  var allocated := grow>0 or fill[index]>0
442
438
  if index!=parent.axis: allocated = StackPolicy.cross_alignment({"align_self":align_self,"stretch":stretch,"fill":fill},parent.alignment[index],index)=="stretch"
443
- if parent.strategy=="scroll" and index<2: allocated = not parent.grid_config.get(["horizontal_scroll","vertical_scroll"][index],false)
439
+ if index<2 and parent.scroll_axes[index]>0: return false
444
440
  if parent.strategy=="grid" and index<2: allocated = parent.alignment[index]=="stretch"
445
441
  return parent.independent_axis(index) if requested[index] < 0 and allocated else false
446
442
 
@@ -453,6 +449,8 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
453
449
  for index in range(3):
454
450
  content[index] = maxf(0,content[index])
455
451
  if independent_axis(index): reference[index] = content[index]
452
+ for index in range(2):
453
+ if scroll_axes[index]>0: reference[index] = -1
456
454
  var changed: bool = reference != content_reference
457
455
  if not _arrange_dirty and size == available and not changed: return
458
456
  content_reference = reference
@@ -488,9 +486,6 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
488
486
  # immediate children against this box before measuring their slots.
489
487
  for child in children:
490
488
  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
489
  child.prepare(child_reference,viewport_size)
495
490
  child.measure()
496
491
  if not _reported_full_percent and children.size()>1:
@@ -501,16 +496,17 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
501
496
  _reported_full_percent = true
502
497
  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
498
  break
499
+ var layout_content := content
500
+ for index in range(2):
501
+ if scroll_axes[index]>0: layout_content[index] = maxf(content[index],natural_extent[index]-leading(padding+border)[index]-trailing(padding+border)[index])
504
502
  var items := _items()
505
503
  var policy := alignment.duplicate()
506
504
  if center: policy[axis] = "center"
507
- if strategy=="scroll":
508
- slots = _scroll_slots(items,content)
509
- elif strategy=="wrap":
505
+ if strategy=="wrap":
510
506
  var wrap_basis := _wrap_basis()
511
- slots = WrapPolicy.layout(items,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
507
+ 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
508
  else:
513
- slots = StackPolicy.slots(items,content,axis,physical_gaps[axis] if axis<2 and length_specs.has("column_gap") else gap,policy)
509
+ slots = StackPolicy.slots(items,layout_content,axis,physical_gaps[axis] if axis<2 and length_specs.has("column_gap") else gap,policy)
514
510
  if strategy=="grid":
515
511
  policy_result = _grid(items,reference)
516
512
  if policy_result.has("error"): return
@@ -526,6 +522,14 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
526
522
  for cross in range(3):
527
523
  if strategy=="grid" and cross<2 and policy[cross]=="stretch" and child.requested[cross]<0 and independent_axis(cross): authority[cross] = 1
528
524
  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
- if strategy=="scroll": authority = _authority(child,items[index],reference)
525
+ for scrolling_axis in range(2):
526
+ if scroll_axes[scrolling_axis]>0: authority[scrolling_axis] = 0
530
527
  child.arrange(slot.extent,authority)
531
528
  arranged.emit(size)
529
+
530
+ func content_extent() -> Vector2:
531
+ var extent := Vector3.ZERO
532
+ for child in children:
533
+ var end: Vector3 = child.offset+child.overflow_extent()+trailing(child.margin)-leading(padding+border)
534
+ for index in range(2): extent[index] = maxf(extent[index],end[index])
535
+ return Vector2(extent.x,extent.y)
@@ -16,6 +16,7 @@ const EDGES := ["padding","padding_top","padding_right","padding_bottom","paddin
16
16
  var specs: Dictionary = {}
17
17
  var parse_count := 0
18
18
  static func domain(name: String, script = null) -> String:
19
+ if name in VisualStyle.RADII: return "inset" if name=="corner_radius" else "edge"
19
20
  if name in ["row_gap","column_gap"]: return "edge"
20
21
  if name=="padding" and VisualStyle.marked(script,"ESTRAGON_BUTTON_STYLE"): return "edge"
21
22
  if name in DIMENSIONS: return "extent"
@@ -27,6 +28,7 @@ static func domain(name: String, script = null) -> String:
27
28
  return "inset" if name=="gap" else ""
28
29
  static func registered(type, name: String) -> bool:
29
30
  if domain(name).is_empty() or not type is Script: return false
31
+ if name in VisualStyle.RADII: return VisualStyle.supported(type)
30
32
  if (name in MINIMUMS or name in MAXIMUMS) and not VisualStyle.marked(type,"ESTRAGON_MINIMUMS_2D"): return false
31
33
  if name in ["row_gap","column_gap"] and not VisualStyle.marked(type,"ESTRAGON_GAPS_2D"): return false
32
34
  if name=="border_width" or name in BORDER_EDGES:
@@ -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
- if host == null or host.get_child_count() != 1:
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 = host.get_child(0)
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,177 @@
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 clipping(): _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 clipping() 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 = clipping()
87
+ if clipping(): _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 clipping() -> bool:
102
+ return host.clip_content or enabled()
103
+ func _external_child(child: Node) -> void:
104
+ if not is_private(child): _adopt_later.call_deferred(weakref(child))
105
+ func _adopt_later(reference: WeakRef) -> void:
106
+ var child = reference.get_ref()
107
+ if child!=null and host!=null and host.is_inside_tree(): _adopt_content(child)
108
+ func stop() -> void:
109
+ _input_guard.stop()
110
+ if host.child_entered_tree.is_connected(_external_child): host.child_entered_tree.disconnect(_external_child)
111
+ if is_instance_valid(_content): Hosts.remove(_content,host.layout)
112
+ func refresh() -> void:
113
+ _refresh_viewport()
114
+ func offset_changed() -> void:
115
+ if not host.layout.model.is_layout_dirty(): _update_scroll()
116
+ func _refresh_viewport() -> void:
117
+ if not is_instance_valid(_clip): return
118
+ var rect: Rect2 = host.get_content_rect()
119
+ _clip.position = rect.position
120
+ _clip.size = rect.size
121
+ host._content_extent = host.layout.model.content_extent()
122
+ 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)
123
+ _update_scroll()
124
+ func _update_scroll() -> void:
125
+ if _updating or not is_instance_valid(_content): return
126
+ _updating = true
127
+ host.scroll_offset = Vector2(clampf(host.scroll_offset.x,0,host.scroll_range.x),clampf(host.scroll_offset.y,0,host.scroll_range.y))
128
+ if _content.position!=-host.get_content_rect().position-host.scroll_offset:
129
+ _input_guard.cancel()
130
+ var entry = host.get_layout_root()
131
+ if entry!=null and entry.has_method("_get_pointer_router"): entry._get_pointer_router().cancel()
132
+ _content.position = -host.get_content_rect().position-host.scroll_offset
133
+ var rect: Rect2 = host.get_content_rect()
134
+ _horizontal.visible = host.scroll_range.x>0
135
+ _vertical.visible = host.scroll_range.y>0
136
+ _horizontal.position = rect.position+Vector2(0,maxf(0,rect.size.y-12))
137
+ _horizontal.size = Vector2(maxf(0,rect.size.x-(12 if _vertical.visible else 0)),12)
138
+ _vertical.position = rect.position+Vector2(maxf(0,rect.size.x-12),0)
139
+ _vertical.size = Vector2(12,maxf(0,rect.size.y-(12 if _horizontal.visible else 0)))
140
+ _horizontal.max_value = host.content_extent.x
141
+ _horizontal.page = rect.size.x
142
+ _horizontal.value = host.scroll_offset.x
143
+ _vertical.max_value = host.content_extent.y
144
+ _vertical.page = rect.size.y
145
+ _vertical.value = host.scroll_offset.y
146
+ _updating = false
147
+ func _horizontal_changed(value: float) -> void:
148
+ if not _updating: host.scroll_offset = Vector2(value,host.scroll_offset.y)
149
+ func _vertical_changed(value: float) -> void:
150
+ if not _updating: host.scroll_offset = Vector2(host.scroll_offset.x,value)
151
+ func pointer_allowed(position: Vector2) -> bool:
152
+ if not enabled(): return true
153
+ for bar in [_horizontal,_vertical]:
154
+ if is_instance_valid(bar) and bar.is_visible_in_tree():
155
+ var point: Vector2 = bar.get_global_transform_with_canvas().affine_inverse()*position
156
+ if Rect2(Vector2.ZERO,bar.size).has_point(point): return false
157
+ return true
158
+ func input(event: InputEvent) -> void:
159
+ 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
160
+ var point: Vector2 = host.get_global_transform_with_canvas().affine_inverse()*event.position
161
+ if not host.get_content_rect().has_point(point) or not Pointer.inside_clips(host,event.position): return
162
+ var delta := Vector2.ZERO
163
+ if event is InputEventMouseButton and event.pressed:
164
+ match event.button_index:
165
+ MOUSE_BUTTON_WHEEL_DOWN: delta.y = 40*event.factor
166
+ MOUSE_BUTTON_WHEEL_UP: delta.y = -40*event.factor
167
+ MOUSE_BUTTON_WHEEL_RIGHT: delta.x = 40*event.factor
168
+ MOUSE_BUTTON_WHEEL_LEFT: delta.x = -40*event.factor
169
+ if event.shift_pressed: delta = Vector2(delta.y,delta.x)
170
+ elif event is InputEventPanGesture: delta = event.delta*40
171
+ else: return
172
+ 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))
173
+ if next==host.scroll_offset: return # An exhausted nested viewport bubbles naturally.
174
+ host.scroll_offset = next
175
+ var entry = host.get_layout_root()
176
+ if entry!=null and entry.has_method("_get_pointer_router"): entry._get_pointer_router().cancel()
177
+ host.get_viewport().set_input_as_handled()
@@ -0,0 +1 @@
1
+ uid://b4qhcxualkktg
@@ -2,6 +2,23 @@
2
2
  extends RefCounted
3
3
  ## Local values and native paint only. No parent lookup, cascade or Nodes.
4
4
  const COLORS := ["background_color","border_color","hover_background_color","pressed_background_color","disabled_background_color","checked_background_color"]
5
+ const RADII := ["corner_radius","corner_radius_top_left","corner_radius_top_right","corner_radius_bottom_right","corner_radius_bottom_left"]
6
+ const SURFACE := ["background_texture","background_texture_mode"]
7
+ var radii: Dictionary = {}
8
+ var texture: Texture2D
9
+ var texture_mode := "stretch"
10
+ var _canvas_texture: CanvasTexture
11
+ var _gradient: Gradient
12
+ var _host: WeakRef
13
+ var _viewport: Viewport
14
+ var _cache_key: Array = []
15
+ var _outer := PackedVector2Array()
16
+ var _inner := PackedVector2Array()
17
+ var _uv := PackedVector2Array()
18
+ var _border_mesh: ArrayMesh
19
+ var _rounded := false
20
+ var geometry_count := 0
21
+ var resource_notifications := 0
5
22
  var colors := {"background_color":Color.TRANSPARENT,"border_color":Color.TRANSPARENT,"hover_background_color":Color("#705a9e"),"pressed_background_color":Color("#302440"),"disabled_background_color":Color("#38343f"),"checked_background_color":Color("#227a60")}
6
23
  var parse_count := 0
7
24
  var draw_count := 0
@@ -24,7 +41,165 @@ static func supported(script) -> bool:
24
41
  current = current.get_base_script()
25
42
  return has_api(script)
26
43
  static func property(name: String) -> bool:
27
- return name in COLORS or name in ["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width"]
44
+ return name in COLORS or name in RADII or name in SURFACE or name in ["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width"]
45
+ static func surface_error(name: String, value) -> String:
46
+ if name=="background_texture" and value!=null and not value is Texture2D: return "background_texture requires Texture2D or null"
47
+ if name=="background_texture_mode" and (not value is String or value not in ["stretch","tile"]): return "background_texture_mode requires stretch or tile"
48
+ return ""
49
+ func start(host: Node) -> void:
50
+ _host = weakref(host)
51
+ _connect_texture()
52
+ sync_viewport()
53
+ func stop() -> void:
54
+ _disconnect_texture()
55
+ if _viewport!=null and _viewport.size_changed.is_connected(_viewport_changed): _viewport.size_changed.disconnect(_viewport_changed)
56
+ _viewport = null
57
+ _host = null
58
+ func sync_viewport() -> void:
59
+ var relative := false
60
+ for spec in radii.values():
61
+ if spec.unit in ["vw","vh","vmin","vmax"]: relative = true
62
+ var host = _host.get_ref() if _host!=null else null
63
+ var viewport: Viewport = host.get_viewport() if relative and host!=null and host.is_inside_tree() else null
64
+ if viewport==_viewport: return
65
+ if _viewport!=null and _viewport.size_changed.is_connected(_viewport_changed): _viewport.size_changed.disconnect(_viewport_changed)
66
+ _viewport = viewport
67
+ if _viewport!=null: _viewport.size_changed.connect(_viewport_changed)
68
+ func _viewport_changed() -> void:
69
+ var host = _host.get_ref() if _host!=null else null
70
+ if host!=null: host._queue_style_redraw()
71
+ func _disconnect_texture() -> void:
72
+ if texture!=null and texture.changed.is_connected(_resource_changed): texture.changed.disconnect(_resource_changed)
73
+ if _gradient!=null and _gradient.changed.is_connected(_resource_changed): _gradient.changed.disconnect(_resource_changed)
74
+ _gradient = null
75
+ func _connect_texture() -> void:
76
+ if _host==null or _host.get_ref()==null or texture==null: return
77
+ if not texture.changed.is_connected(_resource_changed): texture.changed.connect(_resource_changed)
78
+ var gradient: Gradient = texture.gradient if texture is GradientTexture2D else null
79
+ if _gradient!=gradient:
80
+ if _gradient!=null and _gradient.changed.is_connected(_resource_changed): _gradient.changed.disconnect(_resource_changed)
81
+ _gradient = gradient
82
+ if _gradient!=null: _gradient.changed.connect(_resource_changed)
83
+ func set_texture(value: Texture2D) -> void:
84
+ _disconnect_texture()
85
+ texture = value
86
+ _rebuild_texture()
87
+ _connect_texture()
88
+ func _rebuild_texture() -> void:
89
+ _canvas_texture = null
90
+ if texture!=null:
91
+ _canvas_texture = texture.duplicate() if texture is CanvasTexture else CanvasTexture.new()
92
+ if not texture is CanvasTexture: _canvas_texture.diffuse_texture = texture
93
+ _canvas_texture.texture_repeat = CanvasItem.TEXTURE_REPEAT_ENABLED if texture_mode=="tile" else CanvasItem.TEXTURE_REPEAT_DISABLED
94
+ _cache_key = []
95
+ func set_texture_mode(value: String) -> void:
96
+ texture_mode = value
97
+ if _canvas_texture!=null: _canvas_texture.texture_repeat = CanvasItem.TEXTURE_REPEAT_ENABLED if value=="tile" else CanvasItem.TEXTURE_REPEAT_DISABLED
98
+ _cache_key = []
99
+ func _resource_changed() -> void:
100
+ resource_notifications += 1
101
+ _connect_texture()
102
+ _rebuild_texture()
103
+ var host = _host.get_ref() if _host!=null else null
104
+ if host!=null: host._queue_style_redraw()
105
+
106
+ # Fixed 16 chords per quarter arc; fractional coordinates never round to native
107
+ # StyleBoxFlat integer border widths. Contours/UVs/mesh persist between draws.
108
+ func _contour(rect: Rect2, horizontal: Vector4, vertical: Vector4) -> PackedVector2Array:
109
+ var points := PackedVector2Array()
110
+ var centers := [rect.position+Vector2(horizontal.x,vertical.x),rect.position+Vector2(rect.size.x-horizontal.y,vertical.y),rect.end-Vector2(horizontal.z,vertical.z),rect.position+Vector2(horizontal.w,rect.size.y-vertical.w)]
111
+ for corner in range(4):
112
+ for step in range(17):
113
+ var angle := PI+corner*PI/2+step*PI/32
114
+ points.append(centers[corner]+Vector2(cos(angle)*horizontal[corner],sin(angle)*vertical[corner]))
115
+ return points
116
+ func _unique(points: PackedVector2Array) -> PackedVector2Array:
117
+ var result := PackedVector2Array()
118
+ for point in points:
119
+ if result.is_empty() or not result[-1].is_equal_approx(point): result.append(point)
120
+ if result.size()>1 and result[0].is_equal_approx(result[-1]): result.remove_at(result.size()-1)
121
+ return result
122
+ func _ray_edge(center: Vector2, direction: Vector2, contour: PackedVector2Array) -> Vector2:
123
+ var distance := INF
124
+ for index in range(contour.size()):
125
+ var point: Vector2 = contour[index]-center
126
+ var edge: Vector2 = contour[(index+1)%contour.size()]-contour[index]
127
+ var denominator := direction.cross(edge)
128
+ if absf(denominator)<1e-10: continue
129
+ var along := point.cross(edge)/denominator
130
+ var across := point.cross(direction)/denominator
131
+ if along>=-0.001 and across>=-0.001 and across<=1.001: distance = minf(distance,maxf(0,along))
132
+ return center+direction*distance
133
+ func _ring() -> void:
134
+ # Both contours are convex. Rays through the union of their vertices form
135
+ # nonoverlapping bands even when extreme asymmetric insets clip a corner.
136
+ var center := Vector2.ZERO
137
+ for point in _inner: center += point
138
+ center /= _inner.size()
139
+ var angles: Array = []
140
+ for contour in [_outer,_inner]:
141
+ for point in contour: angles.append((point-center).angle())
142
+ angles.sort()
143
+ var outside := PackedVector2Array()
144
+ var inside := PackedVector2Array()
145
+ for angle in angles:
146
+ var direction := Vector2(cos(angle),sin(angle))
147
+ outside.append(_ray_edge(center,direction,_outer))
148
+ inside.append(_ray_edge(center,direction,_inner))
149
+ var vertices := PackedVector3Array()
150
+ for index in range(angles.size()):
151
+ var next := (index+1)%angles.size()
152
+ for point in [outside[index],outside[next],inside[next],outside[index],inside[next],inside[index]]: vertices.append(Vector3(point.x,point.y,0))
153
+ var arrays := []
154
+ arrays.resize(Mesh.ARRAY_MAX)
155
+ arrays[Mesh.ARRAY_VERTEX] = vertices
156
+ _border_mesh = ArrayMesh.new()
157
+ _border_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES,arrays)
158
+ func prepare(extent: Vector2, border: Vector4, resolved: Vector4) -> bool:
159
+ var key := [extent,border,resolved,texture_mode,texture.get_size() if texture!=null else Vector2.ZERO]
160
+ if key==_cache_key: return false
161
+ _cache_key = key
162
+ _rounded = resolved!=Vector4.ZERO
163
+ _outer = PackedVector2Array()
164
+ _inner = PackedVector2Array()
165
+ _uv = PackedVector2Array()
166
+ _border_mesh = null
167
+ if not _rounded and texture==null: return false # Exact S01/S02 fast path.
168
+ geometry_count += 1
169
+ if extent.x<=0 or extent.y<=0: return true
170
+ var radius := resolved
171
+ var scale := 1.0
172
+ for edge in [[extent.x,radius.x+radius.y],[extent.x,radius.w+radius.z],[extent.y,radius.x+radius.w],[extent.y,radius.y+radius.z]]:
173
+ if edge[1]>0: scale = minf(scale,edge[0]/edge[1])
174
+ radius *= scale
175
+ var left := minf(border.x,extent.x)
176
+ var right := minf(border.z,maxf(0,extent.x-left))
177
+ var top := minf(border.y,extent.y)
178
+ var bottom := minf(border.w,maxf(0,extent.y-top))
179
+ var inner_rect := Rect2(left,top,maxf(0,extent.x-left-right),maxf(0,extent.y-top-bottom))
180
+ var outer := _contour(Rect2(Vector2.ZERO,extent),radius,radius)
181
+ _outer = _unique(outer)
182
+ if inner_rect.size.x<=0 or inner_rect.size.y<=0: return true
183
+ var rx := Vector4(maxf(0,radius.x-left),maxf(0,radius.y-right),maxf(0,radius.z-right),maxf(0,radius.w-left))
184
+ var ry := Vector4(maxf(0,radius.x-top),maxf(0,radius.y-top),maxf(0,radius.z-bottom),maxf(0,radius.w-bottom))
185
+ var inner_scale := 1.0
186
+ for edge in [[inner_rect.size.x,rx.x+rx.y],[inner_rect.size.x,rx.w+rx.z],[inner_rect.size.y,ry.x+ry.w],[inner_rect.size.y,ry.y+ry.z]]:
187
+ if edge[1]>0: inner_scale = minf(inner_scale,edge[0]/edge[1])
188
+ rx *= inner_scale
189
+ ry *= inner_scale
190
+ var inner := _contour(inner_rect,rx,ry)
191
+ _inner = _unique(inner)
192
+ if _rounded:
193
+ var intersection := Geometry2D.intersect_polygons(_outer,_inner)
194
+ _inner = _unique(intersection[0]) if not intersection.is_empty() else PackedVector2Array()
195
+ if _inner.size()<3: return true
196
+ if texture!=null:
197
+ var basis := texture.get_size() if texture_mode=="tile" else inner_rect.size
198
+ basis = Vector2(maxf(1,basis.x),maxf(1,basis.y))
199
+ for point in _inner: _uv.append((point-inner_rect.position)/basis)
200
+ if _rounded and border!=Vector4.ZERO:
201
+ _ring()
202
+ return true
28
203
  static func registered(script, name: String) -> bool:
29
204
  if not supported(script): return false
30
205
  if name in ["background_color","border_color"]: return true
@@ -61,7 +236,18 @@ func _rect(canvas: CanvasItem, rect: Rect2, color: Color) -> void:
61
236
  func paint(canvas: CanvasItem, extent: Vector2, border: Vector4, background: Color) -> void:
62
237
  draw_count += 1
63
238
  if extent.x<=0 or extent.y<=0: return
239
+ if _rounded:
240
+ if background.a>0:
241
+ canvas.draw_colored_polygon(_outer,background)
242
+ command_count += 1
243
+ _paint_texture(canvas)
244
+ if colors.border_color.a>0 and border!=Vector4.ZERO:
245
+ if _border_mesh!=null: canvas.draw_mesh(_border_mesh,null,Transform2D.IDENTITY,colors.border_color)
246
+ else: canvas.draw_colored_polygon(_outer,colors.border_color)
247
+ command_count += 1
248
+ return
64
249
  _rect(canvas,Rect2(Vector2.ZERO,extent),background)
250
+ _paint_texture(canvas)
65
251
  # Filled strips stay inside the border-box, including fractional/huge edges.
66
252
  # Top/bottom own the corners; side strips never double-blend those pixels.
67
253
  var left := minf(border.x,extent.x)
@@ -73,3 +259,7 @@ func paint(canvas: CanvasItem, extent: Vector2, border: Vector4, background: Col
73
259
  _rect(canvas,Rect2(0,extent.y-bottom,extent.x,bottom),color)
74
260
  _rect(canvas,Rect2(0,top,left,maxf(0,extent.y-top-bottom)),color)
75
261
  _rect(canvas,Rect2(extent.x-right,top,right,maxf(0,extent.y-top-bottom)),color)
262
+ func _paint_texture(canvas: CanvasItem) -> void:
263
+ if _canvas_texture==null or _inner.size()<3: return
264
+ canvas.draw_colored_polygon(_inner,Color.WHITE,_uv,_canvas_texture)
265
+ command_count += 1
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  "tag": "beta",
30
30
  "registry": "https://registry.npmjs.org/"
31
31
  },
32
- "version": "0.1.0-beta.25"
32
+ "version": "0.1.0-beta.27"
33
33
  }
@@ -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