Class StyleBox
- Namespace
- Godot
- Assembly
- GodotSharp.dll
StyleBox is an abstract base class for drawing stylized boxes for UI elements. It is used for panels, buttons, LineEdit backgrounds, Tree backgrounds, etc. and also for testing a transparency mask for pointer signals. If mask test fails on a StyleBox assigned as mask to a control, clicks and motion signals will go through it to the one below.
Note: For control nodes that have Theme Properties, the focus
StyleBox is displayed over the normal
, hover
or pressed
StyleBox. This makes the focus
StyleBox more reusable across different nodes.
public class StyleBox : Resource, IDisposable
- Inheritance
-
StyleBox
- Implements
- Derived
- Inherited Members
Constructors
StyleBox()
public StyleBox()
Properties
ContentMarginBottom
The bottom margin for the contents of this style box. Increasing this value reduces the space available to the contents from the bottom.
If this value is negative, it is ignored and a child-specific margin is used instead. For example, for StyleBoxFlat, the border thickness (if any) is used instead.
It is up to the code using this style box to decide what these contents are: for example, a Button respects this content margin for the textual contents of the button.
GetMargin(Side) should be used to fetch this value as consumer instead of reading these properties directly. This is because it correctly respects negative values and the fallback mentioned above.
public float ContentMarginBottom { get; set; }
Property Value
ContentMarginLeft
The left margin for the contents of this style box. Increasing this value reduces the space available to the contents from the left.
Refer to ContentMarginBottom for extra considerations.
public float ContentMarginLeft { get; set; }
Property Value
ContentMarginRight
The right margin for the contents of this style box. Increasing this value reduces the space available to the contents from the right.
Refer to ContentMarginBottom for extra considerations.
public float ContentMarginRight { get; set; }
Property Value
ContentMarginTop
The top margin for the contents of this style box. Increasing this value reduces the space available to the contents from the top.
Refer to ContentMarginBottom for extra considerations.
public float ContentMarginTop { get; set; }
Property Value
Methods
Draw(Rid, Rect2)
Draws this stylebox using a canvas item identified by the given Rid.
The Rid value can either be the result of GetCanvasItem() called on an existing CanvasItem-derived node, or directly from creating a canvas item in the RenderingServer with CanvasItemCreate().
public void Draw(Rid canvasItem, Rect2 rect)
Parameters
GetCurrentItemDrawn()
Returns the CanvasItem that handles its NotificationDraw or _Draw() callback at this moment.
public CanvasItem GetCurrentItemDrawn()
Returns
GetMargin(Side)
Returns the content margin offset for the specified Side.
Positive values reduce size inwards, unlike Control's margin values.
public float GetMargin(Side margin)
Parameters
margin
Side
Returns
GetMinimumSize()
Returns the minimum size that this stylebox can be shrunk to.
public Vector2 GetMinimumSize()
Returns
GetOffset()
Returns the "offset" of a stylebox. This helper function returns a value equivalent to Vector2(style.get_margin(MARGIN_LEFT), style.get_margin(MARGIN_TOP))
.
public Vector2 GetOffset()
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
SetContentMarginAll(float)
Sets the default margin to offset
pixels for all sides.
public void SetContentMarginAll(float offset)
Parameters
offset
float
TestMask(Vector2, Rect2)
Test a position in a rectangle, return whether it passes the mask test.
public bool TestMask(Vector2 point, Rect2 rect)
Parameters
Returns
_Draw(Rid, Rect2)
public virtual void _Draw(Rid toCanvasItem, Rect2 rect)
Parameters
_GetDrawRect(Rect2)
public virtual Rect2 _GetDrawRect(Rect2 rect)
Parameters
rect
Rect2
Returns
_GetMinimumSize()
Virtual method to be implemented by the user. Returns a custom minimum size that the stylebox must respect when drawing. By default GetMinimumSize() only takes content margins into account. This method can be overridden to add another size restriction. A combination of the default behavior and the output of this method will be used, to account for both sizes.
public virtual Vector2 _GetMinimumSize()
Returns
_TestMask(Vector2, Rect2)
public virtual bool _TestMask(Vector2 point, Rect2 rect)