Skip to content

Control

Eduard Gushchin edited this page Jun 21, 2026 · 9 revisions

Home | API by Category | Complete API Index | API Compatibility

Field Value
Full name Electron2D.Control
Namespace Electron2D
Kind class
Category UI and Text

Overview

Provides the Electron2D base node for 2D user interface controls.

Syntax

public class Electron2D.Control : Electron2D.CanvasItem

Remarks

Control inherits from Electron2D.CanvasItem and adds a rectangular UI area, theme font overrides, GUI input callbacks, mouse filtering and focus ownership used by Electron2D UI nodes.

Anchors, containers, keyboard navigation graphs and full widgets are later UI tasks, but the baseline input pipeline can already route mouse and focused keyboard events to controls.

Thread Safety

This type is not synchronized. Create and mutate controls on the main scene thread.

Since

This type is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem
  • Electron2D.Label

Members

Member Kind Summary
FocusMode Property Gets or sets how this control can receive focus.
MouseFilter Property Gets or sets how this control receives and consumes mouse input.
Position Property Gets or sets the local position of this control.
Size Property Gets or sets the local size of this control.
Electron2D.Control() Constructor Initializes a new instance of the Control type.
AcceptEvent() Method Marks the current GUI input event as handled.
AddThemeFontOverride(System.String, Electron2D.Font) Method Adds or replaces a font theme override for this control.
AddThemeFontSizeOverride(System.String, System.Int32) Method Adds or replaces a font size theme override for this control.
GetThemeFont(System.String) Method Gets a font theme override by name.
GetThemeFontSize(System.String) Method Gets a font size theme override by name.
GrabFocus() Method Gives keyboard and gamepad focus to this control.
HasFocus() Method Checks whether this control currently owns focus in its viewport.
ReleaseFocus() Method Releases focus from this control when it currently owns it.
_GuiInput(Electron2D.InputEvent) Method Called when a GUI input event is delivered to this control.

Member Details

FocusMode

Kind: Property

public Electron2D.FocusMode FocusMode { get; set; }

Summary

Gets or sets how this control can receive focus.

Remarks

Focus is owned by the nearest Electron2D.Viewport. Only one visible control inside that viewport can report Electron2D.Control.HasFocus at a time.

Electron2D.FocusMode.Click and Electron2D.FocusMode.All allow mouse press events to focus this control before Electron2D.Control._GuiInput(Electron2D.InputEvent) is called.

Value

The current Electron2D.FocusMode value. The default is Electron2D.FocusMode.None.

Thread Safety

This property is not synchronized. Mutate it on the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control.FocusMode
  • Electron2D.Control.GrabFocus
  • Electron2D.Control.HasFocus

MouseFilter

Kind: Property

public Electron2D.MouseFilter MouseFilter { get; set; }

Summary

Gets or sets how this control receives and consumes mouse input.

Remarks

The root Electron2D.Viewport reads this property while routing Electron2D.InputEventMouse events to Electron2D.Control._GuiInput(Electron2D.InputEvent).

Electron2D.MouseFilter.Stop handles the event after this control receives it. Electron2D.MouseFilter.Pass lets unhandled events bubble to the parent control. Electron2D.MouseFilter.Ignore skips this control for mouse hit-testing.

Value

The current Electron2D.Control.MouseFilter value. The default is Electron2D.MouseFilter.Stop.

Thread Safety

This property is not synchronized. Mutate it on the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control.MouseFilter
  • Electron2D.Control._GuiInput(Electron2D.InputEvent)

Position

Kind: Property

public Electron2D.Vector2 Position { get; set; }

Summary

Gets or sets the local position of this control.

Remarks

This property follows the validation and lifetime rules of its declaring type.

Value

The current position value.

Thread Safety

This property is not synchronized. Mutate it on the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control

Size

Kind: Property

public Electron2D.Vector2 Size { get; set; }

Summary

Gets or sets the local size of this control.

Remarks

This property follows the validation and lifetime rules of its declaring type.

Value

The current size value.

Thread Safety

This property is not synchronized. Mutate it on the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control

Electron2D.Control()

Kind: Constructor

public Electron2D.Control()

Summary

Initializes a new instance of the Control type.

Remarks

The new instance follows the lifetime and validation rules of its declaring type.

Thread Safety

