Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

ObservableStyleClass #88

Closed
edvin opened this issue Apr 15, 2016 · 3 comments
Closed

ObservableStyleClass #88

edvin opened this issue Apr 15, 2016 · 3 comments

Comments

@edvin
Copy link
Owner

edvin commented Apr 15, 2016

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 a Node and have the value of the property reflected in the styleClass 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.

@edvin
Copy link
Owner Author

edvin commented Apr 15, 2016

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

edvin pushed a commit that referenced this issue Apr 15, 2016
@edvin
Copy link
Owner Author

edvin commented Apr 15, 2016

@t-boom I put this functionality in CSS.kt. We can merge #80 into this file when you're ready :)

@edvin
Copy link
Owner Author

edvin commented Apr 15, 2016

Completed, will be in the TornadoFX 1.4.3 release.

@edvin edvin closed this as completed Apr 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant