Table of Contents

Class Desktop

Namespace
Myra.Graphics2D.UI
Assembly
Myra.dll

Represents the main UI desktop/screen that manages all widgets and handles user input.

public class Desktop : IDisposable
Inheritance
Desktop
Implements
Inherited Members

Constructors

Desktop()

Initializes a new instance of the Desktop class.

public Desktop()

Fields

KeyDownHandler

Gets or sets the handler for keyboard key down events.

public Action<Keys> KeyDownHandler

Field Value

Action<Keys>

Properties

Background

Gets or sets the background brush for the desktop.

public IBrush Background { get; set; }

Property Value

IBrush

BoundsFetcher

Gets or sets the function that fetches the bounds of the desktop.

public Func<Rectangle> BoundsFetcher { get; set; }

Property Value

Func<Rectangle>

ContextMenu

Gets the context menu widget currently displayed on the desktop.

public Widget ContextMenu { get; }

Property Value

Widget

DownKeys

Gets an array indicating which keys are currently pressed down.

public bool[] DownKeys { get; }

Property Value

bool[]

FocusedKeyboardWidget

Gets or sets the widget that currently has keyboard focus.

public Widget FocusedKeyboardWidget { get; set; }

Property Value

Widget

HasExternalTextInput

Gets or sets a value indicating whether text input is handled by an external mechanism.

public bool HasExternalTextInput { get; set; }

Property Value

bool

HasModalWidget

Gets a value indicating whether any modal widget is currently displayed on the desktop.

public bool HasModalWidget { get; }

Property Value

bool

IsMouseOverGUI

Gets a value indicating whether the mouse cursor is over a GUI widget.

public bool IsMouseOverGUI { get; }

Property Value

bool

IsTouchDown

Gets a value indicating whether the touch is currently down.

public bool IsTouchDown { get; }

Property Value

bool

IsTouchOverGUI

Gets a value indicating whether a touch point is over a GUI widget.

public bool IsTouchOverGUI { get; }

Property Value

bool

MenuBar

Gets the menu bar widget for the desktop.

public HorizontalMenu MenuBar { get; }

Property Value

HorizontalMenu

MousePosition

Current mouse position in the global coordinates

public Point MousePosition { get; }

Property Value

Point

MouseWheelDelta

Gets or sets the mouse wheel delta for the current frame.

public float MouseWheelDelta { get; set; }

Property Value

float

Opacity

Gets or sets the opacity of the desktop (0.0 to 1.0).

public float Opacity { get; set; }

Property Value

float

PreviousMousePosition

Previous mouse position in the global coordinates

public Point PreviousMousePosition { get; }

Property Value

Point

PreviousTouchPosition

Previous touch position in the global coordinates Null if there was no touch

public Point? PreviousTouchPosition { get; }

Property Value

Point?

RepeatKeyDownInternalInMs

Gets or sets the interval in milliseconds between key repeat events.

[Obsolete("Use MyraEnvironment.RepeatKeyDownInternalInMs instead.")]
public int RepeatKeyDownInternalInMs { get; set; }

Property Value

int

RepeatKeyDownStartInMs

Gets or sets the delay in milliseconds before a pressed key starts repeating.

[Obsolete("Use MyraEnvironment.RepeatKeyDownStartInMs instead.")]
public int RepeatKeyDownStartInMs { get; set; }

Property Value

int

Root

Gets or sets the root widget that covers the entire desktop.

public Widget Root { get; set; }

Property Value

Widget

Rotation

Gets or sets the rotation angle of the desktop in radians.

public float Rotation { get; set; }

Property Value

float

Scale

Gets or sets the scale factor for the desktop and all its widgets.

public Vector2 Scale { get; set; }

Property Value

Vector2

Tooltip

Gets the tooltip widget currently displayed on the desktop.

public Widget Tooltip { get; }

Property Value

Widget

TouchPosition

Current touch position in the global coordinates Null if there is no touch

