font([font], [update])

Class: Tree. Method inherited from UIComponent.

Description:

Gets or sets the font used for the component's text. See the example for font object format.

Parameters:

Name Type Description

[font]

Font

Font formatted object.

[update]

boolean

If true, only the specified font properties will be updated instead of replacing the entire font.

Returns:

Type: this | Font

Examples:

Full list of supported font properties:

Font {
    name: string,           // Font family name (e.g., "sans-serif")
    size: number,           // Font size in pixels
    bold: boolean,          // Whether the text is bold
    italic: boolean,        // Whether the text is italic
    underlined: boolean,    // Whether the text is underlined
    strikethrough: boolean, // Whether the text has a strikethrough
    direction: string,      // Text direction: "ltr" or "rtl"
    kerning: boolean,       // Enable or disable kerning
    ligatures: boolean,     // Enable or disable font ligatures
    tracking: number        // Letter spacing adjustment: -1, 0 (default), or 1
};

Usage examples:

// Sets new font
textarea.font({name: "sans-serif", size: 14, italic: true});

// Set a new font; previously set italic style will be removed
textarea.font({name: "sans-serif", size: 14});

// Update only the font size, preserving other properties
textarea.font({size: 20}, true);

// get component's font
const font = textarea.font();

Also See: