TornadoFX: Type-Safe CSS with other libraries

matthjes

I'm new to Kolin and TornadoFX and I'm currently experimenting with some of its features. I'd like to use the JFoenix-Library and style its controls using the type-safe CSS feature of TornadoFX. But I don't know how to modify styles given the CSS class of a JFoenix control.

For example, the JFXDecorator has the default CSS class jfx-decorator. To change the background color of the title bar I have to modify the class jfx-decorator-buttons-container. How can I do this with TornadoFX? In a .css file I would just use

.jfx-decorator-buttons-container {
  -fx-background-color: red;
}

Is this possible with TornadoFX?

Edvin Syse

You mention the classes jfx-decorator and jfx-decorator-buttons-container, but your example CSS uses the classes jfx-decorator-buttons and container. I'm unsure which classes you really want, but I'll add the two latter, since that will produce the CSS from your example.

class Styles : Stylesheet() {
    companion object {
        val jfxDecoratorButtons by cssclass()
        val container by cssclass()
    }

    init {
        jfxDecoratorButtons and container {
            backgroundColor += Color.RED
        }
    }
}

UPDATE: You changed the code in your question, so here is the updated version that will produce that output:

class Styles : Stylesheet() {
    companion object {
        val jfxDecoratorButtonsContainer by cssclass()
    }

    init {
        jfxDecoratorButtonsContainer {
            backgroundColor += Color.RED
        }
    }
}

Camel cased selectors are automatically converted to lower cased with hyphens. You can also specify the exact name inside the cssclass delegate function:

val myCssClass by cssclass("my-slightly-different-css-class")

Notice also that since the backgroundColor property accepts multiple values, you must "add" the color to the list of colors using +=. This is the common pattern for all properties that accept multiple values.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Type-safe css having no effect on controls tornadofx

TornadoFx: Which performs better FXML or type-CSS

Tornadofx CSS Seleccted row

Round-up of Scalaz type class instances for other libraries

TornadoFX runAsyncWithProgress with nullable return type

How to effectively use PyJulia or other non-thread-safe libraries in a background thread or process?

Best way to include other CSS/JS libraries in a Github repo?

Uses of generics in java other than making type safe collections?

How to target pseudo controls using type-safe css in Kotlin

css first-of-type under other class

Apply CSS to first type and other conditions together

JavaFx & TornadoFX changing margin in CSS or TypeSafeCSS

Webpack require other libraries

(CMake) PCL + Other libraries

c++ cannot use libraries in other libraries

ClassNotFoundException from libraries that use other libraries

Is it possible to create a self contained Angularjs app that will not clash with with any other Js or css libraries on the same page

Refactor: What is the type-safe way to overload methods with instance arguments, e.g. method(self, other)?

How to use strictNullChecks with libraries that are not nullCheck safe

Is it safe to use @SuppressLint("RestrictedApi") with AndroidX libraries?

Android is it safe to use github libraries with maven

Safe imports of libraries in multiple LESS or SASS stylesheets

Is always safe to add dependency libraries as compiled in Java?

guava-libraries - Is the Ordering class thread safe?

Is it safe to install old libraries? Wine issue

Where are the type libraries for EnvDTE?

Shared libraries not found on other system

Type safe parameter in method

Type safe field assignment