Denis
Denis

Reputation: 1543

cannot set colors css tornadofx

I am just playing with examples of TornadoFX, but I cannot reproduce the following https://github.com/edvin/tornadofx/wiki/Type-Safe-CSS, more precisely:

backgroundColor += hoverColor

Doesn't compile for me, it says type mismatch, required Paint, found CSSRule Neither can I set the borderColor +=box(dangerColor), I also have a type mismatch type mismatches picture

Upvotes: 0

Views: 1524

Answers (3)

Fazal Jarral
Fazal Jarral

Reputation: 170

you can use two builtin functions

  1. c() //pass color string and opacity as parameters
  2. multi() // pass string color

Upvotes: 0

Aleksandar Stefanović
Aleksandar Stefanović

Reputation: 1593

Your imports are wrong, try using the

import tornadofx.*

statement. Currently, you are using tornadofx.Stylesheet.Companion.box function, instead of the box function from CSSKt.class.

Upvotes: 1

Edvin Syse
Edvin Syse

Reputation: 7297

I just tested your exact code and it compiles and works. Either you're using an outdated version of TornadoFX or you have some other error in your file that confuses IDEA to give you the wrong error message. Try for yourself with this exact snippet and you'll see that it compiles:

class Styles : Stylesheet() {
    companion object {
        val dangerColor = c("#a94442")
        val hoverColor = c("#d49942")
    }

    init {
        root {
            button {
                backgroundColor += Color.GRAY
                borderWidth += box(5.px)
                borderColor += box(dangerColor)
                and(hover) {
                    backgroundColor += hoverColor
                }
            }
        }
    }
}

On another note: Why do you wrap everything in root? There should be no need for that.

Upvotes: 0

Related Questions