Base class of the interface themes. A theme stores the named colors, fonts, sounds, materials and options that the interface looks up through the Theme library, the callbacks that create the panels it provides (ThemeBase:add_panel), and a skin table of overrides for the 'Flux' Derma skin. A file in a themes folder receives a new instance as THEME: set THEME.parent to inherit from another theme, define the values of the theme in THEME:on_loaded, and add methods such as THEME:PaintButton(panel, w, h) to answer the theme hooks that the interface calls with Theme.hook. When a theme is loaded, the on_loaded methods of its parents are run on it as well.

THEME.author = 'TeslaCloud Studios'
THEME.id = 'hl2rp'
THEME.parent = 'factory'

function THEME:on_loaded()
  self:set_color('accent', Color(58, 87, 167))
  self:set_option('bar_height', 7)
end

Summary

Methods

Converts the theme to a string for printing.
Registers a callback that creates a panel for this theme.
Creates a panel using the callback registered with ThemeBase#add_panel.
Returns a color of the theme.
Returns the name of a font of the theme.
Returns a material of the theme.
Returns an option of the theme.
Returns a sound of the theme.
Creates a new theme.
Called when the theme becomes the active one.
Called when the theme is unloaded.
Adds this theme to the list of registered themes.
Registers an asset of the theme.
remove()client
Removes this theme from the list of registered themes.
Sets a color of the theme.
Sets a font of the theme.
Sets a material of the theme.
Sets an option of the theme.
Sets a sound of the theme.

Methods

ThemeBase:__tostring()

client packages/active_ui/lib/classes/cl_theme.lua:247

Converts the theme to a string for printing.

Returns

  • String

ThemeBase:add_panel(id, callback)

client packages/active_ui/lib/classes/cl_theme.lua:68

Registers a callback that creates a panel for this theme. This lets themes replace the panels that are created with Theme.create_panel.

self:add_panel('tab_menu', function(id, parent, ...)
  return vgui.Create('fl_tab_menu', parent)
end)

Parameters

  • id String panel ID
  • callback Function receives the panel ID, the parent panel and any extra arguments, must return the created panel

ThemeBase:create_panel(id, parent, ...)

client packages/active_ui/lib/classes/cl_theme.lua:77

Creates a panel using the callback registered with ThemeBase#add_panel.

Parameters

  • id String panel ID
  • parent Panel parent of the new panel, can be nil
  • ... Vararg extra arguments for the callback

Returns

  • Panel the created panel, or nil if no callback is registered for this ID

ThemeBase:get_color(id, failsafe)

client packages/active_ui/lib/classes/cl_theme.lua:201

Returns a color of the theme.

Parameters

  • id String
  • failsafe Color optional, defaults to Color(255, 255, 255) returned if the color is not set

Returns

  • Color

ThemeBase:get_font(key, default)

client packages/active_ui/lib/classes/cl_theme.lua:185

Returns the name of a font of the theme.

Parameters

  • key String
  • default String optional, defaults to nil returned if the font is not set

Returns

  • String font name

ThemeBase:get_material(id, failsafe)

client packages/active_ui/lib/classes/cl_theme.lua:215

Returns a material of the theme.

Parameters

  • id String
  • failsafe Material optional, defaults to nil returned if the material is not set

Returns

  • Material

ThemeBase:get_option(key, default)

client packages/active_ui/lib/classes/cl_theme.lua:193

Returns an option of the theme.

Parameters

  • key String
  • default Any optional, defaults to nil returned if the option is not set or is false

Returns

  • Any value of the option

ThemeBase:get_sound(id, failsafe)

client packages/active_ui/lib/classes/cl_theme.lua:229

Returns a sound of the theme.

Parameters

  • id String
  • failsafe String optional, defaults to nil returned if the sound is not set

Returns

  • String path to the sound

ThemeBase:init(name, parent)

client packages/active_ui/lib/classes/cl_theme.lua:34

Creates a new theme. The ID of the theme is derived from its name.

Parameters

  • name String optional, defaults to 'Unknown'
  • parent String optional, defaults to nil ID of the theme to inherit from

ThemeBase:on_loaded()

client packages/active_ui/lib/classes/cl_theme.lua:46

Called when the theme becomes the active one. Does nothing by default, override it to set the colors, fonts, options and other assets of the theme.

ThemeBase:on_unloaded()

client packages/active_ui/lib/classes/cl_theme.lua:50

Called when the theme is unloaded. Does nothing by default.

Adds this theme to the list of registered themes.

See also

ThemeBase:register_asset(name, path, options)

client packages/active_ui/lib/classes/cl_theme.lua:97

Registers an asset of the theme. Models are precached, images (PNG and JPEG) are stored as theme materials. When sizes are specified, the smallest scale that covers the height of the screen relative to 720p is picked, and the image is loaded from the file with the '_<scale>x' suffix instead.

-- On a 1080p screen this loads 'materials/flux/gradient_2x.png'.
self:register_asset('gradient', 'materials/flux/gradient.png', { sizes = { 1, 2, 4 } })

Parameters

  • name String key to store the material under
  • path String path to the asset
  • options Map optional, defaults to {} sizes: List<Number> of available image scales, in ascending order

Returns

  • Material the stored material, nil if the asset is not an image

Removes this theme from the list of registered themes.

ThemeBase:set_color(id, val)

client packages/active_ui/lib/classes/cl_theme.lua:155

Sets a color of the theme.

Parameters

  • id String
  • val Color optional, defaults to Color(255, 255, 255)

Returns

  • Color the color that has been set

ThemeBase:set_font(key, value, scale, data)

client packages/active_ui/lib/classes/cl_theme.lua:143

Sets a font of the theme. The font is derived from an existing one with Font.size.

self:set_font('text_bar', 'flRoboto', math.scale(17), { weight = 600 })

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

Returns

  • String name of the font that has been set

ThemeBase:set_material(id, val)

client packages/active_ui/lib/classes/cl_theme.lua:167

Sets a material of the theme.

Parameters

  • id String
  • val String/Material material, or a path to load it from

Returns

  • Material

ThemeBase:set_option(key, value)

client packages/active_ui/lib/classes/cl_theme.lua:126

Sets an option of the theme.

Parameters

  • key String
  • value Any

Returns

  • Any the value

ThemeBase:set_sound(id, val)

client packages/active_ui/lib/classes/cl_theme.lua:176

Sets a sound of the theme.

Parameters

  • id String
  • val String path to the sound

Returns

  • String the path that has been set

Defined in