Class SliderFloat
A control that allows users to select a value from a continuous range.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class SliderFloat : Slider<float, float, FloatField>, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<float>, IValidatableElement<float>, INotifyValueChanging<float>, INotifyValueChanged<float>, IFormattable<float>
Remarks
The SliderFloat component is a user interface control that allows users to select a floating-point value from a continuous range by dragging a thumb along a track. It provides visual feedback through its track and thumb elements, making it intuitive for users to adjust values.
The slider supports both horizontal and vertical orientations, and can be customized with step values, marks, value labels, and input field integration. It's particularly useful for scenarios where users need to adjust values like volume, opacity, size, or any other continuous numeric parameter.
Features
- Continuous value selection with floating-point precision
- Customizable value range with minimum and maximum bounds
- Optional step values for discrete increments
- Support for custom marks and labels
- Value display modes (always on, auto, or off)
- Track display customization
- Optional input field integration
Best Practices
- Use appropriate step values that make sense for your use case
- Provide meaningful labels when using marks
- Consider using value labels for better user feedback
Note: The slider supports keyboard navigation using arrow keys, and the shift key can be used for larger step increments.
Examples
Basic slider with default settings — creates a basic horizontal slider with default range (0-100).
<SliderFloat />
Customized slider with marks and labels — creates a slider for decimal values (0-1) with marks, labels, and visible track.
<SliderFloat
low-value="0"
high-value="1"
step="0.1"
show-marks="true"
show-marks-label="true"
display-value-label="On"
track="On"
/>
Slider with custom scaling and formatting — creates a slider that uses exponential scaling (2^n) and formats values with KB units.
var slider = new SliderFloat {
scale = v => Mathf.Pow(2, v),
formatFunction = v => $"{v:F0} KB",
lowValue = 0,
highValue = 10,
step = 1
};
Vertical slider with custom marks — creates a vertical slider with custom marks and labels at specific positions.
var slider = new SliderFloat {
orientation = Direction.Vertical,
customMarks = new List<SliderMark<float>> {
new() { value = 0, label = "Min" },
new() { value = 50, label = "Mid" },
new() { value = 100, label = "Max" }
},
showMarks = true,
showMarksLabel = true
};
Constructors
SliderFloat()
Default constructor.
Declaration
public SliderFloat()
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
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 v)
Parameters
| Type | Name | Description |
|---|---|---|
| string | strValue | The string value to convert. |
| float | v |
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. |