简体   繁体   English

无法设置颜色 css tornadofx

[英]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:我只是在玩 TornadoFX 的示例,但我无法更准确地重现以下https://github.com/edvin/tornadofx/wiki/Type-Safe-CSS

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 mismatch, required Paint, found CSSRule我也不能设置borderColor +=box(dangerColor) ,我也有类型不匹配图片类型不匹配

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 .目前,使用的是tornadofx.Stylesheet.Companion.box功能,而不是box从功能CSSKt.class

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.要么您使用的是过时版本的 TornadoFX,要么您的文件中存在一些其他错误,使 IDEA 感到困惑,从而为您提供错误的错误消息。 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 ?另一个注意事项:为什么要将所有内容都包装在root There should be no need for that.应该没有这个必要。

you can use two builtin functions您可以使用两个内置函数

  1. c() //pass color string and opacity as parameters c() //传递颜色字符串和不透明度作为参数
  2. multi() // pass string color multi() // 传递字符串颜色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM