mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-11 21:06:37 -04:00
Fix showing a gray horizontal line in component list cell
This commit is contained in:
parent
030b577dee
commit
caf85d2a92
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher.
|
||||
* Copyright (C) 2018 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
@ -106,18 +106,14 @@ public class ComponentList extends Control {
|
||||
protected Skin(ComponentList 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();
|
||||
Bindings.bindContent(vbox.getChildren(), list);
|
||||
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();
|
||||
container.setStyle("-fx-padding: 8 0 0 0;");
|
||||
FXUtils.setLimitHeight(container, 0);
|
||||
Rectangle clipRect = new Rectangle();
|
||||
clipRect.widthProperty().bind(container.widthProperty());
|
||||
clipRect.heightProperty().bind(container.heightProperty());
|
||||
container.setClip(clipRect);
|
||||
FXUtils.setOverflowHidden(container, true);
|
||||
container.getChildren().setAll(content);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user