StyleWithBorder

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

    private class StyleWithBorderScope : Scope
}

Remarks

The border property of a GUIStyle controls the non-stretchable border regions of a 9-sliced background image. This scope allows temporarily changing border 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 border value for that edge.

Save/Restore Pattern

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

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

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

Quick Lookup

Goal
How

Override all borders

DrawGUI.StyleWithBorder(style, 2, 2, 2, 2)

Override left only

DrawGUI.StyleWithBorder(style, left: 10)

Chain onto scope

scope.StyleWithBorder(style, top: 5, bottom: 5)

Factory Methods

Standalone

Extension (Chaining)

Parameter
Type
Default
Description

style

GUIStyle

The style whose border to temporarily modify

left

int?

null

Left border override (null = keep original)

right

int?

null

Right border override (null = keep original)

top

int?

null

Top border override (null = keep original)

bottom

int?

null

Bottom border override (null = keep original)

StyleWithBorderScope (private)

Member
Description

style

GUIStyle — the style being modified

originalRectOffset

RectOffset — captured original style.border values

scopedRectOffset

RectOffset — the computed override values

OnBegin()

Sets style.border = scopedRectOffset

OnEnd()

Sets style.border = originalRectOffset

Common Pitfalls

circle-exclamation

Examples

Removing Border for a Single Draw

See Also

Last updated