Class VulkanThemeSource
java.lang.Object
org.inspirenxe.strata.vulkan.VulkanThemeSource
- All Implemented Interfaces:
org.inspirenxe.strata.spi.ThemeSource
public final class VulkanThemeSource
extends Object
implements org.inspirenxe.strata.spi.ThemeSource
Finds theme files on the class path at
assets/<namespace>/themes/<path>.json, next to where
SpriteResolver.DEFAULT looks for sprites, or wherever a ThemePathResolver says. Every class path
entry that has the file contributes one document. An entry earlier on the class path has higher priority, as it
does for any other resource. Each document's layer is named after the entry it came from: a jar's file name, or
the URL of a directory.
A theme's base can be registered in two ways: a theme built in code with register(ThemeId, Theme), or
base files with register(ThemeId, List), for a theme written as JSON. Files are read once per id and
cached until reload(), which also tells open hosts to resolve their themes again. A file that cannot be
read is left out.
The platform's default theme, which screens opened without a theme use and ThemeRef.platform() names,
is Themes.FLAT until setDefaultTheme(ThemeId) changes it.
Every method may be called from any thread.
-
Field Summary
Fields inherited from interface org.inspirenxe.strata.spi.ThemeSource
NONE -
Constructor Summary
ConstructorsConstructorDescriptionVulkanThemeSource(ClassLoader loader) Creates a source.VulkanThemeSource(ClassLoader loader, ThemePathResolver resolver) Creates a source that finds theme files where a resolver says. -
Method Summary
Modifier and TypeMethodDescriptionOptional<org.inspirenxe.strata.api.theme.Theme> base(org.inspirenxe.strata.api.theme.ThemeId id) List<org.inspirenxe.strata.spi.ThemeDocument> bases(org.inspirenxe.strata.api.theme.ThemeId id) org.inspirenxe.strata.api.theme.ThemeIdList<org.inspirenxe.strata.spi.ThemeDocument> documents(org.inspirenxe.strata.api.theme.ThemeId id) voidregister(org.inspirenxe.strata.api.theme.ThemeId id, List<org.inspirenxe.strata.spi.ThemeDocument> documents) Registers base files under an id, replacing any base theme or base files registered under it before, and reloads.voidregister(org.inspirenxe.strata.api.theme.ThemeId id, org.inspirenxe.strata.api.theme.Theme theme) Registers a theme built in code under an id, replacing any base theme or base files registered under it before, and reloads.voidreload()Drops the cached files and changesversion(), so open hosts read the files again on their next layout or render.org.inspirenxe.strata.api.theme.Themeresolve(org.inspirenxe.strata.api.theme.ThemeRef ref) Resolves a ref against this source once, with the themes and overrides added in code, as a host does when it opens.voidsetDefaultTheme(org.inspirenxe.strata.api.theme.ThemeId id) Sets the platform's default theme for every view whose platform reads this source, and reloads, so open screens in the default theme change to it on their next layout or render.longversion()
-
Constructor Details
-
VulkanThemeSource
Creates a source.- Parameters:
loader- the class loader to find theme files with
-
VulkanThemeSource
Creates a source that finds theme files where a resolver says.- Parameters:
loader- the class loader to find theme files withresolver- where each theme's files live on the class path
-
-
Method Details
-
register
public void register(org.inspirenxe.strata.api.theme.ThemeId id, org.inspirenxe.strata.api.theme.Theme theme) Registers a theme built in code under an id, replacing any base theme or base files registered under it before, and reloads.- Parameters:
id- the id theme refs and theme files usetheme- the theme
-
register
public void register(org.inspirenxe.strata.api.theme.ThemeId id, List<org.inspirenxe.strata.spi.ThemeDocument> documents) Registers base files under an id, replacing any base theme or base files registered under it before, and reloads. Core starts the theme from theparentthe last of them names, applies them in order, and then applies the theme files the class path has for the id, whoseparentit ignores. Each file's keys report itsThemeDocument.layer. A base file that cannot be parsed makes the theme fail to resolve with aThemeExceptionnaming the file's origin.Keep the files somewhere the
ThemePathResolverdoes not look, or they apply twice, once as base files and once as theme files.- Parameters:
id- the id theme refs and theme files usedocuments- the base files, lowest priority first; copied- Throws:
IllegalArgumentException- if there are no documents
-
setDefaultTheme
public void setDefaultTheme(org.inspirenxe.strata.api.theme.ThemeId id) Sets the platform's default theme for every view whose platform reads this source, and reloads, so open screens in the default theme change to it on their next layout or render.- Parameters:
id- the theme screens opened without a theme use- Throws:
IllegalArgumentException- if the id isThemes.PLATFORM, which stands for the default
-
defaultTheme
public org.inspirenxe.strata.api.theme.ThemeId defaultTheme()- Specified by:
defaultThemein interfaceorg.inspirenxe.strata.spi.ThemeSource
-
reload
public void reload()Drops the cached files and changesversion(), so open hosts read the files again on their next layout or render. Call it after theme files change, for example while editing a theme. -
resolve
public org.inspirenxe.strata.api.theme.Theme resolve(org.inspirenxe.strata.api.theme.ThemeRef ref) Resolves a ref against this source once, with the themes and overrides added in code, as a host does when it opens. Tools use it to get a fixedTheme, for example to adjust some of its paints withTheme.toBuilder().- Parameters:
ref- the ref- Returns:
- the theme
- Throws:
org.inspirenxe.strata.api.theme.ThemeException- if the ref cannot be resolved
-
base
public Optional<org.inspirenxe.strata.api.theme.Theme> base(org.inspirenxe.strata.api.theme.ThemeId id) - Specified by:
basein interfaceorg.inspirenxe.strata.spi.ThemeSource
-
bases
public List<org.inspirenxe.strata.spi.ThemeDocument> bases(org.inspirenxe.strata.api.theme.ThemeId id) - Specified by:
basesin interfaceorg.inspirenxe.strata.spi.ThemeSource
-
documents
public List<org.inspirenxe.strata.spi.ThemeDocument> documents(org.inspirenxe.strata.api.theme.ThemeId id) - Specified by:
documentsin interfaceorg.inspirenxe.strata.spi.ThemeSource
-
version
public long version()- Specified by:
versionin interfaceorg.inspirenxe.strata.spi.ThemeSource
-