Views
6 months ago

tornadofx-guide

6. Type Safe CSS Now you

6. Type Safe CSS Now you have orange borders around the HBox as well as the buttons. When nesting styles, keep in mind that wrapping the selection with and() will cascade styles to children controls or classes. Mixins There are times you may want to reuse a set of stylings and apply them to several controls and selectors. This prevents you from having to redundantly define the same properties and values. For instance, if you want to create a set of styling called redAllTheThings , you could define it as a mixin as shown below. Then you can reuse it for a redStyle class, as well as a textInput , a label , and a passwordField with additional style modifications (Figure 6.9). Stylesheet 82

6. Type Safe CSS import javafx.scene.paint.Color import javafx.scene.text.FontWeight import tornadofx.* class Styles : Stylesheet() { companion object { } val redStyle by cssclass(). init { val redAllTheThings = mixin { backgroundInsets += box(5.px) borderColor += box(Color.RED) textFill = Color.RED } redStyle { } +redAllTheThings s(textInput, label) { +redAllTheThings fontWeight = FontWeight.BOLD } } } passwordField { +redAllTheThings backgroundColor += Color.YELLOW } App and View 83

Guide
guide
GUIDE
GUIDE
GUIDE
GUIDE
Guide
GUIDE
Guide
guide
GUIDE
GUIDE
GUIDE
Guide
GUIDE TO
Guide
GUIDE