ThemeBuilder
Builds a Theme. A Theme can be thought of as the rules
which change colors, size and other attributes of Nodes within a Scene.
A ThemeBuilder specifies these rules using a DSL (domain specific language). The DSL is the equivalent to CSS
(cascading style sheets) used by other GUI toolkits.
Using a DSL instead of CSS has some advantages :
No need to learn new syntax. Everything is Kotlin code.
Syntax highlighting, code completion etc. are handled by your IDE like any other Kotlin code.
All the features of Kotlin are available, such as variables, if statements etc.
Attributes can be expressions, rather than constants. e.g. Set a border size of
standardSize + 2
It is really easy to change property values, with a single assignment. All scenes are automatically updated.
Most typos are detected at compile-time (or earlier - while typing in your IDE)
No need to parse a text file at runtime.
Disadvantages
They are executable code, not data, and therefore if you blindly incorporate a 3rd party's theme you are trusting them not to include malicious code. i.e. the same level of trust is required as you give to 3rd party Java/Kotlin libraries.
ThemeBuilders must be in your classpath. You cannot easily incorporate a theme from a file.
Tantalum is the default ThemeBuilder. It has many customisable properties, such as a standard font size, a palette of colors etc. Whenever any of these properties change, the Theme is rebuilt. The Theme doesn't contain any Properties
, only values. So for example, if you change Tantalum.accentColorProperty, a new Theme is created. For performance reasons, the theme is rebuilt at the end of the current frame
. So if you change many properties at the same time, the theme is only rebuilt once.
Rebuilding a theme is relatively expensive, so for example, do NOT constantly change properties to achieve animation effects.
FYI, Tantalum is often referred to as the default theme, despite it being a ThemeBuilder and not a Theme. Using the phrase theme-builder is just too clunky, and most of the time, the subtle distinction between the two types isn't important.
Inheritors
Properties
The theme generated by buildTheme. GlokSettings.defaultTheme is typically bound to this property, so that whenever any of this ThemeBuilder's properties change, the entire application will be re-themed.
Functions
This is where the magic happens. Your theme builder must implement this abstract method.
Combines two ThemeBuilders. The result is an ObservableTheme whose value is a Theme with rules from both of the ThemeBuilders.