docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class BaseSlider<TValueType, THandleValueType>

    Base class for any Slider (TouchSliderFloat, TouchSliderInt, SliderFloat, SliderInt).

    Inheritance
    object
    CallbackEventHandler
    Focusable
    VisualElement
    BaseVisualElement
    ExVisualElement
    BaseSlider<TValueType, THandleValueType>
    ColorSlider
    RangeSliderBase<TRangeType, TValueType>
    SliderBase<TValueType>
    TouchSlider<TValueType>
    Implements
    IEventHandler
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IResolvedStyle
    IContextOverrideElement
    IInputElement<TValueType>
    IValidatableElement<TValueType>
    INotifyValueChanging<TValueType>
    INotifyValueChanged<TValueType>
    Inherited Members
    ExVisualElement.contentContainer
    ExVisualElement.outlineColor
    ExVisualElement.backgroundColor
    ExVisualElement.passMask
    BaseVisualElement.contextPrefix
    BaseVisualElement.scaleOverride
    BaseVisualElement.themeOverride
    BaseVisualElement.langOverride
    BaseVisualElement.layoutDirectionOverride
    BaseVisualElement.preferredTooltipPlacementOverride
    BaseVisualElement.tooltipDelayMsOverride
    BaseVisualElement.GetLayoutDirectionUssClassName(Dir)
    VisualElement.disabledUssClassName
    VisualElement.ExecuteDefaultAction(EventBase)
    VisualElement.Focus()
    VisualElement.SendEvent(EventBase)
    VisualElement.SetEnabledFromHierarchy(bool)
    VisualElement.SetEnabled(bool)
    VisualElement.MarkDirtyRepaint()
    VisualElement.ContainsPoint(Vector2)
    VisualElement.Overlaps(Rect)
    VisualElement.DoMeasure(float, VisualElement.MeasureMode, float, VisualElement.MeasureMode)
    VisualElement.ToString()
    VisualElement.GetClasses()
    VisualElement.ClearClassList()
    VisualElement.AddToClassList(string)
    VisualElement.RemoveFromClassList(string)
    VisualElement.ToggleInClassList(string)
    VisualElement.EnableInClassList(string, bool)
    VisualElement.ClassListContains(string)
    VisualElement.FindAncestorUserData()
    VisualElement.Add(VisualElement)
    VisualElement.Insert(int, VisualElement)
    VisualElement.Remove(VisualElement)
    VisualElement.RemoveAt(int)
    VisualElement.Clear()
    VisualElement.ElementAt(int)
    VisualElement.IndexOf(VisualElement)
    VisualElement.Children()
    VisualElement.Sort(Comparison<VisualElement>)
    VisualElement.BringToFront()
    VisualElement.SendToBack()
    VisualElement.PlaceBehind(VisualElement)
    VisualElement.PlaceInFront(VisualElement)
    VisualElement.RemoveFromHierarchy()
    VisualElement.GetFirstOfType<T>()
    VisualElement.GetFirstAncestorOfType<T>()
    VisualElement.Contains(VisualElement)
    VisualElement.FindCommonAncestor(VisualElement)
    VisualElement.viewDataKey
    VisualElement.userData
    VisualElement.canGrabFocus
    VisualElement.focusController
    VisualElement.usageHints
    VisualElement.transform
    VisualElement.layout
    VisualElement.contentRect
    VisualElement.paddingRect
    VisualElement.worldBound
    VisualElement.localBound
    VisualElement.worldTransform
    VisualElement.pickingMode
    VisualElement.name
    VisualElement.enabledInHierarchy
    VisualElement.enabledSelf
    VisualElement.visible
    VisualElement.generateVisualContent
    VisualElement.experimental
    VisualElement.hierarchy
    VisualElement.cacheAsBitmap
    VisualElement.parent
    VisualElement.panel
    VisualElement.visualTreeAssetSource
    VisualElement.this[int]
    VisualElement.childCount
    VisualElement.schedule
    VisualElement.style
    VisualElement.customStyle
    VisualElement.styleSheets
    VisualElement.tooltip
    VisualElement.resolvedStyle
    Focusable.Blur()
    Focusable.focusable
    Focusable.tabIndex
    Focusable.delegatesFocus
    CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TrickleDown)
    CallbackEventHandler.HandleEvent(EventBase)
    CallbackEventHandler.HasTrickleDownHandlers()
    CallbackEventHandler.HasBubbleUpHandlers()
    CallbackEventHandler.ExecuteDefaultActionAtTarget(EventBase)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Unity.AppUI.UI
    Assembly: Unity.AppUI.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 TValueType.

    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. The method also checks if low and high values are inverted.

    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. Always check if the mouse has moved using hasMoved.

    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 TValueType value to convert.

    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 TValueType value to convert.

    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 TValueType value to convert.

    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

    Implements

    IEventHandler
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IResolvedStyle
    IContextOverrideElement
    IInputElement<TValueType>
    IValidatableElement<TValueType>
    INotifyValueChanging<TValueType>
    INotifyValueChanged<T>

    Extension Methods

    NotifyValueChangingExtensions.RegisterValueChangingCallback<TValueType>(INotifyValueChanging<TValueType>, EventCallback<ChangingEvent<TValueType>>)
    NotifyValueChangingExtensions.UnregisterValueChangingCallback<TValueType>(INotifyValueChanging<TValueType>, EventCallback<ChangingEvent<TValueType>>)
    VisualElementExtensions.FindNavController(VisualElement)
    VisualElementExtensions.GetChildren<T>(VisualElement, bool)
    VisualElementExtensions.GetContextProvider<T>(VisualElement)
    VisualElementExtensions.GetContext<T>(VisualElement)
    VisualElementExtensions.GetPreferredTooltipPlacement(VisualElement)
    VisualElementExtensions.GetSelfContext<T>(VisualElement)
    VisualElementExtensions.GetTooltipTemplate(VisualElement)
    VisualElementExtensions.IsContextProvider<T>(VisualElement)
    VisualElementExtensions.ProvideContext<T>(VisualElement, T)
    VisualElementExtensions.RegisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.SetPreferredTooltipPlacement(VisualElement, OptionalEnum<PopoverPlacement>)
    VisualElementExtensions.SetTooltipTemplate(VisualElement, VisualElement)
    VisualElementExtensions.UnregisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)