Theme libraryclient
Part of Active UI
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
SKIN:apply_theme) and refreshes the skins of all panels.Functions
Returns all of the registered themes.
Returns
- Map themes by ID
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
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
Returns the ID of the theme that is currently loaded.
Returns
- String theme ID, or nil if no theme is loaded
Returns a color of the active theme.
Parameters
- key String
- fallback Color optional, defaults to
nilreturned 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
Returns the name of a font of the active theme.
Parameters
- key String
- fallback String optional, defaults to
nilreturned if the font is not set or no theme is loaded
Returns
- String font name
Returns a material of the active theme.
Parameters
- key String
- fallback Material optional, defaults to
nilreturned if the material is not set or no theme is loaded
Returns
- Material
Returns an option of the active theme.
Parameters
- key String
- fallback Any optional, defaults to
nilreturned if the option is not set (or false), or no theme is loaded
Returns
- Any value of the option
Returns a sound of the active theme.
Parameters
- key String
- fallback String optional, defaults to
nilreturned if the sound is not set or no theme is loaded
Returns
- String path to the sound
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
Checks whether the default theme has been loaded for the local player.
Returns
- Boolean
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.
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
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.
Removes a theme from the list of registered themes.
Parameters
- id String theme ID
Sets a color of the active theme.
Parameters
- key String
- value Color optional, defaults to
Color(255, 255, 255)
See also
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.
Parameters
- key String
- value String name of an existing font to base this one on
- scale Number optional, defaults to
nilfont size, the base font is used as is if omitted - data Map optional, defaults to
nilextra font data to override in the sized font
See also
Sets a material of the active theme.
Parameters
- key String
- value String/Material material, or a path to load it from
See also
Sets an option of the active theme.
Parameters
- key String
- value Any
See also
Sets a sound of the active theme.
Parameters
- key String
- value String path to the sound
See also
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.