API ReferenceSandbox.UI

Menuclass

One entry in a menu, and the menu it opens. A menu with no options is a plain command; give it options and it becomes a submenu. A root menu with no parent is a context menu, or a heading in a `Sandbox.UI.MenuBar`.

object→Panel→Menu
Namespace
Sandbox.UI
Assembly
Sandbox.Engine
Declaration
public class Sandbox.UI.Menu : Sandbox.UI.Panel

Constructors2

Showing 2 constructors

Methods20

Showing 20 methods

public void Activate()PUBLIC

Do what a click on this row does. A submenu row opens, a checkable row toggles, a command runs and takes the whole menu down with it.

Returns:void—

public Sandbox.UI.Menu AddMenu(string text, string icon = null)PUBLIC

Add a submenu. Same as `Sandbox.UI.Menu.AddOption(System.String,System.String,System.Action)` without an action.

ParameterTypeDescription
textstring—
icon = nullstring—
Returns:Menu—

public Sandbox.UI.Menu AddSeparator()PUBLIC

Add a line between rows.

Returns:Menu—

public T AddWidget(T widget)PUBLIC

Add any panel as a row - a text entry, a slider, a heading. It's shown in the list like an option but the menu leaves it alone.

ParameterTypeDescription
widgetT—
Returns:T—

public void Clear()PUBLIC

Delete every row.

Returns:void—

public void Close()PUBLIC

Hide this menu's options, and any open submenus.

Returns:void—

public Sandbox.UI.Menu FindOption(string text)PUBLIC

The first option with this text, or null.

ParameterTypeDescription
textstring—
Returns:Menu—

protected virtual void OnChildAdded(Sandbox.UI.Panel child)PROTECTEDVIRTUAL

A panel nested inside a menu - from Razor, or AddChild - is a row of it, not part of the row itself. It stays hidden in the row until the menu opens and moves it into the list.

ParameterTypeDescription
childPanel—
Returns:void—

public virtual void OnDeleted()PUBLICVIRTUAL

Returns:void—

public void Remove(Sandbox.UI.Panel row)PUBLIC

Take a row out without deleting it.

ParameterTypeDescription
rowPanel—
Returns:void—

Properties17

Showing 17 properties

public bool Sandbox.UI.Menu.Checkable { get; set; }PUBLICGETSET

Clicking toggles `Sandbox.UI.Menu.Checked` instead of running `Sandbox.UI.Menu.Clicked`.

Returns:bool—

public bool Sandbox.UI.Menu.Checked { get; set; }PUBLICGETSET

Shows a check mark in the gutter.

Returns:bool—

public System.Action Sandbox.UI.Menu.Clicked { get; set; }PUBLICGETSET

Runs when the row is activated.

Returns:Action—

public bool Sandbox.UI.Menu.Enabled { get; set; }PUBLICGETSET

A disabled row is dimmed and does nothing when clicked.

Returns:bool—

public bool Sandbox.UI.Menu.HasOptions { get; set; }PUBLICGETSET

Does this row open a submenu?

Returns:bool—

public Sandbox.UI.Menu Sandbox.UI.Menu.Highlighted { get; set; }PUBLICGETSET

The row with the keyboard or hover highlight, in this menu's list.

Returns:Menu—

public string Sandbox.UI.Menu.Icon { get; set; }PUBLICGETSET

Material icon shown in the gutter, before the text.

Returns:string—

public bool Sandbox.UI.Menu.IsOpen { get; set; }PUBLICGETSET

Whether this menu's options are showing.

Returns:bool—

public bool Sandbox.UI.Menu.IsSeparator { get; set; }PUBLICGETSET

Draws a line between rows instead of a row.

Returns:bool—

public System.Collections.Generic.IReadOnlyList`1<Sandbox.UI.Menu> Sandbox.UI.Menu.Options { get; set; }PUBLICGETSET

The option rows of this menu, in order.

Returns:IReadOnlyList<Menu>—

public Sandbox.UI.Menu Sandbox.UI.Menu.ParentMenu { get; set; }PUBLICGETSET

The menu this row is an option of. Null for a root menu.

Returns:Menu—

public Sandbox.UI.Menu Sandbox.UI.Menu.RootMenu { get; set; }PUBLICGETSET

The top of this menu tree.

Returns:Menu—

public System.Collections.Generic.IReadOnlyList`1<Sandbox.UI.Panel> Sandbox.UI.Menu.Rows { get; set; }PUBLICGETSET

