Documentation
¶
Overview ¶
Button is the standard themed button. It can contain text and an icon, and it will display them according to the current Theme.
Example: Create a button and connect a method that will be called when the button is pressed:
package main import ( "graphics.gd/classdb/Button" "graphics.gd/classdb/Node" ) type ExampleForButton struct { Node.Extension[ExampleForButton] } func (eg *ExampleForButton) Ready() { button := Button.New() button.SetText("Click me") button.AsBaseButton().OnPressed(func() { print("Hello world!") }) eg.AsNode().AddChild(button.AsNode()) }
See also BaseButton which contains common properties and methods associated with this node.
Note: Buttons do not detect touch input and therefore don't support multitouch, since mouse emulation can only press one button at a given time. Use TouchScreenButton for buttons that trigger gameplay movement or actions.
Index ¶
- type Advanced
- type Any
- type Extension
- func (self *Extension[T]) AsBaseButton() BaseButton.Instance
- func (self *Extension[T]) AsButton() Instance
- func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance
- func (self *Extension[T]) AsControl() Control.Instance
- func (self *Extension[T]) AsNode() Node.Instance
- func (self *Extension[T]) AsObject() [1]gd.Object
- type ID
- type Instance
- func (self Instance) Alignment() GUI.HorizontalAlignment
- func (self Instance) AsBaseButton() BaseButton.Instance
- func (self Instance) AsButton() Instance
- func (self Instance) AsCanvasItem() CanvasItem.Instance
- func (self Instance) AsControl() Control.Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AutowrapMode() TextServer.AutowrapMode
- func (self Instance) AutowrapTrimFlags() TextServer.LineBreakFlag
- func (self Instance) ClipText() bool
- func (self Instance) ExpandIcon() bool
- func (self Instance) Flat() bool
- func (self Instance) ID() ID
- func (self Instance) Icon() Texture2D.Instance
- func (self Instance) IconAlignment() GUI.HorizontalAlignment
- func (self Instance) Language() string
- func (self Instance) SetAlignment(value GUI.HorizontalAlignment)
- func (self Instance) SetAutowrapMode(value TextServer.AutowrapMode)
- func (self Instance) SetAutowrapTrimFlags(value TextServer.LineBreakFlag)
- func (self Instance) SetClipText(value bool)
- func (self Instance) SetExpandIcon(value bool)
- func (self Instance) SetFlat(value bool)
- func (self Instance) SetIcon(value Texture2D.Instance)
- func (self Instance) SetIconAlignment(value GUI.HorizontalAlignment)
- func (self Instance) SetLanguage(value string)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetText(value string)
- func (self Instance) SetTextDirection(value Control.TextDirection)
- func (self Instance) SetTextOverrunBehavior(value TextServer.OverrunBehavior)
- func (self Instance) SetVerticalIconAlignment(value GUI.VerticalAlignment)
- func (self Instance) Text() string
- func (self Instance) TextDirection() Control.TextDirection
- func (self Instance) TextOverrunBehavior() TextServer.OverrunBehavior
- func (self Instance) VerticalIconAlignment() GUI.VerticalAlignment
- func (self Instance) Virtual(name string) reflect.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsBaseButton ¶
func (self *Extension[T]) AsBaseButton() BaseButton.Instance
func (*Extension[T]) AsCanvasItem ¶
func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) Alignment ¶
func (self Instance) Alignment() GUI.HorizontalAlignment
Text alignment policy for the button's text.
func (Instance) AsBaseButton ¶
func (self Instance) AsBaseButton() BaseButton.Instance
func (Instance) AsCanvasItem ¶
func (self Instance) AsCanvasItem() CanvasItem.Instance
func (Instance) AutowrapMode ¶
func (self Instance) AutowrapMode() TextServer.AutowrapMode
If set to something other than [Textserver.AutowrapOff], the text gets wrapped inside the node's bounding rectangle.
func (Instance) AutowrapTrimFlags ¶
func (self Instance) AutowrapTrimFlags() TextServer.LineBreakFlag
Autowrap space trimming flags. See [Textserver.BreakTrimStartEdgeSpaces] and [Textserver.BreakTrimEndEdgeSpaces] for more info.
func (Instance) ClipText ¶
If true, text that is too large to fit the button is clipped horizontally. If false, the button will always be wide enough to hold the text. The text is not vertically clipped, and the button's height is not affected by this property.
func (Instance) ExpandIcon ¶
When enabled, the button's icon will expand/shrink to fit the button's size while keeping its aspect. See also theme's 'icon_max_width'.
func (Instance) Icon ¶
Button's icon, if text is present the icon will be placed before the text.
To edit margin and spacing of the icon, use theme's 'h_separation' theme property and content_margin_* properties of the used StyleBoxes.
func (Instance) IconAlignment ¶
func (self Instance) IconAlignment() GUI.HorizontalAlignment
Specifies if the icon should be aligned horizontally to the left, right, or center of a button. Uses the same [HorizontalAlignment] constants as the text alignment. If centered horizontally and vertically, text will draw on top of the icon.
func (Instance) Language ¶
Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
func (Instance) SetAlignment ¶
func (self Instance) SetAlignment(value GUI.HorizontalAlignment)
SetAlignment sets the property returned by [GetTextAlignment].
func (Instance) SetAutowrapMode ¶
func (self Instance) SetAutowrapMode(value TextServer.AutowrapMode)
SetAutowrapMode sets the property returned by [GetAutowrapMode].
func (Instance) SetAutowrapTrimFlags ¶
func (self Instance) SetAutowrapTrimFlags(value TextServer.LineBreakFlag)
SetAutowrapTrimFlags sets the property returned by [GetAutowrapTrimFlags].
func (Instance) SetClipText ¶
SetClipText sets the property returned by [GetClipText].
func (Instance) SetExpandIcon ¶
SetExpandIcon sets the property returned by [IsExpandIcon].
func (Instance) SetIconAlignment ¶
func (self Instance) SetIconAlignment(value GUI.HorizontalAlignment)
SetIconAlignment sets the property returned by [GetIconAlignment].
func (Instance) SetLanguage ¶
SetLanguage sets the property returned by [GetLanguage].
func (Instance) SetTextDirection ¶
func (self Instance) SetTextDirection(value Control.TextDirection)
SetTextDirection sets the property returned by [GetTextDirection].
func (Instance) SetTextOverrunBehavior ¶
func (self Instance) SetTextOverrunBehavior(value TextServer.OverrunBehavior)
SetTextOverrunBehavior sets the property returned by [GetTextOverrunBehavior].
func (Instance) SetVerticalIconAlignment ¶
func (self Instance) SetVerticalIconAlignment(value GUI.VerticalAlignment)
SetVerticalIconAlignment sets the property returned by [GetVerticalIconAlignment].
func (Instance) TextDirection ¶
func (self Instance) TextDirection() Control.TextDirection
Base text writing direction.
func (Instance) TextOverrunBehavior ¶
func (self Instance) TextOverrunBehavior() TextServer.OverrunBehavior
Sets the clipping behavior when the text exceeds the node's bounding rectangle.
func (Instance) VerticalIconAlignment ¶
func (self Instance) VerticalIconAlignment() GUI.VerticalAlignment
Specifies if the icon should be aligned vertically to the top, bottom, or center of a button. Uses the same [VerticalAlignment] constants as the text alignment. If centered horizontally and vertically, text will draw on top of the icon.