StyleWithPadding

DrawGUI scope that temporarily overrides a GUIStyle's padding (RectOffset) for the duration of a using block. The original padding values are captured on construction and restored on disposal.

Definition

Namespace: Paragon.Editor Assembly: Paragon.Editor.dll

public static partial class DrawGUI
{
    public static Scope StyleWithPadding(GUIStyle style, int? left = null, int? right = null, int? top = null, int? bottom = null)
    public static Scope StyleWithPadding(this Scope scope, GUIStyle style, int? left = null, int? right = null, int? top = null, int? bottom = null)

    private class StyleWithPaddingScope : Scope
}

Remarks

The padding property of a GUIStyle controls the spacing between the element's border and its content (text, image). This scope allows temporarily changing padding values without permanently modifying the style.

Selective Override

Parameters are nullable (int?). Only non-null values override the corresponding edge. Null parameters keep the style's current padding value for that edge.

Save/Restore Pattern

  1. Constructor — captures the original padding as a new RectOffset, computes the scoped RectOffset

  2. OnBegin — sets style.padding to the scoped values

  3. OnEnd — restores style.padding to the original values

Quick Lookup

Goal
How

Override all padding

DrawGUI.StyleWithPadding(style, 8, 8, 8, 8)

Override left only

DrawGUI.StyleWithPadding(style, left: 16)

Remove all padding

DrawGUI.StyleWithPadding(style, 0, 0, 0, 0)

Chain onto scope

scope.StyleWithPadding(style, top: 4)

Factory Methods

Standalone

Extension (Chaining)

Parameter
Type
Default
Description

style

GUIStyle

The style whose padding to temporarily modify

left

int?

null

Left padding override (null = keep original)

right

int?

null

Right padding override (null = keep original)

top

int?

null

Top padding override (null = keep original)

bottom

int?

null

Bottom padding override (null = keep original)

StyleWithPaddingScope (private)

Member
Description

style

GUIStyle — the style being modified

originalRectOffset

RectOffset — captured original style.padding values

scopedRectOffset

RectOffset — the computed override values

OnBegin()

Sets style.padding = scopedRectOffset

OnEnd()

Sets style.padding = originalRectOffset

Common Pitfalls

circle-exclamation

Examples

Extra Content Padding in a Box

Chained with Layout and Margin

See Also

Last updated