UsoUIElements 0.1.0
Data Centric implimentation of Unity's UI Elements (UI Toolkit)
Loading...
Searching...
No Matches
GWG.UsoUIElements.UsoSlideToggle Class Reference

A custom slide toggle control that extends Unity's BaseField<bool> with USO UI framework functionality and animated sliding behavior. Provides enhanced styling, field validation, data binding capabilities, and integration with the USO UI system for interactive boolean input with visual sliding animation. More...

Inheritance diagram for GWG.UsoUIElements.UsoSlideToggle:

Public Member Functions

 UsoSlideToggle ()
 Initializes a new instance of the UsoSlideToggle class with default settings. Creates a slide toggle control with USO framework integration and no initial label text.
 UsoSlideToggle (string fieldName, string fieldLabelText)
 Initializes a new instance of the UsoSlideToggle class with field name and label text. Creates a slide toggle control with custom identification and display label for user interface clarity.
 UsoSlideToggle (string fieldName, string fieldLabelText, out UsoSlideToggle newField)
 Initializes a new instance of the UsoSlideToggle class with field name, label text, and returns a reference. Creates a slide toggle control with custom identification, display label, and provides an out parameter for immediate access.
 UsoSlideToggle (string fieldName, string fieldLabelText, string fieldBindingPath, BindingMode fieldBindingMode)
 Initializes a new instance of the UsoSlideToggle class with field name, label text, and data binding configuration. Creates a fully configured slide toggle control with custom identification, display label, and automatic data binding for boolean value synchronization.
 UsoSlideToggle (string label)
 Initializes a new instance of the UsoSlideToggle class with the specified label text. Creates a slide toggle control with custom label text for user interface presentation.
void ApplyBinding (string fieldBindingProp, string fieldBindingPath, BindingMode fieldBindingMode)
 Applies data binding to the specified property of this control using Unity's data binding system. Configures the binding with the provided path and mode for automatic data synchronization.
UsoLineItem GetParentLineItem ()
 Retrieves the first ancestor UsoLineItem control in the visual tree hierarchy. This is useful for accessing parent container functionality and maintaining proper UI structure.
void InitElement (string fieldName=null)
 Initializes the USO UI element with comprehensive slide toggle setup including styling, event handlers, and visual components. This method sets up the complete slide toggle functionality with USO framework integration and interactive behavior.
void SetFieldStatus (FieldStatusTypes fieldStatus)
 Updates the field's status type, which affects its visual appearance and validation state. The status change is automatically reflected in the UI through the FieldStatus property.
override void SetValueWithoutNotify (bool newValue)
 Sets the boolean value of the slide toggle without triggering change event notifications. Updates the visual state of the toggle to reflect the new value through CSS class management.
void ShowFieldStatus (bool status)
 Controls the visibility and functionality of the field status/validation system. When disabled, removes validation-related styling from the control.
Public Member Functions inherited from GWG.UsoUIElements.IUsoUiElement
void AddToClassList (string className)
 Adds the specified CSS class name to this element's class list. This method is inherited from Unity's VisualElement and enables dynamic styling modifications.
void ClearBindings ()
 Removes all data binding configurations from this element. This method is inherited from Unity's VisualElement and provides cleanup functionality for data bindings.
void RemoveFromClassList (string className)
 Removes the specified CSS class name from this element's class list. This method is inherited from Unity's VisualElement and provides dynamic styling capabilities.

Properties

FieldStatusTypes FieldStatus [get, private set]
 Gets the current field status type, which determines the visual state and validation feedback. This property is automatically reflected in the UI through CSS class modifications.
bool FieldStatusEnabled [get, private set]
 Gets or sets whether field status/validation functionality is enabled for this control. When enabled, adds validation CSS class for styling. When disabled, removes validation styling.

Private Member Functions

void ToggleValue ()
 Toggles the current boolean value of the slide toggle control between true and false. This method is called by all interaction event handlers to change the toggle state.

Static Private Member Functions

static void OnClick (ClickEvent evt)
 Static event handler for click events on the slide toggle control. Toggles the boolean value when the user clicks on the control and prevents event propagation.
static void OnKeydownEvent (KeyDownEvent evt)
 Static event handler for keyboard events on the slide toggle control. Toggles the boolean value when specific keys (Enter, Return, Space) are pressed in editor contexts.
static void OnSubmit (NavigationSubmitEvent evt)
 Static event handler for navigation submit events on the slide toggle control. Handles gamepad and other navigation device input to toggle the boolean value.

