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,50 +39,60 @@ private class EntryCell(
private val hostServices: HostServices,
) : ListCell<DictionaryEntryFx?>() {
private val labelHeadword = Label().apply {
styleClass.add("headword")
styleProperty().bind(
Bindings.concat(
"-fx-font-size: ",
config.searchResults.headwordFontSize.asString(),
"px;"
private val labelHeadword by lazy {
Label().apply {
styleClass.add("headword")
styleProperty().bind(
Bindings.concat(
"-fx-font-size: ",
config.searchResults.headwordFontSize.asString(),
"px;"
)
)
)
}
}
private val labelDefinition = Label().apply {
styleClass.add("definition")
styleProperty().bind(
Bindings.concat(
"-fx-font-size: ",
config.searchResults.definitionFontSize.asString(),
"px;"
private val labelDefinition by lazy {
Label().apply {
styleClass.add("definition")
styleProperty().bind(
Bindings.concat(
"-fx-font-size: ",
config.searchResults.definitionFontSize.asString(),
"px;"
)
)
)
visibleProperty().bind(config.searchResults.shouldShowDefinition)
managedProperty().bind(config.searchResults.shouldShowDefinition)
visibleProperty().bind(config.searchResults.shouldShowDefinition)
managedProperty().bind(config.searchResults.shouldShowDefinition)
}
}
private val labelPronunciation = Label().apply {
styleClass.add("pronunciation")
styleProperty().bind(
Bindings.concat(
"-fx-font-size: ",
config.searchResults.pronunciationFontSize.asString(),
"px;"
private val labelPronunciation by lazy {
Label().apply {
styleClass.add("pronunciation")
styleProperty().bind(
Bindings.concat(
"-fx-font-size: ",
config.searchResults.pronunciationFontSize.asString(),
"px;"
)
)
)
visibleProperty().bind(config.searchResults.shouldShowPronunciation)
managedProperty().bind(config.searchResults.shouldShowPronunciation)
visibleProperty().bind(config.searchResults.shouldShowPronunciation)
managedProperty().bind(config.searchResults.shouldShowPronunciation)
}
}
private val flowPane = FlowPane(labelHeadword, labelPronunciation).apply {
hgap = FLOW_PANE_HGAP
rowValignment = VPos.BASELINE
private val flowPane by lazy {
FlowPane(labelHeadword, labelPronunciation).apply {
hgap = FLOW_PANE_HGAP
rowValignment = VPos.BASELINE
}
}
private val root = VBox(flowPane, labelDefinition).apply {
styleClass.add("search-result")
private val root by lazy {
VBox(flowPane, labelDefinition).apply {
styleClass.add("search-result")
}
}
init {

View File

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