优化 TwoLineListItem 中标签的展示方式 (#5465)

This commit is contained in:
Glavo
2026-02-07 18:02:20 +08:00
committed by GitHub
parent 4b72639969
commit d9b31ffd18
2 changed files with 33 additions and 10 deletions

View File

@@ -22,9 +22,14 @@ import javafx.beans.property.StringProperty;
import javafx.beans.property.StringPropertyBase;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.css.PseudoClass;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import org.jackhuang.hmcl.ui.FXUtils;
public class TwoLineListItem extends VBox {
private static final String DEFAULT_STYLE_CLASS = "two-line-list-item";
@@ -44,6 +49,7 @@ public class TwoLineListItem extends VBox {
this.firstLine = new HBox(lblTitle);
firstLine.getStyleClass().add("first-line");
firstLine.setAlignment(Pos.CENTER_LEFT);
this.getChildren().setAll(firstLine);
}
@@ -157,23 +163,35 @@ public class TwoLineListItem extends VBox {
var tagsBox = new HBox(8);
tagsBox.getStyleClass().add("tags");
tagsBox.setAlignment(Pos.CENTER_LEFT);
Bindings.bindContent(tagsBox.getChildren(), tags);
firstLine.getChildren().setAll(lblTitle, tagsBox);
var scrollPane = new ScrollPane(tagsBox);
HBox.setHgrow(scrollPane, Priority.ALWAYS);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
FXUtils.onChangeAndOperate(tagsBox.heightProperty(), height -> FXUtils.setLimitHeight(scrollPane, height.doubleValue()));
firstLine.getChildren().setAll(lblTitle, scrollPane);
}
return tags;
}
public void addTag(String tag) {
public void addTag(String tag, PseudoClass pseudoClass) {
var tagLabel = new Label(tag);
tagLabel.getStyleClass().add("tag");
if (pseudoClass != null)
tagLabel.pseudoClassStateChanged(pseudoClass, true);
getTags().add(tagLabel);
}
public void addTag(String tag) {
addTag(tag, null);
}
private static final PseudoClass WARNING_PSEUDO_CLASS = PseudoClass.getPseudoClass("warning");
public void addTagWarning(String tag) {
var tagLabel = new Label(tag);
tagLabel.getStyleClass().add("tag-warning");
getTags().add(tagLabel);
addTag(tag, WARNING_PSEUDO_CLASS);
}
@Override

View File

@@ -324,20 +324,25 @@
-fx-fill: -monet-on-surface-variant;
}
.two-line-list-item > .first-line > .tags > .tag {
.two-line-list-item > .first-line .scroll-bar {
-fx-opacity: 0;
-fx-max-height: 0;
-fx-min-height: 0;
-fx-pref-height: 0;
}
.two-line-list-item > .first-line .tag {
-fx-text-fill: -monet-on-secondary-container;
-fx-background-color: -monet-secondary-container;
-fx-background-radius: 2;
-fx-padding: 2;
-fx-font-weight: normal;
-fx-font-size: 12px;
}
.two-line-list-item > .first-line > .tags > .tag-warning {
.two-line-list-item > .first-line .tag:warning {
-fx-text-fill: -monet-on-error-container;
-fx-background-color: -fixed-warning-tag-background;
-fx-padding: 2;
-fx-font-weight: normal;
-fx-font-size: 12px;
}
.two-line-item-second-large {