Private Attributes

FieldStatusTypes _fieldStatus
bool _fieldStatusEnabled = true
VisualElement m_Input
 Visual element representing the input background area of the slide toggle.
VisualElement m_Knob
 Visual element representing the sliding knob that moves within the toggle.
VisualElement m_Label
 Visual element representing the text label associated with the toggle.

Static Private Attributes

const string DefaultBindProp = "value"
 Default binding property used when applying data bindings to this field. Binds to the 'value' property which controls the toggle's boolean state.
const string ElementClass = "uso-slide-toggle"
 CSS class name applied to all UsoSlideToggle instances for styling purposes.
const string ElementValidationClass = "uso-field-validation"
 CSS class name applied when field validation/status functionality is enabled.
const string InputCheckedUssClassName = "uso-slide-toggle__input--checked"
 USS class name applied when the toggle is in the checked/enabled state.
const string InputKnobUssClassName = "uso-slide-toggle__input-knob"
 USS class name for the sliding knob element within the toggle control.
const string InputUssClassName = "uso-slide-toggle__input"
 USS class name for the input background element of the slide toggle control.
const string LabelUssClassName = "uso-slide-toggle__label"
 USS class name for the label element of the slide toggle control. Reserved for potential future label-specific styling requirements.
const string USSClassName = "uso-slide-toggle"
 Primary USS class name for the slide toggle control following BEM naming conventions.

Detailed Description

A custom slide toggle control that extends Unity's BaseField<bool> with USO UI framework functionality and animated sliding behavior. Provides enhanced styling, field validation, data binding capabilities, and integration with the USO UI system for interactive boolean input with visual sliding animation.

This control implements the IUsoUiElement interface to provide consistent behavior across the USO UI framework. It supports field status indicators, automatic data binding for boolean values, and custom styling through CSS classes. The control is derived from Unity documentation examples with compatibility modifications for the USO framework. It features a visual sliding knob animation that provides intuitive feedback for boolean state changes, supporting multiple interaction methods including mouse clicks, keyboard navigation, and gamepad input. The control requires a specific USS stylesheet to function properly and automatically loads the appropriate styling resources. The sliding toggle provides an enhanced user experience compared to standard checkboxes with smooth visual transitions and responsive interaction handling across different input devices and contexts.

Constructor & Destructor Documentation

◆ UsoSlideToggle() [1/5]

GWG.UsoUIElements.UsoSlideToggle.UsoSlideToggle ( )

Initializes a new instance of the UsoSlideToggle class with default settings. Creates a slide toggle control with USO framework integration and no initial label text.

This default constructor calls the label-based constructor with a null parameter to maintain consistent initialization behavior while providing a parameterless constructor option.

◆ UsoSlideToggle() [2/5]

GWG.UsoUIElements.UsoSlideToggle.UsoSlideToggle ( string fieldName,
string fieldLabelText )

Initializes a new instance of the UsoSlideToggle class with field name and label text. Creates a slide toggle control with custom identification and display label for user interface clarity.

Parameters
fieldNameThe name to assign to this slide toggle element.
fieldLabelTextThe label text to display alongside the slide toggle control.

◆ UsoSlideToggle() [3/5]

GWG.UsoUIElements.UsoSlideToggle.UsoSlideToggle ( string fieldName,
string fieldLabelText,
out UsoSlideToggle newField )

Initializes a new instance of the UsoSlideToggle class with field name, label text, and returns a reference. Creates a slide toggle control with custom identification, display label, and provides an out parameter for immediate access.

Parameters
fieldNameThe name to assign to this slide toggle element.
fieldLabelTextThe label text to display alongside the slide toggle control.
newFieldOutput parameter that receives a reference to the newly created slide toggle.

◆ UsoSlideToggle() [4/5]

GWG.UsoUIElements.UsoSlideToggle.UsoSlideToggle ( string fieldName,
string fieldLabelText,
string fieldBindingPath,
BindingMode fieldBindingMode )

Initializes a new instance of the UsoSlideToggle class with field name, label text, and data binding configuration. Creates a fully configured slide toggle control with custom identification, display label, and automatic data binding for boolean value synchronization.

Parameters
fieldNameThe name to assign to this slide toggle element.
fieldLabelTextThe label text to display alongside the slide toggle control.
fieldBindingPathThe path to the data source property for automatic value binding.
fieldBindingModeThe binding mode that controls data flow between source and target.

