Closed edvin closed 8 years ago
Stylesheet:
.success { -fx-background-color: green }
.danger { -fx-background-color: red }
.warning { -fx-background-color: orange }
Demo app:
class StyleClassView : View() {
override val root = HBox()
init {
importStylesheet(TestStylesheet::class)
with(root) {
padding = Insets(70.0)
// The observable property
val selectedClass = SimpleStringProperty()
// A combo box that updates the observable property
combobox(selectedClass, listOf("success", "danger", "warning").observable())
// Bind the current value as a styleClass on the HBox
bindClass(selectedClass)
}
}
}
No selection
Success selected
Danger selected
Warning selected
@t-boom I put this functionality in CSS.kt
. We can merge https://github.com/edvin/tornadofx/issues/80 into this file when you're ready :)
Completed, will be in the TornadoFX 1.4.3
release.
Some times you want to swap a style class on a node depending on some other state. It would be convenient to ble able to bind a
Property<String>
to aNode
and have the value of the property reflected in thestyleClass
list of that node.When the property changes, the old value would be removed from the style class and the new value would be added.