Themes control how the Flux interface looks. A theme is a ThemeBase object that holds named colors, fonts, sounds, materials and options (sizes, positions and other values), callbacks that create panels, and overrides for the 'Flux' Derma skin. Themes are defined in the themes folder of the schema or of a plugin, where every file gets a THEME table to fill in, and can name a parent theme to inherit from; 'factory' is the base theme that ships with Flux. One theme is active at a time: the default_theme of the schema, or 'factory', is loaded once the local player has been initialized, and it is loaded again when the code is refreshed.

This library is the way to reach the active theme. Theme.get_color, Theme.get_font, Theme.get_option and their siblings read its values, Theme.create_panel creates a panel that the theme provides, and plugins add their own values and panels to the theme from an OnThemeLoaded handler.

Drawing is delegated to the theme through theme hooks. Theme.hook (also available as Theme.call) calls the method of that name on the active theme and returns what it returns, and does nothing if the theme has no such method. A panel calls, for example, Theme.hook('PaintButton', self, w, h) from its Paint function, and a theme changes the look of buttons by defining THEME:PaintButton(panel, w, h). Theme hooks are plain methods of the theme rather than hooks of the hook library: plugins cannot add handlers for them, only the active theme answers, with the methods it defines or inherits from its parents.

Summary

Functions

all()client
Returns all of the registered themes.
Creates a panel through the active theme, using the callback the theme has registered with ThemeBase#add_panel.
Finds a registered theme.
Returns the ID of the theme that is currently loaded.
Returns a color of the active theme.
Returns the name of a font of the active theme.
Returns a material of the active theme.
Returns an option of the active theme.
Returns a sound of the active theme.
Calls a method of the active theme in protected mode.
Checks whether the default theme has been loaded for the local player.
Loads the default theme of the schema, or the 'factory' theme if the schema has none, and marks the theme library as initialized.
Makes the specified theme the active one.
Registers a theme.
reload()client
Loads the active theme again, then calls its 'OnReloaded' method and the 'OnThemeReloaded' hook.
Removes a theme from the list of registered themes.
Sets a color of the active theme.
Copies the skin overrides of the active theme into the 'Flux' Derma skin, recolors the skin from the colors of the theme (see SKIN:apply_theme) and refreshes the skins of all panels.
Sets a font of the active theme.
Sets a material of the active theme.
Sets an option of the active theme.
Sets a sound of the active theme.
Unloads the active theme, calling its on_unloaded method and the 'OnThemeUnloaded' hook.

Functions

Returns all of the registered themes.

Returns

  • Map themes by ID

Theme.create_panel(panel_id, parent, ...)

client packages/active_ui/lib/cl_theme.lua:75

Creates a panel through the active theme, using the callback the theme has registered with ThemeBase#add_panel. Can be prevented with the 'ShouldThemeCreatePanel' hook.

Parameters

  • panel_id String ID the panel was added to the theme with
  • parent Panel parent of the new panel, can be nil
  • ... Vararg extra arguments for the theme's callback

Returns

  • Panel the created panel, or nil if the active theme did not create one

Theme.find_theme(id)

client packages/active_ui/lib/cl_theme.lua:225

Finds a registered theme.

Parameters

  • id String ID or name of the theme, converted with string.to_id

Returns

  • ThemeBase the theme, or nil if it is not registered

Theme.get_active_theme()

client packages/active_ui/lib/cl_theme.lua:106

Returns the ID of the theme that is currently loaded.

Returns

  • String theme ID, or nil if no theme is loaded

Theme.get_color(key, fallback)

client packages/active_ui/lib/cl_theme.lua:158

Returns a color of the active theme.

Parameters

  • key String
  • fallback Color optional, defaults to nil returned if the color is not set or no theme is loaded

Returns

  • Color the color; white if a theme is loaded but has neither it nor a fallback

Theme.get_font(key, fallback)

client packages/active_ui/lib/cl_theme.lua:170

Returns the name of a font of the active theme.

Parameters

  • key String
  • fallback String optional, defaults to nil returned if the font is not set or no theme is loaded

Returns

  • String font name

Theme.get_material(key, fallback)

client packages/active_ui/lib/cl_theme.lua:202

Returns a material of the active theme.

Parameters

  • key String
  • fallback Material optional, defaults to nil returned if the material is not set or no theme is loaded

Returns

  • Material

