Button
Button with text, an icon and theme-based styling.
Button adds visuals to BaseButton behavior. Use Pressed for an action; enable ToggleMode and use Toggled for a persistent setting. Text and Icon define content; theme resources define state styles, fonts, colors and spacing. Defaults are centered text, left/vertically centered icon and MouseFilter = Stop.
Why a long button will not shrink: without ClipText, trimming or wrapping, text width contributes to minimum size. For a single-line ellipsis button, set TextOverrunBehavior = TextServer.OverrunBehavior.TrimEllipsisForce and constrain available width through parent layout. ClipText alone permits clipping without adding an ellipsis. CustomMinimumSize, icon size and StyleBox margins still constrain size.
AutowrapMode enables wrapping; WordSmart wraps words and breaks oversized fragments. Available width must be defined or there is no reason to wrap. Wrapping changes required height; avoid fixed heights for translations of different lengths. AutowrapTrimFlags only controls spaces at line edges: unrelated LineBreakFlag bits are discarded.
With ExpandIcon = false, source icon size contributes to minimum size; theme constant icon_max_width caps it while preserving aspect ratio. ExpandIcon = true fits the icon into available space and removes its source size from the minimum, without automatically creating spare room. IconAlignment and VerticalIconAlignment are independent of text Alignment; top/bottom icons can require additional height.
Icon = null can use the theme icon named icon. GetButtonIcon therefore returns only the explicitly assigned texture rather than necessarily the one drawn. The icon resource is shared and changes are observed. Flat suppresses background StyleBoxes while retaining separate focus styling, sizing and input handling. Use consistent state-style margins for stable sizing.
GetText returns source text rather than its translation or trimmed display. Language sets shaping language rather than switching the application locale. TextDirection sets paragraph direction; horizontal icon/text alignment mirroring follows the Control’s LayoutDirection.
Assign a shared Shortcut resource for a key binding. MatchesEvent can also match release events: matching alone is not button activation. BaseButton additionally checks pressing, echo, visibility and Disabled.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
ButtonConstructor
public Button();Creates a button with empty Text, no explicit Icon, Alignment = Center, IconAlignment = Left and VerticalIconAlignment = Center. Flat/ClipText/ExpandIcon are off; MouseFilter = Stop.
Properties13
AlignmentProperty
public HorizontalAlignment Alignment { get; set; }Horizontal text alignment, default Center. Left/Right mirror with the Control’s RTL LayoutDirection. Does not position the button in its parent or replace IconAlignment.
AutowrapModeProperty
public TextServer.AutowrapMode AutowrapMode { get; set; }Wrapping mode, default Off. Word/WordSmart use word boundaries; Arbitrary uses grapheme boundaries. Requires bounded available width. Releases natural text minimum width but can increase required height.
AutowrapTrimFlagsProperty
public TextServer.LineBreakFlag AutowrapTrimFlags { get; set; }Line-edge space trimming bits; default TrimEndEdgeSpaces. Only TrimStartEdgeSpaces/TrimEndEdgeSpaces are retained; other LineBreakFlag bits are discarded. AutowrapMode separately selects wrapping.
ClipTextProperty
public bool ClipText { get; set; }Permits text clipping and removes natural text width from minimum size, default false. Does not add an ellipsis or remove style margins, icon size or CustomMinimumSize.
ExpandIconProperty
public bool ExpandIcon { get; set; }Fit the icon into available space while preserving aspect ratio, default false. true removes source icon size from minimum size. Theme icon_max_width still applies; layout determines available space.
FlatProperty
public bool Flat { get; set; }Suppress background StyleBoxes, default false. Separate focus style still draws; minimum size, style margins, click handling and Disabled keep their usual behavior.
IconProperty
public Texture2D Icon { get; set; }Explicit shared Texture2D, or null. With null, display can use the theme icon named icon. Resource is not copied and changes are observed. Minimum-size contribution depends on ExpandIcon and icon_max_width.
IconAlignmentProperty
public HorizontalAlignment IconAlignment { get; set; }Horizontal icon alignment, default Left. Left/Right mirror in RTL. Center changes shared-space calculation rather than automatically adding icon/text padding.
LanguageProperty
public string Language { get; set; }Shaping language; empty uses the Control locale. A text-processing hint rather than an application-locale switch or a translated Text result.
TextProperty
public string Text { get; set; }Source label text, empty by default. Display can be translated, wrapped and trimmed; the getter returns the source. Changes refresh shaping and minimum size. Plain text rather than BBCode markup.
TextDirectionProperty
public Control.TextDirection TextDirection { get; set; }Text-processing direction, default Auto. Inherited uses Control layout direction. Does not replace LayoutDirection for mirroring icon placement and horizontal alignment.
TextOverrunBehaviorProperty
public TextServer.OverrunBehavior TextOverrunBehavior { get; set; }Trimming when width is insufficient, default NoTrimming. TrimChar/TrimWord trim; Ellipsis modes add an ellipsis under their conditions, while Force permits short-label ellipses. Does not change source Text and requires a bounded area.
VerticalIconAlignmentProperty
public VerticalAlignment VerticalIconAlignment { get; set; }Vertical icon alignment, default Center. Top/Bottom can add text and icon heights, increasing minimum size. Does not change parent-layout alignment of the Control.
Methods26
GetAutowrapModeTextServer.AutowrapMode
public TextServer.AutowrapMode GetAutowrapMode();Wrapping mode, default Off. Word/WordSmart use word boundaries; Arbitrary uses grapheme boundaries. Requires bounded available width. Releases natural text minimum width but can increase required height.
TextServer.AutowrapModeSelected TextServer.AutowrapMode.
GetAutowrapTrimFlagsTextServer.LineBreakFlag
public TextServer.LineBreakFlag GetAutowrapTrimFlags();Line-edge space trimming bits; default TrimEndEdgeSpaces. Only TrimStartEdgeSpaces/TrimEndEdgeSpaces are retained; other LineBreakFlag bits are discarded. AutowrapMode separately selects wrapping.
TextServer.LineBreakFlagStored line-edge space trimming bits.
GetButtonIconTexture2D
public Texture2D GetButtonIcon();Explicit shared Texture2D, or null. With null, display can use the theme icon named icon. Resource is not copied and changes are observed. Minimum-size contribution depends on ExpandIcon and icon_max_width.
Texture2DExplicit shared Texture2D, or null even when a theme icon is drawn.
GetClipTextbool
public bool GetClipText();Permits text clipping and removes natural text width from minimum size, default false. Does not add an ellipsis or remove style margins, icon size or CustomMinimumSize.
booltrue when text clipping is enabled.
GetIconAlignmentHorizontalAlignment
public HorizontalAlignment GetIconAlignment();Horizontal icon alignment, default Left. Left/Right mirror in RTL. Center changes shared-space calculation rather than automatically adding icon/text padding.
HorizontalAlignmentHorizontal icon alignment before RTL mirroring.
GetLanguagestring
public string GetLanguage();Shaping language; empty uses the Control locale. A text-processing hint rather than an application-locale switch or a translated Text result.
stringStored language code, or empty for the Control locale.
GetTextstring
public string GetText();Source label text, empty by default. Display can be translated, wrapped and trimmed; the getter returns the source. Changes refresh shaping and minimum size. Plain text rather than BBCode markup.
stringSource string before translation and trimming.
GetTextAlignmentHorizontalAlignment
public HorizontalAlignment GetTextAlignment();Horizontal text alignment, default Center. Left/Right mirror with the Control’s RTL LayoutDirection. Does not position the button in its parent or replace IconAlignment.
HorizontalAlignmentHorizontal text alignment before RTL mirroring.
GetTextDirectionControl.TextDirection
public Control.TextDirection GetTextDirection();Text-processing direction, default Auto. Inherited uses Control layout direction. Does not replace LayoutDirection for mirroring icon placement and horizontal alignment.
Control.TextDirectionStored Control.TextDirection.
GetTextOverrunBehaviorTextServer.OverrunBehavior
public TextServer.OverrunBehavior GetTextOverrunBehavior();Trimming when width is insufficient, default NoTrimming. TrimChar/TrimWord trim; Ellipsis modes add an ellipsis under their conditions, while Force permits short-label ellipses. Does not change source Text and requires a bounded area.
TextServer.OverrunBehaviorSelected TextServer.OverrunBehavior.
GetVerticalIconAlignmentVerticalAlignment
public VerticalAlignment GetVerticalIconAlignment();Vertical icon alignment, default Center. Top/Bottom can add text and icon heights, increasing minimum size. Does not change parent-layout alignment of the Control.
VerticalAlignmentStored vertical icon alignment.
IsExpandIconbool
public bool IsExpandIcon();Fit the icon into available space while preserving aspect ratio, default false. true removes source icon size from minimum size. Theme icon_max_width still applies; layout determines available space.
booltrue when the icon is fitted to available space.
IsFlatbool
public bool IsFlat();Suppress background StyleBoxes, default false. Separate focus style still draws; minimum size, style margins, click handling and Disabled keep their usual behavior.
booltrue when background StyleBoxes are suppressed.
SetAutowrapModevoid
public void SetAutowrapMode(TextServer.AutowrapMode autowrapMode);Wrapping mode, default Off. Word/WordSmart use word boundaries; Arbitrary uses grapheme boundaries. Requires bounded available width. Releases natural text minimum width but can increase required height.
| Name | Type | Default |
|---|---|---|
autowrapMode | TextServer.AutowrapMode | — |
autowrapModeWrapping mode, default Off. Word/WordSmart use word boundaries; Arbitrary uses grapheme boundaries. Requires bounded available width. Releases natural text minimum width but can increase required height.
SetAutowrapTrimFlagsvoid
public void SetAutowrapTrimFlags(TextServer.LineBreakFlag autowrapTrimFlags);Line-edge space trimming bits; default TrimEndEdgeSpaces. Only TrimStartEdgeSpaces/TrimEndEdgeSpaces are retained; other LineBreakFlag bits are discarded. AutowrapMode separately selects wrapping.
| Name | Type | Default |
|---|---|---|
autowrapTrimFlags | TextServer.LineBreakFlag | — |
autowrapTrimFlagsLine-edge space trimming bits; default TrimEndEdgeSpaces. Only TrimStartEdgeSpaces/TrimEndEdgeSpaces are retained; other LineBreakFlag bits are discarded. AutowrapMode separately selects wrapping.
SetButtonIconvoid
public void SetButtonIcon(Texture2D texture);Explicit shared Texture2D, or null. With null, display can use the theme icon named icon. Resource is not copied and changes are observed. Minimum-size contribution depends on ExpandIcon and icon_max_width.
| Name | Type | Default |
|---|---|---|
texture | Texture2D | — |
textureExplicit shared Texture2D, or null. With null, display can use the theme icon named icon. Resource is not copied and changes are observed. Minimum-size contribution depends on ExpandIcon and icon_max_width.
SetClipTextvoid
public void SetClipText(bool enabled);Permits text clipping and removes natural text width from minimum size, default false. Does not add an ellipsis or remove style margins, icon size or CustomMinimumSize.
| Name | Type | Default |
|---|---|---|
enabled | bool | — |
enabledPermits text clipping and removes natural text width from minimum size, default false. Does not add an ellipsis or remove style margins, icon size or CustomMinimumSize.
SetExpandIconvoid
public void SetExpandIcon(bool enabled);Fit the icon into available space while preserving aspect ratio, default false. true removes source icon size from minimum size. Theme icon_max_width still applies; layout determines available space.
| Name | Type | Default |
|---|---|---|
enabled | bool | — |
enabledFit the icon into available space while preserving aspect ratio, default false. true removes source icon size from minimum size. Theme icon_max_width still applies; layout determines available space.
SetFlatvoid
public void SetFlat(bool enabled);Suppress background StyleBoxes, default false. Separate focus style still draws; minimum size, style margins, click handling and Disabled keep their usual behavior.
| Name | Type | Default |
|---|---|---|
enabled | bool | — |
enabledSuppress background StyleBoxes, default false. Separate focus style still draws; minimum size, style margins, click handling and Disabled keep their usual behavior.
SetIconAlignmentvoid
public void SetIconAlignment(HorizontalAlignment iconAlignment);Horizontal icon alignment, default Left. Left/Right mirror in RTL. Center changes shared-space calculation rather than automatically adding icon/text padding.
| Name | Type | Default |
|---|---|---|
iconAlignment | HorizontalAlignment | — |
iconAlignmentHorizontal icon alignment, default Left. Left/Right mirror in RTL. Center changes shared-space calculation rather than automatically adding icon/text padding.
SetLanguagevoid
public void SetLanguage(string language);Shaping language; empty uses the Control locale. A text-processing hint rather than an application-locale switch or a translated Text result.
| Name | Type | Default |
|---|---|---|
language | string | — |
languageShaping language; empty uses the Control locale. A text-processing hint rather than an application-locale switch or a translated Text result.
SetTextvoid
public void SetText(string text);Source label text, empty by default. Display can be translated, wrapped and trimmed; the getter returns the source. Changes refresh shaping and minimum size. Plain text rather than BBCode markup.
| Name | Type | Default |
|---|---|---|
text | string | — |
textSource label text, empty by default. Display can be translated, wrapped and trimmed; the getter returns the source. Changes refresh shaping and minimum size. Plain text rather than BBCode markup.
SetTextAlignmentvoid
public void SetTextAlignment(HorizontalAlignment alignment);Horizontal text alignment, default Center. Left/Right mirror with the Control’s RTL LayoutDirection. Does not position the button in its parent or replace IconAlignment.
| Name | Type | Default |
|---|---|---|
alignment | HorizontalAlignment | — |
alignmentHorizontal text alignment, default Center. Left/Right mirror with the Control’s RTL LayoutDirection. Does not position the button in its parent or replace IconAlignment.
SetTextDirectionvoid
public void SetTextDirection(Control.TextDirection direction);Text-processing direction, default Auto. Inherited uses Control layout direction. Does not replace LayoutDirection for mirroring icon placement and horizontal alignment.
| Name | Type | Default |
|---|---|---|
direction | Control.TextDirection | — |
directionText-processing direction, default Auto. Inherited uses Control layout direction. Does not replace LayoutDirection for mirroring icon placement and horizontal alignment.
SetTextOverrunBehaviorvoid
public void SetTextOverrunBehavior(TextServer.OverrunBehavior overrunBehavior);Trimming when width is insufficient, default NoTrimming. TrimChar/TrimWord trim; Ellipsis modes add an ellipsis under their conditions, while Force permits short-label ellipses. Does not change source Text and requires a bounded area.
| Name | Type | Default |
|---|---|---|
overrunBehavior | TextServer.OverrunBehavior | — |
overrunBehaviorTrimming when width is insufficient, default NoTrimming. TrimChar/TrimWord trim; Ellipsis modes add an ellipsis under their conditions, while Force permits short-label ellipses. Does not change source Text and requires a bounded area.
SetVerticalIconAlignmentvoid
public void SetVerticalIconAlignment(VerticalAlignment verticalIconAlignment);Vertical icon alignment, default Center. Top/Bottom can add text and icon heights, increasing minimum size. Does not change parent-layout alignment of the Control.
| Name | Type | Default |
|---|---|---|
verticalIconAlignment | VerticalAlignment | — |
verticalIconAlignmentVertical icon alignment, default Center. Top/Bottom can add text and icon heights, increasing minimum size. Does not change parent-layout alignment of the Control.
Theme properties
These are Theme resource keys, not C# properties. Use the matching Control GetTheme…() and AddTheme…Override() methods for each value type.
| Key and type | Description |
|---|---|
font_colorColor | Default text Color(0.875, 0.875, 0.875, 1) |
font_disabled_colorColor | Text Color(0.875, 0.875, 0.875, 0.5) |
font_focus_colorColor | Text Color(0.95, 0.95, 0.95, 1) |
font_hover_colorColor | Text Color(0.95, 0.95, 0.95, 1) |
font_hover_pressed_colorColor | Text Color(1, 1, 1, 1) |
font_outline_colorColor | The tint of text outline of the Color(0, 0, 0, 1) |
font_pressed_colorColor | Text Color(1, 1, 1, 1) |
icon_disabled_colorColor | Icon modulate Color(1, 1, 1, 0.4) |
icon_focus_colorColor | Icon modulate Color(1, 1, 1, 1) |
icon_hover_colorColor | Icon modulate Color(1, 1, 1, 1) |
icon_hover_pressed_colorColor | Icon modulate Color(1, 1, 1, 1) |
icon_normal_colorColor | Default icon modulate Color(1, 1, 1, 1) |
icon_pressed_colorColor | Icon modulate Color(1, 1, 1, 1) |
align_to_largest_styleboxint | This constant acts as a boolean. If 0 |
h_separationint | The horizontal space between 4 |
icon_max_widthint | The maximum allowed width of the 0 |
line_spacingint | Additional vertical spacing between lines (in pixels), spacing is added to line descent. This value can be negative. Default:0 |
outline_sizeint | The size of the text outline.
Note: If using a font with 0 |
fontFont | |
font_sizeint | Font size of the |
iconTexture2D | Default icon for the |
disabledStyleBox | |
disabled_mirroredStyleBox |
|
focusStyleBox |
|
hoverStyleBox | |
hover_mirroredStyleBox |
|
hover_pressedStyleBox |
|
hover_pressed_mirroredStyleBox |
|
normalStyleBox | |
normal_mirroredStyleBox | Default |
pressedStyleBox | |
pressed_mirroredStyleBox |
|