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.

StyleBox

繼承: Resource < RefCounted < Object

被繼承: StyleBoxEmpty, StyleBoxFlat, StyleBoxLine, StyleBoxTexture

用於為 UI 元素定義風格化方框的抽象基底類別。

說明

樣式盒 StyleBox 是一個為 UI 元素定義風格化方框的抽象基底類別。常用於面板、按鈕、LineEdit 的背景、Tree 的背景等,也用於針對指標訊號檢查透明遮罩。如果 StyleBox 是某個控制項的遮罩,而遮罩檢查失敗,則點擊和運動訊號會穿透這個控制項進入下方控制項。

注意:對於有主題屬性的控制項節點,名為 focusStyleBox 會顯示在名為 normalhoverpressedStyleBox之上。這樣的行為有助於 focus StyleBox 在不同節點上複用。

屬性

float

content_margin_bottom

-1.0

float

content_margin_left

-1.0

float

content_margin_right

-1.0

float

content_margin_top

-1.0

方法

void

_draw(to_canvas_item: RID, rect: Rect2) virtual required const

Rect2

_get_draw_rect(rect: Rect2) virtual const

Vector2

_get_minimum_size() virtual const

bool

_test_mask(point: Vector2, rect: Rect2) virtual const

void

draw(canvas_item: RID, rect: Rect2) const

float

get_content_margin(margin: Side) const

CanvasItem

get_current_item_drawn() const

float

get_margin(margin: Side) const

Vector2

get_minimum_size() const

Vector2

get_offset() const

void

set_content_margin(margin: Side, offset: float)

void

set_content_margin_all(offset: float)

bool

test_mask(point: Vector2, rect: Rect2) const


屬性說明

float content_margin_bottom = -1.0 🔗

  • void set_content_margin(margin: Side, offset: float)

  • float get_content_margin(margin: Side) const

此樣式盒內容的底邊距。增加此值會從底部減少內容的可用空間。

如果此值為負,則將其忽略並改為使用特定於該子型別的邊距。例如,對於 StyleBoxFlat,(如果有厚度的話)將使用邊框厚度。

內容是什麼由使用此樣式盒的程式碼決定:例如 Button 會為其文字內容設定此內容邊距。

使用者應該通過 get_margin() 獲取邊距,而不是直接讀取單獨方向上的屬性。這是因為這個函式會正確處理負值和上述備用邏輯。


float content_margin_left = -1.0 🔗

  • void set_content_margin(margin: Side, offset: float)

  • float get_content_margin(margin: Side) const

此樣式盒內容的左邊距。增加此值會從左側減少內容的可用空間。

額外的注意事項請參閱 content_margin_bottom


float content_margin_right = -1.0 🔗

  • void set_content_margin(margin: Side, offset: float)

  • float get_content_margin(margin: Side) const

此樣式盒內容的右邊距。增加此值會從右側減少內容的可用空間。

額外的注意事項請參閱 content_margin_bottom


float content_margin_top = -1.0 🔗

  • void set_content_margin(margin: Side, offset: float)

  • float get_content_margin(margin: Side) const

此樣式盒內容的頂邊距。增加此值會從頂部減少內容的可用空間。

額外的注意事項請參閱 content_margin_bottom


方法說明

void _draw(to_canvas_item: RID, rect: Rect2) virtual required const 🔗

There is currently no description for this method. Please help us by contributing one!


Rect2 _get_draw_rect(rect: Rect2) virtual const 🔗

There is currently no description for this method. Please help us by contributing one!


Vector2 _get_minimum_size() virtual const 🔗

可以由使用者實作的虛擬方法。樣式盒在繪製時必須遵循所返回的自訂最小尺寸。預設情況下,get_minimum_size() 僅考慮邊距。可以覆蓋這個方法新增其他尺寸限制。會使用預設行為和這個方法輸出的組合,兩個大小均進行考慮。


bool _test_mask(point: Vector2, rect: Rect2) virtual const 🔗

There is currently no description for this method. Please help us by contributing one!


void draw(canvas_item: RID, rect: Rect2) const 🔗

使用由給定 RID 標識的畫布專案繪製此樣式盒。

RID 值可以通過在現有 CanvasItem 衍生節點上呼叫 CanvasItem.get_canvas_item() 得到,也可以在 RenderingServer 中使用 RenderingServer.canvas_item_create() 直接建立。


float get_content_margin(margin: Side) const 🔗

返回指定邊 Side 的預設邊距。


CanvasItem get_current_item_drawn() const 🔗

返回此時處理其 CanvasItem.NOTIFICATION_DRAWCanvasItem._draw() 回呼函式的 CanvasItem


float get_margin(margin: Side) const 🔗

返回指定邊 Side 的內容邊距偏移量。

Control 的邊距不同,正值會向內減小大小。


Vector2 get_minimum_size() const 🔗

返回此樣式盒可以縮小到的最小尺寸。


Vector2 get_offset() const 🔗

返回樣式盒的“偏移量”。這個輔助函式返回一個等價於 Vector2(style.get_margin(MARGIN_LEFT), style.get_margin(MARGIN_TOP)) 的值。


void set_content_margin(margin: Side, offset: float) 🔗

將指定邊 Side 的預設值設定為 offset 圖元。


void set_content_margin_all(offset: float) 🔗

將所有邊的預設邊距設定為 offset 圖元。


bool test_mask(point: Vector2, rect: Rect2) const 🔗

測試矩形中的一個位置,返回它是否通過遮罩測試。