@papercraftgames/estragon 0.1.0-beta.33 → 0.1.0-beta.35
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/editor/plugin.cfg +1 -1
- package/addons/estragon/runtime/composition/computation.gd +9 -0
- package/addons/estragon/runtime/node/component_2d.gd +26 -0
- package/addons/estragon/runtime/node/internal/layout_core.gd +15 -4
- package/addons/estragon/runtime/node/internal/length.gd +4 -0
- package/addons/estragon/runtime/node/internal/scroll_2d.gd +87 -16
- package/addons/estragon/runtime/node/internal/scrollbar_geometry.gd +23 -0
- package/addons/estragon/runtime/node/internal/scrollbar_geometry.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/scrollbar_style.gd +47 -0
- package/addons/estragon/runtime/node/internal/scrollbar_style.gd.uid +1 -0
- package/package.json +1 -1
|
@@ -373,6 +373,12 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
373
373
|
node._apply_grid(_grid_config(desired))
|
|
374
374
|
var stack := StackContract.registered(desired.type)
|
|
375
375
|
var scroll := VisualStyle.marked(desired.type,"ESTRAGON_SCROLL_2D")
|
|
376
|
+
if scroll:
|
|
377
|
+
for key in ["scrollbar_size","vertical_scrollbar_width","horizontal_scrollbar_height","scrollbar_style"]:
|
|
378
|
+
if record.properties.has(key) and not desired.properties.has(key) and not resets.has(key):
|
|
379
|
+
node.set(key,record.defaults[key])
|
|
380
|
+
writes += 1
|
|
381
|
+
if Profile.is_enabled(): Profile.add("property_writes")
|
|
376
382
|
if stack:
|
|
377
383
|
var policy := resets.duplicate()
|
|
378
384
|
policy.merge(desired.properties,true)
|
|
@@ -616,6 +622,9 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
616
622
|
validation_error = desired.location(key)+": "+message+"; previous tree retained"
|
|
617
623
|
return false
|
|
618
624
|
if VisualStyle.marked(desired.type,"ESTRAGON_SCROLL_2D"):
|
|
625
|
+
if desired.properties.has("scrollbar_style"):
|
|
626
|
+
var problem := preload("../node/internal/scrollbar_style.gd").error(desired.properties.scrollbar_style)
|
|
627
|
+
if not problem.is_empty(): return _invalid_attribute(desired,"scrollbar_style",problem)
|
|
619
628
|
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")
|
|
620
629
|
for key in ["scroll_range","content_extent"]:
|
|
621
630
|
if desired.properties.has(key): return _invalid_attribute(desired,key,"read-only scrolling measurement")
|
|
@@ -11,6 +11,31 @@ const ESTRAGON_MINIMUMS_2D := true
|
|
|
11
11
|
const ESTRAGON_GAPS_2D := true
|
|
12
12
|
const ESTRAGON_SCROLL_2D := true
|
|
13
13
|
const Scroll = preload("internal/scroll_2d.gd")
|
|
14
|
+
const ScrollbarStyle = preload("internal/scrollbar_style.gd")
|
|
15
|
+
var scrollbar_size = 12:
|
|
16
|
+
set(value):
|
|
17
|
+
if is_same(scrollbar_size,value) or not lengths.assign("scrollbar_size",value): return
|
|
18
|
+
scrollbar_size = value
|
|
19
|
+
_changed()
|
|
20
|
+
var vertical_scrollbar_width = "auto":
|
|
21
|
+
set(value):
|
|
22
|
+
if is_same(vertical_scrollbar_width,value) or not lengths.assign("vertical_scrollbar_width",value): return
|
|
23
|
+
vertical_scrollbar_width = value
|
|
24
|
+
_changed()
|
|
25
|
+
var horizontal_scrollbar_height = "auto":
|
|
26
|
+
set(value):
|
|
27
|
+
if is_same(horizontal_scrollbar_height,value) or not lengths.assign("horizontal_scrollbar_height",value): return
|
|
28
|
+
horizontal_scrollbar_height = value
|
|
29
|
+
_changed()
|
|
30
|
+
@export var scrollbar_style: Dictionary = {}:
|
|
31
|
+
set(value):
|
|
32
|
+
var problem := ScrollbarStyle.error(value)
|
|
33
|
+
if not problem.is_empty():
|
|
34
|
+
push_error("Estragon "+problem)
|
|
35
|
+
return
|
|
36
|
+
if scrollbar_style==value: return
|
|
37
|
+
scrollbar_style = value.duplicate(true)
|
|
38
|
+
if _scroll!=null: _scroll.refresh_style()
|
|
14
39
|
var _scroll
|
|
15
40
|
@export var clip_content: bool = false:
|
|
16
41
|
set(value):
|
|
@@ -277,6 +302,7 @@ var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry
|
|
|
277
302
|
func _get_property_list() -> Array[Dictionary]:
|
|
278
303
|
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"])
|
|
279
304
|
properties.append_array(Length.properties(["row_gap","column_gap"]))
|
|
305
|
+
properties.append_array(Length.properties(Length.SCROLLBAR_SIZES))
|
|
280
306
|
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
307
|
if VisualStyle.supported(get_script()): properties.append_array(Length.properties(VisualStyle.RADII))
|
|
282
308
|
return properties
|
|
@@ -5,6 +5,7 @@ const WrapPolicy = preload("wrap_policy.gd")
|
|
|
5
5
|
const GridDefinition = preload("grid_definition.gd")
|
|
6
6
|
const GridPolicy = preload("grid_policy.gd")
|
|
7
7
|
const Length = preload("length.gd")
|
|
8
|
+
const ScrollbarGeometry = preload("scrollbar_geometry.gd")
|
|
8
9
|
const Profile = preload("../../composition/profile.tres")
|
|
9
10
|
## Shared B2/C1 mathematical row layout. No Nodes, rendering or SceneTree dependencies.
|
|
10
11
|
signal invalidated
|
|
@@ -44,6 +45,7 @@ var policy_result: Dictionary = {}
|
|
|
44
45
|
var strategy := "stack"
|
|
45
46
|
# Viewport decoration; never replaces Stack/Wrap/Grid.
|
|
46
47
|
var scroll_axes := Vector2.ZERO
|
|
48
|
+
var scroll_geometry: Dictionary = {}
|
|
47
49
|
var clips_content := false
|
|
48
50
|
var align_content := "start"
|
|
49
51
|
var physical_gaps := Vector2.ZERO
|
|
@@ -214,13 +216,18 @@ func constrain(extent: Vector3) -> Vector3:
|
|
|
214
216
|
extent[index] = maxf(extent[index],floor[index])
|
|
215
217
|
return extent
|
|
216
218
|
|
|
217
|
-
func
|
|
219
|
+
func _inner_basis() -> Vector3:
|
|
218
220
|
var basis := Vector3(-1,-1,-1)
|
|
219
221
|
for index in range(3):
|
|
220
222
|
var allocated: float = constrain(requested)[index] if requested[index]>=0 else measurement_allocation[index]
|
|
221
223
|
if allocated>=0: basis[index] = maxf(0,maxf(allocated,minimum()[index])-leading(padding+border)[index]-trailing(padding+border)[index])
|
|
224
|
+
return basis
|
|
225
|
+
|
|
226
|
+
func _content_basis() -> Vector3:
|
|
227
|
+
var basis := _inner_basis()
|
|
228
|
+
var strips := ScrollbarGeometry.thickness(Vector2(basis.x,basis.y),scroll_axes,length_specs,viewport_size)
|
|
222
229
|
for index in range(2):
|
|
223
|
-
if
|
|
230
|
+
if basis[index]>=0: basis[index] = maxf(0,basis[index]-strips[index])
|
|
224
231
|
return basis
|
|
225
232
|
|
|
226
233
|
static func valid_extent(value: Vector3) -> bool:
|
|
@@ -369,6 +376,7 @@ func set_capacity(value: Vector3) -> void:
|
|
|
369
376
|
|
|
370
377
|
func _wrap_basis() -> Vector3:
|
|
371
378
|
var basis := _content_basis()
|
|
379
|
+
if axis<2 and scroll_axes[axis]>0: basis[axis] = -1
|
|
372
380
|
if strategy=="wrap" and scroll_axes[axis]==0 and requested[axis]<0 and basis[axis]<0 and available_capacity[axis]>=0:
|
|
373
381
|
basis[axis] = maxf(0,available_capacity[axis]-leading(padding+border)[axis]-trailing(padding+border)[axis])
|
|
374
382
|
var cap := maximum()
|
|
@@ -499,12 +507,15 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
|
|
|
499
507
|
_external_axes = external_axes
|
|
500
508
|
_warn_unanchored()
|
|
501
509
|
var content := available-leading(padding+border)-trailing(padding+border)
|
|
510
|
+
for index in range(3): content[index] = maxf(0,content[index])
|
|
511
|
+
var origin := leading(padding+border)
|
|
512
|
+
scroll_geometry = ScrollbarGeometry.snapshot(Rect2(Vector2(origin.x,origin.y),Vector2(content.x,content.y)),ScrollbarGeometry.border_inner(Vector2(available.x,available.y),border),scroll_axes,length_specs,viewport_size)
|
|
513
|
+
content.x = scroll_geometry.viewport.size.x
|
|
514
|
+
content.y = scroll_geometry.viewport.size.y
|
|
502
515
|
var reference := Vector3(-1,-1,-1)
|
|
503
516
|
for index in range(3):
|
|
504
517
|
content[index] = maxf(0,content[index])
|
|
505
518
|
if independent_axis(index): reference[index] = content[index]
|
|
506
|
-
for index in range(2):
|
|
507
|
-
if scroll_axes[index]>0: reference[index] = -1
|
|
508
519
|
var changed: bool = reference != content_reference
|
|
509
520
|
if not _arrange_dirty and size == available and not changed: return
|
|
510
521
|
content_reference = reference
|
|
@@ -12,10 +12,12 @@ const MINIMUMS := ["min_width","min_height"]
|
|
|
12
12
|
const DIMENSIONS := ["width","height","depth"]
|
|
13
13
|
const BORDER_EDGES := ["border_top_width","border_right_width","border_bottom_width","border_left_width"]
|
|
14
14
|
const OFFSETS := ["x","y","z"]
|
|
15
|
+
const SCROLLBAR_SIZES := ["scrollbar_size","vertical_scrollbar_width","horizontal_scrollbar_height"]
|
|
15
16
|
const EDGES := ["padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"]
|
|
16
17
|
var specs: Dictionary = {}
|
|
17
18
|
var parse_count := 0
|
|
18
19
|
static func domain(name: String, script = null) -> String:
|
|
20
|
+
if name in SCROLLBAR_SIZES: return "inset" if name=="scrollbar_size" else "edge"
|
|
19
21
|
if name in VisualStyle.RADII: return "inset" if name=="corner_radius" else "edge"
|
|
20
22
|
if name in ["row_gap","column_gap"]: return "edge"
|
|
21
23
|
if name=="padding" and VisualStyle.marked(script,"ESTRAGON_BUTTON_STYLE"): return "edge"
|
|
@@ -28,6 +30,7 @@ static func domain(name: String, script = null) -> String:
|
|
|
28
30
|
return "inset" if name=="gap" else ""
|
|
29
31
|
static func registered(type, name: String) -> bool:
|
|
30
32
|
if domain(name).is_empty() or not type is Script: return false
|
|
33
|
+
if name in SCROLLBAR_SIZES: return VisualStyle.marked(type,"ESTRAGON_SCROLL_2D")
|
|
31
34
|
if name in VisualStyle.RADII: return VisualStyle.supported(type)
|
|
32
35
|
if (name in MINIMUMS or name in MAXIMUMS) and not VisualStyle.marked(type,"ESTRAGON_MINIMUMS_2D"): return false
|
|
33
36
|
if name in ["row_gap","column_gap"] and not VisualStyle.marked(type,"ESTRAGON_GAPS_2D"): return false
|
|
@@ -87,6 +90,7 @@ static func dependencies(specs: Dictionary, stack_axis: int) -> Array:
|
|
|
87
90
|
for name in specs:
|
|
88
91
|
var unit: String = specs[name].unit
|
|
89
92
|
if unit=="%":
|
|
93
|
+
if name in SCROLLBAR_SIZES: continue # Own pre-gutter content, not parent.
|
|
90
94
|
if name in ["width","min_width","max_width","x","column_gap","margin_left","margin_right","padding_left","padding_right","border_left_width","border_right_width"]: parent_axes.x = 1
|
|
91
95
|
elif name in ["height","min_height","max_height","y","row_gap","margin_top","margin_bottom","padding_top","padding_bottom","border_top_width","border_bottom_width"]: parent_axes.y = 1
|
|
92
96
|
elif name in ["depth","z"]: parent_axes.z = 1
|
|
@@ -4,6 +4,8 @@ extends RefCounted
|
|
|
4
4
|
const Hosts = preload("composition_hosts.tres")
|
|
5
5
|
const Pointer = preload("pointer_2d.gd")
|
|
6
6
|
const Focus = preload("focus.tres")
|
|
7
|
+
const ScrollbarSkin = preload("scrollbar_style.gd")
|
|
8
|
+
const Geometry = preload("scrollbar_geometry.gd")
|
|
7
9
|
var owner_ref: WeakRef
|
|
8
10
|
var host:
|
|
9
11
|
get: return owner_ref.get_ref()
|
|
@@ -11,6 +13,11 @@ var _clip: Control
|
|
|
11
13
|
var _content: Node2D
|
|
12
14
|
var _horizontal: HScrollBar
|
|
13
15
|
var _vertical: VScrollBar
|
|
16
|
+
var _corner: ColorRect
|
|
17
|
+
var _geometry: Dictionary = {}
|
|
18
|
+
var _skin_context: Array = []
|
|
19
|
+
var style_updates := 0
|
|
20
|
+
var _fit_pending := false
|
|
14
21
|
var _updating := false
|
|
15
22
|
var _input_guard = preload("scroll_input.gd").new()
|
|
16
23
|
func _init(owner: Node2D) -> void:
|
|
@@ -42,6 +49,9 @@ func _ensure_viewport() -> void:
|
|
|
42
49
|
_content.child_exiting_tree.connect(_children_changed)
|
|
43
50
|
_horizontal = HScrollBar.new()
|
|
44
51
|
_vertical = VScrollBar.new()
|
|
52
|
+
_corner = ColorRect.new()
|
|
53
|
+
_corner.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
54
|
+
host.add_child(_corner,false,Node.INTERNAL_MODE_BACK)
|
|
45
55
|
host.add_child(_horizontal,false,Node.INTERNAL_MODE_BACK)
|
|
46
56
|
# BACK appends internal children after the clip/content branch. FRONT is
|
|
47
57
|
# the beginning of SceneTree order and would let native Controls win GUI
|
|
@@ -53,8 +63,14 @@ func _ensure_viewport() -> void:
|
|
|
53
63
|
_vertical.custom_step = 40
|
|
54
64
|
_horizontal.value_changed.connect(_horizontal_changed)
|
|
55
65
|
_vertical.value_changed.connect(_vertical_changed)
|
|
66
|
+
# Arrowless native bars: the thumb/track still own all native interaction.
|
|
67
|
+
var blank := ImageTexture.create_from_image(Image.create(1,1,false,Image.FORMAT_RGBA8))
|
|
68
|
+
for bar in [_horizontal,_vertical]:
|
|
69
|
+
bar.clip_contents = true # Explicit StyleBox expansion cannot paint over V.
|
|
70
|
+
bar.minimum_size_changed.connect(_minimum_changed)
|
|
71
|
+
for icon in ["increment","increment_highlight","increment_pressed","decrement","decrement_highlight","decrement_pressed"]: bar.add_theme_icon_override(icon,blank)
|
|
56
72
|
func is_private(child: Node) -> bool:
|
|
57
|
-
return child==_clip or child==_horizontal or child==_vertical
|
|
73
|
+
return child==_clip or child==_horizontal or child==_vertical or child==_corner
|
|
58
74
|
func _children_changed(_child: Node) -> void:
|
|
59
75
|
if host!=null: host._layout_children_changed.emit()
|
|
60
76
|
func _remember_owners(node: Node, values: Dictionary) -> void:
|
|
@@ -78,6 +94,12 @@ func _adopt_content(child: Node) -> void:
|
|
|
78
94
|
if owners[node].is_ancestor_of(node): node.owner = owners[node]
|
|
79
95
|
if is_instance_valid(focus) and focus.is_inside_tree(): focus.grab_focus()
|
|
80
96
|
host.layout._sync()
|
|
97
|
+
# Native reparent notifications can precede the new ancestor's coordinator
|
|
98
|
+
# activation. Refresh keyboard/pointer scope after that tree transition.
|
|
99
|
+
_refresh_scope.call_deferred(weakref(child))
|
|
100
|
+
func _refresh_scope(reference: WeakRef) -> void:
|
|
101
|
+
var child = reference.get_ref()
|
|
102
|
+
if host!=null and host.is_inside_tree() and child!=null and child.is_inside_tree() and _content.is_ancestor_of(child): Hosts._refresh_scope(child)
|
|
81
103
|
func start() -> void:
|
|
82
104
|
if not clipping() and not is_instance_valid(_clip) and host.get_node_or_null("_EstragonViewport")==null: return
|
|
83
105
|
_ensure_viewport()
|
|
@@ -116,12 +138,59 @@ func offset_changed() -> void:
|
|
|
116
138
|
if not host.layout.model.is_layout_dirty(): _update_scroll()
|
|
117
139
|
func _refresh_viewport() -> void:
|
|
118
140
|
if not is_instance_valid(_clip): return
|
|
119
|
-
|
|
141
|
+
_geometry = host.layout.model.scroll_geometry
|
|
142
|
+
if _geometry.is_empty(): _geometry = Geometry.snapshot(host.get_content_rect(),Geometry.border_inner(host.layout_size,host.layout.model.border),Vector2(1 if host.horizontal_scroll else 0,1 if host.vertical_scroll else 0),host.lengths.specs,host.layout.model.viewport_size)
|
|
143
|
+
var rect: Rect2 = _geometry.viewport
|
|
120
144
|
_clip.position = rect.position
|
|
121
145
|
_clip.size = rect.size
|
|
122
146
|
host._content_extent = host.layout.model.content_extent()
|
|
123
147
|
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)
|
|
124
148
|
_update_scroll()
|
|
149
|
+
func refresh_style() -> void:
|
|
150
|
+
if not is_instance_valid(_horizontal) or _geometry.is_empty(): return
|
|
151
|
+
var context := [host.scrollbar_style,_geometry.vertical.size,_geometry.horizontal.size,host.layout.model.viewport_size]
|
|
152
|
+
if context==_skin_context: return
|
|
153
|
+
_skin_context = context.duplicate(true)
|
|
154
|
+
style_updates += 1
|
|
155
|
+
for axis in ["horizontal","vertical"]:
|
|
156
|
+
var bar: ScrollBar = _horizontal if axis=="horizontal" else _vertical
|
|
157
|
+
var rect: Rect2 = _geometry[axis]
|
|
158
|
+
var style := ScrollbarSkin.values(host.scrollbar_style,axis)
|
|
159
|
+
bar.add_theme_stylebox_override("scroll",ScrollbarSkin.box(style,"track","",rect.size,host.layout.model.viewport_size))
|
|
160
|
+
for pair in [["grabber",""],["grabber_highlight","_hover"],["grabber_pressed","_pressed"]]:
|
|
161
|
+
bar.add_theme_stylebox_override(pair[0],ScrollbarSkin.box(style,"thumb",pair[1],rect.size,host.layout.model.viewport_size))
|
|
162
|
+
var focus := StyleBoxFlat.new()
|
|
163
|
+
focus.bg_color = Color.TRANSPARENT
|
|
164
|
+
focus.border_color = Color("#eeeeee")
|
|
165
|
+
focus.set_border_width_all(1)
|
|
166
|
+
bar.add_theme_stylebox_override("scroll_focus",focus)
|
|
167
|
+
_corner.color = ScrollbarSkin.color(ScrollbarSkin.values(host.scrollbar_style,"vertical"),"corner_color")
|
|
168
|
+
_fit_tracks()
|
|
169
|
+
func _minimum_changed() -> void:
|
|
170
|
+
if _fit_pending: return
|
|
171
|
+
_fit_pending = true
|
|
172
|
+
_fit_tracks.call_deferred()
|
|
173
|
+
func _fit_tracks() -> void:
|
|
174
|
+
_fit_pending = false
|
|
175
|
+
if host==null or not is_instance_valid(_horizontal) or _geometry.is_empty(): return
|
|
176
|
+
_place_bar(_horizontal,_geometry.horizontal)
|
|
177
|
+
_place_bar(_vertical,_geometry.vertical)
|
|
178
|
+
func _place_bar(bar: ScrollBar, rect: Rect2) -> void:
|
|
179
|
+
# There is no native hit surface for an empty strip. In particular, 4.0
|
|
180
|
+
# coerces zero Control scales to epsilon; never feed that degenerate transform
|
|
181
|
+
# into native minimum-size adjustment.
|
|
182
|
+
if rect.size.x<=0 or rect.size.y<=0:
|
|
183
|
+
bar.hide()
|
|
184
|
+
return
|
|
185
|
+
if bar.position!=rect.position: bar.position = rect.position
|
|
186
|
+
# Custom StyleBox minimums must never enlarge the parent-owned strip.
|
|
187
|
+
# Native Control hit testing follows this same transform, including drag.
|
|
188
|
+
var floor := bar.get_combined_minimum_size()
|
|
189
|
+
var logical := Vector2(maxf(rect.size.x,floor.x),maxf(rect.size.y,floor.y))
|
|
190
|
+
if bar.size!=logical: bar.size = logical
|
|
191
|
+
var native_size := Vector2(maxf(1,bar.size.x),maxf(1,bar.size.y))
|
|
192
|
+
var physical_scale := rect.size/native_size
|
|
193
|
+
if bar.scale!=physical_scale: bar.scale = physical_scale
|
|
125
194
|
func _update_scroll() -> void:
|
|
126
195
|
if _updating or not is_instance_valid(_content): return
|
|
127
196
|
_updating = true
|
|
@@ -131,17 +200,22 @@ func _update_scroll() -> void:
|
|
|
131
200
|
var entry = host.get_layout_root()
|
|
132
201
|
if entry!=null and entry.has_method("_get_pointer_router"): entry._get_pointer_router().cancel()
|
|
133
202
|
_content.position = -host.get_content_rect().position-host.scroll_offset
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
_vertical.
|
|
141
|
-
_horizontal.
|
|
203
|
+
if _geometry.is_empty():
|
|
204
|
+
_updating = false
|
|
205
|
+
return
|
|
206
|
+
var rect: Rect2 = _geometry.viewport
|
|
207
|
+
refresh_style()
|
|
208
|
+
_horizontal.visible = host.scroll_range.x>0 and _geometry.horizontal.size.x>0 and _geometry.horizontal.size.y>0
|
|
209
|
+
_vertical.visible = host.scroll_range.y>0 and _geometry.vertical.size.x>0 and _geometry.vertical.size.y>0
|
|
210
|
+
_place_bar(_horizontal,_geometry.horizontal)
|
|
211
|
+
_place_bar(_vertical,_geometry.vertical)
|
|
212
|
+
_corner.position = _geometry.corner.position
|
|
213
|
+
_corner.size = _geometry.corner.size
|
|
214
|
+
_corner.visible = _corner.size.x>0 and _corner.size.y>0
|
|
215
|
+
_horizontal.max_value = maxf(host.content_extent.x,rect.size.x)
|
|
142
216
|
_horizontal.page = rect.size.x
|
|
143
217
|
_horizontal.value = host.scroll_offset.x
|
|
144
|
-
_vertical.max_value = host.content_extent.y
|
|
218
|
+
_vertical.max_value = maxf(host.content_extent.y,rect.size.y)
|
|
145
219
|
_vertical.page = rect.size.y
|
|
146
220
|
_vertical.value = host.scroll_offset.y
|
|
147
221
|
_updating = false
|
|
@@ -152,11 +226,8 @@ func _vertical_changed(value: float) -> void:
|
|
|
152
226
|
if not _updating: host.scroll_offset = Vector2(host.scroll_offset.x,value)
|
|
153
227
|
func pointer_allowed(position: Vector2) -> bool:
|
|
154
228
|
if not enabled(): return true
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
var point: Vector2 = bar.get_global_transform_with_canvas().affine_inverse()*position
|
|
158
|
-
if Rect2(Vector2.ZERO,bar.size).has_point(point): return false
|
|
159
|
-
return true
|
|
229
|
+
var point: Vector2 = host.get_global_transform_with_canvas().affine_inverse()*position
|
|
230
|
+
return _geometry.is_empty() or _geometry.viewport.has_point(point)
|
|
160
231
|
func input(event: InputEvent) -> void:
|
|
161
232
|
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
|
|
162
233
|
var point: Vector2 = host.get_global_transform_with_canvas().affine_inverse()*event.position
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## P owns thickness/child references; border-inner B owns chrome placement.
|
|
4
|
+
const Length=preload("length.gd")
|
|
5
|
+
static func thickness(inner: Vector2,axes: Vector2,specs: Dictionary,viewport: Vector2) -> Vector2:
|
|
6
|
+
var shared: Dictionary=specs.get("scrollbar_size",{"unit":"native","value":12.0})
|
|
7
|
+
var vertical: Dictionary=specs.get("vertical_scrollbar_width",shared)
|
|
8
|
+
var horizontal: Dictionary=specs.get("horizontal_scrollbar_height",shared)
|
|
9
|
+
if vertical.unit=="auto": vertical=shared
|
|
10
|
+
if horizontal.unit=="auto": horizontal=shared
|
|
11
|
+
var result=Vector2.ZERO
|
|
12
|
+
if axes.y>0: result.x=maxf(0,Length.resolve(vertical,inner.x,viewport))
|
|
13
|
+
if axes.x>0: result.y=maxf(0,Length.resolve(horizontal,inner.y,viewport))
|
|
14
|
+
if inner.x>=0: result.x=minf(inner.x,result.x)
|
|
15
|
+
if inner.y>=0: result.y=minf(inner.y,result.y)
|
|
16
|
+
return result
|
|
17
|
+
static func border_inner(outer: Vector2,border: Vector4) -> Rect2:
|
|
18
|
+
return Rect2(Vector2(minf(outer.x,border.x),minf(outer.y,border.y)),Vector2(maxf(0,outer.x-border.x-border.z),maxf(0,outer.y-border.y-border.w)))
|
|
19
|
+
static func snapshot(inner: Rect2,chrome: Rect2,axes: Vector2,specs: Dictionary,viewport: Vector2) -> Dictionary:
|
|
20
|
+
var strips=thickness(inner.size,axes,specs,viewport)
|
|
21
|
+
var size=Vector2(maxf(0,inner.size.x-strips.x),maxf(0,inner.size.y-strips.y))
|
|
22
|
+
var end=chrome.end-strips
|
|
23
|
+
return {"inner":inner,"chrome":chrome,"viewport":Rect2(inner.position,size),"thickness":strips,"vertical":Rect2(Vector2(end.x,chrome.position.y),Vector2(strips.x,maxf(0,chrome.size.y-strips.y))),"horizontal":Rect2(Vector2(chrome.position.x,end.y),Vector2(maxf(0,chrome.size.x-strips.x),strips.y)),"corner":Rect2(end,strips)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://cxvto2nj2s2xj
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Local native scrollbar skin contract. No themes, Nodes or layout policy.
|
|
4
|
+
const Length=preload("length.gd")
|
|
5
|
+
const Visual=preload("visual_style_2d.gd")
|
|
6
|
+
const COLORS=["track_color","thumb_color","thumb_hover_color","thumb_pressed_color","corner_color","track_border_color","thumb_border_color"]
|
|
7
|
+
const LENGTHS=["track_corner_radius","thumb_corner_radius","track_border_width","thumb_border_width"]
|
|
8
|
+
const BOXES=["track_stylebox","thumb_stylebox","thumb_hover_stylebox","thumb_pressed_stylebox"]
|
|
9
|
+
const DEFAULTS={"track_color":"#292929","thumb_color":"#727272","thumb_hover_color":"#919191","thumb_pressed_color":"#aaaaaa","corner_color":"#383838","track_border_color":"transparent","thumb_border_color":"transparent","track_corner_radius":0,"thumb_corner_radius":0,"track_border_width":0,"thumb_border_width":0}
|
|
10
|
+
static func error(value, nested: bool=false) -> String:
|
|
11
|
+
if not value is Dictionary: return "scrollbar_style requires Dictionary"
|
|
12
|
+
for key in value:
|
|
13
|
+
if not key is String: return "scrollbar_style keys require String"
|
|
14
|
+
var item=value[key]
|
|
15
|
+
if key in ["vertical","horizontal"] and not nested:
|
|
16
|
+
var problem=error(item,true)
|
|
17
|
+
if not problem.is_empty(): return key+": "+problem
|
|
18
|
+
elif key in COLORS:
|
|
19
|
+
if Visual.parse_color(item).has("error"): return key+" requires a finite Color, hex or transparent"
|
|
20
|
+
elif key in LENGTHS:
|
|
21
|
+
if Length.parse(item,"inset").has("error"): return key+" requires a finite nonnegative Length"
|
|
22
|
+
elif key in BOXES:
|
|
23
|
+
if not item is StyleBox: return key+" requires StyleBox Resource"
|
|
24
|
+
else: return "unknown scrollbar_style key "+key
|
|
25
|
+
return ""
|
|
26
|
+
static func values(style: Dictionary, axis: String) -> Dictionary:
|
|
27
|
+
var result=DEFAULTS.duplicate()
|
|
28
|
+
for key in style:
|
|
29
|
+
if key not in ["vertical","horizontal"]: result[key]=style[key]
|
|
30
|
+
result.merge(style.get(axis,{}),true)
|
|
31
|
+
return result
|
|
32
|
+
static func color(style: Dictionary,key: String) -> Color: return Visual.parse_color(style[key]).color
|
|
33
|
+
static func box(style: Dictionary,part: String,state: String,rect: Vector2,viewport: Vector2) -> StyleBox:
|
|
34
|
+
var key=part+state+"_stylebox"
|
|
35
|
+
if style.has(key): return style[key]
|
|
36
|
+
var result=StyleBoxFlat.new()
|
|
37
|
+
var tint=part+state+"_color"
|
|
38
|
+
result.bg_color=color(style,tint)
|
|
39
|
+
result.border_color=color(style,part+"_border_color")
|
|
40
|
+
var reference=minf(rect.x,rect.y)
|
|
41
|
+
var border=mini(ceili(reference*0.5),ceili(Length.resolve(Length.parse(style[part+"_border_width"],"inset"),reference,viewport)))
|
|
42
|
+
var radius=mini(ceili(reference*0.5),ceili(Length.resolve(Length.parse(style[part+"_corner_radius"],"inset"),reference,viewport)))
|
|
43
|
+
for edge in [SIDE_LEFT,SIDE_TOP,SIDE_RIGHT,SIDE_BOTTOM]:
|
|
44
|
+
result.set_border_width(edge,border)
|
|
45
|
+
result.set_content_margin(edge,0)
|
|
46
|
+
for corner in range(4): result.set_corner_radius(corner,radius)
|
|
47
|
+
return result
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://ccucmnac0fbnh
|
package/package.json
CHANGED