GUIStyleExtensions

Fluent builder-pattern extension methods for UnityEngine.GUIStyle. Every method creates a new GUIStyle copy with the specified property changed, leaving the original unmodified. Enables chaining for concise IMGUI style declarations.

Definition

Namespace: Paragon.Editor Assembly: Editor assembly

public static class GUIStyleExtensions

Quick Lookup

Goal
Method

Set text alignment

style.WithAlignment(TextAnchor.MiddleCenter)

Set border (all sides)

style.WithBorder(2)

Set border (per side)

style.WithBorder(left: 1, top: 2)

Set margin (all sides)

style.WithMargin(4)

Set margin (per side)

style.WithMargin(left: 2, right: 2)

Set padding (all sides)

style.WithPadding(4)

Set padding (per side)

style.WithPadding(left: 8, top: 4)

Set overflow (all sides)

style.WithOverflow(1)

Set overflow (per side)

style.WithOverflow(left: 0, bottom: 2)

Set fixed height

style.WithFixedHeight(24)

Set fixed width

style.WithFixedWidth(100)

Set text clipping

style.WithTextClipping(TextClipping.Overflow)

Set font

style.WithFont(myFont)

Set font size

style.WithFontSize(14)

Set font style

style.WithFontStyle(FontStyle.Bold)

Set background texture

style.WithBackground(texture)

Enable/disable rich text

style.WithRichText(true)

Set stretch height

style.WithStretchHeight(true)

Set stretch width

style.WithStretchWidth(true)

Set word wrap

style.WithWordWrap(true)

Methods

Layout Methods

Each layout method has two overloads: one that sets all sides uniformly, and one with optional per-side values that preserve unspecified sides from the original style.

WithBorder

WithMargin

WithPadding

WithOverflow

Size Methods

WithFixedHeight

WithFixedWidth

Text Methods

WithAlignment

WithTextClipping

WithFont

WithFontSize

WithFontStyle

WithRichText

WithWordWrap

Appearance Methods

WithBackground

Sets the normal.background texture of the style.

circle-info

Only sets the normal state background. Other states (hover, active, focused) are not affected. To set backgrounds for other states, modify the returned GUIStyle directly.

WithStretchHeight

WithStretchWidth

Common Pitfalls

circle-exclamation
circle-exclamation

Examples

Fluent style chaining

Selective per-side padding

See Also

Last updated