09.04.2018 Views

tornadofx-guide

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

9. Shapes and Animation<br />

Shapes and Animation<br />

JavaFX comes with nodes that represent almost any geometric shape as well as a Path<br />

node that provides facilities required for assembly and management of a geometric path (to<br />

create custom shapes). JavaFX also has animation support to gradually change a Node<br />

property, creating a visual transition between two states. TornadoFX seeks to streamline all<br />

these features through builder constructs.<br />

Shape Basics<br />

Every parameter to the shape builders are optional, and in most cases default to a value of<br />

0.0 . This means that you only need to provide the parameters you care about. The<br />

builders have positional parameters for most of the properties of each shape, and the rest<br />

can be set in the functional block that follows. Therefore these are all valid ways to create a<br />

rectangle:<br />

rectangle {<br />

width = 100.0<br />

height = 100.0<br />

}<br />

rectangle(width = 100.0, height = 100.0)<br />

rectangle(0.0, 0.0, 100.0, 100.0)<br />

The form you choose is a matter of preference, but obviously consider the legibility of the<br />

code you write. The examples in this chapter specify most of the properties inside the code<br />

block for clarity, except when there is no code block support or the parameters are<br />

reasonably self-explanatory.<br />

Positioning within the Parent<br />

Most of the shape builders give you the option to specify the location of the shape within the<br />

parent. Whether or not this will have any effect depends on the parent node. An HBox will<br />

not care about the x and y coordinates you specify unless you call setManaged(false)<br />

on the shape. However, a Group control will. The screenshots in the following examples will<br />

be created by wrapping a StackPane with padding around a Group , and finally the shape<br />

was created inside that Group as shown below.<br />

132

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!