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...
StyleBox
继承: Resource < RefCounted < Object
派生: StyleBoxEmpty, StyleBoxFlat, StyleBoxLine, StyleBoxTexture
用于为 UI 元素定义风格化方框的抽象基类。
描述
样式盒 StyleBox 是一个为 UI 元素定义风格化方框的抽象基类。常用于面板、按钮、LineEdit 的背景、Tree 的背景等,也用于针对指针信号检查透明掩码。如果 StyleBox 是某个控件的掩码,而掩码检查失败,则点击和运动信号会穿透这个控件进入下方控件。
注意:对于有主题属性的控件节点,名为 focus
的 StyleBox 会显示在名为 normal
、hover
、pressed
的 StyleBox之上。这样的行为有助于 focus
StyleBox 在不同节点上复用。
属性
|
||
|
||
|
||
|
方法
void |
|
_get_draw_rect(rect: Rect2) virtual const |
|
_get_minimum_size() virtual const |
|
_test_mask(point: Vector2, rect: Rect2) virtual const |
|
void |
|
get_content_margin(margin: Side) const |
|
get_current_item_drawn() const |
|
get_margin(margin: Side) const |
|
get_minimum_size() const |
|
get_offset() const |
|
void |
set_content_margin(margin: Side, offset: float) |
void |
set_content_margin_all(offset: float) |
属性说明
float content_margin_bottom = -1.0
🔗
该样式盒内容的底边距。增加该值会从底部减少内容的可用空间。
如果该值为负,则忽略该值并使用特定于子项的边距。例如,对于 StyleBoxFlat,(如果有厚度的话)将使用边框厚度。
内容是什么由使用该样式盒的代码决定:例如,Button 会为其文本内容设置该内容边距。
应使用 get_margin() 作为消费者获取该值,而不是直接读取这些属性。这是因为它能够正确地尊重负值和上面提到的后备值。
float content_margin_left = -1.0
🔗
该样式盒内容的左边距。增加该值会从左侧减少内容的可用空间。
额外的注意事项请参阅 content_margin_bottom。
float content_margin_right = -1.0
🔗
此样式盒内容的右边距。增加此值会从右侧减少内容的可用空间。
额外的注意事项请参阅 content_margin_bottom。
float content_margin_top = -1.0
🔗
此样式盒内容的顶边距。增加此值会从顶部减少内容的可用空间。
额外的注意事项请参阅 content_margin_bottom。
方法说明
void _draw(to_canvas_item: RID, rect: Rect2) virtual const 🔗
该方法目前没有描述,请帮我们贡献一个吧!
Rect2 _get_draw_rect(rect: Rect2) virtual const 🔗
该方法目前没有描述,请帮我们贡献一个吧!
Vector2 _get_minimum_size() virtual const 🔗
可以由用户实现的虚拟方法。样式盒在绘制时必须遵循所返回的自定义最小尺寸。默认情况下,get_minimum_size() 仅考虑边距。可以覆盖这个方法添加其他尺寸限制。会使用默认行为和这个方法输出的组合,两个大小均进行考虑。
bool _test_mask(point: Vector2, rect: Rect2) virtual const 🔗
该方法目前没有描述,请帮我们贡献一个吧!
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_DRAW 或 CanvasItem._draw() 回调的 CanvasItem。
float get_margin(margin: Side) const 🔗
返回指定边 Side 的内容边距偏移量。
与 Control 的边距不同,正值会向内减小大小。
Vector2 get_minimum_size() 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 🔗
测试矩形中的一个位置,返回它是否通过掩码测试。