Fix showing a gray horizontal line in component list cell
This commit is contained in:
@@ -106,18 +106,14 @@ public class ComponentList extends Control {
|
|||||||
protected Skin(ComponentList control) {
|
protected Skin(ComponentList control) {
|
||||||
super(control);
|
super(control);
|
||||||
|
|
||||||
list = MappedObservableList.create(control.getContent(), this::mapper);
|
list = MappedObservableList.create(control.getContent(), ComponentListCell::new);
|
||||||
|
ListFirstElementListener.observe(list,
|
||||||
|
first -> first.getStyleClass().setAll("options-list-item-ahead"),
|
||||||
|
last -> last.getStyleClass().setAll("options-list-item"));
|
||||||
|
|
||||||
VBox vbox = new VBox();
|
VBox vbox = new VBox();
|
||||||
Bindings.bindContent(vbox.getChildren(), list);
|
Bindings.bindContent(vbox.getChildren(), list);
|
||||||
getChildren().setAll(vbox);
|
getChildren().setAll(vbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node mapper(Node node) {
|
|
||||||
StackPane child = new StackPane();
|
|
||||||
child.getChildren().add(new ComponentListCell(node));
|
|
||||||
child.getStyleClass().add("options-list-item");
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,10 +122,7 @@ class ComponentListCell extends StackPane {
|
|||||||
VBox container = new VBox();
|
VBox container = new VBox();
|
||||||
container.setStyle("-fx-padding: 8 0 0 0;");
|
container.setStyle("-fx-padding: 8 0 0 0;");
|
||||||
FXUtils.setLimitHeight(container, 0);
|
FXUtils.setLimitHeight(container, 0);
|
||||||
Rectangle clipRect = new Rectangle();
|
FXUtils.setOverflowHidden(container, true);
|
||||||
clipRect.widthProperty().bind(container.widthProperty());
|
|
||||||
clipRect.heightProperty().bind(container.heightProperty());
|
|
||||||
container.setClip(clipRect);
|
|
||||||
container.getChildren().setAll(content);
|
container.getChildren().setAll(content);
|
||||||
|
|
||||||
VBox holder = new VBox();
|
VBox holder = new VBox();
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package org.jackhuang.hmcl.ui.construct;
|
||||||
|
|
||||||
|
import javafx.collections.ListChangeListener;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class ListFirstElementListener<T> implements ListChangeListener<T> {
|
||||||
|
|
||||||
|
private final Consumer<? super T> first, last;
|
||||||
|
|
||||||
|
public ListFirstElementListener(Consumer<? super T> first, Consumer<? super T> last) {
|
||||||
|
this.first = first;
|
||||||
|
this.last = last;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChanged(Change<? extends T> c) {
|
||||||
|
ObservableList<? extends T> list = c.getList();
|
||||||
|
if (list.isEmpty()) return;
|
||||||
|
while (c.next()) {
|
||||||
|
int from = c.getFrom();
|
||||||
|
int to = c.getTo();
|
||||||
|
|
||||||
|
if (c.wasPermutated()) {
|
||||||
|
for (int i = from; i < to; ++i) {
|
||||||
|
int newIdx = c.getPermutation(i);
|
||||||
|
if (i == 0 && newIdx != 0)
|
||||||
|
last.accept(list.get(newIdx));
|
||||||
|
else if (i != 0 && newIdx == 0)
|
||||||
|
first.accept(list.get(newIdx));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (c.wasRemoved()) {
|
||||||
|
if (!list.isEmpty() && from == 0)
|
||||||
|
first.accept(list.get(0));
|
||||||
|
}
|
||||||
|
if (c.wasAdded()) {
|
||||||
|
for (int i = from; i < to; ++i) {
|
||||||
|
if (i == 0)
|
||||||
|
first.accept(list.get(0));
|
||||||
|
else
|
||||||
|
last.accept(list.get(i));
|
||||||
|
}
|
||||||
|
if (list.size() > to)
|
||||||
|
last.accept(list.get(to));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void observe(ObservableList<? extends T> list, Consumer<? super T> first, Consumer<? super T> last) {
|
||||||
|
for (int i = 0; i < list.size(); ++i) {
|
||||||
|
if (i == 0) first.accept(list.get(i));
|
||||||
|
else last.accept(list.get(i));
|
||||||
|
}
|
||||||
|
list.addListener(new ListFirstElementListener<>(first, last));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user