◆ UsoSlideToggle() [5/5]

GWG.UsoUIElements.UsoSlideToggle.UsoSlideToggle ( string label)

Initializes a new instance of the UsoSlideToggle class with the specified label text. Creates a slide toggle control with custom label text for user interface presentation.

Parameters
labelThe label text to display alongside the slide toggle control.

This constructor provides the primary initialization path for slide toggle controls with labels, setting up the control with appropriate styling and interactive behavior for boolean value management.

Member Function Documentation

◆ ApplyBinding()

void GWG.UsoUIElements.UsoSlideToggle.ApplyBinding ( string fieldBindingProp,
string fieldBindingPath,
BindingMode fieldBindingMode )

Applies data binding to the specified property of this control using Unity's data binding system. Configures the binding with the provided path and mode for automatic data synchronization.

Parameters
fieldBindingPropThe property name on this control to bind to.
fieldBindingPathThe path to the data source property to bind from.
fieldBindingModeThe binding mode that determines how data flows between source and target.
Exceptions
ExceptionThrown when binding setup fails. Original exception is preserved and re-thrown.

Implements GWG.UsoUIElements.IUsoUiElement.

◆ GetParentLineItem()

UsoLineItem GWG.UsoUIElements.UsoSlideToggle.GetParentLineItem ( )

Retrieves the first ancestor UsoLineItem control in the visual tree hierarchy. This is useful for accessing parent container functionality and maintaining proper UI structure.

Returns
The parent UsoLineItem if found; otherwise, null.

◆ InitElement()

void GWG.UsoUIElements.UsoSlideToggle.InitElement ( string fieldName = null)

Initializes the USO UI element with comprehensive slide toggle setup including styling, event handlers, and visual components. This method sets up the complete slide toggle functionality with USO framework integration and interactive behavior.

Parameters
fieldNameOptional name to assign to the element. If null, no name is set.

The initialization process includes:

  • Loading required USS stylesheet for slide toggle styling
  • Setting up visual elements (input background, knob, label)
  • Configuring CSS classes following BEM naming conventions
  • Registering event handlers for click, keyboard, and navigation input
  • Applying Unity Editor-specific styling for inspector compatibility The control requires the UsoSlideToggle stylesheet to function properly and will attempt to load it from resources.

Implements GWG.UsoUIElements.IUsoUiElement.

◆ OnClick()

void GWG.UsoUIElements.UsoSlideToggle.OnClick ( ClickEvent evt)
staticprivate

Static event handler for click events on the slide toggle control. Toggles the boolean value when the user clicks on the control and prevents event propagation.

Parameters
evtThe ClickEvent containing information about the click interaction.

This method follows Unity's static event handler pattern for custom controls to ensure proper event handling and performance. It safely casts the event target and invokes the toggle operation.

◆ OnKeydownEvent()

void GWG.UsoUIElements.UsoSlideToggle.OnKeydownEvent ( KeyDownEvent evt)
staticprivate

Static event handler for keyboard events on the slide toggle control. Toggles the boolean value when specific keys (Enter, Return, Space) are pressed in editor contexts.

Parameters
evtThe KeyDownEvent containing information about the key press.

This method specifically handles keyboard input in editor contexts, as runtime navigation is handled by NavigationSubmitEvent. It responds to Enter, Return, and Space key presses to provide standard keyboard accessibility for toggle operations.

◆ OnSubmit()

void GWG.UsoUIElements.UsoSlideToggle.OnSubmit ( NavigationSubmitEvent evt)
staticprivate

Static event handler for navigation submit events on the slide toggle control. Handles gamepad and other navigation device input to toggle the boolean value.

Parameters
evtThe NavigationSubmitEvent containing information about the navigation input.

This method provides accessibility and gamepad support for the slide toggle control, following Unity's static event handler pattern for optimal performance and proper event management.

◆ SetFieldStatus()

void GWG.UsoUIElements.UsoSlideToggle.SetFieldStatus ( FieldStatusTypes fieldStatus)

Updates the field's status type, which affects its visual appearance and validation state. The status change is automatically reflected in the UI through the FieldStatus property.

Parameters
fieldStatusThe new field status type to apply.

Implements GWG.UsoUIElements.IUsoUiElement.

◆ SetValueWithoutNotify()

override void GWG.UsoUIElements.UsoSlideToggle.SetValueWithoutNotify ( bool newValue)

Sets the boolean value of the slide toggle without triggering change event notifications. Updates the visual state of the toggle to reflect the new value through CSS class management.

