feat: unify look.

This commit is contained in:
huanghongxun
2021-09-18 02:57:03 +08:00
parent 7d9cce131b
commit 05562b5c2a
9 changed files with 67 additions and 49 deletions

View File

@@ -18,13 +18,13 @@
package org.jackhuang.hmcl.ui; package org.jackhuang.hmcl.ui;
import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXButton;
import com.jfoenix.effects.JFXDepthManager;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.*; import javafx.beans.property.*;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Cursor; import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.Control; import javafx.scene.control.Control;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.Skin; import javafx.scene.control.Skin;
@@ -37,6 +37,7 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority; import javafx.scene.layout.Priority;
import org.jackhuang.hmcl.download.LibraryAnalyzer; import org.jackhuang.hmcl.download.LibraryAnalyzer;
import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.ui.construct.RipplerContainer;
import org.jackhuang.hmcl.util.i18n.I18n; import org.jackhuang.hmcl.util.i18n.I18n;
import static org.jackhuang.hmcl.download.LibraryAnalyzer.LibraryType.*; import static org.jackhuang.hmcl.download.LibraryAnalyzer.LibraryType.*;
@@ -153,24 +154,29 @@ public class InstallerItem extends Control {
super(control); super(control);
HBox hbox = new HBox(); HBox hbox = new HBox();
getChildren().setAll(hbox); hbox.getStyleClass().add("md-list-cell");
JFXDepthManager.setDepth(hbox, 1); hbox.setPadding(new Insets(8));
RipplerContainer container = new RipplerContainer(hbox);
hbox.getStyleClass().add("card"); getChildren().setAll(container);
hbox.setAlignment(Pos.CENTER_LEFT); hbox.setAlignment(Pos.CENTER_LEFT);
if (control.imageUrl != null) { if (control.imageUrl != null) {
hbox.getChildren().add(FXUtils.limitingSize(new ImageView(new Image(control.imageUrl, 32, 32, true, true)), 32, 32)); ImageView view = new ImageView(new Image(control.imageUrl, 32, 32, true, true));
Node node = FXUtils.limitingSize(view, 32, 32);
node.setMouseTransparent(true);
hbox.getChildren().add(node);
} }
Label nameLabel = new Label(); Label nameLabel = new Label();
nameLabel.setMouseTransparent(true);
hbox.getChildren().add(nameLabel); hbox.getChildren().add(nameLabel);
nameLabel.setPrefWidth(80); nameLabel.setPrefWidth(80);
nameLabel.textProperty().set(I18n.hasKey("install.installer." + control.id) ? i18n("install.installer." + control.id) : control.id); nameLabel.textProperty().set(I18n.hasKey("install.installer." + control.id) ? i18n("install.installer." + control.id) : control.id);
HBox.setMargin(nameLabel, new Insets(0, 4, 0, 4)); HBox.setMargin(nameLabel, new Insets(0, 4, 0, 4));
Label label = new Label(); Label label = new Label();
label.setMouseTransparent(true);
hbox.getChildren().add(label); hbox.getChildren().add(label);
label.setMaxWidth(Double.MAX_VALUE); label.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(label, Priority.ALWAYS); HBox.setHgrow(label, Priority.ALWAYS);
@@ -213,11 +219,11 @@ public class InstallerItem extends Control {
FXUtils.onChangeAndOperate(arrowButton.visibleProperty(), clickable -> { FXUtils.onChangeAndOperate(arrowButton.visibleProperty(), clickable -> {
if (clickable) { if (clickable) {
hbox.onMouseClickedProperty().bind(control.action); container.onMouseClickedProperty().bind(control.action);
hbox.setCursor(Cursor.HAND); hbox.setCursor(Cursor.HAND);
} else { } else {
hbox.onMouseClickedProperty().unbind(); container.onMouseClickedProperty().unbind();
hbox.onMouseClickedProperty().set(null); container.onMouseClickedProperty().set(null);
hbox.setCursor(Cursor.DEFAULT); hbox.setCursor(Cursor.DEFAULT);
} }
}); });

View File

@@ -17,10 +17,7 @@
*/ */
package org.jackhuang.hmcl.ui; package org.jackhuang.hmcl.ui;
import javafx.beans.property.BooleanProperty; import javafx.beans.property.*;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.scene.control.Control; import javafx.scene.control.Control;
@@ -28,6 +25,7 @@ import javafx.scene.control.Control;
public class ListPageBase<T> extends Control { public class ListPageBase<T> extends Control {
private final ListProperty<T> items = new SimpleListProperty<>(this, "items", FXCollections.observableArrayList()); private final ListProperty<T> items = new SimpleListProperty<>(this, "items", FXCollections.observableArrayList());
private final BooleanProperty loading = new SimpleBooleanProperty(this, "loading", false); private final BooleanProperty loading = new SimpleBooleanProperty(this, "loading", false);
private final StringProperty failedReason = new SimpleStringProperty(this, "failed");
public ObservableList<T> getItems() { public ObservableList<T> getItems() {
return items.get(); return items.get();
@@ -52,4 +50,16 @@ public class ListPageBase<T> extends Control {
public BooleanProperty loadingProperty() { public BooleanProperty loadingProperty() {
return loading; return loading;
} }
public String getFailedReason() {
return failedReason.get();
}
public StringProperty failedReasonProperty() {
return failedReason;
}
public void setFailedReason(String failedReason) {
this.failedReason.set(failedReason);
}
} }

View File

@@ -22,14 +22,16 @@ import com.jfoenix.controls.JFXScrollPane;
import com.jfoenix.effects.JFXDepthManager; import com.jfoenix.effects.JFXDepthManager;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane;
import javafx.scene.control.SkinBase; import javafx.scene.control.SkinBase;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.ui.construct.ComponentList;
import org.jackhuang.hmcl.ui.construct.SpinnerPane; import org.jackhuang.hmcl.ui.construct.SpinnerPane;
import java.util.List; import java.util.List;
@@ -40,43 +42,39 @@ public abstract class ToolbarListPageSkin<T extends ListPageBase<? extends Node>
super(skinnable); super(skinnable);
SpinnerPane spinnerPane = new SpinnerPane(); SpinnerPane spinnerPane = new SpinnerPane();
spinnerPane.loadingProperty().bind(skinnable.loadingProperty());
spinnerPane.failedReasonProperty().bind(skinnable.failedReasonProperty());
spinnerPane.getStyleClass().add("large-spinner-pane"); spinnerPane.getStyleClass().add("large-spinner-pane");
BorderPane root = new BorderPane(); ComponentList root = new ComponentList();
root.getStyleClass().add("no-padding");
StackPane.setMargin(root, new Insets(10));
List<Node> toolbarButtons = initializeToolbar(skinnable); List<Node> toolbarButtons = initializeToolbar(skinnable);
if (!toolbarButtons.isEmpty()) { if (!toolbarButtons.isEmpty()) {
HBox toolbar = new HBox(); HBox toolbar = new HBox();
toolbar.getStyleClass().add("jfx-tool-bar-second"); toolbar.setAlignment(Pos.CENTER_LEFT);
JFXDepthManager.setDepth(toolbar, 1); JFXDepthManager.setDepth(toolbar, 1);
toolbar.setPickOnBounds(false); toolbar.setPickOnBounds(false);
toolbar.getChildren().setAll(toolbarButtons); toolbar.getChildren().setAll(toolbarButtons);
root.setTop(toolbar); root.getContent().add(toolbar);
} }
{ {
ScrollPane scrollPane = new ScrollPane(); ScrollPane scrollPane = new ScrollPane();
ComponentList.setVgrow(scrollPane, Priority.ALWAYS);
scrollPane.setFitToWidth(true); scrollPane.setFitToWidth(true);
VBox content = new VBox(); VBox content = new VBox();
content.setSpacing(10);
content.setPadding(new Insets(10));
Bindings.bindContent(content.getChildren(), skinnable.itemsProperty()); Bindings.bindContent(content.getChildren(), skinnable.itemsProperty());
scrollPane.setContent(content); scrollPane.setContent(content);
JFXScrollPane.smoothScrolling(scrollPane); JFXScrollPane.smoothScrolling(scrollPane);
root.setCenter(scrollPane); root.getContent().add(scrollPane);
} }
FXUtils.onChangeAndOperate(skinnable.loadingProperty(), loading -> {
if (loading) {
spinnerPane.showSpinner();
} else {
spinnerPane.hideSpinner();
}
});
spinnerPane.setContent(root); spinnerPane.setContent(root);
getChildren().setAll(spinnerPane); getChildren().setAll(spinnerPane);

View File

@@ -36,6 +36,7 @@ import org.jackhuang.hmcl.download.RemoteVersion;
import org.jackhuang.hmcl.game.HMCLGameRepository; import org.jackhuang.hmcl.game.HMCLGameRepository;
import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.InstallerItem; import org.jackhuang.hmcl.ui.InstallerItem;
import org.jackhuang.hmcl.ui.construct.ComponentList;
import org.jackhuang.hmcl.ui.construct.MessageDialogPane; import org.jackhuang.hmcl.ui.construct.MessageDialogPane;
import org.jackhuang.hmcl.ui.construct.RequiredValidator; import org.jackhuang.hmcl.ui.construct.RequiredValidator;
import org.jackhuang.hmcl.ui.construct.Validator; import org.jackhuang.hmcl.ui.construct.Validator;
@@ -139,22 +140,24 @@ public class InstallersPage extends Control implements WizardPage {
BorderPane root = new BorderPane(); BorderPane root = new BorderPane();
root.setPadding(new Insets(16)); root.setPadding(new Insets(16));
VBox list = new VBox(8); ComponentList list = new ComponentList();
list.getStyleClass().add("no-padding");
root.setCenter(list); root.setCenter(list);
{ {
HBox versionNamePane = new HBox(8); HBox versionNamePane = new HBox(8);
versionNamePane.setAlignment(Pos.CENTER_LEFT); versionNamePane.setAlignment(Pos.CENTER_LEFT);
versionNamePane.getStyleClass().add("card"); versionNamePane.setPadding(new Insets(20, 8, 20, 16));
versionNamePane.setStyle("-fx-padding: 20 8 20 16");
versionNamePane.getChildren().add(new Label(i18n("archive.name")));
control.txtName.setMaxWidth(300); control.txtName.setMaxWidth(300);
versionNamePane.getChildren().add(control.txtName); versionNamePane.getChildren().setAll(new Label(i18n("archive.name")), control.txtName);
list.getChildren().add(versionNamePane); list.getContent().add(versionNamePane);
}
{
VBox libraryPane = new VBox(control.group.getLibraries());
list.getContent().add(libraryPane);
} }
list.getChildren().addAll(control.group.getLibraries());
{ {
JFXButton installButton = new JFXButton(i18n("button.install")); JFXButton installButton = new JFXButton(i18n("button.install"));

View File

@@ -20,7 +20,6 @@ package org.jackhuang.hmcl.ui.versions;
import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXPopup; import com.jfoenix.controls.JFXPopup;
import com.jfoenix.controls.JFXRadioButton; import com.jfoenix.controls.JFXRadioButton;
import com.jfoenix.effects.JFXDepthManager;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Cursor; import javafx.scene.Cursor;
import javafx.scene.control.SkinBase; import javafx.scene.control.SkinBase;
@@ -33,6 +32,7 @@ import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.ui.construct.IconedMenuItem; import org.jackhuang.hmcl.ui.construct.IconedMenuItem;
import org.jackhuang.hmcl.ui.construct.MenuSeparator; import org.jackhuang.hmcl.ui.construct.MenuSeparator;
import org.jackhuang.hmcl.ui.construct.PopupMenu; import org.jackhuang.hmcl.ui.construct.PopupMenu;
import org.jackhuang.hmcl.ui.construct.RipplerContainer;
import org.jackhuang.hmcl.util.Lazy; import org.jackhuang.hmcl.util.Lazy;
import static org.jackhuang.hmcl.ui.FXUtils.runInFX; import static org.jackhuang.hmcl.ui.FXUtils.runInFX;
@@ -109,11 +109,11 @@ public class GameListItemSkin extends SkinBase<GameListItem> {
root.setRight(right); root.setRight(right);
root.getStyleClass().add("card"); root.getStyleClass().add("md-list-cell");
root.setStyle("-fx-padding: 8 8 8 0"); root.setStyle("-fx-padding: 8 8 8 0");
JFXDepthManager.setDepth(root, 1);
getChildren().setAll(root); RipplerContainer container = new RipplerContainer(root);
getChildren().setAll(container);
root.setCursor(Cursor.HAND); root.setCursor(Cursor.HAND);
root.setOnMouseClicked(e -> { root.setOnMouseClicked(e -> {

View File

@@ -174,7 +174,7 @@ public class InstallerListPage extends ListPageBase<InstallerItem> implements Ve
@Override @Override
protected List<Node> initializeToolbar(InstallerListPage skinnable) { protected List<Node> initializeToolbar(InstallerListPage skinnable) {
return Collections.singletonList( return Collections.singletonList(
createToolbarButton(i18n("install.installer.install_offline"), SVG::plus, skinnable::installOffline)); createToolbarButton2(i18n("install.installer.install_offline"), SVG::plus, skinnable::installOffline));
} }
} }
} }

View File

@@ -114,6 +114,7 @@ class ModListPageSkin extends SkinBase<ModListPage> {
label.prefWidthProperty().bind(pane.widthProperty().add(-100)); label.prefWidthProperty().bind(pane.widthProperty().add(-100));
FXUtils.onChangeAndOperate(skinnable.moddedProperty(), modded -> { FXUtils.onChangeAndOperate(skinnable.moddedProperty(), modded -> {
if (modded) pane.getChildren().setAll(root); if (modded) pane.getChildren().setAll(root);
else pane.getChildren().setAll(label); else pane.getChildren().setAll(label);
}); });
@@ -281,7 +282,7 @@ class ModListPageSkin extends SkinBase<ModListPage> {
container.getChildren().setAll(checkBox, content, revealButton, infoButton); container.getChildren().setAll(checkBox, content, revealButton, infoButton);
StackPane.setMargin(container, new Insets(10, 16, 10, 16)); StackPane.setMargin(container, new Insets(8));
getContainer().getChildren().setAll(container); getContainer().getChildren().setAll(container);
} }

View File

@@ -19,6 +19,7 @@ package org.jackhuang.hmcl.ui.versions;
import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXPopup; import com.jfoenix.controls.JFXPopup;
import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.control.SkinBase; import javafx.scene.control.SkinBase;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
@@ -30,6 +31,7 @@ import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.ui.construct.IconedMenuItem; import org.jackhuang.hmcl.ui.construct.IconedMenuItem;
import org.jackhuang.hmcl.ui.construct.PopupMenu; import org.jackhuang.hmcl.ui.construct.PopupMenu;
import org.jackhuang.hmcl.ui.construct.RipplerContainer;
import org.jackhuang.hmcl.ui.construct.TwoLineListItem; import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
@@ -42,6 +44,7 @@ public class WorldListItemSkin extends SkinBase<WorldListItem> {
BorderPane root = new BorderPane(); BorderPane root = new BorderPane();
HBox center = new HBox(); HBox center = new HBox();
center.setMouseTransparent(true);
center.setSpacing(8); center.setSpacing(8);
center.setAlignment(Pos.CENTER_LEFT); center.setAlignment(Pos.CENTER_LEFT);
@@ -82,9 +85,9 @@ public class WorldListItemSkin extends SkinBase<WorldListItem> {
right.getChildren().add(btnManage); right.getChildren().add(btnManage);
root.setRight(right); root.setRight(right);
root.getStyleClass().add("card"); root.getStyleClass().add("md-list-cell");
root.setStyle("-fx-padding: 8 8 8 0"); root.setPadding(new Insets(8));
getChildren().setAll(root); getChildren().setAll(new RipplerContainer(root));
} }
} }

View File

@@ -25,7 +25,6 @@ import javafx.scene.Node;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import org.jackhuang.hmcl.game.World; import org.jackhuang.hmcl.game.World;
import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.ui.*; import org.jackhuang.hmcl.ui.*;
@@ -161,14 +160,12 @@ public class WorldListPage extends ListPageBase<WorldListItem> implements Versio
@Override @Override
protected List<Node> initializeToolbar(WorldListPage skinnable) { protected List<Node> initializeToolbar(WorldListPage skinnable) {
JFXCheckBox chkShowAll = new JFXCheckBox(); JFXCheckBox chkShowAll = new JFXCheckBox();
chkShowAll.getStyleClass().add("jfx-tool-bar-checkbox");
chkShowAll.textFillProperty().bind(Theme.foregroundFillBinding());
chkShowAll.setText(i18n("world.show_all")); chkShowAll.setText(i18n("world.show_all"));
chkShowAll.selectedProperty().bindBidirectional(skinnable.showAllProperty()); chkShowAll.selectedProperty().bindBidirectional(skinnable.showAllProperty());
return Arrays.asList(chkShowAll, return Arrays.asList(chkShowAll,
createToolbarButton(i18n("button.refresh"), SVG::refresh, skinnable::refresh), createToolbarButton2(i18n("button.refresh"), SVG::refresh, skinnable::refresh),
createToolbarButton(i18n("world.add"), SVG::plus, skinnable::add)); createToolbarButton2(i18n("world.add"), SVG::plus, skinnable::add));
} }
} }
} }