StyleWithMargin

DrawGUI scope that temporarily overrides a GUIStyle's margin (RectOffset) for the duration of a using block. The original margin 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 StyleWithMargin(GUIStyle style, int? left = null, int? right = null, int? top = null, int? bottom = null)
    public static Scope StyleWithMargin(this Scope scope, GUIStyle style, int? left = null, int? right = null, int? top = null, int? bottom = null)

    private class StyleWithMarginScope : Scope
}

Remarks

The margin property of a GUIStyle controls the spacing between this element and adjacent elements in a layout group. This scope allows temporarily changing margin 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 margin value for that edge.

Save/Restore Pattern

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

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

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

Quick Lookup

Goal
How

Override all margins

DrawGUI.StyleWithMargin(style, 4, 4, 4, 4)

Override top only

DrawGUI.StyleWithMargin(style, top: 10)

Remove all margins

DrawGUI.StyleWithMargin(style, 0, 0, 0, 0)

Chain onto scope

scope.StyleWithMargin(style, left: 8, right: 8)

Factory Methods

Standalone

Extension (Chaining)

Parameter
Type
Default
Description

style

GUIStyle

The style whose margin to temporarily modify

left

int?

null

Left margin override (null = keep original)

right

int?

null

Right margin override (null = keep original)

top

int?

null

Top margin override (null = keep original)

bottom

int?

null

Bottom margin override (null = keep original)

StyleWithMarginScope (private)

Member
Description

style

GUIStyle — the style being modified

originalRectOffset

RectOffset — captured original style.margin values

scopedRectOffset

RectOffset — the computed override values

OnBegin()

Sets style.margin = scopedRectOffset

OnEnd()

Sets style.margin = originalRectOffset

Common Pitfalls

circle-exclamation

Examples

Adding Indentation via Left Margin

Combining with Layout

See Also

Last updated