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.
Checking the stable version of the documentation...
BaseButton
繼承: Control < CanvasItem < Node < Object
被繼承: Button, LinkButton, TextureButton
GUI 按鈕的抽象基底類別。
說明
BaseButton 是 GUI 按鈕的抽象基底類別,本身不會顯示任何內容。
屬性
|
||
BitField[MouseButtonMask] |
|
|
|
||
|
||
focus_mode |
|
|
|
||
|
||
|
||
|
方法
void |
_pressed() virtual |
void |
|
get_draw_mode() const |
|
is_hovered() const |
|
void |
set_pressed_no_signal(pressed: bool) |
訊號
button_down() 🔗
當開始按住按鈕時發出。
button_up() 🔗
當停止按住按鈕時發出。
pressed() 🔗
當按鈕被切換或按下時發出。若 action_mode 為 ACTION_MODE_BUTTON_PRESS,則在 button_down 觸發;否則在 button_up 觸發。
若需知道按鈕目前的按下狀態(且已啟用 toggle_mode),請改用 toggled。
當按鈕於按下與正常狀態間剛完成切換時發出(僅在 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 🔗
void set_action_mode(value: ActionMode)
ActionMode get_action_mode()
決定按鈕被視為已點擊的時機。
ButtonGroup button_group 🔗
void set_button_group(value: ButtonGroup)
ButtonGroup get_button_group()
與此按鈕關聯的 ButtonGroup,不要與「節點群組」混淆。
注意: 如果為按鈕指定了 ButtonGroup,它將被設定為單選按鈕。
BitField[MouseButtonMask] button_mask = 1 🔗
void set_button_mask(value: BitField[MouseButtonMask])
BitField[MouseButtonMask] get_button_mask()
二進位遮罩,用來指定此按鈕要回應哪些滑鼠鍵。
若要同時允許左鍵與右鍵點擊,請使用 MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT。
若為 true,表示按鈕處於按下狀態,或在 toggle_mode 啟用時處於切換狀態。僅在 toggle_mode 為 true 時有效。
注意: 直接修改 button_pressed 會觸發 toggled。若要在不發出該訊號的情況下改變狀態,請使用 set_pressed_no_signal()。
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 🔗
若為 true,按下按鈕後即使將游標移出按鈕區域,按鈕仍保持按下狀態。
注意: 此屬性僅影響視覺效果,訊號的觸發時機不受其影響。
與此按鈕關聯的 Shortcut。
bool shortcut_feedback = true 🔗
若為 true,當其快捷鍵被觸發時,按鈕會短暫反白。若為 false 且 toggle_mode 為 false,快捷鍵將在無視覺回饋下觸發。
bool shortcut_in_tooltip = true 🔗
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().
若為 true,按鈕進入切換模式:每次點擊都會在按下/彈起狀態間切換。
方法說明
void _pressed() virtual 🔗
當按下按鈕時呼叫。如果你需要得知按鈕的按下狀態(且已啟用 toggle_mode),請改用 _toggled()。
void _toggled(toggled_on: bool) virtual 🔗
當按鈕被切換時呼叫(僅在 toggle_mode 啟用時)。
DrawMode get_draw_mode() const 🔗
傳回用於繪製按鈕的視覺狀態。通常於覆寫 _draw() 或連接「draw」訊號,實作自訂繪製程式碼時使用。按鈕的視覺狀態由 DrawMode 列舉定義。
若滑鼠已進入按鈕且尚未離開,則返回 true。
void set_pressed_no_signal(pressed: bool) 🔗
變更按鈕的 button_pressed 狀態而不觸發 toggled。當你只想改變狀態而不送出按下事件(例如在初始化場景時)可使用此方法。僅在 toggle_mode 為 true 時有效。
注意: 這個方法不會將 button_group 內的其他按鈕彈起。