Views
6 months ago

tornadofx-guide

6. Type Safe CSS Infact,

6. Type Safe CSS Infact, manipulating classes on several nodes at once is so common that TornadoFX provides a shortcut for it: children.filter { it is Button }.addClass(MyStyle.tackyButton) } You can also target all Button instances in your application by selecting and modifying the button in the Stylesheet . This will apply the style to all Buttons. import javafx.scene.paint.Color import tornadofx.* class MyStyle: Stylesheet() { companion object { val tackyButton by cssclass() } private val topColor = Color.RED private val rightColor = Color.DARKGREEN private val leftColor = Color.ORANGE private val bottomColor = Color.PURPLE } init { button { rotate = 10.deg borderColor += box(topColor,rightColor,leftColor,bottomColor) fontFamily = "Comic Sans MS" fontSize = 20.px } } import javafx.scene.layout.VBox import tornadofx.* class MyApp: App(MyView::class, MyStyle::class) { init { reloadStylesheetsOnFocus() } } class MyView: View() { override val root = vbox { button("Press Me") button("Press Me Too") } } 76

6. Type Safe CSS Figure 6.3 Note also you can select multiple classes and control types to mix-and-match styles. For example, you can set the font size of labels and buttons to 20 pixels, and create tacky borders and fonts only for buttons (Figure 6.4). class MyStyle: Stylesheet() { companion object { } private val topColor = Color.RED private val rightColor = Color.DARKGREEN private val leftColor = Color.ORANGE private val bottomColor = Color.PURPLE } init { s(button, label) { fontSize = 20.px } button { rotate = 10.deg borderColor += box(topColor,rightColor,leftColor,bottomColor) fontFamily = "Comic Sans MS" } } class MyApp: App(MyView::class, MyStyle::class) { init { reloadStylesheetsOnFocus() } } class MyView: View() { override val root = vbox { label("Lorem Ipsum") button("Press Me") button("Press Me Too") } } 77

Guide
Guide
GUIDE
GUIDE
GUIDE
GUIDE
GUIDE
Guide
GUIDE
GUIDE
GUIDE
Guide
The Guide
GUIDE
Guide
GUIDE
Guide
GUIDE
Guide
Guide
GUIDE
GUIDE
GUIDE
GUIDE
guide
Guide
Guide
Guide to
SELECTION GUIDE SELECTION GUIDE
The Ultimate Guide The Ultimate Guide