|
| 1 | +/* |
| 2 | + * Hello Minecraft! Launcher |
| 3 | + * Copyright (C) 2026 huangyuhui <huanghongxun2008@126.com> and contributors |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | +package org.jackhuang.hmcl.ui.construct; |
| 19 | + |
| 20 | +import javafx.beans.property.SimpleStringProperty; |
| 21 | +import javafx.beans.property.StringProperty; |
| 22 | +import javafx.beans.property.StringPropertyBase; |
| 23 | +import javafx.geometry.Insets; |
| 24 | +import javafx.geometry.Pos; |
| 25 | +import javafx.scene.control.Label; |
| 26 | +import javafx.scene.layout.BorderPane; |
| 27 | +import javafx.scene.layout.Region; |
| 28 | +import javafx.scene.layout.StackPane; |
| 29 | +import javafx.scene.layout.VBox; |
| 30 | + |
| 31 | +/// @author Glavo |
| 32 | +public abstract class LineButtonBase extends StackPane { |
| 33 | + |
| 34 | + private static final Insets PADDING = new Insets(8, 8, 8, 16); |
| 35 | + |
| 36 | + protected final BorderPane root; |
| 37 | + protected final RipplerContainer container; |
| 38 | + |
| 39 | + private final Label titleLabel; |
| 40 | + |
| 41 | + public LineButtonBase() { |
| 42 | + this.root = new BorderPane(); |
| 43 | + root.setPadding(PADDING); |
| 44 | + root.setMinHeight(48); |
| 45 | + |
| 46 | + this.container = new RipplerContainer(root); |
| 47 | + this.getChildren().setAll(container); |
| 48 | + |
| 49 | + this.titleLabel = new Label(); |
| 50 | + root.setCenter(titleLabel); |
| 51 | + BorderPane.setAlignment(titleLabel, Pos.CENTER_LEFT); |
| 52 | + titleLabel.textProperty().bind(titleProperty()); |
| 53 | + titleLabel.getStyleClass().add("title"); |
| 54 | + } |
| 55 | + |
| 56 | + private final StringProperty title = new SimpleStringProperty(this, "title"); |
| 57 | + |
| 58 | + public StringProperty titleProperty() { |
| 59 | + return title; |
| 60 | + } |
| 61 | + |
| 62 | + public String getTitle() { |
| 63 | + return titleProperty().get(); |
| 64 | + } |
| 65 | + |
| 66 | + public void setTitle(String title) { |
| 67 | + this.titleProperty().set(title); |
| 68 | + } |
| 69 | + |
| 70 | + private StringProperty subtitle; |
| 71 | + |
| 72 | + public StringProperty subtitleProperty() { |
| 73 | + if (subtitle == null) { |
| 74 | + subtitle = new StringPropertyBase() { |
| 75 | + private VBox left; |
| 76 | + private Label subtitleLabel; |
| 77 | + |
| 78 | + @Override |
| 79 | + public String getName() { |
| 80 | + return "subtitle"; |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public Object getBean() { |
| 85 | + return LineButtonBase.this; |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + protected void invalidated() { |
| 90 | + String subtitle = get(); |
| 91 | + if (subtitle != null && !subtitle.isEmpty()) { |
| 92 | + if (left == null) { |
| 93 | + left = new VBox(); |
| 94 | + left.setMouseTransparent(true); |
| 95 | + left.setAlignment(Pos.CENTER_LEFT); |
| 96 | + |
| 97 | + subtitleLabel = new Label(); |
| 98 | + subtitleLabel.setWrapText(true); |
| 99 | + subtitleLabel.setMinHeight(Region.USE_PREF_SIZE); |
| 100 | + subtitleLabel.getStyleClass().add("subtitle"); |
| 101 | + } |
| 102 | + subtitleLabel.setText(subtitle); |
| 103 | + left.getChildren().setAll(titleLabel, subtitleLabel); |
| 104 | + root.setCenter(left); |
| 105 | + } else if (left != null) { |
| 106 | + subtitleLabel.setText(null); |
| 107 | + root.setCenter(titleLabel); |
| 108 | + } |
| 109 | + } |
| 110 | + }; |
| 111 | + } |
| 112 | + |
| 113 | + return subtitle; |
| 114 | + } |
| 115 | + |
| 116 | + public String getSubtitle() { |
| 117 | + return subtitleProperty().get(); |
| 118 | + } |
| 119 | + |
| 120 | + public void setSubtitle(String subtitle) { |
| 121 | + subtitleProperty().set(subtitle); |
| 122 | + } |
| 123 | +} |
0 commit comments