UI Toolbox logoUI Toolbox
Support

Theme API

Video tutorial: Themes. All videos: Video tutorials.

Member Kind Effect
theme-name UXML attribute (ThemeName) The theme to load on attach. A new value on an attached workspace switches the theme, as SetTheme does. Default: default.
auto-load-styles UXML attribute (AutoLoadStyles) If false, WindowStyles.uss and the theme sheet are not loaded. Default: true.
SetTheme(string themeName) Method Removes the previous theme sheet and adds UIToolbox/Themes/{themeName}. User sheets stay above it. default or dark removes the theme sheet. It also swaps the theme class, such as tb-theme--game, on the workspace.
ThemeChanged Event Raised after SetTheme switches the theme, with the new theme name. The new sheet and the new class are on the workspace when it is raised. The same theme raises nothing.
ThemeClass(string? themeName) Static method The class of a theme on its workspace: tb-theme-- and the theme name. null, "", default and dark give tb-theme--dark. See The theme class.
THEMES_FOLDER Constant "UIToolbox/Themes/", the Resources folder of the theme sheets. Resources.Load<StyleSheet>(Workspace.THEMES_FOLDER + "game") loads a theme sheet for an element that is not a workspace.
AvailableThemes Static property The names of the sheets in Resources/UIToolbox/Themes: dark first, then the others by name. A theme of your game is in the list when its sheet is in a Resources/UIToolbox/Themes folder.
AddUserStyleSheet(StyleSheet) Method Adds a sheet above the theme. Theme changes do not remove it.
RemoveUserStyleSheet(StyleSheet) Method Removes a sheet that you added with AddUserStyleSheet.
text-size UXML attribute (TextSize) Text size: Normal, Large (125%), Larger (150%) or Largest (200%). You can change it at any time. Default: Normal.

You can call these methods before the workspace attaches. They apply on attach. ThemeSelector is a dropdown of the themes.

Built-in themes

Theme Look
dark The base palette, VS Code dark. default is the same.
light Light gray surfaces and dark text.
high-contrast Black, white and yellow, with thicker borders.
toolbox The UI Toolbox logo colors: charcoal surfaces, a blue accent and green for success and dock targets.
toolbox-light The logo colors on light gray.
game Night glass windows with a blur, a gold accent, the Rajdhani font and glossy buttons. See The Game theme.
game-custom An example user sheet with a purple palette and larger sizes. It also works as a theme.

dark stays the default of the package and of the samples. Every other theme is opt-in.

The Game theme

SetTheme("game") gives the workspace the look of a game menu. It shows that one style sheet can change every part of the toolbox.

Your own Button in a workspace with the Game theme gets the gloss too. To keep one flat, turn the gloss off for the Game theme only:

.tb-theme--game .my-flat-button {
    background-image: none;
}

The theme class

Each workspace has the class of its theme: tb-theme--dark for the base palette, tb-theme--light, tb-theme--game and so on (Workspace.ThemeClass(name)). SetTheme swaps it before it raises ThemeChanged. With the class, a sheet can style a part for one theme only:

.tb-theme--game .my-hud {
    border-color: var(--tb-color-accent);
}

The class is on the workspace only, so an element outside the workspace does not have it. The workspace gives its open dropdown menus its theme sheet, and the :root rule of the sheet matches the menu. To give another element outside the workspace a theme, add the theme sheet to it: Resources.Load<StyleSheet>(Workspace.THEMES_FOLDER + "game").

Text size

TextSize is for users who need larger text. Any value other than Normal adds the class tb-text-size--125, --150 or --200 (Workspace.TextSizeClass) to the workspace and to its open dropdown menus. The rules for these classes in WindowStyles.uss set fixed values for the font size variables, --tb-size-title-bar and --tb-size-button.

<tb:Workspace theme-name="high-contrast" text-size="Larger" />

Set the theme

In UXML:

<tb:Workspace name="workspace" theme-name="light" />

In code:

#nullable enable
using UIToolbox;
using UnityEngine;
using UnityEngine.UIElements;

public class ThemeSwitcher : MonoBehaviour
{
    [SerializeField] private StyleSheet? _brandSheet;

    private void Start()
    {
        var workspace = GetComponent<UIDocument>().rootVisualElement
            .Q<Workspace>();
        workspace.SetTheme("high-contrast");
        if (_brandSheet != null)
            workspace.AddUserStyleSheet(_brandSheet);
    }
}