Skip to content

PopupMenu

Eduard Gushchin edited this page Jun 22, 2026 · 3 revisions

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

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

Overview

Displays a temporary menu of command items.

Syntax

public class Electron2D.PopupMenu : Electron2D.Control

Remarks

PopupMenu stores labeled items, separators and checkable commands. It emits both item index and command id when an enabled item is activated.

The 0.1.0 Preview implementation is a Electron2D.Control-based runtime menu. Native window integration and submenus are outside this task.

Thread Safety

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

Since

This type is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control
  • Electron2D.ItemList

Members

Member Kind Summary
Electron2D.PopupMenu() Constructor Initializes a new instance of the Electron2D.PopupMenu class.
AddCheckItem(System.String, System.Int32) Method Adds a checkable command item.
AddIconCheckItem(Electron2D.Texture2D, System.String, System.Int32) Method Adds a checkable command item with an icon.
AddIconItem(Electron2D.Texture2D, System.String, System.Int32) Method Adds a command item with an icon.
AddItem(System.String, System.Int32) Method Adds a plain text command item.
AddSeparator(System.String, System.Int32) Method Adds a separator item.
Clear() Method Removes every menu item.
GetItemCount() Method Gets the number of menu items.
GetItemIcon(System.Int32) Method Gets the icon of an item.
GetItemId(System.Int32) Method Gets the id stored on an item.
GetItemText(System.Int32) Method Gets the text of an item.
IsItemChecked(System.Int32) Method Reports whether an item is checked.
IsItemDisabled(System.Int32) Method Reports whether an item is disabled.
IsItemSeparator(System.Int32) Method Reports whether an item is a separator.
Popup(Electron2D.Rect2) Method Shows this menu inside a rectangle.
SetItemChecked(System.Int32, System.Boolean) Method Sets whether a checkable item is checked.
SetItemDisabled(System.Int32, System.Boolean) Method Sets whether an item ignores activation input.
SetItemIcon(System.Int32, Electron2D.Texture2D) Method Sets the icon of an item.
SetItemId(System.Int32, System.Int32) Method Sets the id stored on an item.
SetItemText(System.Int32, System.String) Method Sets the text of an item.
_Draw() Method Draws the menu rows and labels.
_GetMinimumSize() Method Gets the minimum size requested by this popup menu.
_GuiInput(Electron2D.InputEvent) Method Handles GUI input routed to this menu.

Member Details

Electron2D.PopupMenu()

Kind: Constructor

public Electron2D.PopupMenu()

Summary

Initializes a new instance of the Electron2D.PopupMenu class.

Remarks

The constructor registers index_pressed and id_pressed signals and hides the menu until Electron2D.PopupMenu.Popup(Electron2D.Rect2) is called.

Thread Safety

This constructor is not synchronized. Call it from the main scene thread.

Since

This constructor is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.PopupMenu

AddCheckItem(System.String, System.Int32)

Kind: Method

public System.Void AddCheckItem(System.String, System.Int32)(System.String label, System.Int32 id)

Summary

Adds a checkable command item.

Remarks

The item starts unchecked. Use Electron2D.PopupMenu.SetItemChecked(System.Int32,System.Boolean) to change the checked state.

Parameters

  • label: The item label.
  • id: The command id emitted by id_pressed.

Exceptions

  • System.ArgumentNullException: Thrown when label 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.PopupMenu.AddIconCheckItem(Electron2D.Texture2D,System.String,System.Int32)

AddIconCheckItem(Electron2D.Texture2D, System.String, System.Int32)

Kind: Method

public System.Void AddIconCheckItem(Electron2D.Texture2D, System.String, System.Int32)(Electron2D.Texture2D texture, System.String label, System.Int32 id)

Summary

Adds a checkable command item with an icon.

Remarks

The item starts unchecked and can be toggled by Electron2D.PopupMenu.SetItemChecked(System.Int32,System.Boolean).

Parameters

  • texture: The icon texture.
  • label: The item label.
  • id: The command id emitted by id_pressed.

Exceptions

  • System.ArgumentNullException: Thrown when texture or label 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.PopupMenu.AddCheckItem(System.String,System.Int32)

