Font libraryclient
Part of Active UI
Creates and keeps track of the fonts of the Flux interface. Font.create wraps
surface.CreateFont and remembers the data of the font, which lets Font.size derive a
copy of any created font at another size on demand (named 'name:size'), so that the
interface can ask for a scaled font wherever it draws text. All fonts are created again by
Font.create_fonts when the gamemode loads on the client, once the schema has loaded and
whenever the screen resolution changes. It creates the built-in Roboto family ('flRoboto',
'flRobotoCondensed' and so on) and then runs the CreateFonts theme hook and the
CreateFonts hook. Plugins create their fonts from a CreateFonts handler so that they
survive these rebuilds, and themes give fonts a role with ThemeBase:set_font, which the
interface looks up with Theme.get_font.
Summary
Functions
Functions
Forgets all of the created fonts, so that they can be created again.
Creates a font and remembers its data. Does nothing if a font with this name has already been created. The extended (UTF-8) character range is always enabled.
Font.create('flRoboto', {
font = 'Roboto',
size = 16,
weight = 500
})
Parameters
- name String unique name of the new font
- font_data Map font structure, same as the one surface.CreateFont accepts
Returns
- Map the stored font data, or nil if the arguments are invalid or the font exists
Clears the stored fonts and creates the built-in Flux fonts again, then calls the 'CreateFonts' theme and plugin hooks so that everything else can create theirs.
Returns the data of a font created with Font.create.
Parameters
- name String
Returns
- Map font data, or nil if there is no such font
Returns the name of the specified font scaled to the specified size. The sized font is created from the original one on first use and is named 'name:size'.
-- Creates 'flRobotoCondensed:24' if it does not exist yet.
local font = Font.size('flRobotoCondensed', 24)
Parameters
- name String name of a font created with Font.create
- size Number optional, defaults to
nilfont size, the name is returned unchanged if omitted - data Map optional, defaults to
nilextra font data to merge into the sized font
Returns
- String name of the sized font, or false if no name was given