Class BaseButton
- Namespace
- Godot
- Assembly
- GodotSharp.dll
BaseButton is an abstract base class for GUI buttons. It doesn't display anything by itself.
public class BaseButton : Control, IDisposable
- Inheritance
-
BaseButton
- Implements
- Derived
- Inherited Members
Constructors
BaseButton()
public BaseButton()
Properties
ActionMode
Determines when the button is considered clicked, one of the BaseButton.ActionModeEnum constants.
public BaseButton.ActionModeEnum ActionMode { get; set; }
Property Value
ButtonGroup
The ButtonGroup associated with the button. Not to be confused with node groups.
Note: The button will be configured as a radio button if a ButtonGroup is assigned to it.
public ButtonGroup ButtonGroup { get; set; }
Property Value
ButtonMask
Binary mask to choose which mouse buttons this button will respond to.
To allow both left-click and right-click, use MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT
.
public MouseButtonMask ButtonMask { get; set; }
Property Value
ButtonPressed
If true
, the button's state is pressed. Means the button is pressed down or toggled (if ToggleMode is active). Only works if ToggleMode is true
.
Note: Setting ButtonPressed will result in Toggled to be emitted. If you want to change the pressed state without emitting that signal, use SetPressedNoSignal(bool).
public bool ButtonPressed { get; set; }
Property Value
Disabled
If true
, the button is in disabled state and can't be clicked or toggled.
public bool Disabled { get; set; }
Property Value
KeepPressedOutside
If true
, the button stays pressed when moving the cursor outside the button while pressing it.
Note: This property only affects the button's visual appearance. Signals will be emitted at the same moment regardless of this property's value.
public bool KeepPressedOutside { get; set; }
Property Value
Shortcut
Shortcut associated to the button.
public Shortcut Shortcut { get; set; }
Property Value
ShortcutFeedback
If true
, the button will highlight for a short amount of time when its shortcut is activated. If false
and ToggleMode is false
, the shortcut will activate without any visual feedback.
public bool ShortcutFeedback { get; set; }
Property Value
ShortcutInTooltip
If true
, the button will add information about its shortcut in the tooltip.
public bool ShortcutInTooltip { get; set; }
Property Value
ToggleMode
If true
, the button is in toggle mode. Makes the button flip state between pressed and unpressed each time its area is clicked.
public bool ToggleMode { get; set; }
Property Value
Methods
GetDrawMode()
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 BaseButton.DrawMode enum.
public BaseButton.DrawMode GetDrawMode()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
IsHovered()
Returns true
if the mouse has entered the button and has not left it yet.
public bool IsHovered()
Returns
SetPressedNoSignal(bool)
Changes the ButtonPressed state of the button, without emitting 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 if ToggleMode is true
.
Note: This method doesn't unpress other buttons in ButtonGroup.
public void SetPressedNoSignal(bool pressed)
Parameters
pressed
bool
_Pressed()
Called when the button is pressed. If you need to know the button's pressed state (and ToggleMode is active), use _Toggled(bool) instead.
public virtual void _Pressed()
_Toggled(bool)
Called when the button is toggled (only if ToggleMode is active).
public virtual void _Toggled(bool toggledOn)
Parameters
toggledOn
bool
Events
ButtonDown
Emitted when the button starts being held down.
public event Action ButtonDown
Event Type
ButtonUp
Emitted when the button stops being held down.
public event Action ButtonUp
Event Type
Pressed
Emitted when the button is toggled or pressed. This is on ButtonDown if ActionMode is Press and on ButtonUp otherwise.
If you need to know the button's pressed state (and ToggleMode is active), use Toggled instead.
public event Action Pressed
Event Type
Toggled
Emitted when the button was just toggled between pressed and normal states (only if ToggleMode is active). The new state is contained in the toggledOn
argument.
public event BaseButton.ToggledEventHandler Toggled