public Point? TouchPosition { get; }

Property Value

Point?

TransformOrigin

Gets or sets the origin point for transformations (rotation and scale).

public Vector2 TransformOrigin { get; set; }

Property Value

Vector2

Widgets

Gets the collection of all widgets on the desktop.

public ObservableCollection<Widget> Widgets { get; }

Property Value

ObservableCollection<Widget>

Methods

CalculateTotalWidgets(bool)

Calculates the total number of widgets on the desktop and all their descendants.

public int CalculateTotalWidgets(bool visibleOnly)

Parameters

visibleOnly bool

If true, only counts visible widgets.

Returns

int

The total number of widgets.

DefaultBoundsFetcher()

Gets the default bounds of the desktop from the game window.

public static Rectangle DefaultBoundsFetcher()

Returns

Rectangle

A rectangle representing the desktop bounds.

Dispose()

Releases all resources used by the desktop.

public void Dispose()

~Desktop()

Finalizer that releases unmanaged resources.

protected ~Desktop()

FindChild(Func<Widget, bool>)

Finds the first child widget that matches the specified predicate, recursively searching all descendants.

public Widget FindChild(Func<Widget, bool> filter)

Parameters

filter Func<Widget, bool>

A function to test each widget.

Returns

Widget

The first matching widget, or null if no match is found.

FindChild(string)

Finds a child widget by its ID, recursively searching all descendants.

public Widget FindChild(string id)

Parameters

id string

The ID of the widget to find.

Returns

Widget

The widget with the specified ID, or null if not found.

GetChild(int)

Gets the child widget at the specified index.

public Widget GetChild(int index)

Parameters

index int

The zero-based index of the child widget.

Returns

Widget

The child widget at the specified index.

HideContextMenu()

Hides the currently displayed context menu.

public void HideContextMenu()

HideTooltip()

Hides the currently displayed tooltip.

public void HideTooltip()

InvalidateLayout()

Marks the layout as dirty, requiring an update on the next render.

public void InvalidateLayout()

IsKeyDown(Keys)

Determines whether a specific keyboard key is currently pressed.

public bool IsKeyDown(Keys keys)

Parameters

keys Keys

The key to check.

Returns

bool

true if the key is pressed; otherwise, false.

IsPointOverGUI(Point)

Determines whether a point is over a GUI widget.

public bool IsPointOverGUI(Point p)

Parameters

p Point

The point to test.

Returns

bool

True if the point is over a GUI widget; otherwise, false.

OnChar(char)

Handles character input from the keyboard. Routes character to focused widget unless menu bar is active. Fires global character event.

public void OnChar(char c)

Parameters

c char

The character that was input.

OnKeyDown(Keys)

Handles a keyboard key down event. Routes to menu bar if active, otherwise to focused widget. Generates character events for printable keys. Escape key closes context menus.

public void OnKeyDown(Keys key)

Parameters

key Keys

The key that was pressed.

Render()

Updates the layout of all widgets and processes input events. Performs a multi-pass render pipeline: layout → input processing → input events → layout → visual rendering.

public void Render()

RenderVisual()

Renders the visual representation of the desktop and all its widgets. Sets up rendering context with transform, opacity, and scissor clipping, then renders all visible widgets.

public void RenderVisual()

ShowContextMenu(Widget, Point)

Shows the context menu

public void ShowContextMenu(Widget menu, Point position)

Parameters

menu Widget

Widget to show

position Point

Show position in the global coordinates

ShowTooltip(Widget, Point)

Shows a tooltip for the specified widget at the given position.

public void ShowTooltip(Widget widget, Point position)

Parameters

widget Widget

The widget to show the tooltip for.

position Point

The position to show the tooltip in global coordinates.

ToGlobal(Point)

Converts a local coordinate to global (screen) coordinates.

public Point ToGlobal(Point pos)

Parameters

pos Point

The local position.

Returns

Point

The position in global coordinates.

