Class BaseSlider<TValueType, THandleValueType>
Base class for any Slider (TouchSliderFloat, TouchSliderInt, SliderFloat, SliderInt).
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: solution.dll
Syntax
public abstract class BaseSlider<TValueType, THandleValueType> : ExVisualElement, IEventHandler, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IResolvedStyle, IContextOverrideElement, IInputElement<TValueType>, IValidatableElement<TValueType>, INotifyValueChanging<TValueType>, INotifyValueChanged<TValueType> where TValueType : IEquatable<TValueType> where THandleValueType : struct, IComparable, IEquatable<THandleValueType>
Type Parameters
Name | Description |
---|---|
TValueType | A comparable value type. |
THandleValueType | A value type for a single handle of the slider. This can be the same as |
Constructors
BaseSlider()
Default constructor.
Declaration
protected BaseSlider()
Fields
m_CurrentDirection
The current direction of the layout.
Declaration
protected Dir m_CurrentDirection
Field Value
Type | Description |
---|---|
Dir |
m_DraggerManipulator
The dragger manipulator used to move the slider.
Declaration
protected Draggable m_DraggerManipulator
Field Value
Type | Description |
---|---|
Draggable |
m_HighValue
Slider max value.
Declaration
protected THandleValueType m_HighValue
Field Value
Type | Description |
---|---|
THandleValueType |
m_LowValue
Slider min value.
Declaration
protected THandleValueType m_LowValue
Field Value
Type | Description |
---|---|
THandleValueType |
m_PreviousValue
The previous value of the slider before the user started interacting with it.
Declaration
protected TValueType m_PreviousValue
Field Value
Type | Description |
---|---|
TValueType |
m_Value
The current value of the slider.
Declaration
protected TValueType m_Value
Field Value
Type | Description |
---|---|
TValueType |
Properties
formatString
The format string used to display the value of the slider.
Declaration
public string formatString { get; set; }
Property Value
Type | Description |
---|---|
string |
highValue
Specify the maximum value in the range of this slider.
Declaration
public THandleValueType highValue { get; set; }
Property Value
Type | Description |
---|---|
THandleValueType |
invalid
The invalid state of the slider.
Declaration
public bool invalid { get; set; }
Property Value
Type | Description |
---|---|
bool |
lowValue
Specify the minimum value in the range of this slider.
Declaration
public THandleValueType lowValue { get; set; }
Property Value
Type | Description |
---|---|
THandleValueType |
validateValue
The validation function used to validate the value of the slider.
Declaration
public Func<TValueType, bool> validateValue { get; set; }
Property Value
Type | Description |
---|---|
Func<TValueType, bool> |
value
The current value of the slider.
Declaration
public TValueType value { get; set; }
Property Value
Type | Description |
---|---|
TValueType |
Methods
Clamp(TValueType, THandleValueType, THandleValueType)
Utility method to clamp a TValueType
value between specified bounds.
Declaration
protected abstract TValueType Clamp(TValueType v, THandleValueType lowBound, THandleValueType highBound)
Parameters
Type | Name | Description |
---|---|---|
TValueType | v | The value to clamp. |
THandleValueType | lowBound | Minimum |
THandleValueType | highBound | Maximum |
Returns
Type | Description |
---|---|
TValueType | The clamped value. |
ClampValue()
Called when the low or high value has changed and needs to check if the current value fits in this new range.
Declaration
protected virtual void ClampValue()
ComputeValueFromHandlePosition(float, float)
Returns the value to set as slider value based on a given dragger position.
Declaration
protected virtual TValueType ComputeValueFromHandlePosition(float sliderLength, float dragElementPos)
Parameters
Type | Name | Description |
---|---|---|
float | sliderLength | The length of the slider. |
float | dragElementPos | The position of the dragger. |
Returns
Type | Description |
---|---|
TValueType | The value to set as slider value based on a given dragger position. |
Decrement(THandleValueType)
Method to implement which returns the decrement of a given value.
Declaration
protected abstract THandleValueType Decrement(THandleValueType val)
Parameters
Type | Name | Description |
---|---|---|
THandleValueType | val | The value to decrement. |
Returns
Type | Description |
---|---|
THandleValueType | The decremented value. |
GetClampedValue(TValueType)
Return the clamped value using current lowValue and highValue values.
Declaration
protected virtual TValueType GetClampedValue(TValueType newValue)
Parameters
Type | Name | Description |
---|---|---|
TValueType | newValue | The value to clamp. |
Returns
Type | Description |
---|---|
TValueType |
GetSliderRect()
Returns the rect of the interactive part of the slider.
Declaration
protected virtual Rect GetSliderRect()
Returns
Type | Description |
---|---|
Rect | The rect of the interactive part of the slider. |
Increment(THandleValueType)
Method to implement which returns the increment of a given value.
Declaration
protected abstract THandleValueType Increment(THandleValueType val)
Parameters
Type | Name | Description |
---|---|---|
THandleValueType | val | The value to increment. |
Returns
Type | Description |
---|---|
THandleValueType | The incremented value. |
InvokeValueChangedCallbacks()
Called when the value of the slider has changed via the value property.
Declaration
protected virtual void InvokeValueChangedCallbacks()
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 |
---|---|---|
ContextChangedEvent<DirContext> | evt |
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 |
---|---|---|
GeometryChangedEvent | evt | The geometry changed event. |
OnSliderRangeChanged()
Called when the low or high value of Slider has changed.
Declaration
protected virtual void OnSliderRangeChanged()
OnTrackClicked()
Called when the track has received a click event.
Declaration
protected virtual void OnTrackClicked()
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. |
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. |
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. |
ParseHandleValueToString(THandleValueType)
Method to implement to resolve a TValueType
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 virtual string ParseHandleValueToString(THandleValueType val)
Parameters
Type | Name | Description |
---|---|---|
THandleValueType | val | The |
Returns
Type | Description |
---|---|
string |
ParseRawValueToString(TValueType)
Method to implement to resolve a TValueType
value into a string value.
Declaration
protected virtual string ParseRawValueToString(TValueType val)
Parameters
Type | Name | Description |
---|---|---|
TValueType | 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 formatString property.
ParseStringToValue(string, out TValueType)
Method to implement to resolve a string value into a TValueType
value.
You can use TryParse(string, out float) for floating point value types for example.
Declaration
protected abstract bool ParseStringToValue(string strValue, out TValueType value)
Parameters
Type | Name | Description |
---|---|---|
string | strValue | The string value to convert. |
TValueType | value | The stringThe converted value. |
Returns
Type | Description |
---|---|
bool | True if can be parsed, False otherwise. |
ParseValueToString(TValueType)
Method to implement to resolve a TValueType
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 virtual string ParseValueToString(TValueType val)
Parameters
Type | Name | Description |
---|---|---|
TValueType | val | The |
Returns
Type | Description |
---|---|
string |
SetValueFromDrag(float)
Custom implementation of the slider value from the drag position.
Declaration
protected virtual void SetValueFromDrag(float newPos)
Parameters
Type | Name | Description |
---|---|---|
float | newPos | The new position of the dragger. |
SetValueWithoutNotify(TValueType)
Set the value of the slider without sending any event.
Declaration
public abstract void SetValueWithoutNotify(TValueType newValue)
Parameters
Type | Name | Description |
---|---|---|
TValueType | newValue | The new value of the slider. |
SliderLerpUnclamped(THandleValueType, THandleValueType, 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 abstract TValueType SliderLerpUnclamped(THandleValueType a, THandleValueType b, float interpolant)
Parameters
Type | Name | Description |
---|---|---|
THandleValueType | a | The lowest value in the range. |
THandleValueType | b | The highest value in the range. |
float | interpolant | The normalized value to process. |
Returns
Type | Description |
---|---|
TValueType |
SliderNormalizeValue(THandleValueType, THandleValueType, THandleValueType)
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 abstract float SliderNormalizeValue(THandleValueType currentValue, THandleValueType lowerValue, THandleValueType higherValue)
Parameters
Type | Name | Description |
---|---|---|
THandleValueType | currentValue | The value to normalize. |
THandleValueType | lowerValue | The lowest value in the range. |
THandleValueType | higherValue | The highest value in the range. |
Returns
Type | Description |
---|---|
float |