Class RangeSliderFloat
A dual-thumb slider component for selecting a range of floating point values.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class RangeSliderFloat : Slider<Vector2, float, Vector2Field>, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<Vector2>, IValidatableElement<Vector2>, INotifyValueChanging<Vector2>, INotifyValueChanged<Vector2>, IFormattable<float>
Remarks
The RangeSliderFloat is an input component that allows users to select a range between two numeric values by dragging two thumbs along a track. It's particularly useful when users need to define minimum and maximum bounds within a larger range of values.
The slider supports both horizontal and vertical orientations, customizable step increments, and various visual feedback options like marks, labels, and track highlighting.
The slider automatically handles RTL (Right-to-Left) layouts and will reverse its direction accordingly when in RTL context.
Examples
Basic range slider setup with UXML.
<UXML>
<ui:RangeSliderFloat
low-value="0"
high-value="100"
min-value="20"
max-value="80"
step="5"
show-marks="true"
display-value-label="Auto"
track="On" />
</UXML>
Creating and configuring a range slider in C#.
var rangeSlider = new RangeSliderFloat
{
lowValue = 0f,
highValue = 100f,
value = new Vector2(25f, 75f),
step = 5f,
showMarks = true,
displayValueLabel = ValueDisplayMode.Auto,
track = TrackDisplayType.On
};
rangeSlider.RegisterValueChangedCallback(evt => {
Debug.Log($"Range changed: - ");
});
Custom formatting of values.
rangeSlider.formatString = "F1"; // Display one decimal place
rangeSlider.formatFunction = (value) => $"{value:F1}°C"; // Add units
Constructors
RangeSliderFloat()
Default constructor.
Declaration
public RangeSliderFloat()
Properties
maxValue
The high part of the range value.
Declaration
public float maxValue { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
minValue
The low part of the range value.
Declaration
public float minValue { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
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(Vector2, Span<float>)
Get the list of thumb values from the TValue value. This must be sorted.
Declaration
protected override void GetScalarValuesFromValue(Vector2 v, Span<float> values)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | 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 Vector2 GetValueFromScalarValues(Span<float> values)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<float> | values | The list of thumb values. |
Returns
| Type | Description |
|---|---|
| Vector2 | 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
ParseStringToValue(string, out Vector2)
Method to implement to resolve a string value into a Vector2 value.
You can use TryParse(string, out float) for floating point value types for example.
Declaration
protected override bool ParseStringToValue(string strValue, out Vector2 val)
Parameters
| Type | Name | Description |
|---|---|---|
| string | strValue | The string value to convert. |
| Vector2 | val |
Returns
| Type | Description |
|---|---|
| bool | True if can be parsed, False otherwise. |
Overrides
ParseSubValueToString(float)
Method to implement to resolve a Vector2 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 Vector2 value to convert. |
Returns
| Type | Description |
|---|---|
| string | The converted value. |
Overrides
ParseValueToString(Vector2)
Method to implement to resolve a Vector2 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(Vector2 val)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | val | The Vector2 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. |