ToGlobal(Vector2)

Converts a local coordinate to global (screen) coordinates.

public Vector2 ToGlobal(Vector2 pos)

Parameters

pos Vector2

The local position.

Returns

Vector2

The position in global coordinates.

ToLocal(Point)

Converts a global (screen) coordinate to local coordinates.

public Point ToLocal(Point pos)

Parameters

pos Point

The global position.

Returns

Point

The position in local coordinates.

ToLocal(Vector2)

Converts a global (screen) coordinate to local coordinates.

public Vector2 ToLocal(Vector2 pos)

Parameters

pos Vector2

The global position.

Returns

Vector2

The position in local coordinates.

UpdateInput()

Updates all input states (keyboard, mouse, and touch) for the current frame.

public void UpdateInput()

UpdateKeyboardInput()

Updates the keyboard input state based on the current keyboard information.

public void UpdateKeyboardInput()

UpdateLayout()

Updates the layout of all widgets on the desktop. Fetches bounds from BoundsFetcher, arranges all visible widgets, discovers MenuBar, and processes layout expressions.

public void UpdateLayout()

UpdateMouseInput()

Updates the mouse input state based on the current mouse information.

public void UpdateMouseInput()

UpdateTouchInput()

Updates the touch input state based on the current touch information from the platform.

public void UpdateTouchInput()

Events

Char

Occurs when a character is input from the keyboard. The event args contain the character value.

public event MyraEventHandler<GenericEventArgs<char>> Char

Event Type

MyraEventHandler<GenericEventArgs<char>>

ContextMenuClosed

Occurs after a context menu is closed.

public event MyraEventHandler<GenericEventArgs<Widget>> ContextMenuClosed

Event Type

MyraEventHandler<GenericEventArgs<Widget>>

ContextMenuClosing

Occurs before a context menu is closed.

public event MyraEventHandler<CancellableEventArgs<Widget>> ContextMenuClosing

Event Type

MyraEventHandler<CancellableEventArgs<Widget>>

KeyDown

Occurs when a key is pressed. The event args contain the key code.

public event MyraEventHandler<GenericEventArgs<Keys>> KeyDown

Event Type

MyraEventHandler<GenericEventArgs<Keys>>

KeyUp

Occurs when a key is released. The event args contain the key code.

public event MyraEventHandler<GenericEventArgs<Keys>> KeyUp

Event Type

MyraEventHandler<GenericEventArgs<Keys>>

MouseMoved

Occurs when the mouse moves.

public event MyraEventHandler MouseMoved

Event Type

MyraEventHandler

MouseWheelChanged

Occurs when the mouse wheel is scrolled. The event args contain the wheel delta value.

public event MyraEventHandler<GenericEventArgs<float>> MouseWheelChanged

Event Type

MyraEventHandler<GenericEventArgs<float>>

TouchDoubleClick

Occurs when a touch point is double-clicked on the screen.

public event MyraEventHandler TouchDoubleClick

Event Type

MyraEventHandler

TouchDown

Occurs when a touch point is pressed on the screen.

public event MyraEventHandler TouchDown

Event Type

MyraEventHandler

TouchMoved

Occurs when a touch point moves on the screen.

public event MyraEventHandler TouchMoved

Event Type

MyraEventHandler

TouchUp

Occurs when a touch point is released from the screen.

public event MyraEventHandler TouchUp

Event Type

MyraEventHandler

WidgetGotKeyboardFocus

Occurs after a widget gets keyboard focus.

public event MyraEventHandler<GenericEventArgs<Widget>> WidgetGotKeyboardFocus

Event Type

MyraEventHandler<GenericEventArgs<Widget>>

WidgetLosingKeyboardFocus

Occurs before a widget loses keyboard focus.

public event MyraEventHandler<CancellableEventArgs<Widget>> WidgetLosingKeyboardFocus

Event Type

MyraEventHandler<CancellableEventArgs<Widget>>