|
UsoUIElements 0.1.0
Data Centric implimentation of Unity's UI Elements (UI Toolkit)
|
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...
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. | |
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.
| 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.
| 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.
| fieldName | The name to assign to this slide toggle element. |
| fieldLabelText | The label text to display alongside the slide toggle control. |
| 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.
| fieldName | The name to assign to this slide toggle element. |
| fieldLabelText | The label text to display alongside the slide toggle control. |
| newField | Output parameter that receives a reference to the newly created slide toggle. |
| 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.
| fieldName | The name to assign to this slide toggle element. |
| fieldLabelText | The label text to display alongside the slide toggle control. |
| fieldBindingPath | The path to the data source property for automatic value binding. |
| fieldBindingMode | The binding mode that controls data flow between source and target. |
| 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.
| label | The 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.
| 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.
| fieldBindingProp | The property name on this control to bind to. |
| fieldBindingPath | The path to the data source property to bind from. |
| fieldBindingMode | The binding mode that determines how data flows between source and target. |
| Exception | Thrown when binding setup fails. Original exception is preserved and re-thrown. |
Implements GWG.UsoUIElements.IUsoUiElement.
| 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.
| 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.
| fieldName | Optional name to assign to the element. If null, no name is set. |
The initialization process includes:
Implements GWG.UsoUIElements.IUsoUiElement.
|
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.
| evt | The 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.
|
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.
| evt | The 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.
|
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.
| evt | The 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.
| 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.
| fieldStatus | The new field status type to apply. |
Implements GWG.UsoUIElements.IUsoUiElement.
| 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.
| newValue | The 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.
| 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.
| status | True to enable field status functionality; false to disable it. |
Implements GWG.UsoUIElements.IUsoUiElement.
|
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.
|
private |
|
private |
|
staticprivate |
Default binding property used when applying data bindings to this field. Binds to the 'value' property which controls the toggle's boolean state.
|
staticprivate |
CSS class name applied to all UsoSlideToggle instances for styling purposes.
|
staticprivate |
CSS class name applied when field validation/status functionality is enabled.
|
staticprivate |
USS class name applied when the toggle is in the checked/enabled state.
|
staticprivate |
USS class name for the sliding knob element within the toggle control.
|
staticprivate |
USS class name for the input background element of the slide toggle control.
|
staticprivate |
USS class name for the label element of the slide toggle control. Reserved for potential future label-specific styling requirements.
|
private |
Visual element representing the input background area of the slide toggle.
|
private |
Visual element representing the sliding knob that moves within the toggle.
|
private |
Visual element representing the text label associated with the toggle.
|
staticprivate |
Primary USS class name for the slide toggle control following BEM naming conventions.
|
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.
|
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.