我试图将这个JavaFX 类翻译成 TornadoFX。将鼠标悬停在我无法弄清楚protected void layoutChildren()
TornadoFX 应该如何处理?
这是我到目前为止的代码:
class ReversiSquare(x: Int, y: Int) : View() {
var x by property(x)
fun xProperty() = getProperty(ReversiSquare::y)
var y by property(y)
fun yProperty() = getProperty(ReversiSquare::y)
var highlight: Region by singleAssign()
var highlightTransition: FadeTransition by singleAssign()
val model = ReversiModel
override val root = region {
region {
opacity = 0.0
style = "-fx-border-width: 3; -fx-border-color: dodgerblue"
highlight = this
}
// todo not sure this works with singleAssign
highlightTransition = FadeTransition(Duration.millis(200.0), highlight).apply {
fromValue = 0.0
toValue = 1.0
}
styleProperty().bind(Bindings.`when`(model.legalMove(x, y))
.then("-fx-background-color: derive(dodgerblue, -60%)")
.otherwise("-fx-background-color: burlywood"))
val light = Light.Distant().apply {
azimuth = -135.0
elevation = 30.0
}
effect = Lighting(light)
setPrefSize(200.0,200.0)
this += highlight
addEventHandler(MouseEvent.MOUSE_ENTERED_TARGET) {
if(model.legalMove(x ,y).get()) {
with(highlightTransition) {
rate =1.0
play()
}
}
}
addEventHandler(MouseEvent.MOUSE_EXITED_TARGET) {
with(highlightTransition) {
rate = -1.0
play()
}
}
onDoubleClick {
model.play(x, y)
highlightTransition.rate = -1.0
highlightTransition.play()
}
}
}