Everything the list shows, in order - the options and any other panels added.

Returns:IReadOnlyList<Panel>—

public string Sandbox.UI.Menu.Shortcut { get; set; }PUBLICGETSET

Shortcut text drawn on the right, like "Ctrl+S". Display only - nothing dispatches it yet.

Returns:string—

public bool Sandbox.UI.Menu.StaysOpen { get; set; }PUBLICGETSET

Whether the menu stays up after this row is activated. Checkable rows do, so several can be flipped in one go; commands close the menu. Set it to say otherwise.

Returns:bool—

public string Sandbox.UI.Menu.Text { get; set; }PUBLICGETSET

The text shown on the row.

Returns:string—

public System.Action`1<bool> Sandbox.UI.Menu.Toggled { get; set; }PUBLICGETSET

Runs with the new state when a checkable row is toggled. Setting it makes the row checkable.

Returns:Action<bool>—

On this page

Constructorspublic Menu()public Menu(System.String text, System.String icon = null)Methodspublic System.Void Activate()public Sandbox.UI.Menu AddMenu(System.String text, System.String icon = null)public Sandbox.UI.Menu AddOption(Sandbox.UI.Menu option)public Sandbox.UI.Menu AddOption(System.String text, System.Action action)public Sandbox.UI.Menu AddOption(System.String text, System.Action`1<System.Boolean> toggled)public Sandbox.UI.Menu AddOption(System.String text, System.String icon = null, System.Action action = null)public Sandbox.UI.Menu AddSeparator()public T AddWidget(T widget)public System.Void Clear()public System.Void Close()public Sandbox.UI.Menu FindOption(System.String text)protected virtual System.Void OnChildAdded(Sandbox.UI.Panel child)protected virtual System.Void OnClick(Sandbox.UI.MousePanelEvent e)public virtual System.Void OnDeleted()protected virtual System.Void OnMouseMove(Sandbox.UI.MousePanelEvent e)protected virtual System.Void OnMouseOut(Sandbox.UI.MousePanelEvent e)protected virtual System.Void OnMouseOver(Sandbox.UI.MousePanelEvent e)public System.Void Open()public System.Void Open(Sandbox.UI.Panel source, Sandbox.UI.Popup.PositionMode position, System.Single offset = 0)public System.Void Remove(Sandbox.UI.Panel row)Propertiespublic System.Boolean Sandbox.UI.Menu.Checkable { get; set; }public System.Boolean Sandbox.UI.Menu.Checked { get; set; }public System.Action Sandbox.UI.Menu.Clicked { get; set; }public System.Boolean Sandbox.UI.Menu.Enabled { get; set; }public System.Boolean Sandbox.UI.Menu.HasOptions { get; set; }public Sandbox.UI.Menu Sandbox.UI.Menu.Highlighted { get; set; }public System.String Sandbox.UI.Menu.Icon { get; set; }public System.Boolean Sandbox.UI.Menu.IsOpen { get; set; }public System.Boolean Sandbox.UI.Menu.IsSeparator { get; set; }public System.Collections.Generic.IReadOnlyList`1<Sandbox.UI.Menu> Sandbox.UI.Menu.Options { get; set; }public Sandbox.UI.Menu Sandbox.UI.Menu.ParentMenu { get; set; }public Sandbox.UI.Menu Sandbox.UI.Menu.RootMenu { get; set; }public System.Collections.Generic.IReadOnlyList`1<Sandbox.UI.Panel> Sandbox.UI.Menu.Rows { get; set; }public System.String Sandbox.UI.Menu.Shortcut { get; set; }public System.Boolean Sandbox.UI.Menu.StaysOpen { get; set; }public System.String Sandbox.UI.Menu.Text { get; set; }public System.Action`1<System.Boolean> Sandbox.UI.Menu.Toggled { get; set; }Metadata