Method Button
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
Button(string?, string?, Action?, string?, string?, string?, bool?, StyleOverrides?, Func<VisualElement, Action>?, Func<VisualElement, VisualElement>?, string?, string?, string?, VNode?[]?, IReadOnlyDictionary<string, string>?, IReadOnlyDictionary<string, string>?)
Creates a Button.
text and children can be combined. UI Toolkit's Button inherits from TextElement and
keeps the text property and child VisualElements independently, so use children when
declaring multiple children (e.g. icon + label) and text for text-only buttons.
public static ElementNode Button(string? className = null, string? text = null, Action? onClick = null, string? key = null, string? name = null, string? tooltip = null, bool? enabled = null, StyleOverrides? styles = null, Func<VisualElement, Action>? refCallback = null, Func<VisualElement, VisualElement>? wrapElement = null, string? whileHoverClass = null, string? whileTapClass = null, string? whileFocusClass = null, VNode?[]? children = null, IReadOnlyDictionary<string, string>? data = null, IReadOnlyDictionary<string, string>? aria = null)
Parameters
classNamestringCSS-like utility class string. Multiple classes separated by spaces.
textstringButton label text. Coexists with
children.onClickActionClick handler. When null, no click event is bound.
keystringKey used to disambiguate siblings at the same position.
namestringElement name assigned to UnityEngine.UIElements.VisualElement.name for query/debug.
tooltipstringTooltip string shown on hover.
enabledbool?When false, disables the button (greyed out, no click).
stylesStyleOverridesInline style overrides applied on top of USS classes.
refCallbackFunc<VisualElement, Action>Callback invoked on mount with the created VisualElement; returned Action runs on unmount.
wrapElementFunc<VisualElement, VisualElement>Optional wrapper that returns a parent VisualElement enclosing the button (e.g. for shadow effects).
whileHoverClassstringUSS class toggled while the pointer hovers the element.
whileTapClassstringUSS class toggled while the pointer is pressed on the element.
whileFocusClassstringUSS class toggled while the element holds keyboard/UI focus.
childrenVNode[]Child VNodes (e.g. icon + label) rendered inside the button.
dataIReadOnlyDictionary<string, string>data-* attribute map matched by
data-[...]variants.ariaIReadOnlyDictionary<string, string>aria-* attribute map matched by
aria-[...]variants.
Returns
- ElementNode
The created ElementNode representing this button.
Button(string, params VNode?[])
Shorthand overload: positional className + variadic
children, building a Button with just a class string and children (e.g. an
icon + label). For any other prop — notably onClick — use the long-form overload
with named arguments.
public static ElementNode Button(string className, params VNode?[] children)
Parameters
classNamestringCSS-like utility class string. Multiple classes separated by spaces.
childrenVNode[]Child VNodes; pass zero or more positionals or expand an existing array.
Returns
- ElementNode
The created ElementNode.