Views
7 months ago

tornadofx-guide

Workspaces Drawer

Workspaces Drawer navigation The Workspace has built in support for the Drawer control. You can access workspace.leftDrawer and workspace.rightDrawer to add items to each drawer. They will show up on either the left or right side whenever you have added one or more items to them. Items added from a View in onDock will automatically be removed when the View is undocked. Items added directly in the Workspace subclass, from the onBeforeShow App callback or from any other place will stay until they are manually removed. The combination of static and dynamic drawer items makes for a very powerful navigation and menu structure. Only your imagination is the limit! The following example creates a customize Workspace primed with a docked Customer Editor in the editor area and the three drawer items we created in the Drawer chapter configured statically in the leftDrawer of the Workspace: 242

Workspaces // A Form based View we will dock in the workspace editor area class CustomerEditor : View("Customer Editor") { override val root = form { fieldset(title) { field("Name") { textfield() } field("Username") { textfield() } button("Save") } } } class DrawerWorkspace : Workspace() { init { // Dock the Customer Editor by default dock() } init { // Add items to the left drawers with(leftDrawer) { item("Screencasts") { webview { prefWidth = 470.0 engine.userAgent = iPhoneUserAgent engine.load(TornadoFXScreencastsURI) } } item("Links") { listview(links) { cellFormat { link -> graphic = hyperlink(link.name).action { hostServices.showDocument(link.uri) } } } } item("People") { tableview(people) { column("Name", Person::name) column("Nick", Person::nick) } } } } } // Sample data and configuration omitted for this example In Figure 16.8 we have expanded the Links drawer item. Notice how it pushes the Customer Editor to the right. 243

GUIDE
GUIDE
GUIDE
Guide
GUIDE
Guide
GUIDE
GUIDE
Guide
GUIDE
Guide
GUIDE
Guide
GUIDE
GUIDE
GUIDE