Skip to content

Styles

Class ยท server and client scripts

Styles stores StyleBox overrides keyed by UI part (StylePart) and interaction state (StyleState) on a styled UI entity or World.Theme entity. Descendants inherit styles from the nearest ancestor with a matching entry.

Example

-- Client script.
local function configureTheme(styles: Styles)
    styles:Set("Button.Frame", "Normal", StyleBox.new({ Color = Color.new(0.15, 0.2, 0.3) }))
    styles:Set("Button.Frame", "Hover", StyleBox.new({ Color = Color.new(0.2, 0.3, 0.45) }))
end
print(configureTheme)

Set

Method
Set(part: StylePart, state: StyleState, box: StyleBox) -> ()

Set assigns box as the StyleBox drawn for part while in interaction state.

Parameter Type Description
self Styles The Styles component view.
part StylePart Control part name from StylePart.
state StyleState Interaction state name from StyleState.
box StyleBox Immutable StyleBox to apply.

Example

-- Client script.
local function stylePanel(styles: Styles)
    styles:Set("Panel.Frame", "Normal", StyleBox.new({ Color = Color.new(0.1, 0.1, 0.12) }))
end
print(stylePanel)

Get

Method
Get(part: StylePart, state: StyleState) -> StyleBox?

Get returns the StyleBox currently assigned to part and state on this entity, or nil when none is set.

Parameter Type Description
self Styles The Styles component view.
part StylePart Control part name from StylePart.
state StyleState Interaction state name from StyleState.

Returns The assigned StyleBox, or nil.

Example

-- Client script.
local function hasButtonStyle(styles: Styles): boolean
    return styles:Get("Button.Frame", "Normal") ~= nil
end
print(hasButtonStyle)

Clear

Method
Clear(part: StylePart, state: StyleState) -> ()

Clear removes the StyleBox override for part and state on this entity so controls fall back to parent or default styles.

Parameter Type Description
self Styles The Styles component view.
part StylePart Control part name from StylePart.
state StyleState Interaction state name from StyleState.

Example

-- Client script.
local function resetHover(styles: Styles)
    styles:Clear("Button.Frame", "Hover")
end
print(resetHover)