Button

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 30 Imported by: 0

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

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 Any

type Any interface {
	gd.IsClass
	AsButton() Instance
}

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

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]) AsButton

func (self *Extension[T]) AsButton() Instance

func (*Extension[T]) AsCanvasItem

func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance

func (*Extension[T]) AsControl

func (self *Extension[T]) AsControl() Control.Instance

func (*Extension[T]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.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.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.Button

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 New

func New() Instance

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) AsButton

func (self Instance) AsButton() Instance

func (Instance) AsCanvasItem

func (self Instance) AsCanvasItem() CanvasItem.Instance

func (Instance) AsControl

func (self Instance) AsControl() Control.Instance

func (Instance) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

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

func (self Instance) ClipText() bool

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

func (self Instance) ExpandIcon() bool

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) Flat

func (self Instance) Flat() bool

Flat buttons don't display decoration.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) Icon

func (self Instance) Icon() Texture2D.Instance

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

func (self Instance) Language() string

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

func (self Instance) SetClipText(value bool)

SetClipText sets the property returned by [GetClipText].

func (Instance) SetExpandIcon

func (self Instance) SetExpandIcon(value bool)

SetExpandIcon sets the property returned by [IsExpandIcon].

func (Instance) SetFlat

func (self Instance) SetFlat(value bool)

SetFlat sets the property returned by [IsFlat].

func (Instance) SetIcon

func (self Instance) SetIcon(value Texture2D.Instance)

SetIcon sets the property returned by [GetButtonIcon].

func (Instance) SetIconAlignment

func (self Instance) SetIconAlignment(value GUI.HorizontalAlignment)

SetIconAlignment sets the property returned by [GetIconAlignment].

func (Instance) SetLanguage

func (self Instance) SetLanguage(value string)

SetLanguage sets the property returned by [GetLanguage].

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetText

func (self Instance) SetText(value string)

SetText sets the property returned by [GetText].

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) Text

func (self Instance) Text() string

The button's text that will be displayed inside the button's area.

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.

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL