Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

BaseButton

繼承: Control < CanvasItem < Node < Object

被繼承: Button, LinkButton, TextureButton

GUI 按鈕的抽象基底類別。

說明

BaseButton 是 GUI 按鈕的抽象基底類別,本身不會顯示任何內容。

屬性

ActionMode

action_mode

1

ButtonGroup

button_group

BitField[MouseButtonMask]

button_mask

1

bool

button_pressed

false

bool

disabled

false

FocusMode

focus_mode

2 (overrides Control)

bool

keep_pressed_outside

false

Shortcut

shortcut

bool

shortcut_feedback

true

bool

shortcut_in_tooltip

true

bool

toggle_mode

false

方法

void

_pressed() virtual

void

_toggled(toggled_on: bool) virtual

DrawMode

get_draw_mode() const

bool

is_hovered() const

void

set_pressed_no_signal(pressed: bool)


訊號

button_down() 🔗

當開始按住按鈕時發出。


button_up() 🔗

當停止按住按鈕時發出。


pressed() 🔗

當按鈕被切換或按下時發出。若 action_modeACTION_MODE_BUTTON_PRESS,則在 button_down 觸發;否則在 button_up 觸發。

若需知道按鈕目前的按下狀態(且已啟用 toggle_mode),請改用 toggled


toggled(toggled_on: bool) 🔗

當按鈕於按下與正常狀態間剛完成切換時發出(僅在 toggle_mode 啟用時)。新狀態會包含於參數 toggled_on 中。


列舉

enum DrawMode: 🔗

DrawMode DRAW_NORMAL = 0

按鈕的正常狀態(未按下、未懸停、未切換且已啟用)。

DrawMode DRAW_PRESSED = 1

按鈕被按下的狀態。

DrawMode DRAW_HOVER = 2

按鈕處於滑鼠懸停的狀態。

DrawMode DRAW_DISABLED = 3

按鈕處於停用狀態。

DrawMode DRAW_HOVER_PRESSED = 4

按鈕同時處於懸停且按下的狀態。


enum ActionMode: 🔗

ActionMode ACTION_MODE_BUTTON_PRESS = 0

只需按下即可視為已點擊。

ActionMode ACTION_MODE_BUTTON_RELEASE = 1

需按下後再釋放才算一次點擊。


屬性說明

ActionMode action_mode = 1 🔗

決定按鈕被視為已點擊的時機。


ButtonGroup button_group 🔗

與此按鈕關聯的 ButtonGroup,不要與「節點群組」混淆。

注意: 如果為按鈕指定了 ButtonGroup,它將被設定為單選按鈕。


BitField[MouseButtonMask] button_mask = 1 🔗

二進位遮罩,用來指定此按鈕要回應哪些滑鼠鍵。

若要同時允許左鍵與右鍵點擊,請使用 MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT


bool button_pressed = false 🔗

  • void set_pressed(value: bool)

  • bool is_pressed()

若為 true,表示按鈕處於按下狀態,或在 toggle_mode 啟用時處於切換狀態。僅在 toggle_modetrue 時有效。

注意: 直接修改 button_pressed 會觸發 toggled。若要在不發出該訊號的情況下改變狀態,請使用 set_pressed_no_signal()


bool disabled = false 🔗

  • void set_disabled(value: bool)

  • bool is_disabled()

If true, the button is in disabled state and can't be clicked or toggled.

Note: If the button is disabled while held down, button_up will be emitted.


bool keep_pressed_outside = false 🔗

  • void set_keep_pressed_outside(value: bool)

  • bool is_keep_pressed_outside()

若為 true,按下按鈕後即使將游標移出按鈕區域,按鈕仍保持按下狀態。

注意: 此屬性僅影響視覺效果,訊號的觸發時機不受其影響。


Shortcut shortcut 🔗

與此按鈕關聯的 Shortcut


bool shortcut_feedback = true 🔗

  • void set_shortcut_feedback(value: bool)

  • bool is_shortcut_feedback()

若為 true,當其快捷鍵被觸發時,按鈕會短暫反白。若為 falsetoggle_modefalse,快捷鍵將在無視覺回饋下觸發。


bool shortcut_in_tooltip = true 🔗

  • void set_shortcut_in_tooltip(value: bool)

  • bool is_shortcut_in_tooltip_enabled()

If true, the button will add information about its shortcut in the tooltip. This includes the shortcut's events and its Resource.resource_name. If both events and name are empty, the shortcut will not be included.

Note: This property does nothing when the tooltip control is customized using Control._make_custom_tooltip().


bool toggle_mode = false 🔗

  • void set_toggle_mode(value: bool)

  • bool is_toggle_mode()

若為 true,按鈕進入切換模式:每次點擊都會在按下/彈起狀態間切換。


方法說明

void _pressed() virtual 🔗

當按下按鈕時呼叫。如果你需要得知按鈕的按下狀態(且已啟用 toggle_mode),請改用 _toggled()


void _toggled(toggled_on: bool) virtual 🔗

當按鈕被切換時呼叫(僅在 toggle_mode 啟用時)。


DrawMode get_draw_mode() const 🔗

傳回用於繪製按鈕的視覺狀態。通常於覆寫 _draw() 或連接「draw」訊號,實作自訂繪製程式碼時使用。按鈕的視覺狀態由 DrawMode 列舉定義。


bool is_hovered() const 🔗

若滑鼠已進入按鈕且尚未離開,則返回 true


void set_pressed_no_signal(pressed: bool) 🔗

變更按鈕的 button_pressed 狀態而不觸發 toggled。當你只想改變狀態而不送出按下事件(例如在初始化場景時)可使用此方法。僅在 toggle_modetrue 時有效。

注意: 這個方法不會將 button_group 內的其他按鈕彈起。