AddIconItem(Electron2D.Texture2D, System.String, System.Int32)

Kind: Method

public System.Void AddIconItem(Electron2D.Texture2D, System.String, System.Int32)(Electron2D.Texture2D texture, System.String label, System.Int32 id)

Summary

Adds a command item with an icon.

Remarks

Icon drawing uses the existing texture draw path when a renderer consumes the generated canvas commands.

Parameters

  • texture: The icon texture.
  • label: The item label.
  • id: The command id emitted by id_pressed.

Exceptions

  • System.ArgumentNullException: Thrown when texture or label 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.PopupMenu.AddItem(System.String,System.Int32)

AddItem(System.String, System.Int32)

Kind: Method

public System.Void AddItem(System.String, System.Int32)(System.String label, System.Int32 id)

Summary

Adds a plain text command item.

Remarks

Passing -1 for id stores the current item index as the command id.

Parameters

  • label: The item label.
  • id: The command id emitted by id_pressed.

Exceptions

  • System.ArgumentNullException: Thrown when label 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.PopupMenu.AddIconItem(Electron2D.Texture2D,System.String,System.Int32)

AddSeparator(System.String, System.Int32)

Kind: Method

public System.Void AddSeparator(System.String, System.Int32)(System.String label, System.Int32 id)

Summary

Adds a separator item.

Remarks

Separators cannot be activated and do not emit press signals.

Parameters

  • label: The optional separator label.
  • id: The separator id stored for metadata queries.

Exceptions

  • System.ArgumentNullException: Thrown when label 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.PopupMenu.IsItemSeparator(System.Int32)

Clear()

Kind: Method

public System.Void Clear()()

Summary

Removes every menu item.

Remarks

Visibility and registered signals are not changed.

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.PopupMenu.AddItem(System.String,System.Int32)

GetItemCount()

Kind: Method

public System.Int32 GetItemCount()()

Summary

Gets the number of menu items.

Remarks

Separators are included in the count.

Returns

The current menu item count.

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.PopupMenu.Clear

GetItemIcon(System.Int32)

Kind: Method

public Electron2D.Texture2D GetItemIcon(System.Int32)(System.Int32 index)

Summary

Gets the icon of an item.

Remarks

Use Electron2D.PopupMenu.SetItemIcon(System.Int32,Electron2D.Texture2D) to replace the icon.

Parameters

  • index: The item index.

Returns

The item icon, or null when none is set.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when index is outside the item list.

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.PopupMenu.SetItemIcon(System.Int32,Electron2D.Texture2D)

GetItemId(System.Int32)

Kind: Method

public System.Int32 GetItemId(System.Int32)(System.Int32 index)

Summary

Gets the id stored on an item.

Remarks

The id is emitted through id_pressed when the item activates.

Parameters

  • index: The item index.

Returns

The item id.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when index is outside the item list.

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.PopupMenu.SetItemId(System.Int32,System.Int32)

GetItemText(System.Int32)

Kind: Method

public System.String GetItemText(System.Int32)(System.Int32 index)

Summary

Gets the text of an item.

Remarks

The returned string is never null.

Parameters

  • index: The item index.

Returns

The item text.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when index is outside the item list.

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.PopupMenu.SetItemText(System.Int32,System.String)

IsItemChecked(System.Int32)

Kind: Method

public System.Boolean IsItemChecked(System.Int32)(System.Int32 index)

Summary

Reports whether an item is checked.

Remarks

Checked state is independent from activation.

Parameters

  • index: The item index.

Returns

true when the item is checked; otherwise, false.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when index is outside the item list.

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.PopupMenu.SetItemChecked(System.Int32,System.Boolean)

IsItemDisabled(System.Int32)

Kind: Method

public System.Boolean IsItemDisabled(System.Int32)(System.Int32 index)

Summary

Reports whether an item is disabled.

Remarks

Disabled items cannot emit press signals from user input.

Parameters

  • index: The item index.

Returns

true when the item is disabled; otherwise, false.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when index is outside the item list.

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.PopupMenu.SetItemDisabled(System.Int32,System.Boolean)

IsItemSeparator(System.Int32)