This member is not synchronized. Call it from the thread that owns the related object unless the declaring type states otherwise.

Since

This API is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control

AcceptEvent()

Kind: Method

public System.Void AcceptEvent()()

Summary

Marks the current GUI input event as handled.

Remarks

This method forwards to Electron2D.Viewport.SetInputAsHandled on the containing viewport. It has no effect when this control is outside a scene tree or when no input event is currently being dispatched.

Thread Safety

This method is not synchronized. Call it on the main scene thread while handling Electron2D.Control._GuiInput(Electron2D.InputEvent).

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control._GuiInput(Electron2D.InputEvent)
  • Electron2D.Viewport.SetInputAsHandled

AddThemeFontOverride(System.String, Electron2D.Font)

Kind: Method

public System.Void AddThemeFontOverride(System.String, Electron2D.Font)(System.String name, Electron2D.Font font)

Summary

Adds or replaces a font theme override for this control.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • name: The theme font name, for example font.
  • font: The font resource to use.

Exceptions

  • System.ArgumentException: Thrown when name is null, empty or whitespace.
  • System.ArgumentNullException: Thrown when font is null.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control

AddThemeFontSizeOverride(System.String, System.Int32)

Kind: Method

public System.Void AddThemeFontSizeOverride(System.String, System.Int32)(System.String name, System.Int32 fontSize)

Summary

Adds or replaces a font size theme override for this control.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • name: The theme font size name, for example font_size.
  • fontSize: The font size in pixels. It must be greater than zero.

Exceptions

  • System.ArgumentException: Thrown when name is null, empty or whitespace.
  • System.ArgumentOutOfRangeException: Thrown when fontSize is less than or equal to zero.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control

GetThemeFont(System.String)

Kind: Method

public Electron2D.Font GetThemeFont(System.String)(System.String name)

Summary

Gets a font theme override by name.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • name: The theme font name.

Returns

The overridden font, or null when no override exists.

Exceptions

  • System.ArgumentException: Thrown when name is null, empty or whitespace.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control

GetThemeFontSize(System.String)

Kind: Method

public System.Int32 GetThemeFontSize(System.String)(System.String name)

Summary

Gets a font size theme override by name.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • name: The theme font size name.

Returns

The overridden font size in pixels, or 16 when no override exists.

Exceptions

  • System.ArgumentException: Thrown when name is null, empty or whitespace.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control

GrabFocus()

Kind: Method

public System.Void GrabFocus()()

Summary

Gives keyboard and gamepad focus to this control.

Remarks

The control must be inside a scene tree, visible in that tree and have Electron2D.Control.FocusMode set to a value other than Electron2D.FocusMode.None. If any of those conditions is not met, the call has no effect.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control.FocusMode
  • Electron2D.Control.HasFocus
  • Electron2D.Control.ReleaseFocus

HasFocus()

Kind: Method

public System.Boolean HasFocus()()

Summary

Checks whether this control currently owns focus in its viewport.

Remarks

Hidden controls and controls outside a scene tree do not report focus, even if they were the last control selected before becoming invalid for focus dispatch.

Returns

true when this control is the focused visible control in its viewport; otherwise, false.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control.GrabFocus
  • Electron2D.Control.ReleaseFocus

ReleaseFocus()

Kind: Method

public System.Void ReleaseFocus()()

Summary

Releases focus from this control when it currently owns it.

Remarks

Calling this method on a control that does not currently own focus is a no-op.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control.GrabFocus
  • Electron2D.Control.HasFocus

_GuiInput(Electron2D.InputEvent)

Kind: Method

public System.Void _GuiInput(Electron2D.InputEvent)(Electron2D.InputEvent inputEvent)

Summary

Called when a GUI input event is delivered to this control.

Remarks

Mouse events reach this method when the event position falls inside the control rectangle and Electron2D.Control.MouseFilter is not Electron2D.MouseFilter.Ignore. Non-mouse events reach only the currently focused control.

Call Electron2D.Control.AcceptEvent to stop further propagation of the current event.

Parameters

  • inputEvent: The input event delivered by the containing Electron2D.Viewport.

Thread Safety

This method is not synchronized. It is called on the main scene thread during input dispatch.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control.AcceptEvent
  • Electron2D.Control.FocusMode
  • Electron2D.Control.MouseFilter

Clone this wiki locally