|
Window Framework v1.2.4
Window Framework for Unity UI Toolkit
|
Represents a customizable window frame for UI elements in Unity. Provides functionality for resizing, moving, locking, and saving window state. Includes support for themes, tooltips, and context menus. More...
Public Member Functions | |
| WindowFrame () | |
| Represents a custom UI element serving as a container for window-based content, including a header, content, and footer, providing event handling and theme adaptability for Unity's UI Toolkit. | |
| void | CloseWindow (bool forceAll=false) |
| Closes the window if allowed. | |
| void | Hide () |
| Hides the window while keeping it in memory. | |
| void | SetOpeningPosition () |
| Sets the opening position of the window based on the selected position. Options include: TopLeft, Top, TopRight, Left, Center, Right, BottomLeft, Bottom, BottomRight. | |
| void | Show () |
| Shows the window by setting its display style to flex and opacity to 1.0f. | |
Properties | |
| bool | Active [get, set] |
| Gets or sets whether the window is active. | |
| bool | AllowClose = true [get, set] |
| Gets or sets whether the window can be closed. | |
| bool | AllowFullscreen = true [get, set] |
| Determines whether the window frame can toggle to fullscreen mode. | |
| bool | AllowLock [get, set] |
| Gets or sets whether the window can be locked. | |
| bool | AllowMove = true [get, set] |
| Gets or sets whether the window can be moved. | |
| bool | AllowMultipleInstances = true [get, set] |
| Gets or sets whether multiple instances of this window are allowed. | |
| bool | AllowResize [get, set] |
| Gets or sets whether the window can be resized. | |
| VisualElement | Content [get, set] |
| Gets or sets the content area of the window. | |
| override VisualElement | contentContainer [get] |
| Overrides the contentContainer to return the window's content area instead of the root. | |
| ContextMenuConfig | ContextMenuConfig [get, set] |
| Gets or sets the context menu configuration for this window. | |
| float | DefaultHeight = 300 [get, set] |
| Gets or sets the default height of the window. | |
| float | DefaultWidth = 300 [get, set] |
| Gets or sets the default width of the window. | |
| VisualElement | FooterToolbar [get, set] |
| Gets or sets the toolbar in the footer area of the window. | |
| bool | Fullscreen [get, set] |
| Gets or sets whether the window is in fullscreen mode. | |
| bool | Locked [get, set] |
| Gets or sets whether the window is locked. | |
| bool | LockedFullscreen [get, set] |
| Determines whether the fullscreen mode of the window is locked, preventing the user from toggling fullscreen on or off. | |
| bool | LockedToStartPosition [get, set] |
| Gets or sets whether the window is locked to its start position. | |
| float | MinHeight [get, set] |
| Gets or sets the minimum height of the window. | |
| float | MinWidth [get, set] |
| Gets or sets the minimum width of the window. | |
| string | OptionsMenuTooltip [get, set] |
| Gets or sets the tooltip for the options menu button. | |
| string | ParentObjectId [get, set] |
| Gets or sets the ID of the parent object associated with the window. | |
| string | ResizeAreaTooltip [get, set] |
| Gets or sets the tooltip for the resize area. | |
| bool | ShowFooter [get, set] |
| Gets or sets whether the footer is visible. | |
| bool | ShowHeader [get, set] |
| Gets or sets whether the header is visible. | |
| WindowFramePosition | StartPosition [get, set] |
| Gets or sets the position of the window frame. | |
| List< StyleSheet > | StyleSheet [get, set] |
| Gets or sets the stylesheet applied to the window. | |
| string | Title [get, set] |
| Gets or sets the title of the window. | |
| string | WindowId [get, set] |
| Gets or sets the unique ID of the window. | |
| bool | WindowMemoryEnabled = false [get, set] |
| Gets or sets whether the window memory is enabled. | |
Events | |
| static Action< WindowFrame > | OnWindowFrameAdded |
| Event triggered when a new WindowFrame is added to the panel. | |
| static Action< WindowFrame > | OnWindowFrameRemoved |
| Event triggered when a WindowFrame is removed from the panel. | |
Private Member Functions | |
| void | Close () |
| Performs complete window closure and cleanup. | |
| ContextMenuConfig | ContextMenuDefaultConfig () |
| Creates the default context menu configuration with standard window operations. | |
| void | CreateLayout () |
| Creates the basic layout structure of the window by adding header, content, and footer. | |
| void | GeometryChangeCallback (GeometryChangedEvent evt) |
| Called whenever a change in the window geometry occurs. | |
| bool | HandleMultipleInstanceCheck () |
| Checks if multiple instances are allowed and handles singleton behavior. | |
| void | KeepOnScreen () |
| Ensures the window remains within screen boundaries. | |
| bool | LoadWindowData () |
| Loads previously saved window data and applies it to the current window. | |
| void | OnAttachToPanel (AttachToPanelEvent evt) |
| Handles the panel attach event. | |
| void | OnClickEvent (ClickEvent evt) |
| Handles click events on the window for activation. | |
| void | OnDetachFromPanel (DetachFromPanelEvent evt) |
| Handles the panel detach event for proper cleanup. | |
| void | OnOnScreenSizeChanged (GeometryChangedEvent evt) |
| Handles screen size changes by repositioning windows as needed. | |
| void | OnWindowMove () |
| Called when the window is moved, starts a resetable timmer watching for idle and then save the window data. | |
| void | RegisterCallbacks () |
| Registers all necessary event callbacks for window functionality. | |
| void | SaveWindowData () |
| Save window data. | |
| void | SaveWindowData (bool isOpen) |
| Saves the window data to the WindowFrameController. | |
| void | SetFullScreenMode (bool value) |
| Toggles the fullscreen mode for the window frame. | |
| void | SetHeaderFade () |
| Updates header visual appearance based on active state. | |
| void | UnregisterCallbacks () |
| Unregisters all event callbacks to prevent memory leaks. | |
| void | UpdateTheme (List< StyleSheet > newTheme, List< StyleSheet > oldTheme) |
| Updates the theme stylesheet for the windows in the system. | |
| async void | WaitForIdle () |
| Waits for the window to not be moving for 2 seconds before saving the window data. | |
| VisualElement | WindowFrameContent () |
| Creates the content area of the WindowFrame custom control. | |
| VisualElement | WindowFrameFooter () |
| Generates the Footer portion of a WindowFrame custom control. | |
| VisualElement | WindowFrameHeader () |
| Generates the header portion of a WindowFrame custom control. | |
Static Private Member Functions | |
| static void | ApplyContentStyles (VisualElement newContentContainer) |
| Applies standard content styling to a container element. | |
Private Attributes | |
| bool | _active = true |
| Indicates whether the window is currently active/focused. | |
| bool | _allowLock = true |
| Indicates whether the window can be locked. | |
| bool | _allowResize = true |
| Indicates whether the window can be resized. | |
| VisualElement | _content |
| Content area of the window where main UI elements are placed. | |
| ContextMenuConfig | _contextMenuConfig |
| Configuration for the context menu associated with this window. | |
| VisualElement | _footer |
| Footer area of the window containing toolbar and resize handle. | |
| VisualElement | _footerToolbar |
| Toolbar element in the footer area. | |
| VisualElement | _footerToolbarArea |
| Container for the footer toolbar. | |
| bool | _fullScreen |
| Indicates whether the window is in fullscreen mode. | |
| VisualElement | _header |
| Header area of the window containing title and controls. | |
| float | _lastMoveTime |
| Timestamp of the last window move operation. | |
| Vector2 | _lastPosition |
| Last recorded position of the window for change detection. | |
| Vector2 | _lastSize |
| Last recorded size of the window for change detection. | |
| bool | _locked |
| Indicates whether the window is currently locked. | |
| bool | _lockedFullScreen = false |
| Whether fullscreen mode is locked and cannot be changed. | |
| bool | _lockedToStartPosition = false |
| Whether the window is locked to its start position. | |
| VisualElement | _lockIndicator = new Button() |
| Button indicator for locking/unlocking the window. | |
| float | _minHeight = 50 |
| Minimum height of the window in pixels. | |
| float | _minWidth = 50 |
| Minimum width of the window in pixels. | |
| VisualElement | _optionsMenu = new Button() |
| Button for opening the options menu. | |
| bool | _origAllowMove |
| Original value of the allow move flag before fullscreen. | |
| bool | _origAllowResize |
| Original value of the allow resize flag before fullscreen. | |
| float | _origBorderBLRadius |
| Original bottom-left border radius value before fullscreen. | |
| float | _origBorderBRRadius |
| Original bottom-right border radius value before fullscreen. | |
| float | _origBorderTLRadius |
| Original top-left border radius value before fullscreen. | |
| float | _origBorderTRRadius |
| Original top-right border radius value before fullscreen. | |
| float | _origHeight |
| Original height before fullscreen mode. | |
| float | _origWidth |
| Original width before fullscreen mode. | |
| float | _origX |
| Original X position before fullscreen mode. | |
| float | _origY |
| Original Y position before fullscreen mode. | |
| bool | _overrideStartPosition |
| Indicates whether to override the default start position. | |
| string | _parentObjectId |
| ID of the parent object associated with the window. | |
| VisualElement | _resizeArea = new VisualElement() |
| Area for resizing the window, typically in the bottom-right corner. | |
| Color | _resolvedHeaderBgColor |
| The resolved background color for the active header state. | |
| Color | _resolvedHeaderBgColorInactive |
| The resolved background color for the inactive header state. | |
| WindowFramePosition | _selectedPosition = WindowFramePosition.TopLeft |
| Initial positioning preference for the window. | |
| bool | _showFooter = true |
| Indicates whether the footer is visible. | |
| bool | _showHeader = true |
| Indicates whether the header is visible. | |
| List< StyleSheet > | _styleSheet |
| List of stylesheets applied to the window. | |
| string | _title = "Window Title" |
| Title of the window displayed in the header. | |
| Label | _titleLabel = new Label() |
| Label displaying the window title in the header. | |
| bool | _waitingForIdle |
| Indicates whether the window is waiting for idle state before saving data. | |
Static Private Attributes | |
| static readonly CustomStyleProperty< Color > | s_CustomColor = new("--windowFrame__header-background-color") |
| Custom style property for header background color theming. | |
WindowFrame is a comprehensive window system that provides desktop-style window functionality including:
| GWG.WindowFramework.WindowFrame.WindowFrame | ( | ) |
The constructor performs comprehensive initialization including:
|
staticprivate |
| newContentContainer | The container to apply styling to |
Configures the container for flexible vertical layout with proper overflow handling. Ensures consistent content area behavior across all windows.
|
private |
Handles the full window closure process including:
| void GWG.WindowFramework.WindowFrame.CloseWindow | ( | bool | forceAll = false | ) |
| forceAll | Forces closure regardless of permissions when true |
Respects AllowClose and Locked properties unless forceAll is true. When forceAll is true, overrides all restrictions for emergency shutdown scenarios. Calls the private Close() method to perform actual cleanup.
|
private |
Provides a standard context menu with common window operations. Each item includes appropriate visibility and enabled logic based on window permissions. Serves as an example for creating custom context menu configurations.
|
private |
Establishes the three-part window structure in the correct hierarchical order. Each section is created and configured for its specific purpose.
|
private |
| evt | The geometry change event data |
Handles window geometry changes by tracking position and size changes. Implements idle detection to avoid excessive save operations during continuous movement. Respects LockedToStartPosition setting by resetting position when needed.
|
private |
When AllowMultipleInstances is false, searches for existing instances of the same type. If found, activates the existing instance and marks the new one for destruction. Only performs check during runtime to avoid editor issues.
| void GWG.WindowFramework.WindowFrame.Hide | ( | ) |
Removes the window from layout calculations while keeping it in the hierarchy. Updates display style and visibility flag for fast show/hide operations. Schedules a save operation to persist the hidden state.
|
private |
Adjusts window position to prevent it from moving off-screen. Handles all four screen edges and maintains window visibility. Called automatically during positioning operations.
|
private |
Attempts to restore window state from saved data including position, size, and visibility. Falls back to default positioning if no saved data exists or memory is disabled. Handles multiple instance checking and applies appropriate sizing for fullscreen mode.
|
private |
| evt | The attach event data |
Triggered when the window is added to the UI hierarchy. Fires the OnWindowFrameAdded event for system notification.
|
private |
| evt | The click event data |
Sets this window as the active window when clicked (except options menu clicks). Only operates during play mode to avoid editor interference. Uses WindowFrameController to properly manage window activation.
|
private |
| evt | The detach event data |
Triggered when the window is removed from the UI hierarchy. Fires the OnWindowFrameRemoved event and unregisters all callbacks. Essential for notifying other systems and preventing memory leaks.
|
private |
| evt | The geometry change event from the screen/panel |
Responds to screen resolution changes or panel size modifications. Updates window position if LockedToStartPosition is true. Ensures windows remain on screen after size changes.
|
private |
Tracks the last move time and initiates idle detection to batch save operations. Prevents excessive saving during continuous window movement operations.
|
private |
Sets up comprehensive event handling including:
|
private |
Convenience method that saves window data with current visibility state. Uses the more detailed SaveWindowData(bool) method internally.
|
private |
| isOpen | Whether the window is currently open |
Saves comprehensive window state including position, size, visibility, lock state, and other properties. Only saves if WindowMemoryEnabled is true and proper identification is available. Creates a unique data key combining type, parent ID, and window ID.
|
private |
| value | A boolean indicating whether to enable or disable fullscreen mode. |
Manages fullscreen state by storing original dimensions and settings. Temporarily disables resize and move capabilities in fullscreen mode. Restores original state when exiting fullscreen. Respects AllowFullscreen, Locked, and LockedFullscreen properties.
|
private |
Applies different opacity levels to provide visual feedback about window focus:
| void GWG.WindowFramework.WindowFrame.SetOpeningPosition | ( | ) |
Calculates window position based on screen dimensions and window size. Respects LockedToStartPosition and _overrideStartPosition settings. Uses scheduled execution to ensure layout calculations are complete.
| void GWG.WindowFramework.WindowFrame.Show | ( | ) |
Makes the window immediately visible and interactive. Updates display style, visibility flag, and opacity. Schedules a save operation to persist the visible state.
|
private |
Removes all registered event callbacks including:
|
private |
| newTheme | The new stylesheet to apply |
| oldTheme | The old stylesheet to remove |
Safely replaces old stylesheets with new ones during theme changes. Ensures proper cleanup and prevents style conflicts.
|
private |
Implements asynchronous idle detection to batch save operations. Waits 1 second of inactivity before saving to avoid excessive file operations. Includes error handling for async operation failures.
|
private |
Creates the main content container with appropriate flex layout settings. This is where application content should be placed.
|
private |
Creates the footer with toolbar area and resize handle. Configured for proper layout and resize functionality.
|
private |
Creates the header with title label, lock indicator, and options menu. Configured for dragging and proper event handling.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
getset |
Active state affects visual appearance (inactive windows appear dimmed). Only one window should be active at a time. Managed by WindowFrameController.
|
getset |
When disabled, users cannot close the window through normal means. Can still be closed programmatically with CloseWindow(true).
|
getset |
When disabled, users cannot toggle fullscreen through context menu or double-click. The Fullscreen property can still be set programmatically if needed.
|
getset |
When enabled, users can lock/unlock through context menu or lock indicator. Locked windows cannot be moved, resized, or closed by normal interactions.
|
getset |
When enabled, users can drag the header to reposition the window. Movement is constrained to keep window within screen bounds. Automatically disabled when locked or in fullscreen mode.
|
getset |
When false, creating a new instance will activate the existing one instead. Useful for singleton windows like settings or main inventory.
|
getset |
When enabled, users can drag the resize handle to change dimensions. Subject to MinWidth/MinHeight constraints and disabled when locked.
|
getset |
The main container where application UI elements should be placed. When set, existing content is removed and tooltips are automatically applied. This is where forms, data displays, and interactive controls go.
|
get |
This ensures that elements added directly to the WindowFrame are placed in the content area rather than the root, maintaining the window's internal structure while providing intuitive behavior.
|
getset |
If no custom configuration is provided, a default context menu is generated with standard window operations (fullscreen, lock, close). Custom configurations can add application-specific options.
|
getset |
Used when the window is first created or when no saved size data is available. Provides the initial height for new window instances.
|
getset |
Used when the window is first created or when no saved size data is available. Provides the initial width for new window instances.
|
getset |
Provides a dedicated area for action buttons and controls at the bottom of the window. Positioned to the left of the resize handle. Setting to null removes toolbar content.
|
getset |
Fullscreen mode expands the window to fill the entire screen and temporarily disables movement and resizing. Original dimensions are preserved for restoration.
|
getset |
When locked, the window cannot be moved, resized, or closed through normal means. Displays lock indicator and adds appropriate CSS classes for styling. Only available if AllowLock is true.
|
getset |
When true, forces the window into fullscreen mode and prevents users from exiting. Creates a kiosk-style interface where the window permanently occupies the screen.
|
getset |
When true, the window will always return to its StartPosition and ignore saved position data. Useful for windows that should maintain consistent positioning.
|
getset |
Enforces a lower bound on window resizing to ensure usability. Should account for header, content area, and footer visibility.
|
getset |
Enforces a lower bound on window resizing to ensure usability. Applied through both CSS styling and drag-resize operations.
|
getset |
Supports positioning hints using format "Position:Text" where Position can be T, B, L, or R. Provides users with information about the options menu functionality.
|
getset |
ParentObjectId allows windows to be associated with specific game objects or contexts. This enables multiple windows of the same type to maintain separate state data.
|
getset |
Supports positioning hints using format "Position:Text" where Position can be T, B, L, or R. Provides users with instructions for resizing the window.
|
getset |
The footer contains toolbar area and resize handle. Hiding it removes resize functionality unless handled elsewhere.
|
getset |
The header contains title, options menu, and lock indicator. Hiding it removes the drag handle, so ensure alternative movement methods if needed.
|
getset |
Determines where the window will initially appear on screen. Can be overridden by saved window data if WindowMemoryEnabled is true.
|
getset |
Allows individual windows to have custom styling beyond the global theme. Stylesheets are applied immediately and replace existing window-specific styles. Falls back to global theme on loading failure.
|
getset |
The title is displayed in the window header and can be changed dynamically. Changes immediately update the visual title label.
|
getset |
The WindowId is used for persistence and should be unique within the application. It's combined with ParentObjectId to create unique save keys.
|
getset |
When enabled, window position, size, and state are automatically saved and restored. Requires both this property and WindowFrameController.MemoryEnabled to be true.
|
static |
This static event allows other systems to respond to window creation for registration, initialization, or UI management purposes.
|
static |
This static event allows other systems to respond to window removal for cleanup, deregistration, or UI management purposes.