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.

Advanced Data Controls<br />

Figure 5.2 - A custom cell rendering for ListView<br />

The cellFormat function lets you configure the text and/or graphic property of the cell<br />

whenever it comes into view on the screen. The cells themselves are reused, but whenever<br />

the ListView asks the cell to update its content, the cellFormat function is called. In our<br />

example we only assign to graphic , but if you just want to change the string representation<br />

you should assign it to text . It is completely legitimate to assign it to both text and<br />

graphic . The values will automatically be cleared by the cellFormat function when a<br />

certain list cell is not showing an active item.<br />

Note that assigning new nodes to the graphic property every time the list cell is asked to<br />

update can be expensive. It might be fine for many use cases, but for heavy node graphs, or<br />

node graphs where you utilize binding towards the UI components inside the cell, you should<br />

cache the resulting node so the Node graph will only be created once per node. This is done<br />

using the cache wrapper in the above example.<br />

202

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

Saved successfully!

Ooh no, something went wrong!