Adding custom themes to Boomega
April 28, 2022 ยท View on GitHub
This page will guide you how to contribute UI Themes to the app, and also gives the fundamentals for developing theme-plugins.
Prerequisites
These apply to you only if you're contributing to the core project:
- Make sure you've read the contribution guideline
- Work in the
boomega-guisubproject
Stylesheets
For creating your custom themes, you should have knowledge in JavaFX CSS. The Boomega UI elements have unique style-classes and identifiers. Look at the internal Boomega style-sheets to get in touch:
- base.css - global UI style
configuration (used in both the
lightanddarktheme); you are free to import it in your own stylesheets. - light.css - the light-theme styles.
Used by
LightTheme - dark.css - the dark-theme styles. Used
by
DarkTheme
Note that these stylesheets are partial, because these internal themes use the JMetro JavaFX Theme as a basis. So if you write your stylesheets from scratch you may have to work more.
These apply to you only if you're contributing to the core project:
- Place your stylesheets into the resources/com/dansoftware/boomega/gui/theme directory.
The Theme class
In Boomega, a Theme is responsible for
applying the styles on the UI (usually by simply adding the stylesheets to the JavaFX elements).
Methods need to be implemented:
apply(Scene)- should apply the styles on a JavaFX Sceneapply(Parent)- should apply the styles on a JavaFX Parent
Also, the theme should also provide a way to "reset" the UI:
deApply(Scene)- should remove the styles from a JavaFX ScenedeApply(Parent)- should remove the styles from a JavaFX Parent
Optional:
init()- executed when theThemeis set asdefaultdestroy()- executed when theThemeis not default anymore
These apply to you only if you're contributing to the core project:
- Place your theme classes into the com.dansoftware.boomega.gui.theme directory.
A simple example:
| Kotlin | Java |
|---|---|
|
|
Registering your theme
This page applies to you only if you're contributing to the core project.
After you've created your theme implementation you have to register it's full class-name in the internal_themes.json config file.
Like this:
{
...
"themeClassNames" : [
...
"com.dansoftware.boomega.gui.theme.NordTheme"
]
}
Creating themes on top of JMetro
If you want to build you theme on top of the JMetro JavaFX Theme, then you can do it easily by extending the JMetroTheme class.
E.g:
class ExtendedDarkTheme : JMetroTheme(Style.DARK) {
...
private val styleSheet: String = ...;
override fun apply(region: Parent) {
super.apply(region)
region.stylesheets.add(styleSheet)
}
override fun apply(scene: Scene) {
super.apply(scene)
scene.stylesheets.add(styleSheet)
}
override fun deApply(region: Parent) {
super.deApply(region)
region.stylesheets.remove(styleSheet)
}
override fun deApply(scene: Scene) {
super.deApply(scene)
scene.stylesheets.remove(styleSheet)
}
}
Other examples
You can view the internal Theme implementations (for understanding the concepts better)
in the com.dansoftware.boomega.gui.theme package e.g:
You are free to contribute your own theme to be included in the core Boomega itself. However, if you want to add your theme as a plugin, go to the plugin guide!