Class TouchSliderFloat
A touch-optimized slider component for selecting floating-point values with support for step increments and custom formatting.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class TouchSliderFloat : TouchSlider<float>, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<float>, IValidatableElement<float>, INotifyValueChanging<float>, INotifyValueChanged<float>, IFormattable<float>
Remarks
TouchSliderFloat is a touch-optimized slider component that allows users to select a floating-point value from a defined range. It supports both touch and keyboard interactions, making it suitable for touch devices while maintaining accessibility.
The component features a visual track with a progress indicator, customizable step increments, shift-key modifier for larger steps, and support for value formatting. It can be oriented horizontally or vertically and adapts to RTL (Right-to-Left) layouts automatically.
For optimal touch interaction, the slider defaults to a medium size that provides an adequately sized touch target. You can adjust the size using the size property to match your UI requirements.
The slider supports both UXML definition and runtime instantiation, making it flexible for various UI development workflows.
Examples
Basic slider with default settings — creates a basic horizontal slider with default range (0-1) and initial value of 0.5.
<TouchSliderFloat value="0.5" />
Customized slider with specific range and step values — creates a large slider with a range from -10 to 10, 0.5 step increments, 2.0 shift-step, and one decimal place formatting.
<TouchSliderFloat
low-value="-10"
high-value="10"
value="0"
step="0.5"
shift-step="2.0"
format-string="F1"
size="L"
/>
Vertical slider with custom styling — creates a vertical slider with a range from 0 to 100 and custom styling class.
<TouchSliderFloat
orientation="Vertical"
low-value="0"
high-value="100"
value="50"
class="custom-slider"
/>
Runtime instantiation and event handling — creates a slider in code, configures it to display values as percentages, and handles value changes.
var slider = new TouchSliderFloat();
slider.lowValue = 0f;
slider.highValue = 1f;
slider.value = 0.5f;
slider.formatString = "P0";
slider.RegisterValueChangedCallback(evt => {
Debug.Log($"New value: {evt.newValue}");
});
Constructors
TouchSliderFloat()
Default constructor.
Declaration
public TouchSliderFloat()
Properties
thumbCount
Get the number of thumbs for this slider.
Declaration
protected override int thumbCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Methods
ClampThumb(float, float, float)
Clamp the thumb value.
Declaration
protected override float ClampThumb(float x, float min, float max)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | The value to clamp. |
| float | min | The minimum value. |
| float | max | The maximum value. |
Returns
| Type | Description |
|---|---|
| float | The clamped values. |
Overrides
GetScalarValuesFromValue(float, Span<float>)
Get the list of thumb values from the TValue value. This must be sorted.
Declaration
protected override void GetScalarValuesFromValue(float v, Span<float> values)
Parameters
| Type | Name | Description |
|---|---|---|
| float | v | |
| Span<float> | values | The list of thumb values. |
Overrides
GetStepCount(float)
Declaration
protected override int GetStepCount(float stepValue)
Parameters
| Type | Name | Description |
|---|---|---|
| float | stepValue | The step value. |
Returns
| Type | Description |
|---|---|
| int | The number of possible steps. |
Overrides
GetValueFromScalarValues(Span<float>)
Get the TValue value from the list of thumb values.
Declaration
protected override float GetValueFromScalarValues(Span<float> values)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<float> | values | The list of thumb values. |
Returns
| Type | Description |
|---|---|
| float | The TValue value. |
Overrides
Mad(int, float, float)
Performs an arithmetic multiply/add operation.
Declaration
protected override float Mad(int m, float a, float b)
Parameters
| Type | Name | Description |
|---|---|---|
| int | m | The number of times to multiply the a value. |
| float | a | The value that will be multiplied N times and then added to the base value. |
| float | b | The addition value. |
Returns
| Type | Description |
|---|---|
| float | The incremented value. |
Overrides
ParseRawValueToString(float)
Declaration
protected override string ParseRawValueToString(float val)
Parameters
| Type | Name | Description |
|---|---|---|
| float | val | The float 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 float)
Method to implement to resolve a string value into a float value.
You can use TryParse(string, out float) for floating point value types for example.
Declaration
protected override bool ParseStringToValue(string strValue, out float val)
Parameters
| Type | Name | Description |
|---|---|---|
| string | strValue | The string value to convert. |
| float | val |
Returns
| Type | Description |
|---|---|
| bool | True if can be parsed, False otherwise. |
Overrides
ParseSubValueToString(float)
Method to implement to resolve a float 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(float val)
Parameters
| Type | Name | Description |
|---|---|---|
| float | val | The float value to convert. |
Returns
| Type | Description |
|---|---|
| string | The converted value. |
Overrides
ParseValueToString(float)
Method to implement to resolve a float 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(float val)
Parameters
| Type | Name | Description |
|---|---|---|
| float | val | The float value to convert. |
Returns
| Type | Description |
|---|---|
| string | The converted value. |
Overrides
SliderLerpUnclamped(float, float, 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 float SliderLerpUnclamped(float a, float b, float interpolant)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The lowest value in the range. |
| float | b | The highest value in the range. |
| float | interpolant | The normalized value to process. |
Returns
| Type | Description |
|---|---|
| float | The interpolated value. |
Overrides
SliderNormalizeValue(float, float, float)
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(float currentValue, float lowerValue, float higherValue)
Parameters
| Type | Name | Description |
|---|---|---|
| float | currentValue | The value to normalize. |
| float | lowerValue | The lowest value in the range. |
| float | higherValue | The highest value in the range. |
Returns
| Type | Description |
|---|---|
| float | The normalized value. |