UI Styling
Styling can be done in .ui files or programmatically from the server. See Markup for .ui file syntax.
PatchStyle
Section titled “PatchStyle”9-patch texture styling for backgrounds and borders.
PatchStyle style = new PatchStyle();style.setTexturePath(Value.of("Textures/Button.png"));style.setBorder(Value.of(4)); // all sides// or per-axis:style.setHorizontalBorder(Value.of(4));style.setVerticalBorder(Value.of(8));
style.setColor(Value.of("#FF0000"));
cmd.setObject("#Element.Style", style);In .ui:
Group { Style: ( TexturePath: "Textures/Panel.png", Border: 4, Color: #FFFFFF );}Anchor
Section titled “Anchor”Positioning and sizing. Like PatchStyle, setters use Value<T> wrappers.
Anchor anchor = new Anchor();
// positionanchor.setLeft(Value.of(10));anchor.setTop(Value.of(10));anchor.setRight(Value.of(10)); // from right edgeanchor.setBottom(Value.of(10)); // from bottom edge
// sizeanchor.setWidth(Value.of(200));anchor.setHeight(Value.of(100));anchor.setMinWidth(Value.of(50));anchor.setMaxWidth(Value.of(400));
// fill modesanchor.setFull(Value.of(1)); // fill parentanchor.setHorizontal(Value.of(1)); // fill widthanchor.setVertical(Value.of(1)); // fill height
cmd.setObject("#Element.Anchor", anchor);In .ui:
Group { Anchor: ( Left: 10, Top: 10, Width: 200, Height: 100 );}
// fill parentGroup { Anchor: (Full: true);}Defines a rectangular region (for texture slicing, etc).
Area area = new Area(x, y, width, height);// orArea area = new Area();area.setX(0);area.setY(0);area.setWidth(100);area.setHeight(50);FormattedMessage
Section titled “FormattedMessage”Rich text with styling. Uses public fields:
FormattedMessage msg = new FormattedMessage();msg.rawText = "Hello World";msg.color = "#FF0000";msg.bold = MaybeBool.True;msg.italic = MaybeBool.True;msg.underlined = MaybeBool.True;msg.monospace = MaybeBool.True;msg.link = "https://example.com";
cmd.set("#Label.Text", msg);Nested Messages
Section titled “Nested Messages”Build complex formatted text with children:
FormattedMessage parent = new FormattedMessage();parent.rawText = "Score: ";
FormattedMessage score = new FormattedMessage();score.rawText = "100";score.color = "#00FF00";score.bold = MaybeBool.True;
parent.children = new FormattedMessage[]{score};cmd.set("#Label.Text", parent);Translation with Parameters
Section titled “Translation with Parameters”FormattedMessage msg = new FormattedMessage();msg.messageId = "mymod.welcome"; // translation keyMaybeBool
Section titled “MaybeBool”Three-state boolean for style inheritance:
| Value | Meaning |
|---|---|
MaybeBool.Null | Inherit from parent |
MaybeBool.False | Explicitly false |
MaybeBool.True | Explicitly true |
msg.bold = MaybeBool.True; // force boldmsg.bold = MaybeBool.Null; // inheritValue References
Section titled “Value References”Reference styles defined in .ui files:
// reference a value from another filecmd.set("#Element.Style", Value.ref("Pages/Styles.ui", "ButtonStyle"));In the referenced file:
@ButtonStyle = ( TexturePath: "Textures/Button.png", Border: 4, Color: #FFFFFF);Color Formats
Section titled “Color Formats”Both in .ui and Java:
| Format | Example |
|---|---|
| RGB hex | #FF0000 |
| RGBA hex | #FF0000FF |
| RGB + alpha | #FF0000(0.5) |
| rgb() | rgb(255, 0, 0) |
| rgba() | rgba(255, 0, 0, 128) |
Text Styles in .ui
Section titled “Text Styles in .ui”Label { Style: ( FontSize: 24, FontName: "Secondary", LetterSpacing: 1.5, HorizontalAlignment: Center, VerticalAlignment: Center, RenderBold: true, RenderItalic: true, RenderUppercase: true, Wrap: true );}Alignment Values
Section titled “Alignment Values”| Property | Values |
|---|---|
HorizontalAlignment | Left, Center, Right |
VerticalAlignment | Top, Center, Bottom |
Alignment | Center, Left, Right, Top, Bottom |
Button Styles
Section titled “Button Styles”Buttons support multiple states:
TextButton { Style: ( TexturePath: "Textures/Button.png", Border: 4, Hovered: ( TexturePath: "Textures/ButtonHover.png" ), Pressed: ( TexturePath: "Textures/ButtonPressed.png" ), Disabled: ( TexturePath: "Textures/ButtonDisabled.png", Color: #808080 ) );}Sounds
Section titled “Sounds”Attach sounds to UI interactions:
$Sounds = "../Sounds.ui";
TextButton { Style: ( Sounds: ( Hovered: "UI/ButtonHover", Activated: "UI/ButtonClick" ) );}
// or use predefinedTextButton { Style: ( ...$Sounds.@ButtonSounds );}