Parameters
newValueThe new boolean value to assign to the toggle control.

This override method extends the base functionality to include visual state updates for the slide toggle. It manages the checked CSS class to ensure the sliding animation and visual appearance correctly reflect the current boolean state. This method is called automatically when the value property changes through the BaseField change event system.

◆ ShowFieldStatus()

void GWG.UsoUIElements.UsoSlideToggle.ShowFieldStatus ( bool status)

Controls the visibility and functionality of the field status/validation system. When disabled, removes validation-related styling from the control.

Parameters
statusTrue to enable field status functionality; false to disable it.

Implements GWG.UsoUIElements.IUsoUiElement.

◆ ToggleValue()

void GWG.UsoUIElements.UsoSlideToggle.ToggleValue ( )
private

Toggles the current boolean value of the slide toggle control between true and false. This method is called by all interaction event handlers to change the toggle state.

This private method provides the core toggle functionality used by click, keyboard, and navigation event handlers. Setting the value property automatically triggers change notifications and visual updates through the BaseField change event system and SetValueWithoutNotify method.

Member Data Documentation

◆ _fieldStatus

FieldStatusTypes GWG.UsoUIElements.UsoSlideToggle._fieldStatus
private

◆ _fieldStatusEnabled

bool GWG.UsoUIElements.UsoSlideToggle._fieldStatusEnabled = true
private

◆ DefaultBindProp

const string GWG.UsoUIElements.UsoSlideToggle.DefaultBindProp = "value"
staticprivate

Default binding property used when applying data bindings to this field. Binds to the 'value' property which controls the toggle's boolean state.

◆ ElementClass

const string GWG.UsoUIElements.UsoSlideToggle.ElementClass = "uso-slide-toggle"
staticprivate

CSS class name applied to all UsoSlideToggle instances for styling purposes.

◆ ElementValidationClass

const string GWG.UsoUIElements.UsoSlideToggle.ElementValidationClass = "uso-field-validation"
staticprivate

CSS class name applied when field validation/status functionality is enabled.

◆ InputCheckedUssClassName

const string GWG.UsoUIElements.UsoSlideToggle.InputCheckedUssClassName = "uso-slide-toggle__input--checked"
staticprivate

USS class name applied when the toggle is in the checked/enabled state.

◆ InputKnobUssClassName

const string GWG.UsoUIElements.UsoSlideToggle.InputKnobUssClassName = "uso-slide-toggle__input-knob"
staticprivate

USS class name for the sliding knob element within the toggle control.

◆ InputUssClassName

const string GWG.UsoUIElements.UsoSlideToggle.InputUssClassName = "uso-slide-toggle__input"
staticprivate

USS class name for the input background element of the slide toggle control.

◆ LabelUssClassName

const string GWG.UsoUIElements.UsoSlideToggle.LabelUssClassName = "uso-slide-toggle__label"
staticprivate

USS class name for the label element of the slide toggle control. Reserved for potential future label-specific styling requirements.

◆ m_Input

VisualElement GWG.UsoUIElements.UsoSlideToggle.m_Input
private

Visual element representing the input background area of the slide toggle.

◆ m_Knob

VisualElement GWG.UsoUIElements.UsoSlideToggle.m_Knob
private

Visual element representing the sliding knob that moves within the toggle.

◆ m_Label

VisualElement GWG.UsoUIElements.UsoSlideToggle.m_Label
private

Visual element representing the text label associated with the toggle.

◆ USSClassName

const string GWG.UsoUIElements.UsoSlideToggle.USSClassName = "uso-slide-toggle"
staticprivate

Primary USS class name for the slide toggle control following BEM naming conventions.

Property Documentation

◆ FieldStatus

FieldStatusTypes GWG.UsoUIElements.UsoSlideToggle.FieldStatus
getprivate set

Gets the current field status type, which determines the visual state and validation feedback. This property is automatically reflected in the UI through CSS class modifications.

The current FieldStatusTypes value indicating the field's validation state.

Implements GWG.UsoUIElements.IUsoUiElement.

◆ FieldStatusEnabled

bool GWG.UsoUIElements.UsoSlideToggle.FieldStatusEnabled
getprivate set

Gets or sets whether field status/validation functionality is enabled for this control. When enabled, adds validation CSS class for styling. When disabled, removes validation styling.

True if field status functionality is enabled; otherwise, false. Default is true.

Implements GWG.UsoUIElements.IUsoUiElement.