Skip to content

UICanvas Class

Definition

Namespace: Brine2D.UI

Canvas that holds and manages UI components, routing input and rendering.

C#
public class UICanvas : Brine2D.Input.IInputLayer, System.IDisposable

Inheritance System.Object → UICanvas

Implements IInputLayer, System.IDisposable

Constructors
UICanvas\(IInputContext, IEventBus\) Creates a canvas subscribed to WindowResizedEvent on eventBus so ScreenSize tracks window resizes. The subscription is released on Dispose().
Properties
ActiveContextMenu The context menu currently shown as an overlay, or null when none is open.
ActiveMenuBar The most recently added or clicked menu bar on this canvas, or null if none has been added.
ActiveToasts Read-only view of currently active toasts \(oldest first\).
ActiveTweens Read-only view of currently running tweens.
ActiveTweenSequences Read-only view of currently running tween sequences.
Components Ordered list of components on this canvas \(front = last, back = first\). Exposed internally for testing.
DragSource The component currently being dragged, or null.
FocusedWidget The component that currently holds keyboard focus, or null when nothing is focused.
IsDragging Whether a drag operation is currently in progress.
MaxVisibleToasts Maximum number of toasts shown simultaneously. Older toasts are dismissed first when the limit is exceeded. 0 = unlimited.
Priority UI has high priority so it intercepts input first.
ScreenSize Current screen dimensions used to resolve UIAnchor positions and to center any UIDialog components. Update this whenever the window is resized. Defaults to 1280×720.
ToastAnchor Corner of the screen where toast notifications are stacked. Defaults to Brine2D.UI.ToastAnchor.BottomRight.
ToastPadding Gap in pixels between the screen edge and the toast stack, and between individual toasts.
WorldCamera Optional camera used to project WorldPosition values to screen space during Brine2D.UI.UICanvas.Render\(Brine2D\.Rendering\.IRenderer\). When null, world components are not projected and are rendered at their last assigned Position.
Methods
ActivateFocusedWidget\(IInputContext, bool, bool, bool\) Activates or nudges the focused widget. Shared by keyboard and gamepad paths.
Add\(IUIComponent\) Adds a component to the canvas. UIDialog is auto-centered; ScreenHeight and UIMenuBar state are initialised from the current ScreenSize.
AddWorldComponent\(IUIWorldComponent\) Adds a world-space overlay component. Its WorldPosition is projected to screen coordinates via WorldCamera on every Brine2D.UI.UICanvas.Render\(Brine2D\.Rendering\.IRenderer\) call.
BringToFront\(IUIComponent\) Moves a component to the top of the draw/input order. If it is not a direct child, the owning top-level container is brought to front instead. No-op if the component is not on this canvas or is already at the front.
CloseContextMenu() Closes the active context menu, if any, and fires OnClosed.
DismissToast\(UIToast\) Starts early dismissal of toast. No-op if not active.
Dispose() Releases the WindowResizedEvent subscription if any.
FindByName\(string\) Searches all components \(including nested children\) for the first one whose Name matches name. Returns null if not found.
FindByName<T>\(string\) Typed overload — returns the first component with the given name that is assignable to T, or null.
InRenderOrder() Stable ZOrder-sorted view of Brine2D.UI.UICanvas._components. Equal ZOrder values preserve insertion order.
ProcessGamepadInput\(IInputContext, bool, int\) Processes gamepad input for UI navigation. Returns true if input was consumed. D-Pad/left-stick up/down cycles focus; left/right nudges sliders or switches tabs. A activates the focused widget; B dismisses the active modal dialog. Navigation is scoped to the dialog when one is active.
ProcessKeyboardInput\(IInputContext, bool\) Processes keyboard input for UI. Returns true if input was consumed. When consumed is true, unfocuses any active text input. Tab/Shift+Tab cycles focus; Enter/Space activates; arrow keys nudge sliders. All input is blocked while a modal dialog is active.
ProcessMouseInput\(IInputContext, bool\) Processes mouse input for UI. Returns true if input was consumed. When consumed is true, clears hover/press state. Non-dialog input is blocked while a modal dialog is active.
PropagateScreenSize\(IUIComponent, Vector2\) Recursively pushes screenSize into nested UIDropdown, UITabContainer, and container children. Called from the ScreenSize setter, Add\(IUIComponent\), and container AddChild methods.
RebuildInputBuffer() Rebuilds the flat input dispatch buffer from top-level components by recursively expanding containers \([UIPanel](../UIPanel/index.md 'Brine2D\.UI\.UIPanel'), [UITabContainer](../UITabContainer/index.md 'Brine2D\.UI\.UITabContainer'), [UIScrollView](../UIScrollView/index.md 'Brine2D\.UI\.UIScrollView')\) at any nesting depth. Each entry carries the coordinate offset required so that the component's own Contains\(Vector2\) check works correctly against screen-space mouse positions. Called once per ProcessMouseInput\(IInputContext, bool\) frame before any handlers run.
RegisterDraggable\(IUIComponent, IDragPayload\) Registers component as a drag source carrying payload. Once the user drags past the threshold the ghost overlay appears.
RegisterDropTarget\(UIDropTarget\) Registers target as a drop zone. It must already be on the canvas.
RemoveWorldComponent\(IUIWorldComponent\) Removes a world-space overlay component.
ScrollFocusedWidgetIntoView\(IUIComponent\) Scrolls any UIScrollView that contains widget so the widget is visible.
SendToBack\(IUIComponent\) Moves a component to the start of the draw/input order so it renders behind all others. No-op if the component is not on this canvas or is already at the back.
SetFocus\(IUIComponent\) Programmatically moves keyboard focus to component. The component must already be added to this canvas \(directly, or inside a [UIPanel](../UIPanel/index.md 'Brine2D\.UI\.UIPanel'), [UIScrollView](../UIScrollView/index.md 'Brine2D\.UI\.UIScrollView'), or [UITabContainer](../UITabContainer/index.md 'Brine2D\.UI\.UITabContainer')\) and must be a focusable type \([UIButton](../UIButton/index.md 'Brine2D\.UI\.UIButton'), [UICheckbox](../UICheckbox/index.md 'Brine2D\.UI\.UICheckbox'), [UISlider](../UISlider/index.md 'Brine2D\.UI\.UISlider'), [UIRadioButton](../UIRadioButton/index.md 'Brine2D\.UI\.UIRadioButton'), [UIDropdown](../UIDropdown/index.md 'Brine2D\.UI\.UIDropdown'), [UIScrollView](../UIScrollView/index.md 'Brine2D\.UI\.UIScrollView'), [UITabContainer](../UITabContainer/index.md 'Brine2D\.UI\.UITabContainer'), or [UITextInput](../UITextInput/index.md 'Brine2D\.UI\.UITextInput')\). Returns true when focus was applied, false if the component is not focusable, not enabled, or not visible.
ShowContextMenu\(UIContextMenu, Vector2\) Opens menu as a top-level overlay at position, clamped to ScreenSize. Closes any previously open context menu first.
ShowToast\(UIToast\) Enqueues a toast. When MaxVisibleToasts would be exceeded, the oldest toast is dismissed immediately to make room.
StartTween\(UITween\) Registers a UITween for automatic advancement each Brine2D.UI.UICanvas.Update\(System\.Single\). Removed automatically on completion \(looping tweens run until [StopTween\(UITween\)](StopTween.md#Brine2D.UI.UICanvas.StopTween(Brine2D.UI.UITween) 'Brine2D.UI.UICanvas.StopTween\(Brine2D\.UI\.UITween\)') is called).
StartTween\(UITweenSequence\) Registers a UITweenSequence for automatic advancement each Brine2D.UI.UICanvas.Update\(System\.Single\). Removed automatically on completion.
StopAllTweens() Stops and removes all active tweens and sequences.
StopTween\(UITween\) Removes a tween from the active list. No-op if not registered. Does not call Complete().
StopTween\(UITweenSequence\) Removes a sequence from the active list. No-op if it is not registered.
UnregisterDraggable\(IUIComponent\) Removes a previously registered draggable component. No-op if not registered.
UnregisterDropTarget\(UIDropTarget\) Removes a previously registered drop target. No-op if not registered.
UnregisterRadioButtons\(IUIComponent\) Recursively unregisters all UIRadioButton instances in component from their UIRadioButtonGroup. Called from Brine2D.UI.UICanvas.Remove\(Brine2D\.UI\.IUIComponent\) to avoid stale group references.
ValidateFocusedWidgets() Clears focus on any widget that is no longer visible or enabled.
Events
OnDragCancelled Fired when a drag is cancelled \(released over no valid target\).
OnDragStarted Fired when a drag operation begins.