Mark Fisher
11/18/2019, 3:41 PMclass CardAlignController : Controller() {
val cards = FXCollections.observableArrayList<CardData>()
val model = CardDataModel()
var currentIndex = 0
init {
cards.addAll(...) // some loader code here
model.item = cards[0]
}
fun nextCard() {
model.item = cards[++currentIndex]
println("Next invoked, index: $currentIndex, currentCard: ${model.card.value.name}")
}
but the main view doesn't update.
How can I tie moving through the list to the main view?
I don't have anything to do a bindSelected() on, so I'm not sure how to proceed.
Thanks!Carlton Whitehead
11/18/2019, 3:48 PMCarlton Whitehead
11/18/2019, 3:48 PMMark Fisher
11/18/2019, 3:49 PMpackage aligner.model
import tesl.model.Card
import tornadofx.ItemViewModel
import tornadofx.getProperty
import tornadofx.property
class CardData(
card: Card,
xOffset: Double,
yOffset: Double,
scale: Double,
index: Int
) {
var card by property(card)
fun cardProperty() = getProperty(CardData::card)
var xOffset by property(xOffset)
fun xOffsetProperty() = getProperty(CardData::xOffset)
var yOffset by property(yOffset)
fun yOffsetProperty() = getProperty(CardData::yOffset)
var scale by property(scale)
fun scaleProperty() = getProperty(CardData::scale)
var index by property(index)
fun indexProperty() = getProperty(CardData::index)
}
class CardDataModel: ItemViewModel<CardData>() {
val card = bind { item?.cardProperty() }
val xOffset = bind { item?.xOffsetProperty() }
val yOffset = bind { item?.yOffsetProperty() }
val scale = bind { item?.scaleProperty() }
val index = bind { item?.indexProperty() }
}
Mark Fisher
11/18/2019, 3:50 PMclass CardAlignMainView: View("Card Align Main View") {
val cardAlignController: CardAlignController by inject()
val model: CardDataModel by inject()
Mark Fisher
11/18/2019, 3:50 PMoverride val root = gridpane {
row {
stackpane {
group {
val name = cardAlignController.model.card.value.name
Mark Fisher
11/18/2019, 3:51 PMmodel.card.name
gives nothingCarlton Whitehead
11/18/2019, 3:52 PMCarlton Whitehead
11/18/2019, 3:53 PMby inject()
Carlton Whitehead
11/18/2019, 3:53 PMMark Fisher
11/18/2019, 3:54 PMmodel.item = cards[0]
?Carlton Whitehead
11/18/2019, 3:55 PMinit
block aloneMark Fisher
11/18/2019, 3:55 PMMark Fisher
11/18/2019, 3:56 PMnextCard()
be directly setting the model.item
as I'm doing?Carlton Whitehead
11/18/2019, 3:57 PMMark Fisher
11/18/2019, 3:59 PMMark Fisher
11/18/2019, 3:59 PMCarlton Whitehead
11/18/2019, 4:00 PM.value.name
is causing your view take the current backing value CardData
from your CardDataModel
. Use properties from CardDataModel
directly in that caseCarlton Whitehead
11/18/2019, 4:00 PMtextfield(model.name)
or similarMark Fisher
11/18/2019, 4:01 PMmodel.card.name
value is empty when the GUI is being displayed. which is why i reached into the controller. The value for model.card.value.name
is set thoughCarlton Whitehead
11/18/2019, 4:05 PMcards.addAll(...) // some loader code here
-- is that in a runAsync, or a coroutine, or is it happening synchronously in the init
for the controller?Mark Fisher
11/18/2019, 4:05 PMMark Fisher
11/18/2019, 4:06 PMCarlton Whitehead
11/18/2019, 4:07 PMcard: Card
Carlton Whitehead
11/18/2019, 4:08 PMselect
to obtain a selection binding that follows the current card
, selecting the nameProperty
from the Card
Mark Fisher
11/18/2019, 4:09 PMCarlton Whitehead
11/18/2019, 4:09 PMCarlton Whitehead
11/18/2019, 4:10 PMMark Fisher
11/18/2019, 4:11 PMBogdan
11/18/2019, 4:12 PMBogdan
11/18/2019, 4:12 PMbindSelect
Mark Fisher
11/18/2019, 4:13 PMCarlton Whitehead
11/18/2019, 4:14 PMMark Fisher
11/18/2019, 4:15 PMMark Fisher
11/18/2019, 4:56 PMimageview(model.cardUrl) {
... etc which now updates the view when I move through the list. thanks for the help all.