StyleBox
Style resource separating content padding from drawing.
StyleBox is a resource rather than a Control or container. Assign it to an appropriate theme slot, such as panel on PanelContainer or normal on Button. Multiple elements can share one resource; editing that StyleBox affects all consumers. Duplicate for individual styling.
ContentMarginLeft/Top/Right/Bottom default to -1. Negative values mean derived-style automatic margins rather than negative padding. GetContentMargin returns stored input; GetMargin returns resolved padding. For example, StyleBoxTexture raw -1 can resolve to 4 from TextureMargin. Explicit 0 disables automatic padding on that side.
GetMinimumSize sums resolved opposite margins and takes a componentwise maximum with a custom script’s _GetMinimumSize. GetOffset returns resolved left/top margins only. Style minimum is not necessarily full Control minimum: text, icons and explicit constraints contribute separately.
Drawing and padding differ. Texture ExpandMargin enlarges drawing without reserving room; StyleBoxEmpty can add padding without drawing. Keep button-state margins consistent to avoid unexpected size changes on hover/press. A margin setter can emit Changed even for repeated identical values.
Implement _Draw with its supplied RID and rectangle for a custom StyleBox. Styles are normally invoked through CanvasItem.DrawStyleBox during an element’s _Draw. GetCurrentItemDrawn returns the current CanvasItem in draw context and can be null outside it. This is a shared reference rather than an object to free. _GetDrawRect describes drawing bounds and _TestMask separately tests points; do not call callbacks instead of ordinary getters on existing styles.
TestMask without a custom callback returns true even outside rect. It does not itself enforce Control bounds or exclude transparent texture pixels from input. Configure a TextureButton Bitmap mask separately for shaped hits.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
StyleBoxConstructor
public StyleBox();Creates a base resource with ContentMargin = -1 on every side. Does not supply visuals itself: use a concrete style or implement _Draw.
Properties4
ContentMarginBottomProperty
public float ContentMarginBottom { get; set; }Stored Bottom content margin: default -1 uses derived automatic padding. 0 is explicit zero. GetMargin returns the resolved value.
ContentMarginLeftProperty
public float ContentMarginLeft { get; set; }Stored Left content margin: default -1 uses derived automatic padding. 0 is explicit zero. GetMargin returns the resolved value.
ContentMarginRightProperty
public float ContentMarginRight { get; set; }Stored Right content margin: default -1 uses derived automatic padding. 0 is explicit zero. GetMargin returns the resolved value.
ContentMarginTopProperty
public float ContentMarginTop { get; set; }Stored Top content margin: default -1 uses derived automatic padding. 0 is explicit zero. GetMargin returns the resolved value.
Methods13
Drawvoid
public void Draw(Rid canvasItem, Rect2 rect);Draws into the supplied canvas-item RID and Rect2. Normally use CanvasItem.DrawStyleBox from the element’s _Draw. RID must belong to a live drawing item. Does not lay out child Controls.
| Name | Type | Default |
|---|---|---|
canvasItem | Rid | — |
rect | Rect2 | — |
canvasItemLive canvas-item RID receiving draw commands.
rectStyle rectangle in drawing-target coordinates.
GetContentMarginfloat
public float GetContentMargin(Side margin);Returns stored margin, including negative automatic values. Use GetMargin for resolved padding.
| Name | Type | Default |
|---|---|---|
margin | Side | — |
marginSide.Left, Top, Right or Bottom.
floatStored margin, including negative auto value.
GetCurrentItemDrawnCanvasItem
public CanvasItem GetCurrentItemDrawn();Returns the current drawing-context CanvasItem, or null outside drawing. Do not free the shared object. It is not a StyleBox resource owner.
CanvasItemShared current CanvasItem, or null.
GetMarginfloat
public float GetMargin(Side margin);Returns resolved padding: negative ContentMargin uses derived-style margins. Explicit 0 remains zero.
| Name | Type | Default |
|---|---|---|
margin | Side | — |
marginSide.Left, Top, Right or Bottom.
floatResolved selected-side padding in pixels.
GetMinimumSizeVector2
public Vector2 GetMinimumSize();Returns opposite resolved-margin sums with a componentwise maximum against custom _GetMinimumSize. Style minimum rather than full Control minimum.
Vector2Style minimum Vector2 from margins/custom callback.
GetOffsetVector2
public Vector2 GetOffset();Returns resolved left/top padding. Does not include decorative ExpandMargin and is not a global position.
Vector2Resolved (Left, Top) padding.
SetContentMarginvoid
public void SetContentMargin(Side margin, float offset);Stores side padding and emits Changed even for the same value. Negative means derived automatic margin; nonnegative means explicit padding.
| Name | Type | Default |
|---|---|---|
margin | Side | — |
offset | float | — |
marginSide.Left, Top, Right or Bottom.
offsetStores side padding and emits Changed even for the same value. Negative means derived automatic margin; nonnegative means explicit padding.
SetContentMarginAllvoid
public void SetContentMarginAll(float offset);Sets one value on all four sides, emitting Changed once. Negative selects automatic margins; 0 supplies explicit zeroes.
| Name | Type | Default |
|---|---|---|
offset | float | — |
offsetSets one value on all four sides, emitting Changed once. Negative selects automatic margins; 0 supplies explicit zeroes.
TestMaskbool
public bool TestMask(Vector2 point, Rect2 rect);Calls custom _TestMask, otherwise returns true even outside rect. Does not automatically enforce rectangle containment or test texture alpha.
| Name | Type | Default |
|---|---|---|
point | Vector2 | — |
rect | Rect2 | — |
pointTest point in the same coordinate space as rect.
rectStyle rectangle in drawing-target coordinates.
boolCallback result, or true without it; not automatic rect containment.
_Drawvoid
public virtual void _Draw(Rid toCanvasItem, Rect2 rect);Custom StyleBox drawing callback for supplied RID/Rect2. Implement visuals in a subclass; not an ordinary getter or signal.
| Name | Type | Default |
|---|---|---|
toCanvasItem | Rid | — |
rect | Rect2 | — |
toCanvasItemLive canvas-item RID receiving draw commands.
rectStyle rectangle in drawing-target coordinates.
_GetDrawRectRect2
public virtual Rect2 _GetDrawRect(Rect2 rect);Custom-style drawing-bounds callback, for example decorative overflow beyond rect. Does not replace _Draw or change content padding. Not a getter for a native concrete style.
| Name | Type | Default |
|---|---|---|
rect | Rect2 | — |
rectStyle rectangle in drawing-target coordinates.
Rect2Drawing area supplied by the custom style.
_GetMinimumSizeVector2
public virtual Vector2 _GetMinimumSize();Custom-style extra minimum lower-bound callback. Result combines componentwise with padding sums rather than replacing them with smaller values.
Vector2Additional minimum-size lower bound.
_TestMaskbool
public virtual bool _TestMask(Vector2 point, Rect2 rect);Custom point-test callback against supplied rect. Implement containment explicitly; base StyleBox without a callback accepts any point.
| Name | Type | Default |
|---|---|---|
point | Vector2 | — |
rect | Rect2 | — |
pointTest point in the same coordinate space as rect.
rectStyle rectangle in drawing-target coordinates.
boolCustom point-test result.