简体   繁体   English

从ViewModel TornadoFX绘制线条

[英]Drawing lines from ViewModel TornadoFX

So I got a ViewModel containing Lines (that is 2 point objects that both have an x and y double property). 因此,我得到了一个包含Lines的ViewModel(即两个具有x和y double属性的点对象)。 I want to bind this to some canvas or something a like. 我想将此绑定到某些画布或类似的东西。 Furthermore, it could be that lines are not added incrementally to the ViewModel, but all in one time (eg when loading an external file that contains a lot of lines data). 此外,可能是行没有一次增量地添加到ViewModel中,而是一次全部添加(例如,当加载包含很多行数据的外部文件时)。

How can you solve this with TornadoFX? 您如何使用TornadoFX解决此问题? Moreover, how to make it run smoothly even with a lot of line data. 此外,即使有很多行数据,如何使它平稳运行。 Is it possible with gui builders? 图形用户界面建造者有可能吗?

A simple bindChildren fixes it: 一个简单的bindChildren可以解决此问题:

stackpane {
    group {
        bindChildren(model.segments) { segment ->
            line(segment.first.x, segment.first.y, segment.second.x, segment.second.y)
        }
    }
}

In the model, the declaration of the segments: 在模型中,段的声明:

val segments: ObservableList<Segment> = FXCollections.observableArrayList<Segment>()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM