New Features #1

Open
marvinelsen wants to merge 76 commits from develop into main
3 changed files with 27 additions and 9 deletions
Showing only changes of commit a4e5b9145f - Show all commits

View File

@ -1,16 +1,19 @@
package com.marvinelsen.willow.ui.cells package com.marvinelsen.willow.ui.cells
import com.marvinelsen.willow.config.Config
import com.marvinelsen.willow.config.Script
import com.marvinelsen.willow.ui.SentenceFx import com.marvinelsen.willow.ui.SentenceFx
import javafx.beans.binding.Bindings
import javafx.scene.control.Label import javafx.scene.control.Label
import javafx.scene.control.ListCell import javafx.scene.control.ListCell
import javafx.scene.control.ListView import javafx.scene.control.ListView
import javafx.scene.layout.VBox import javafx.scene.layout.VBox
import javafx.util.Callback import javafx.util.Callback
class SentenceCellFactory() : Callback<ListView<SentenceFx?>, ListCell<SentenceFx?>> { class SentenceCellFactory(private val config: Config) : Callback<ListView<SentenceFx?>, ListCell<SentenceFx?>> {
override fun call(listView: ListView<SentenceFx?>): ListCell<SentenceFx?> { override fun call(listView: ListView<SentenceFx?>): ListCell<SentenceFx?> {
val sentenceCell = SentenceCell() val sentenceCell = SentenceCell(config)
sentenceCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING)) sentenceCell.prefWidthProperty().bind(listView.widthProperty().subtract(CELL_PADDING))
return sentenceCell return sentenceCell
} }
@ -20,12 +23,11 @@ class SentenceCellFactory() : Callback<ListView<SentenceFx?>, ListCell<SentenceF
} }
} }
internal class SentenceCell() : ListCell<SentenceFx?>() { private class SentenceCell(private val config: Config) : ListCell<SentenceFx?>() {
private val labelTraditional = Label().apply { private val labelSentence = Label().apply {
styleClass.add("chinese") styleClass.add("sentence")
styleClass.add("list-view-sentence-cell")
} }
private val root = VBox(labelTraditional) private val root = VBox(labelSentence)
init { init {
text = null text = null
@ -36,7 +38,18 @@ internal class SentenceCell() : ListCell<SentenceFx?>() {
if (empty || sentence == null) { if (empty || sentence == null) {
graphic = null graphic = null
} else { } else {
labelTraditional.text = sentence.traditionalProperty.value labelSentence.textProperty().bind(
Bindings.createStringBinding(
{
when (config.script.value!!) {
Script.SIMPLIFIED -> sentence.simplifiedProperty.value
Script.TRADITIONAL -> sentence.traditionalProperty.value
}
},
config.script
)
)
graphic = root graphic = root
} }

View File

@ -182,7 +182,7 @@ class DetailsController(private val model: Model, private val config: Config) {
private fun initializeListViewSentences() { private fun initializeListViewSentences() {
listViewSentences.apply { listViewSentences.apply {
cellFactory = SentenceCellFactory() cellFactory = SentenceCellFactory(config)
items = model.sentences items = model.sentences
disableProperty().bind(Bindings.or(model.isFindingSentences, Bindings.isEmpty(model.sentences))) disableProperty().bind(Bindings.or(model.isFindingSentences, Bindings.isEmpty(model.sentences)))

View File

@ -9,3 +9,8 @@
.list-view .headword { .list-view .headword {
-fx-font-family: "Noto Sans TC"; -fx-font-family: "Noto Sans TC";
} }
.list-view .sentence {
-fx-font-family: "Noto Sans TC";
-fx-font-size: 14px;
}