Class TouchSliderInt
A touch-optimized slider component for selecting integer values within a specified range.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class TouchSliderInt : TouchSlider<int>, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<int>, IValidatableElement<int>, INotifyValueChanging<int>, INotifyValueChanged<int>, IFormattable<int>
Remarks
TouchSliderInt is a user interface control that allows users to select an integer value from a continuous range by dragging a thumb along a track. It is specifically designed for touch interactions while maintaining full keyboard and mouse support.
The slider provides visual feedback through a progress bar that fills according to the current value. It supports both horizontal and vertical orientations, and automatically adapts to RTL (Right-to-Left) layouts.
The component includes a label that can display units or descriptions, and a value display that shows the current selection. Users can directly edit the value through a text input field that appears when clicking on the value display.
For performance reasons, it's recommended to set appropriate step values to limit the number of possible values in very large ranges.
Examples
Basic usage of TouchSliderInt in UXML — creating an age selector slider in UXML.
<TouchSliderInt name="ageSlider"
low-value="0"
high-value="100"
value="25"
label="years"
step="1"
shift-step="5"
size="M" />
Creating and configuring TouchSliderInt in C# — creating a volume control slider programmatically.
var volumeSlider = new TouchSliderInt
{
lowValue = 0,
highValue = 100,
value = 50,
label = "%",
step = 5,
shiftStep = 10,
size = Size.M
};
// Add value change listener
volumeSlider.RegisterValueChangedCallback(evt =>
{
Debug.Log($"Volume changed from to ");
});
Creating a vertical slider with custom styling — creating a height measurement slider.
var heightSlider = new TouchSliderInt
{
orientation = Direction.Vertical,
lowValue = 0,
highValue = 200,
value = 170,
label = "cm",
step = 1,
shiftStep = 10
};
// Add custom styling
heightSlider.AddToClassList("custom-slider");
Constructors
TouchSliderInt()
Default constructor.
Declaration
public TouchSliderInt()
Properties
thumbCount
Get the number of thumbs for this slider.
Declaration
protected override int thumbCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Methods
ClampThumb(int, int, int)
Clamp the thumb value.
Declaration
protected override int ClampThumb(int x, int min, int max)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | The value to clamp. |
| int | min | The minimum value. |
| int | max | The maximum value. |
Returns
| Type | Description |
|---|---|
| int | The clamped values. |
Overrides
GetScalarValuesFromValue(int, Span<int>)
Get the list of thumb values from the TValue value. This must be sorted.
Declaration
protected override void GetScalarValuesFromValue(int v, Span<int> values)
Parameters
| Type | Name | Description |
|---|---|---|
| int | v | |
| Span<int> | values | The list of thumb values. |
Overrides
GetStepCount(int)
Declaration
protected override int GetStepCount(int stepValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | stepValue | The step value. |
Returns
| Type | Description |
|---|---|
| int | The number of possible steps. |
Overrides
GetValueFromScalarValues(Span<int>)
Get the TValue value from the list of thumb values.
Declaration
protected override int GetValueFromScalarValues(Span<int> values)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<int> | values | The list of thumb values. |
Returns
| Type | Description |
|---|---|
| int | The TValue value. |
Overrides
Mad(int, int, int)
Performs an arithmetic multiply/add operation.
Declaration
protected override int Mad(int m, int a, int b)
Parameters
| Type | Name | Description |
|---|---|---|
| int | m | The number of times to multiply the a value. |
| int | a | The value that will be multiplied N times and then added to the base value. |
| int | b | The addition value. |
Returns
| Type | Description |
|---|---|
| int | The incremented value. |
Overrides
ParseRawValueToString(int)
Declaration
protected override string ParseRawValueToString(int val)
Parameters
| Type | Name | Description |
|---|---|---|
| int | val | The int value to convert. |
Returns
| Type | Description |
|---|---|
| string | The converted value. |
Overrides
Remarks
This method is used to convert the value to a string when the user is editing the value in the input field. This must not use the formatString property.
ParseStringToValue(string, out int)
Method to implement to resolve a string value into a int value.
You can use TryParse(string, out float) for floating point value types for example.
Declaration
protected override bool ParseStringToValue(string strValue, out int val)
Parameters
| Type | Name | Description |
|---|---|---|
| string | strValue | The string value to convert. |
| int | val |
Returns
| Type | Description |
|---|---|
| bool | True if can be parsed, False otherwise. |
Overrides
ParseSubValueToString(int)
Method to implement to resolve a int value into a string value.
You can use ToString() for floating point value types for example.
You can also round the value if you want a specific number of decimals.
Declaration
protected override string ParseSubValueToString(int val)
Parameters
| Type | Name | Description |
|---|---|---|
| int | val | The int value to convert. |
Returns
| Type | Description |
|---|---|
| string | The converted value. |
Overrides
ParseValueToString(int)
Method to implement to resolve a int value into a string value.
You can use ToString() for floating point value types for example.
You can also round the value if you want a specific number of decimals.
Declaration
protected override string ParseValueToString(int val)
Parameters
| Type | Name | Description |
|---|---|---|
| int | val | The int value to convert. |
Returns
| Type | Description |
|---|---|
| string | The converted value. |
Overrides
SliderLerpUnclamped(int, int, float)
Method to implement which returns a value based on the linear interpolation of a given interpolant between a specific range.
Usually, you can use directly LerpUnclamped(float, float, float) for floating point value types.
Declaration
protected override int SliderLerpUnclamped(int a, int b, float interpolant)
Parameters
| Type | Name | Description |
|---|---|---|
| int | a | The lowest value in the range. |
| int | b | The highest value in the range. |
| float | interpolant | The normalized value to process. |
Returns
| Type | Description |
|---|---|
| int | The interpolated value. |
Overrides
SliderNormalizeValue(int, int, int)
Method to implement which returns the normalized value of a given value in a specific range.
Usually, you can use directly an InverseLerp(float, float, float) for floating point value types.
Declaration
protected override float SliderNormalizeValue(int currentValue, int lowerValue, int higherValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | currentValue | The value to normalize. |
| int | lowerValue | The lowest value in the range. |
| int | higherValue | The highest value in the range. |
Returns
| Type | Description |
|---|---|
| float | The normalized value. |