Loading
Docs / Components / Switches
v1.0.0 JAVA MOD LIBRARY

Switches

Two-state toggle switch with harmonic spring handle physics and optional I/O track symbols.

ui.toggle(...) renders a 25×14 toggle track with a 14×14 GENERAL-styled handle that springs between off and on using damped harmonic physics (stiffness = 2729, damping = 60, mass = 1.5, permitting natural overshoot). Keyboard Tab focus draws the 1px white focus ring directly around the moving handle rather than the track.

Interactive Preview & Matrix

Click or press Space/Enter while focused with Tab
Colored
General
Destructive
Warning
Realms
State
Colored
General
Destructive
Warning
Realms
On (Default)
On (Hover)
On (Focused)
Off (Default)
Off (Focused)
Disabled

Method Signatures (OreUi)

// Default green switch (25x14) without track symbols
public void toggle(int x, int y, boolean on, String key, String tip, Runnable action)

// Full switch control
public void toggle(int x, int y, boolean on, OreVariant variant, boolean icon,
                   boolean enabled, boolean focused, String key, String tip, Runnable action)

Parameters

ParameterTypeDescription
x, yintTop-left GUI pixel coordinates (25×14 footprint).
onbooleanCurrent toggle state (true slides handle right and tints the track).
variantOreVariantTrack color when on (COLORED, GENERAL, WARNING, DESTRUCTIVE, REALMS).
iconbooleanWhen true, draws I (on) and O (off) glyphs inside the track.
enabledbooleanEnables interaction (false renders flat disabled track and handle).
focusedbooleanForces the focus ring onto the 14×14 handle.
keyStringUnique animation key ("switch:" + key) preserving spring velocity across frames.
tipStringOptional hover tooltip.
actionRunnableInvoked when toggled.

Example

private boolean vsync = true;

ui.toggle(x, y, vsync, OreVariant.COLORED, true, true, false,
	"vsyncSwitch", "Toggle VSync", () -> vsync = !vsync);