Last active
February 28, 2018 04:34
-
-
Save ahinchman1/565c57de444f084130bf8477786ca57b to your computer and use it in GitHub Desktop.
TornadoFX View setup for custom DnD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DragAndDrop : View() { | |
/***** Global Variables *****/ | |
private val tileBuilderController: TileBuilderController by inject() | |
val workbenchController: WorkbenchController by inject() | |
private val controller: TileGUIController by inject() | |
var workArea: GridPane by singleAssign() | |
var moduleBoxItems = mutableListOf<Node>() | |
lateinit var gridInfo: GridInfo | |
/***** View *****/ | |
override val root = stackpane { | |
gridInfo = GridInfo(controller.useTileGrid(workbenchController.tile)) | |
workArea = passGridInfo(gridInfo) | |
setPrefSize(1000.0, 650.0) | |
borderpane { | |
top { | |
label(title) { | |
font = Font.font(22.0) | |
} | |
menubar { | |
menu("File") { | |
item("Quit").action { | |
Platform.exit() | |
} | |
} | |
} | |
} | |
center = workArea | |
right { | |
vbox { | |
maxWidth = 300.0 | |
drawer = drawer(side = Side.RIGHT) { | |
item("Small Modules", expanded = true) { | |
datagrid(tileBuilderController.tileList) { | |
maxCellsInRow = 2 | |
cellWidth = 100.0 | |
cellHeight = 100.0 | |
cellFormat { | |
graphic = it | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
pane { | |
style { | |
backgroundColor += c(0, 100, 100, 0.05) | |
} | |
isMouseTransparent = true | |
} | |
addEventFilter(MouseEvent.MOUSE_PRESSED, ::startDrag) | |
addEventFilter(MouseEvent.MOUSE_DRAGGED, ::animateDrag) | |
addEventFilter(MouseEvent.MOUSE_RELEASED, ::stopDrag) | |
addEventFilter(MouseEvent.MOUSE_RELEASED, ::drop) | |
} | |
private fun startDrag(evt: MouseEvent) { | |
controller.startDrag(evt) | |
} | |
private fun animateDrag(evt: MouseEvent) { | |
controller.animateDrag(evt) | |
} | |
private fun stopDrag(evt: MouseEvent) { | |
controller.stopDrag(evt) | |
} | |
private fun drop(evt: MouseEvent) { | |
controller.drop(evt, this@TileGUI) | |
} | |
init { | |
moduleBoxItems.addAll( tileBuilderController.tileList ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment