Interface ThemeRegistry
public interface ThemeRegistry
Themes and overrides added in code, for every host in the process. Get it from
Strata.themes(). Do not implement this interface.
// Every screen that shows the engine's theme gets these buttons
Subscription buttons = Strata.themes().override(engineTheme, ThemeOverrides.of()
.with(Button.STYLE_NORMAL, Paint.nineSlice(SpriteId.of("myapp", "button"), Insets.of(3f))));
// A theme of the application's own that follows packs for every key it leaves alone
Strata.themes().define(ThemeId.of("myapp", "dark"), engineTheme, ThemeOverrides.of()
.with(Window.STYLE_BACKGROUND, Paint.solid(0xF0101010)));
Nothing here is written to a theme, a theme file or the engine's packs. The keys apply each time a theme
resolves, and once a subscription is closed, the keys it set resolve as they did before it. Every change here
makes each host that shows a ThemeRef resolve it again at the start of its next layout or render, so
open screens pick the change up. Every method may be called from any thread.
-
Method Summary
Modifier and TypeMethodDescriptiondefine(ThemeId id, ThemeId parent, ThemeOverrides overrides) Defines a theme that starts from another and sets the overrides' keys, until the subscription is closed.override(ThemeId id, ThemeOverrides overrides) Sets keys on a theme for every screen that uses it, until the subscription is closed.
-
Method Details
-
override
Sets keys on a theme for every screen that uses it, until the subscription is closed. The keys apply above the base and every theme file for the id, so code has the final say over packs. Overrides for one id apply in the order they were added, and aThemeRef's own overrides apply after all of them. The keys report the layercodefromTheme.layer(String).The id need not resolve yet; the overrides wait until it does. Overrides for
Themes.PLATFORMapply to whichever theme is the platform's default, above that theme's own overrides.- Parameters:
id- the theme to changeoverrides- the keys to set- Returns:
- a subscription that removes the overrides when closed
-
define
Defines a theme that starts from another and sets the overrides' keys, until the subscription is closed. The defined theme resolves as one whose base is its parent, resolved in full, with the overrides above it. Theme files for the id still apply on top, as for any theme, but theirparentis ignored. The overrides' keys report the layercodefromTheme.layer(String).An id that the engine adapter already gives a base, in code or as base files, cannot be defined. That is found when the theme resolves, which then throws
ThemeException.- Parameters:
id- the theme to defineparent- the theme it starts fromoverrides- the keys it sets on the parent- Returns:
- a subscription that removes the definition when closed, after which the id can be defined again
- Throws:
ThemeException- if the id is already defined in code and that definition is still open, isThemes.FLAT, which Strata builds in code, or isThemes.PLATFORM, which stands for the platform's default theme
-