ThemeBase classclient
Part of Active UI
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
Methods
Converts the theme to a string for printing.
Returns
- String
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
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
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
Returns the name of a font of the theme.
Parameters
- key String
- default String optional, defaults to
nilreturned if the font is not set
Returns
- String font name
Returns a material of the theme.
Parameters
- id String
- failsafe Material optional, defaults to
nilreturned if the material is not set
Returns
- Material
Returns an option of the theme.
Parameters
- key String
- default Any optional, defaults to
nilreturned if the option is not set or is false
Returns
- Any value of the option
Returns a sound of the theme.
Parameters
- id String
- failsafe String optional, defaults to
nilreturned if the sound is not set
Returns
- String path to the sound
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
nilID of the theme to inherit from
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.
Called when the theme is unloaded. Does nothing by default.
Adds this theme to the list of registered themes.
See also
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.
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
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
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
Returns
- String name of the font that has been set
Sets a material of the theme.
Parameters
- id String
- val String/Material material, or a path to load it from
Returns
- Material
Sets an option of the theme.
Parameters
- key String
- value Any
Returns
- Any the value
Sets a sound of the theme.
Parameters
- id String
- val String path to the sound
Returns
- String the path that has been set