Skip to content

Commit

Permalink
Merge pull request #30 from saalfeldlab/fix/matchselectionnode
Browse files Browse the repository at this point in the history
fix: MatchSelection Node initial cell height
  • Loading branch information
cmhulbert authored May 23, 2024
2 parents 2c6f7b1 + 819f4b1 commit 68a95a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fun ListView<*>.bindHeightToItemSize() {
val defaultMaxRows = 18
val cellHeightFallBack = 24.0
val prefHeightBinding: ObjectBinding<Double> = items.createObservableBinding {
val cellHeight = (lookup(".list-cell") as? ListCell<*>)?.height ?: cellHeightFallBack
val cellHeight = (lookup(".list-cell") as? ListCell<*>)?.height?.let { h -> if (h == 0.0) cellHeightFallBack else h } ?: cellHeightFallBack
val borderPadding = padding.top + padding.bottom
borderPadding + cellHeight * it.size.coerceAtMost(defaultMaxRows)
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/kotlin/org/janelia/saalfeldlab/fx/ui/MatchSelection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ class MatchSelection(
fuzzySearchField.requestFocus()
fuzzySearchField.selectEnd()
}
val currentOrder = FXCollections.observableArrayList<String>()
fuzzySearchField.textProperty().addListener { _, _, fuzzyFilter ->
val matches = when (emptyBehavior) {
EmptyBehavior.MATCH_ALL -> if (fuzzyFilter == null || fuzzyFilter.isEmpty()) candidates else matcher.apply(fuzzyFilter, candidates)
EmptyBehavior.MATCH_NONE -> matcher.apply(fuzzyFilter ?: "", candidates)
}
currentOrder.setAll(matches)
}

val labelList = ListView(currentOrder)
val labelList = ListView<String>()
labelList.selectionModel.selectionMode = SelectionMode.SINGLE
registerStyleSheet(labelList)

labelList.maxWidthProperty().bind(maxWidthProperty())
labelList.prefWidthProperty().bind(maxWidthProperty())
labelList.bindHeightToItemSize()

fuzzySearchField.textProperty().addListener { _, _, fuzzyFilter ->
val matches = when (emptyBehavior) {
EmptyBehavior.MATCH_ALL -> if (fuzzyFilter == null || fuzzyFilter.isEmpty()) candidates else matcher.apply(fuzzyFilter, candidates)
EmptyBehavior.MATCH_NONE -> matcher.apply(fuzzyFilter ?: "", candidates)
}
labelList.items.setAll(matches)
}


/* NOTE: I would have prefered that `labelList.scrollTo(idx)` would have worked here,
* but that always calls `scrollToTop()` which we don't want. We create our own skin here,
Expand Down

0 comments on commit 68a95a2

Please sign in to comment.