BaseButton
Abstract base class for GUI buttons.
BaseButton.swift:25class BaseButton
BaseButton
is an abstract base class for GUI buttons. It doesn’t display anything by itself.
This object emits the following signals:
Superclasses
class Control
Base class for all GUI controls. Adapts its position and size based on its parent control.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
enum ActionMode
enum DrawMode
class Signal1
Signal support.
Type members
Instance members
var actionMode: BaseButton.ActionMode
Determines when the button is considered clicked, one of the
ActionMode
constants.var disabled: Bool
If
true
, the button is in disabled state and can’t be clicked or toggled.var keepPressedOutside: Bool
If
true
, the button stays pressed when moving the cursor outside the button while pressing it.var pressed: SimpleSignal
Emitted when the button is toggled or pressed. This is on [signal button_down] if
actionMode
is .buttonPress and on [signal button_up] otherwise.var shortcut: Shortcut?
Shortcut
associated to the button.var shortcutFeedback: Bool
If
true
, the button will highlight for a short amount of time when its shortcut is activated. Iffalse
andtoggleMode
isfalse
, the shortcut will activate without any visual feedback.var shortcutInTooltip: Bool
If
true
, the button will add information about its shortcut in the tooltip.var toggleMode: Bool
If
true
, the button is in toggle mode. Makes the button flip state between pressed and unpressed each time its area is clicked.var toggled: Signal1
Emitted when the button was just toggled between pressed and normal states (only if
toggleMode
is active). The new state is contained in thetoggledOn
argument.func getDrawMode(
) -> BaseButton.DrawMode Returns the visual state used to draw the button. This is useful mainly when implementing your own draw code by either overriding _draw() or connecting to “draw” signal. The visual state of the button is defined by the
DrawMode
enum.func isHovered(
) -> Bool Returns
true
if the mouse has entered the button and has not left it yet.func setPressedNoSignal(pressed: Bool
) Changes the
buttonPressed
state of the button, without emitting [signal toggled]. Use when you just want to change the state of the button without sending the pressed event (e.g. when initializing scene). Only works iftoggleMode
istrue
.
Show implementation details (2)
Hide implementation details
func _pressed(
) Called when the button is pressed. If you need to know the button’s pressed state (and
toggleMode
is active), use_toggled(toggledOn:)
instead.func _toggled(toggledOn: Bool
) Called when the button is toggled (only if
toggleMode
is active).
Subclasses
class Button
A themed button that can contain text and an icon.
class LinkButton
A button that represents a link.
class TextureButton
Texture-based button. Supports Pressed, Hover, Disabled and Focused states.