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

    Constructors
    Constructor
    Description
    Creates a source.
    Creates a source that finds theme files where a resolver says.
  • Method Summary

    Modifier and Type
    Method
    Description
    Optional<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.ThemeId
     
    List<org.inspirenxe.strata.spi.ThemeDocument>
    documents(org.inspirenxe.strata.api.theme.ThemeId id)
     
    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.
    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.
    void
    Drops the cached files and changes version(), so open hosts read the files again on their next layout or render.
    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.
    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.
    long
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • VulkanThemeSource

      public VulkanThemeSource(ClassLoader loader)
      Creates a source.
      Parameters:
      loader - the class loader to find theme files with
    • VulkanThemeSource

      public VulkanThemeSource(ClassLoader loader, ThemePathResolver resolver)
      Creates a source that finds theme files where a resolver says.
      Parameters:
      loader - the class loader to find theme files with
      resolver - 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 use
      theme - 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 the parent the last of them names, applies them in order, and then applies the theme files the class path has for the id, whose parent it ignores. Each file's keys report its ThemeDocument.layer. A base file that cannot be parsed makes the theme fail to resolve with a ThemeException naming the file's origin.

      Keep the files somewhere the ThemePathResolver does not look, or they apply twice, once as base files and once as theme files.

      Parameters:
      id - the id theme refs and theme files use
      documents - 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 is Themes.PLATFORM, which stands for the default
    • defaultTheme

      public org.inspirenxe.strata.api.theme.ThemeId defaultTheme()
      Specified by:
      defaultTheme in interface org.inspirenxe.strata.spi.ThemeSource
    • reload

      public void reload()
      Drops the cached files and changes version(), 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 fixed Theme, for example to adjust some of its paints with Theme.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:
      base in interface org.inspirenxe.strata.spi.ThemeSource
    • bases

      public List<org.inspirenxe.strata.spi.ThemeDocument> bases(org.inspirenxe.strata.api.theme.ThemeId id)
      Specified by:
      bases in interface org.inspirenxe.strata.spi.ThemeSource
    • documents

      public List<org.inspirenxe.strata.spi.ThemeDocument> documents(org.inspirenxe.strata.api.theme.ThemeId id)
      Specified by:
      documents in interface org.inspirenxe.strata.spi.ThemeSource
    • version

      public long version()
      Specified by:
      version in interface org.inspirenxe.strata.spi.ThemeSource