Theme.get_option(key, fallback)

client packages/active_ui/lib/cl_theme.lua:214

Returns an option of the active theme.

Parameters

  • key String
  • fallback Any optional, defaults to nil returned if the option is not set (or false), or no theme is loaded

Returns

  • Any value of the option

Theme.get_sound(key, fallback)

client packages/active_ui/lib/cl_theme.lua:124

Returns a sound of the active theme.

Parameters

  • key String
  • fallback String optional, defaults to nil returned if the sound is not set or no theme is loaded

Returns

  • String path to the sound

Theme.hook(id, ...)

client packages/active_ui/lib/cl_theme.lua:96

Calls a method of the active theme in protected mode. Errors are printed to the console instead of being raised. Also available as Theme.call.

function PANEL:Paint(w, h)
  Theme.hook('PaintButton', self, w, h)
end

Parameters

  • id String name of the theme method
  • ... Vararg arguments to pass to the method

Returns

  • Any everything the method has returned; nil if there is no active theme, it has no such method or the method has failed

Theme.initialized()

client packages/active_ui/lib/cl_theme.lua:357

Checks whether the default theme has been loaded for the local player.

Returns

  • Boolean

Theme.load_default()

client packages/active_ui/lib/cl_theme.lua:364

Loads the default theme of the schema, or the 'factory' theme if the schema has none, and marks the theme library as initialized. Called by the flThemeHooks handlers once the local player has been initialized.

Theme.load_theme(theme_id)

client packages/active_ui/lib/cl_theme.lua:262

Makes the specified theme the active one. Calls on_loaded of every theme it derives from and of the theme itself, applies its Derma skin, and runs the 'OnThemeLoaded' hook. It can be prevented with the 'ShouldThemeLoad' hook.

Parameters

  • theme_id String ID of a registered theme

Returns

  • Boolean true if the theme has been loaded, false if it is not registered or the 'ShouldThemeLoad' hook has prevented it

Theme.register_theme(obj)

client packages/active_ui/lib/cl_theme.lua:52

Registers a theme. If the theme has a registered parent, it is replaced with a copy of the parent that has the theme merged on top of it.

Parameters

  • obj ThemeBase

Loads the active theme again, then calls its 'OnReloaded' method and the 'OnThemeReloaded' hook. Does nothing if the theme has should_reload set to false, or if the 'ShouldThemeReload' hook returns false. The theme is loaded the same way as the first time, so the 'ShouldThemeLoad' hook can prevent the reload too; 'OnReloaded' and 'OnThemeReloaded' are then not called.

Theme.remove_theme(id)

client packages/active_ui/lib/cl_theme.lua:231

Removes a theme from the list of registered themes.

Parameters

  • id String theme ID

Theme.set_color(key, value)

client packages/active_ui/lib/cl_theme.lua:136

Sets a color of the active theme.

Parameters

  • key String
  • value Color optional, defaults to Color(255, 255, 255)

See also

Theme.set_derma_skin()

client packages/active_ui/lib/cl_theme.lua:240

Copies the skin overrides of the active theme into the 'Flux' Derma skin, recolors the skin from the colors of the theme (see SKIN:apply_theme) and refreshes the skins of all panels.

Theme.set_font(key, value, scale, data)

client packages/active_ui/lib/cl_theme.lua:148

Sets a font of the active theme.

Parameters

  • key String
  • value String name of an existing font to base this one on
  • scale Number optional, defaults to nil font size, the base font is used as is if omitted
  • data Map optional, defaults to nil extra font data to override in the sized font

See also

Theme.set_material(key, value)

client packages/active_ui/lib/cl_theme.lua:192

Sets a material of the active theme.

Parameters

  • key String
  • value String/Material material, or a path to load it from

See also

Theme.set_option(key, value)

client packages/active_ui/lib/cl_theme.lua:182

Sets an option of the active theme.

Parameters

  • key String
  • value Any

See also

Theme.set_sound(key, value)

client packages/active_ui/lib/cl_theme.lua:114

Sets a sound of the active theme.

Parameters

  • key String
  • value String path to the sound

See also

Theme.unload_theme()

client packages/active_ui/lib/cl_theme.lua:307

Unloads the active theme, calling its on_unloaded method and the 'OnThemeUnloaded' hook. Can be prevented with the 'ShouldThemeUnload' hook. Does nothing if no theme is loaded.

Defined in