Module Scroll
Component to handle scroll content.
# Overview #
The Scroll component is designed to handle scrollable content and consists of two nodes: the scroll parent and the scroll input.
The scroll input represents the user input zone and remains static.
The scroll parent is the movable part of the scroll and changes its position.
The initial scroll size can be set by adjusting the size of the scroll parent. If the size of the scroll parent is smaller than the scroll input size, scrolling is not available.
# Notes #
• By default, the scroll style includes inertia and extra size for a stretching effect. These settings can be adjusted using the scroll style settings. For more details, refer to the scroll style settings.
• "Points of interest" can be set up for the scroll. The scroll will always be centered on the closest point of interest. This feature allows creating a slider without inertia and with points of interest on each scroll element.
• The scroll content size can be adjusted using the scroll:set_size(node_size) method. This method sets a new size for the _content node.
• Inertial scrolling mode can be enabled or disabled using the scroll:set_inert(state) method.
• The extra stretch size can be adjusted using the scroll:set_extra_stretch_size method.
• Multitouch is required for scrolling. The scroll component correctly handles touch ID swaps while dragging the scroll.
Functions
bind_grid(self, grid) | Bind the grid component (Static or Dynamic) to recalculate scroll size on grid changes |
get_percent(self) | Return current scroll progress status. |
get_scroll_size(self) | Return vector of scroll size with width and height. |
init(self, view_node, content_node) | The Scroll constructor |
is_inert(self) | Return if scroll have inertion. |
is_node_in_view(self, node) | Check node if it visible now on scroll. |
scroll_to(self, point, is_instant) | Start scroll to target point. |
scroll_to_index(self, index, skip_cb) | Scroll to item in scroll by point index. |
scroll_to_percent(self, percent, is_instant) | Start scroll to target scroll percent |
set_click_zone(self, node) | Strict drag scroll area. |
set_extra_stretch_size(self, stretch_size) | Set extra size for scroll stretching. |
set_horizontal_scroll(self, state) | Lock or unlock horizontal scroll |
set_inert(self, state) | Enable or disable scroll inert. |
set_points(self, points) | Set points of interest. |
set_size(self, size, offset) | Set scroll content size. |
set_vertical_scroll(self, state) | Lock or unlock vertical scroll |
set_view_size(self, size) | Set new scroll view size in case the node size was changed. |
update_view_size(self) | Refresh scroll view size |
Tables
style | Component style params. |
Fields
_is_inert | Flag, if scroll now moving by inertion |
available_pos | Available position for content node: (min_x, max_y, max_x, min_y) |
available_size | Size of available positions: (width, height, 0) |
content_node | Scroll content node |
drag | Drag Druid component |
inertion | Current inert speed |
is_animate | Flag, if scroll now animating by gui.animate |
on_point_scroll | On scroll_to_index function callback(self, index, point) |
on_scroll | On scroll move callback(self, position) |
on_scroll_to | On scroll_to function callback(self, target, is_instant) |
position | Current scroll posisition |
selected | Current index of points of interests |
target_position | Current scroll target position |
view_node | Scroll view node |
view_size | Scroll view size |
Functions
- bind_grid(self, grid)
-
Bind the grid component (Static or Dynamic) to recalculate
scroll size on grid changes
Parameters:
- self Scroll Scroll
- grid StaticGrid Druid grid component
Returns:
-
druid.scroll
Current scroll instance
- get_percent(self)
-
Return current scroll progress status.
Values will be in [0..1] interval
Parameters:
- self Scroll Scroll
Returns:
-
vector3
New vector with scroll progress values
- get_scroll_size(self)
-
Return vector of scroll size with width and height.
Parameters:
- self Scroll Scroll
Returns:
-
vector3
Available scroll size
- init(self, view_node, content_node)
-
The Scroll constructor
Parameters:
- is_inert(self)
-
Return if scroll have inertion.
Parameters:
- self Scroll Scroll
Returns:
-
boolean
@If scroll have inertion
- is_node_in_view(self, node)
-
Check node if it visible now on scroll.
Extra border is not affected. Return true for elements in extra scroll zone
Parameters:
- self Scroll Scroll
- node node The node to check
Returns:
-
boolean
True if node in visible scroll area
- scroll_to(self, point, is_instant)
-
Start scroll to target point.
Parameters:
- self Scroll Scroll
- point vector3 Target point
- is_instant boolean or nil Instant scroll flag
Usage:
scroll:scroll_to(vmath.vector3(0, 50, 0))
scroll:scroll_to(vmath.vector3(0), true)
- scroll_to_index(self, index, skip_cb)
-
Scroll to item in scroll by point index.
Parameters:
- self Scroll Scroll
- index number Point index
- skip_cb boolean or nil If true, skip the point callback
- scroll_to_percent(self, percent, is_instant)
-
Start scroll to target scroll percent
Parameters:
- self Scroll Scroll
- percent vector3 target percent
- is_instant boolean or nil instant scroll flag
Usage:
scroll:scroll_to_percent(vmath.vector3(0.5, 0, 0))
- set_click_zone(self, node)
-
Strict drag scroll area. Useful for
restrict events outside stencil node
Parameters:
- self Drag
- node node or string Gui node
- set_extra_stretch_size(self, stretch_size)
-
Set extra size for scroll stretching.
Set 0 to disable stretching effect
Parameters:
- self Scroll Scroll
- stretch_size number or nil Size in pixels of additional scroll area
Returns:
-
druid.scroll
Current scroll instance
- set_horizontal_scroll(self, state)
-
Lock or unlock horizontal scroll
Parameters:
- self Scroll Scroll
- state boolean or nil True, if horizontal scroll is enabled
Returns:
-
druid.scroll
Current scroll instance
- set_inert(self, state)
-
Enable or disable scroll inert.
If disabled, scroll through points (if exist)
If no points, just simple drag without inertion
Parameters:
- self Scroll Scroll
- state boolean or nil Inert scroll state
Returns:
-
druid.scroll
Current scroll instance
- set_points(self, points)
-
Set points of interest.
Scroll will always centered on closer points
Parameters:
Returns:
-
druid.scroll
Current scroll instance
- set_size(self, size, offset)
-
Set scroll content size.
It will change content gui node size
Parameters:
- self Scroll Scroll
- size vector3 The new size for content node
- offset vector3 or nil Offset value to set, where content is starts
Returns:
-
druid.scroll
Current scroll instance
- set_vertical_scroll(self, state)
-
Lock or unlock vertical scroll
Parameters:
- self Scroll Scroll
- state boolean or nil True, if vertical scroll is enabled
Returns:
-
druid.scroll
Current scroll instance
- set_view_size(self, size)
-
Set new scroll view size in case the node size was changed.
Parameters:
- self Scroll Scroll
- size vector3 The new size for view node
Returns:
-
druid.scroll
Current scroll instance
- update_view_size(self)
-
Refresh scroll view size
Parameters:
- self Scroll Scroll
Tables
- style
-
Component style params.
You can override this component styles params in druid styles table
or create your own style
Fields:
- FRICT number or nil Multiplier for free inertion. Default: 0
- FRICT_HOLD number or nil Multiplier for inertion, while touching. Default: 0
- INERT_THRESHOLD number or nil Scroll speed to stop inertion. Default: 3
- INERT_SPEED number or nil Multiplier for inertion speed. Default: 30
- POINTS_DEADZONE number or nil Speed to check points of interests in no_inertion mode. Default: 20
- BACK_SPEED number or nil Scroll back returning lerp speed. Default: 35
- ANIM_SPEED number or nil Scroll gui.animation speed for scroll_to function. Default: 2
- EXTRA_STRETCH_SIZE number or nil extra size in pixels outside of scroll (stretch effect). Default: 0
- SMALL_CONTENT_SCROLL boolean or nil If true, content node with size less than view node size can be scrolled. Default: false
- WHEEL_SCROLL_SPEED boolean or nil The scroll speed via mouse wheel scroll or touchpad. Set to 0 to disable wheel scrolling. Default: 0
- WHEEL_SCROLL_INVERTED boolean or nil If true, invert direction for touchpad and mouse wheel scroll. Default: false
- WHEEL_SCROLL_BY_INERTION boolean or nil If true, wheel will add inertion to scroll. Direct set position otherwise.. Default: false
Fields
- _is_inert
-
Flag, if scroll now moving by inertion
- _is_inert boolean
- available_pos
-
Available position for content node: (min_x, max_y, max_x, min_y)
- available_pos vector4
- available_size
-
Size of available positions: (width, height, 0)
- available_size vector3
- content_node
-
Scroll content node
- content_node node
- drag
-
Drag Druid component
- drag Drag Drag
- inertion
-
Current inert speed
- inertion vector3
- is_animate
-
Flag, if scroll now animating by gui.animate
- is_animate boolean
- on_point_scroll
-
On scroll_to_index function callback(self, index, point)
- on_point_scroll DruidEvent DruidEvent
- on_scroll
-
On scroll move callback(self, position)
- on_scroll DruidEvent DruidEvent
- on_scroll_to
-
On scroll_to function callback(self, target, is_instant)
- on_scroll_to DruidEvent DruidEvent
- position
-
Current scroll posisition
- position vector3
- selected
-
Current index of points of interests
- selected number or nil
- target_position
-
Current scroll target position
- target_position vector3
- view_node
-
Scroll view node
- view_node node
- view_size
-
Scroll view size
- view_size vector3