Kind: Method

public System.Boolean IsItemSeparator(System.Int32)(System.Int32 index)

Summary

Reports whether an item is a separator.

Remarks

Separators cannot be activated.

Parameters

  • index: The item index.

Returns

true when the item is a separator; otherwise, false.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when index is outside the item list.

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.PopupMenu.AddSeparator(System.String,System.Int32)

Popup(Electron2D.Rect2)

Kind: Method

public System.Void Popup(Electron2D.Rect2)(Electron2D.Rect2 bounds)

Summary

Shows this menu inside a rectangle.

Remarks

The menu becomes visible and grabs focus when it is already inside a scene tree.

Parameters

  • bounds: The global rectangle used for the menu position and size.

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.CanvasItem.Hide

SetItemChecked(System.Int32, System.Boolean)

Kind: Method

public System.Void SetItemChecked(System.Int32, System.Boolean)(System.Int32 index, System.Boolean checked)

Summary

Sets whether a checkable item is checked.

Remarks

The value can be stored on plain items too, but only checkable items draw a check indicator.

Parameters

  • index: The item index.
  • checked: true to mark the item checked; otherwise, false.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when index is outside the item list.

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.PopupMenu.IsItemChecked(System.Int32)

SetItemDisabled(System.Int32, System.Boolean)

Kind: Method

public System.Void SetItemDisabled(System.Int32, System.Boolean)(System.Int32 index, System.Boolean disabled)

Summary

Sets whether an item ignores activation input.

Remarks

Disabled items still occupy rows and can be inspected through metadata methods.

Parameters

  • index: The item index.
  • disabled: true to disable the item; otherwise, false.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when index is outside the item list.

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.PopupMenu.IsItemDisabled(System.Int32)

SetItemIcon(System.Int32, Electron2D.Texture2D)

Kind: Method

public System.Void SetItemIcon(System.Int32, Electron2D.Texture2D)(System.Int32 index, Electron2D.Texture2D icon)

Summary

Sets the icon of an item.

Remarks

Separators may also store icons, although the preview drawing path does not render separator icons.

Parameters

  • index: The item index.
  • icon: The icon texture, or null to clear it.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when index is outside the item list.

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.PopupMenu.GetItemIcon(System.Int32)

SetItemId(System.Int32, System.Int32)

Kind: Method

public System.Void SetItemId(System.Int32, System.Int32)(System.Int32 index, System.Int32 id)

Summary

Sets the id stored on an item.

Remarks

Item ids are independent from item order.

Parameters

  • index: The item index.
  • id: The id emitted by id_pressed.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when index is outside the item list.

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.PopupMenu.GetItemId(System.Int32)

SetItemText(System.Int32, System.String)

Kind: Method

public System.Void SetItemText(System.Int32, System.String)(System.Int32 index, System.String text)

Summary

Sets the text of an item.

Remarks

Assigning text queues a redraw.

Parameters

  • index: The item index.
  • text: The new item text.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when index is outside the item list.
  • System.ArgumentNullException: Thrown when text 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.PopupMenu.GetItemText(System.Int32)

_Draw()

Kind: Method

public System.Void _Draw()()

Summary

Draws the menu rows and labels.

Remarks

Text drawing is skipped when no theme font is available.

Thread Safety

This callback is invoked on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem.DrawRect(Electron2D.Rect2,Electron2D.Color,System.Boolean,System.Single,System.Boolean)

_GetMinimumSize()

Kind: Method

public Electron2D.Vector2 _GetMinimumSize()()

Summary

Gets the minimum size requested by this popup menu.

Remarks

The minimum width is fixed in the preview implementation.

Returns

A conservative menu size based on item count.

Thread Safety

This callback is invoked on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control.GetMinimumSize

_GuiInput(Electron2D.InputEvent)

Kind: Method

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

Summary

Handles GUI input routed to this menu.

Remarks

Mouse and touch press activate the row under the pointer. Keyboard activation currently uses the first enabled item.

Parameters

  • inputEvent: The input event delivered by the viewport.

Thread Safety

This callback is invoked on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control._GuiInput(Electron2D.InputEvent)

Clone this wiki locally