Class SliderInt
A slider component for selecting an integer value from a range.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class SliderInt : Slider<int, int, IntField>, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<int>, IValidatableElement<int>, INotifyValueChanging<int>, INotifyValueChanged<int>, IFormattable<int>
Remarks
The SliderInt component lets users select a value by moving a thumb control along a horizontal or vertical track. It's ideal for adjusting settings that have a fixed numerical range and where users benefit from visual feedback.
The component supports various features like:
- Customizable range with minimum and maximum values
- Optional step values for incremental changes
- Value display modes (always visible, on interaction, or hidden)
- Customizable track appearance
- Optional marks and labels along the track
- Keyboard navigation and accessibility support
- RTL (Right-to-Left) layout support
The SliderInt only works with integer values. For decimal values, use SliderFloat instead.
Examples
Basic slider with default settings: Creates a basic horizontal slider with range 0-100 and initial value 50
<Slider value="50" />
Slider with custom range and step: Creates a slider with range -50 to 50, step size 5, and visible marks
<Slider low-value="-50" high-value="50" step="5" value="0" show-marks="true" />
Vertical slider with value label: Creates a vertical slider with always visible value label and track
<Slider orientation="Vertical" display-value-label="On" track="On" />
Advanced slider with custom formatting: Creates a slider for selecting memory sizes with custom value formatting
var slider = new SliderInt {
value = 1024,
lowValue = 0,
highValue = 8192,
step = 1024,
showMarks = true,
displayValueLabel = ValueDisplayMode.On,
formatFunction = (v) => $"{v / 1024}MB"
};
Constructors
SliderInt()
Default constructor.
Declaration
public SliderInt()
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
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 v)
Parameters
| Type | Name | Description |
|---|---|---|
| string | strValue | The string value to convert. |
| int | v |
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. |