Class BaseSlider<TValue, TScalar>
Base class for any kind of Slider such as Touch
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
public abstract class BaseSlider<TValue, TScalar> : ExVisualElement, IEventHandler, IVisualElementScheduler, IExperimentalFeatures, ITransitionAnimations, ITransform, IResolvedStyle, IContextOverrideElement, IAdditionalDataHolder, IInputElement<TValue>, IValidatableElement<TValue>, INotifyValueChanging<TValue>, INotifyValueChanged<TValue>, IFormattable<TScalar> where TScalar : unmanaged
Type Parameters
Name | Description |
---|---|
TValue | A value type for the slider. |
TScalar | A value type for a single thumb of the slider. |
Constructors
BaseSlider()
Default constructor.
Declaration
protected BaseSlider()
See Also
Fields
m_CurrentDirection
The current direction of the layout.
Declaration
protected Dir m_CurrentDirection
Field Value
Type | Description |
---|---|
Dir |
See Also
m_DraggedThumbIndex
The current thumb index that is being dragged.
Declaration
protected int m_DraggedThumbIndex
Field Value
Type | Description |
---|---|
int |
See Also
m_DraggerManipulator
The dragger manipulator used to move the slider.
Declaration
protected Draggable m_DraggerManipulator
Field Value
Type | Description |
---|---|
Draggable |
See Also
m_FormatFunc
The format function used to display the value of the slider.
Declaration
protected FormatFunction<TScalar> m_FormatFunc
Field Value
Type | Description |
---|---|
Format |
See Also
m_FormatString
The format string used to display the value of the slider.
Declaration
protected string m_FormatString
Field Value
Type | Description |
---|---|
string |
See Also
m_HighValue
Slider max value.
Declaration
protected TScalar m_HighValue
Field Value
Type | Description |
---|---|
TScalar |
See Also
m_LowValue
Slider min value.
Declaration
protected TScalar m_LowValue
Field Value
Type | Description |
---|---|
TScalar |
See Also
m_Orientation
The orientation of the slider.
Declaration
protected Direction m_Orientation
Field Value
Type | Description |
---|---|
Direction |
See Also
m_PreviousValue
The previous value of the slider before the user started interacting with it.
Declaration
protected TValue m_PreviousValue
Field Value
Type | Description |
---|---|
TValue |
See Also
m_ShiftStep
The shift step value of the slider.
Declaration
protected TScalar m_ShiftStep
Field Value
Type | Description |
---|---|
TScalar |
See Also
m_Step
The step value of the slider.
Declaration
protected TScalar m_Step
Field Value
Type | Description |
---|---|
TScalar |
See Also
m_SwapThumbs
Whether the thumbs can be swapped if the low value is greater than the high value. If false, each thumb will be clamped to its respective value.
Declaration
protected bool m_SwapThumbs
Field Value
Type | Description |
---|---|
bool |
See Also
m_ValidateValue
The validation function used to validate the value of the slider.
Declaration
protected Func<TValue, bool> m_ValidateValue
Field Value
See Also
m_Value
The current value of the slider.
Declaration
protected TValue m_Value
Field Value
Type | Description |
---|---|
TValue |
See Also
Properties
comparer
The comparer used to compare the values of the slider.
Declaration
public IComparer<TValue> comparer { get; set; }
Property Value
Type | Description |
---|---|
IComparer<TValue> |
See Also
formatFunction
The format function used to display the value of the slider.
Declaration
public FormatFunction<TScalar> formatFunction { get; set; }
Property Value
Type | Description |
---|---|
Format |
See Also
formatString
The format string used to display the value of the slider.
Declaration
public string formatString { get; set; }
Property Value
Type | Description |
---|---|
string |
See Also
highValue
Specify the maximum value in the range of this slider.
Declaration
public TScalar highValue { get; set; }
Property Value
Type | Description |
---|---|
TScalar |
See Also
invalid
The invalid state of the slider.
Declaration
public bool invalid { get; set; }
Property Value
Type | Description |
---|---|
bool |
See Also
lowValue
Specify the minimum value in the range of this slider.
Declaration
public TScalar lowValue { get; set; }
Property Value
Type | Description |
---|---|
TScalar |
See Also
orientation
The orientation of the slider. It can be horizontal or vertical. In vertical orientation, the slider will be drawn from bottom to top. In horizontal orientation, the slider will be drawn from left to right in LTR context and from right to left in RTL context.
Declaration
public Direction orientation { get; set; }
Property Value
Type | Description |
---|---|
Direction |
See Also
shiftStep
The step value of the slider when the shift key is pressed.
Declaration
public TScalar shiftStep { get; set; }
Property Value
Type | Description |
---|---|
TScalar |
See Also
step
The step value of the slider.
Declaration
public TScalar step { get; set; }
Property Value
Type | Description |
---|---|
TScalar |
See Also
swapThumbs
Whether the thumbs can be swapped a thumb value becomes greater than the next one or when it becomes smaller than the previous one.
Declaration
public bool swapThumbs { get; set; }
Property Value
Type | Description |
---|---|
bool |
See Also
thumbComparer
The comparer used to compare the thumb values of the slider.
Declaration
public IComparer<TScalar> thumbComparer { get; set; }
Property Value
Type | Description |
---|---|
IComparer<TScalar> |
See Also
thumbCount
Get the number of thumbs for this slider.
Declaration
protected abstract int thumbCount { get; }
Property Value
Type | Description |
---|---|
int |
See Also
validateValue
The validation function used to validate the value of the slider.
Declaration
public Func<TValue, bool> validateValue { get; set; }
Property Value
See Also
value
The current value of the slider.
Declaration
public TValue value { get; set; }
Property Value
Type | Description |
---|---|
TValue |
See Also
Methods
Clamp(TValue, TScalar, TScalar)
Utility method to clamp a TValue
value between specified bounds.
Declaration
protected virtual TValue Clamp(TValue v, TScalar lowBound, TScalar highBound)
Parameters
Type | Name | Description |
---|---|---|
TValue | v | The value to clamp. |
TScalar | lowBound | Minimum |
TScalar | highBound | Maximum |
Returns
Type | Description |
---|---|
TValue | The clamped value. |
See Also
ClampThumb(TScalar, TScalar, TScalar)
Clamp the thumb value.
Declaration
protected abstract TScalar ClampThumb(TScalar x, TScalar min, TScalar max)
Parameters
Type | Name | Description |
---|---|---|
TScalar | x | The value to clamp. |
TScalar | min | The minimum value. |
TScalar | max | The maximum value. |
Returns
Type | Description |
---|---|
TScalar | The clamped values. |
See Also
ComputeValueFromDrag(Draggable)
Returns the value to set as slider value based on a given dragger position.
Declaration
protected virtual TValue ComputeValueFromDrag(Draggable dragger)
Parameters
Type | Name | Description |
---|---|---|
Draggable | dragger | The dragger manipulator. |
Returns
Type | Description |
---|---|
TValue | The value to set as slider value based on a given dragger position. |
See Also
FindClosestThumbValue(Draggable, ReadOnlySpan<TScalar>, out int)
Find the closest thumb value to the given dragger position.
Declaration
protected TScalar FindClosestThumbValue(Draggable dragger, ReadOnlySpan<TScalar> values, out int index)
Parameters
Type | Name | Description |
---|---|---|
Draggable | dragger | The dragger manipulator. |
Read |
values | The values of the thumbs. |
int | index | The index of the closest thumb value. |
Returns
Type | Description |
---|---|
TScalar | The closest thumb value to the given dragger position. |
See Also
FindClosestThumbValue(TScalar, int, Func<int, TScalar>, out int)
Find the closest thumb value to the given value.
Declaration
protected TScalar FindClosestThumbValue(TScalar v, int count, Func<int, TScalar> predicate, out int index)
Parameters
Type | Name | Description |
---|---|---|
TScalar | v | The value to find the closest thumb value to. |
int | count | The number of thumbs. |
Func<int, TScalar> | predicate | The predicate to get the thumb value at a specific index. |
int | index | The index of the closest thumb value. |
Returns
Type | Description |
---|---|
TScalar | The closest thumb value to the given value. |
See Also
FindClosestThumbValue(TScalar, ReadOnlySpan<TScalar>, out int)
Find the closest thumb value to the given value.
Declaration
protected TScalar FindClosestThumbValue(TScalar v, ReadOnlySpan<TScalar> values, out int index)
Parameters
Type | Name | Description |
---|---|---|
TScalar | v | The value to find the closest thumb value to. |
Read |
values | The values of the thumbs. |
int | index | The index of the closest thumb value. |
Returns
Type | Description |
---|---|
TScalar | The closest thumb value to the given value. |
See Also
GetClampedValue(TValue)
Declaration
protected virtual TValue GetClampedValue(TValue newValue)
Parameters
Type | Name | Description |
---|---|---|
TValue | newValue | The value to clamp. |
Returns
Type | Description |
---|---|
TValue | The clamped value. |
Remarks
The method also checks if low and high values are inverted.
See Also
GetNormalizedValueFromDrag(Draggable)
Get a normalized value from a dragger position.
Declaration
protected float GetNormalizedValueFromDrag(Draggable dragger)
Parameters
Type | Name | Description |
---|---|---|
Draggable | dragger | The dragger manipulator. |
Returns
Type | Description |
---|---|
float | The normalized value from a dragger position. |
See Also
GetScalarValuesFromValue(TValue, Span<TScalar>)
Get the list of thumb values from the TValue value. This must be sorted.
Declaration
protected abstract void GetScalarValuesFromValue(TValue value, Span<TScalar> values)
Parameters
Type | Name | Description |
---|---|---|
TValue | value | The TValue value. |
Span<TScalar> | values | The list of thumb values. |
See Also
GetStepCount(TScalar)
Declaration
protected abstract int GetStepCount(TScalar stepValue)
Parameters
Type | Name | Description |
---|---|---|
TScalar | stepValue | The step value. |
Returns
Type | Description |
---|---|
int | The number of possible steps. |
See Also
GetTrackElement()
Get the element that represent the entire track of the slider.
Declaration
protected virtual VisualElement GetTrackElement()
Returns
Type | Description |
---|---|
Visual |
The element that represent the entire track of the slider. |
See Also
GetValueFromScalarValues(Span<TScalar>)
Get the TValue value from the list of thumb values.
Declaration
protected abstract TValue GetValueFromScalarValues(Span<TScalar> values)
Parameters
Type | Name | Description |
---|---|---|
Span<TScalar> | values | The list of thumb values. |
Returns
Type | Description |
---|---|
TValue | The TValue value. |
See Also
InvokeValueChangedCallbacks()
Called when the value of the slider has changed via the value property.
Declaration
protected virtual void InvokeValueChangedCallbacks()
See Also
KeyDecrement(TScalar, TScalar, KeyDownEvent)
Decrement the value of the slider on a specific thumb.
Declaration
protected virtual TScalar KeyDecrement(TScalar baseValue, TScalar stepValue, KeyDownEvent evt)
Parameters
Type | Name | Description |
---|---|---|
TScalar | baseValue | The base value to decrement. |
TScalar | stepValue | The decrement step value. |
Key |
evt | The key down event. |
Returns
Type | Description |
---|---|
TScalar | The decremented value. |
See Also
KeyIncrement(TScalar, TScalar, KeyDownEvent)
Increment the value of the slider on a specific thumb.
Declaration
protected virtual TScalar KeyIncrement(TScalar baseValue, TScalar stepValue, KeyDownEvent evt)
Parameters
Type | Name | Description |
---|---|---|
TScalar | baseValue | The base value to increment. |
TScalar | stepValue | The increment step value. |
Key |
evt | The key down event. |
Returns
Type | Description |
---|---|
TScalar | The incremented value. |
See Also
Mad(int, TScalar, TScalar)
Performs an arithmetic multiply/add operation.
Declaration
protected abstract TScalar Mad(int m, TScalar a, TScalar b)
Parameters
Type | Name | Description |
---|---|---|
int | m | The number of times to multiply the a value. |
TScalar | a | The value that will be multiplied N times and then added to the base value. |
TScalar | b | The addition value. |
Returns
Type | Description |
---|---|
TScalar | The incremented value. |
See Also
OnDirectionChanged(ContextChangedEvent<DirContext>)
Event callback called when the direction of the layout has changed.
Declaration
protected virtual void OnDirectionChanged(ContextChangedEvent<DirContext> evt)
Parameters
Type | Name | Description |
---|---|---|
Context |
evt | The direction context changed event |
See Also
OnGeometryChanged(GeometryChangedEvent)
Event callback called when the geometry of the slider has changed in the layout.
Declaration
protected virtual void OnGeometryChanged(GeometryChangedEvent evt)
Parameters
Type | Name | Description |
---|---|---|
Geometry |
evt | The geometry changed event. |
See Also
OnKeyDown(KeyDownEvent)
Base implementation of KeyDown event handler.
Declaration
protected virtual void OnKeyDown(KeyDownEvent evt)
Parameters
Type | Name | Description |
---|---|---|
Key |
evt | The key down event. |
See Also
OnSliderRangeChanged()
Called when the low or high value of Slider has changed.
Declaration
protected virtual void OnSliderRangeChanged()
See Also
OnStyleResolved(CustomStyleResolvedEvent)
Event callback called when the style of the slider has been resolved.
Declaration
protected virtual void OnStyleResolved(CustomStyleResolvedEvent evt)
Parameters
Type | Name | Description |
---|---|---|
Custom |
evt | The custom style resolved event. |
See Also
OnTrackClicked()
Called when the track has received a click event.
Declaration
protected virtual void OnTrackClicked()
Remarks
Always check if the mouse has moved using has
See Also
OnTrackDown(Draggable)
Event callback called when a pointer down event is received.
Declaration
protected virtual void OnTrackDown(Draggable dragger)
Parameters
Type | Name | Description |
---|---|---|
Draggable | dragger | The dragger manipulator. |
See Also
OnTrackDragged(Draggable)
Event callback called when the dragger is dragged.
Declaration
protected virtual void OnTrackDragged(Draggable dragger)
Parameters
Type | Name | Description |
---|---|---|
Draggable | dragger | The dragger manipulator. |
See Also
OnTrackUp(Draggable)
Event callback called when a pointer up event is received.
Declaration
protected virtual void OnTrackUp(Draggable dragger)
Parameters
Type | Name | Description |
---|---|---|
Draggable | dragger | The dragger manipulator. |
See Also
ParseRawValueToString(TValue)
Method to implement to resolve a TValue
value into a string value.
Declaration
protected virtual string ParseRawValueToString(TValue val)
Parameters
Type | Name | Description |
---|---|---|
TValue | val | The |
Returns
Type | Description |
---|---|
string | The converted value. |
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 format
See Also
ParseStringToValue(string, out TValue)
Method to implement to resolve a string value into a TValue
value.
You can use Try
Declaration
protected abstract bool ParseStringToValue(string strValue, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
string | strValue | The string value to convert. |
TValue | value | The stringThe converted value. |
Returns
Type | Description |
---|---|
bool | True if can be parsed, False otherwise. |
See Also
ParseSubValueToString(TScalar)
Method to implement to resolve a TValue
value into a string value.
You can use To
You can also round the value if you want a specific number of decimals.
Declaration
protected virtual string ParseSubValueToString(TScalar val)
Parameters
Type | Name | Description |
---|---|---|
TScalar | val | The |
Returns
Type | Description |
---|---|
string | The converted value. |
See Also
ParseValueToString(TValue)
Method to implement to resolve a TValue
value into a string value.
You can use To
You can also round the value if you want a specific number of decimals.
Declaration
protected virtual string ParseValueToString(TValue val)
Parameters
Type | Name | Description |
---|---|---|
TValue | val | The |
Returns
Type | Description |
---|---|
string | The converted value. |
See Also
SetOrientation(Direction)
Called when the orientation of the slider has changed.
Declaration
protected virtual void SetOrientation(Direction newValue)
Parameters
Type | Name | Description |
---|---|---|
Direction | newValue | The new orientation value. |
See Also
SetShiftStep(TScalar)
Set the shift step value of the slider.
Declaration
protected virtual void SetShiftStep(TScalar newShiftStep)
Parameters
Type | Name | Description |
---|---|---|
TScalar | newShiftStep | The new shift step value. |
See Also
SetStep(TScalar)
Set the step value of the slider.
Declaration
protected virtual void SetStep(TScalar newStep)
Parameters
Type | Name | Description |
---|---|---|
TScalar | newStep | The new step value. |
See Also
SetSwapThumbs(bool)
Set the swap thumbs value of the slider.
Declaration
protected virtual void SetSwapThumbs(bool newSwapThumbs)
Parameters
Type | Name | Description |
---|---|---|
bool | newSwapThumbs | The new swap thumbs value. |
See Also
SetValueWithoutNotify(TValue)
Set the value of the slider without sending any event.
Declaration
public abstract void SetValueWithoutNotify(TValue newValue)
Parameters
Type | Name | Description |
---|---|---|
TValue | newValue | The new value of the slider. |
See Also
SliderLerpUnclamped(TScalar, TScalar, 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 Lerp
Declaration
protected abstract TScalar SliderLerpUnclamped(TScalar a, TScalar b, float interpolant)
Parameters
Type | Name | Description |
---|---|---|
TScalar | a | The lowest value in the range. |
TScalar | b | The highest value in the range. |
float | interpolant | The normalized value to process. |
Returns
Type | Description |
---|---|
TScalar | The interpolated value. |
See Also
SliderNormalizeValue(TScalar, TScalar, TScalar)
Method to implement which returns the normalized value of a given value in a specific range.
Usually, you can use directly an Inverse
Declaration
protected abstract float SliderNormalizeValue(TScalar currentValue, TScalar lowerValue, TScalar higherValue)
Parameters
Type | Name | Description |
---|---|---|
TScalar | currentValue | The value to normalize. |
TScalar | lowerValue | The lowest value in the range. |
TScalar | higherValue | The highest value in the range. |
Returns
Type | Description |
---|---|
float | The normalized value. |