Skip to content

Styling

“Perrier” edited this page May 10, 2026 · 2 revisions

Styling

Every component takes a Style (immutable) that controls size, spacing, color, font, border, alignment, opacity, and click handling. Styles are built with a fluent Style.Builder; static factories on Style and Styles give you a head start.

Quick reference

import org.triggersstudio.moddinglib.client.ui.styling.Style;
import org.triggersstudio.moddinglib.client.ui.styling.Styles;

Style s = Style.builder()
        .width(120).height(28)
        .padding(4, 8)
        .backgroundColor(0xFF_2A_2A_2A)
        .textColor(0xFF_FF_FF_FF)
        .border(0xFF_55_55_55, 1)
        .borderRadius(4)
        .build();

Or with the static-import helpers:

import static org.triggersstudio.moddinglib.client.ui.styling.Styles.*;

Style s = padding(4, 8)
        .width(120).height(28)
        .backgroundColor(0xFF_2A_2A_2A)
        .textColor(WHITE)
        .border(0xFF_55_55_55, 1)
        .borderRadius(4)
        .build();

Style.DEFAULT is the no-op style: WRAP_CONTENT size, white text, 9pt font, no background, no border, fully opaque.

Style.Builder

Every method returns the builder for chaining. Call .build() at the end.

Method Notes
width(int) / height(int) Accepts Size.WRAP_CONTENT (-1), Size.MATCH_PARENT (-2), or a positive pixel count.
padding(int all) Same on every side.
padding(int vertical, int horizontal) Top/bottom = vertical, left/right = horizontal.
padding(int top, int right, int bottom, int left) Per-side.
margin(...) Same overloads.
backgroundColor(int color) ARGB. 0x00_00_00_00 = transparent.
textColor(int color) ARGB. Default 0xFF_FF_FF_FF.
fontSize(float) Default 9f.
borderRadius(int) Corner rounding in pixels. Clamped to min(width, height) / 2.
border(int color, int width) Shorthand for color + width.
align(Alignment h, Alignment v) Text/content alignment.
onClick(ClickHandler) (double x, double y, int button) -> void.
opacity(float) Clamped to [0, 1].
bold() Bold text (renders via Minecraft's bold formatting).
placeholderColor(int) TextField/TextArea placeholder color. 0 = derive from textColor at reduced alpha.

Style.toBuilder() returns a builder pre-populated with the style's current values, so you can derive variants without restating everything.

Static factories on Style

Each one creates a builder with that property set, so you can drop .builder() from one-liners:

Style.width(60).height(20).build()
Style.padding(8).backgroundColor(0xFF_22_22_22).build()
Style.border(0xFF_55_55_55, 1).borderRadius(4).build()

Available: width, height, padding, margin, backgroundColor, textColor, fontSize, borderRadius, border, align, onClick, opacity, bold, placeholderColor.

Styles helper

org.triggersstudio.moddinglib.client.ui.styling.Styles re-exports the static factories plus a few constants. Import statically and you don't need the Style. prefix:

import static org.triggersstudio.moddinglib.client.ui.styling.Styles.*;

Size constants

WRAP_CONTENT   // -1
MATCH_PARENT   // -2

Alignment constants

START   CENTER   END   STRETCH

Color constants

BLACK         = 0xFF_00_00_00
WHITE         = 0xFF_FF_FF_FF
RED           = 0xFF_FF_00_00
GREEN         = 0xFF_00_FF_00
BLUE          = 0xFF_00_00_FF
TRANSPARENT   = 0x00_00_00_00

Builder shortcuts

size(int width, int height) plus the same factory list as on Style (width, height, padding, margin, backgroundColor, textColor, fontSize, borderRadius, border, align, onClick, opacity, bold, placeholderColor).

Insets

Used internally by padding(...) and margin(...). You rarely instantiate one yourself.

new Insets(int all)
new Insets(int vertical, int horizontal)
new Insets(int top, int right, int bottom, int left)

insets.getHorizontal()   // left + right
insets.getVertical()     // top + bottom

Insets.ZERO              // no inset constant

Alignment

public enum Alignment { START, CENTER, END, STRETCH }

Used for text alignment in Text and content alignment in containers when the cross-axis has free space.

Size

Layout sentinels:

Size.WRAP_CONTENT          // -1
Size.MATCH_PARENT          // -2

Size.isWrapContent(int)
Size.isMatchParent(int)
Size.isFixed(int)

Defaults

The builder defaults match Style.DEFAULT:

Property Default
width / height WRAP_CONTENT
padding / margin Insets.ZERO
backgroundColor 0x00_00_00_00 (transparent)
textColor 0xFF_FF_FF_FF (white)
fontSize 9f
borderRadius 0
borderColor 0xFF_00_00_00
borderWidth 0
horizontalAlignment Alignment.START
verticalAlignment Alignment.START
clickHandler null
opacity 1.0f
bold false
placeholderColor 0 (derive from textColor)

Clone this wiki locally