简体   繁体   English

TornadoFX:具有其他库的类型安全CSS

[英]TornadoFX: Type-Safe CSS with other libraries

I'm new to Kolin and TornadoFX and I'm currently experimenting with some of its features. 我是Kolin和TornadoFX的新手,目前正在尝试使用其某些功能。 I'd like to use the JFoenix-Library and style its controls using the type-safe CSS feature of TornadoFX. 我想使用JFoenix-Library并使用TornadoFX的类型安全CSS功能设置其控件的样式。 But I don't know how to modify styles given the CSS class of a JFoenix control. 但是在给定JFoenix控件的CSS类的情况下,我不知道如何修改样式。

For example, the JFXDecorator has the default CSS class jfx-decorator . 例如, JFXDecorator具有默认的CSS类jfx-decorator To change the background color of the title bar I have to modify the class jfx-decorator-buttons-container . 要更改标题栏的背景颜色,我必须修改类jfx-decorator-buttons-container How can I do this with TornadoFX? 如何使用TornadoFX做到这一点? In a .css file I would just use 在一个.css文件中,我只会使用

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

Is this possible with TornadoFX? TornadoFX有可能吗?

You mention the classes jfx-decorator and jfx-decorator-buttons-container , but your example CSS uses the classes jfx-decorator-buttons and container . 您提到了jfx-decoratorjfx-decorator-buttons-container ,但是示例CSS使用了jfx-decorator-buttonscontainer I'm unsure which classes you really want, but I'll add the two latter, since that will produce the CSS from your example. 我不确定您真正想要的是哪个类,但是我将添加后者,因为这将从您的示例中生成CSS。

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: 您还可以在cssclass委托函数中指定确切的名称:

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 += . 还要注意,由于backgroundColor属性接受多个值,因此必须使用+=将颜色“添加”到颜色列表中。 This is the common pattern for all properties that accept multiple values. 这是接受多个值的所有属性的通用模式。

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

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