Scroller
A vertical or horizontal scrollbar. For more information, refer to UXML element Scroller.
Read time 9 minutesLast updated 5 days ago
Definition
- Type: Class
- Namespace: UnityEngine.UIElements
- Assembly: UnityEngine.UIElementsModule
- Inherits from: VisualElement
- Implements: IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, ICustomStyle
[Icon("UIToolkit/Icons/Scroller.png")][UxmlElement(libraryPath = "Controls")]public class Scroller : VisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, ICustomStyle
Remarks
Each ScrollView has a Scroller for each axis, controlled by ScrollerVisibility. For more information, refer to ScrollView. If a Scroller is used in ScrollView, its _highValue and _lowValue are automatically overridden to match the ScrollView content size on GeometryChangedEvent. A Scroller contains a Slider and two RepeatButtons for scrolling.
The following example creates a scroller independently from a ScrollView:
Examples
using System;using UnityEngine;using UnityEngine.UIElements;[RequireComponent(typeof(UIDocument))]public class Scroller_Example : MonoBehaviour{ // To use this example in runtime, add a UIDocument component to your Scene and attach a UXML file to the UIDocument component. // The UXML file can be empty. public UIDocument uiDocument; public int minXValue = 20; public int maXValue = 80; private void Start() { var ballBlocker = new VisualElement(); ballBlocker.style.width = 20; ballBlocker.style.height = 10; ballBlocker.style.backgroundColor = Color.red; var horizontalScroller = new Scroller(minXValue, maXValue, null, SliderDirection.Horizontal); var minLabel = new Label($"Minimum Value: {minXValue}"); var maxLabel = new Label($"Maximum Value: {maXValue}"); var ballBlockerLabel = new Label($"Ball Blocker Position: {ballBlocker.style.left}"); ballBlocker.style.left = horizontalScroller.value; // The width of the Scroller is independent of its value range. horizontalScroller.style.width = 200; horizontalScroller.valueChanged += (value) => { ballBlocker.style.left = value; ballBlockerLabel.text = $"Ball Blocker Position: {ballBlocker.style.left}"; }; uiDocument.rootVisualElement.Add(ballBlocker); uiDocument.rootVisualElement.Add(horizontalScroller); uiDocument.rootVisualElement.Add(minLabel); uiDocument.rootVisualElement.Add(maxLabel); uiDocument.rootVisualElement.Add(ballBlockerLabel); }}
Static Fields
Value | Description |
|---|---|
| highButtonUssClassName | USS class name of high buttons in elements of this type. |
| horizontalVariantUssClassName | USS class name of elements of this type, when they are displayed horizontally. |
| lowButtonUssClassName | USS class name of low buttons in elements of this type. |
| sliderUssClassName | USS class name of slider elements in elements of this type. |
| ussClassName | USS class name of elements of this type. |
| verticalVariantUssClassName | USS class name of elements of this type, when they are displayed vertically. |
Constructors
Constructor | Description |
|---|---|
| Scroller() | Constructor. |
| Scroller(System.Single,System.Single,System.Action{System.Single},UnityEngine.UIElements.SliderDirection) | Constructor. |
Properties
Property | Description |
|---|---|
| direction | Direction of this scrollbar. |
| highButton | Top or right scroll button. |
| highValue | Maximum value. |
| lowButton | Bottom or left scroll button. |
| lowValue | Minimum value. |
| slider | The slider used by this scroller. |
| value | Value that defines the slider position. It lies between _lowValue and _highValue. |
Methods
Method | Description |
|---|---|
| Adjust | Updates the slider element size as a ratio of total range. A value greater than or equal to 1 will disable the Scroller. |
| ScrollPageDown | Will change the value according to the current slider pageSize. |
| ScrollPageUp | Will change the value according to the current slider pageSize. |
Events
Member | Description |
|---|---|
| valueChanged | Event sent when the slider value has changed. |