Lazyload listview cell elements

This commit is contained in:
Marvin Elsen 2024-11-06 18:14:16 +01:00
parent f5126e2d9e
commit 892058c47e
Signed by: marvinelsen
GPG Key ID: 820672408CC318C2
2 changed files with 53 additions and 37 deletions

View File

@ -39,7 +39,8 @@ private class EntryCell(
private val hostServices: HostServices, private val hostServices: HostServices,
) : ListCell<DictionaryEntryFx?>() { ) : ListCell<DictionaryEntryFx?>() {
private val labelHeadword = Label().apply { private val labelHeadword by lazy {
Label().apply {
styleClass.add("headword") styleClass.add("headword")
styleProperty().bind( styleProperty().bind(
Bindings.concat( Bindings.concat(
@ -49,8 +50,10 @@ private class EntryCell(
) )
) )
} }
}
private val labelDefinition = Label().apply { private val labelDefinition by lazy {
Label().apply {
styleClass.add("definition") styleClass.add("definition")
styleProperty().bind( styleProperty().bind(
Bindings.concat( Bindings.concat(
@ -62,8 +65,10 @@ private class EntryCell(
visibleProperty().bind(config.searchResults.shouldShowDefinition) visibleProperty().bind(config.searchResults.shouldShowDefinition)
managedProperty().bind(config.searchResults.shouldShowDefinition) managedProperty().bind(config.searchResults.shouldShowDefinition)
} }
}
private val labelPronunciation = Label().apply { private val labelPronunciation by lazy {
Label().apply {
styleClass.add("pronunciation") styleClass.add("pronunciation")
styleProperty().bind( styleProperty().bind(
Bindings.concat( Bindings.concat(
@ -75,15 +80,20 @@ private class EntryCell(
visibleProperty().bind(config.searchResults.shouldShowPronunciation) visibleProperty().bind(config.searchResults.shouldShowPronunciation)
managedProperty().bind(config.searchResults.shouldShowPronunciation) managedProperty().bind(config.searchResults.shouldShowPronunciation)
} }
}
private val flowPane = FlowPane(labelHeadword, labelPronunciation).apply { private val flowPane by lazy {
FlowPane(labelHeadword, labelPronunciation).apply {
hgap = FLOW_PANE_HGAP hgap = FLOW_PANE_HGAP
rowValignment = VPos.BASELINE rowValignment = VPos.BASELINE
} }
}
private val root = VBox(flowPane, labelDefinition).apply { private val root by lazy {
VBox(flowPane, labelDefinition).apply {
styleClass.add("search-result") styleClass.add("search-result")
} }
}
init { init {
text = null text = null

View File

@ -36,11 +36,16 @@ private class SentenceCell(
private val hostServices: HostServices, private val hostServices: HostServices,
) : ListCell<SentenceFx?>() { ) : ListCell<SentenceFx?>() {
private val labelSentence = Label().apply { private val labelSentence by lazy {
Label().apply {
styleClass.add("sentence") styleClass.add("sentence")
isWrapText = true isWrapText = true
} }
private val root = VBox(labelSentence) }
private val root by lazy {
VBox(labelSentence)
}
init { init {
text = null text = null
@ -50,6 +55,7 @@ private class SentenceCell(
super.updateItem(sentence, empty) super.updateItem(sentence, empty)
if (empty || sentence == null) { if (empty || sentence == null) {
graphic = null graphic = null
contextMenu = null
} else { } else {
labelSentence.textProperty().bind( labelSentence.textProperty().bind(
Bindings.createStringBinding( Bindings.createStringBinding(