Use iconedItem instead of ListView in popup menu

This commit is contained in:
huangyuhui 2018-09-03 10:58:45 +08:00
parent 16ee0a040a
commit 28aa137dc1
4 changed files with 48 additions and 45 deletions

View File

@ -60,7 +60,7 @@ public final class LeftPaneController extends AdvancedListBox {
profileListItem.setOnAction(e -> Controllers.navigate(Controllers.getProfileListPage())); profileListItem.setOnAction(e -> Controllers.navigate(Controllers.getProfileListPage()));
profileListItem.profileProperty().bind(Profiles.selectedProfileProperty()); profileListItem.profileProperty().bind(Profiles.selectedProfileProperty());
IconedItem launcherSettingsItem = new IconedItem(SVG.gear(Theme.blackFillBinding(), 20, 20)); IconedItem launcherSettingsItem = new IconedItem(SVG.gear(Theme.blackFillBinding(), 20, 20), "iconed-item");
launcherSettingsItem.getLabel().textProperty().bind( launcherSettingsItem.getLabel().textProperty().bind(
new When(UpdateChecker.outdatedProperty()) new When(UpdateChecker.outdatedProperty())
@ -72,7 +72,6 @@ public final class LeftPaneController extends AdvancedListBox {
.then(Color.RED) .then(Color.RED)
.otherwise(Color.BLACK)); .otherwise(Color.BLACK));
launcherSettingsItem.maxWidthProperty().bind(widthProperty());
launcherSettingsItem.setOnMouseClicked(e -> Controllers.navigate(Controllers.getSettingsPage())); launcherSettingsItem.setOnMouseClicked(e -> Controllers.navigate(Controllers.getSettingsPage()));
this this

View File

@ -91,6 +91,10 @@ public final class SVG {
return createSVGPath("M1008 6.286q18.857 13.714 15.429 36.571l-146.286 877.714q-2.857 16.571-18.286 25.714-8 4.571-17.714 4.571-6.286 0-13.714-2.857l-258.857-105.714-138.286 168.571q-10.286 13.143-28 13.143-7.429 0-12.571-2.286-10.857-4-17.429-13.429t-6.571-20.857v-199.429l493.714-605.143-610.857 528.571-225.714-92.571q-21.143-8-22.857-31.429-1.143-22.857 18.286-33.714l950.857-548.571q8.571-5.143 18.286-5.14311.429 0 20.571 6.286z", fill, width, height); return createSVGPath("M1008 6.286q18.857 13.714 15.429 36.571l-146.286 877.714q-2.857 16.571-18.286 25.714-8 4.571-17.714 4.571-6.286 0-13.714-2.857l-258.857-105.714-138.286 168.571q-10.286 13.143-28 13.143-7.429 0-12.571-2.286-10.857-4-17.429-13.429t-6.571-20.857v-199.429l493.714-605.143-610.857 528.571-225.714-92.571q-21.143-8-22.857-31.429-1.143-22.857 18.286-33.714l950.857-548.571q8.571-5.143 18.286-5.14311.429 0 20.571 6.286z", fill, width, height);
} }
public static Node launch2(ObjectBinding<? extends Paint> fill, double width, double height) {
return createSVGPath("M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z", fill, width, height);
}
public static Node script(ObjectBinding<? extends Paint> fill, double width, double height) { public static Node script(ObjectBinding<? extends Paint> fill, double width, double height) {
return createSVGPath("M14,20A2,2 0 0,0 16,18V5H9A1,1 0 0,0 8,6V16H5V5A3,3 0 0,1 8,2H19A3,3 0 0,1 22,5V6H18V18L18,19A3,3 0 0,1 15,22H5A3,3 0 0,1 2,19V18H12A2,2 0 0,0 14,20Z", fill, width, height); return createSVGPath("M14,20A2,2 0 0,0 16,18V5H9A1,1 0 0,0 8,6V16H5V5A3,3 0 0,1 8,2H19A3,3 0 0,1 22,5V6H18V18L18,19A3,3 0 0,1 15,22H5A3,3 0 0,1 2,19V18H12A2,2 0 0,0 14,20Z", fill, width, height);
} }
@ -138,4 +142,8 @@ public final class SVG {
public static Node importIcon(ObjectBinding<? extends Paint> fill, double width, double height) { public static Node importIcon(ObjectBinding<? extends Paint> fill, double width, double height) {
return createSVGPath("M14,12L10,8V11H2V13H10V16M20,18V6C20,4.89 19.1,4 18,4H6A2,2 0 0,0 4,6V9H6V6H18V18H6V15H4V18A2,2 0 0,0 6,20H18A2,2 0 0,0 20,18Z", fill, width, height); return createSVGPath("M14,12L10,8V11H2V13H10V16M20,18V6C20,4.89 19.1,4 18,4H6A2,2 0 0,0 4,6V9H6V6H18V18H6V15H4V18A2,2 0 0,0 6,20H18A2,2 0 0,0 20,18Z", fill, width, height);
} }
public static Node export(ObjectBinding<? extends Paint> fill, double width, double height) {
return createSVGPath("M23,12L19,8V11H10V13H19V16M1,18V6C1,4.89 1.9,4 3,4H15A2,2 0 0,1 17,6V9H15V6H3V18H15V15H17V18A2,2 0 0,1 15,20H3A2,2 0 0,1 1,18Z", fill, width, height);
}
} }

View File

@ -26,30 +26,33 @@ public class IconedItem extends RipplerContainer {
private Label label; private Label label;
public IconedItem(Node icon, String text) { public IconedItem(Node icon, String text, String styleClass) {
this(icon); this(icon, styleClass);
label.setText(text); label.setText(text);
} }
public IconedItem(Node icon) { public IconedItem(Node icon, String styleClass) {
super(createHBox(icon)); super(createHBox(icon, styleClass));
label = ((Label) lookup("#label")); label = ((Label) lookup("#label"));
} }
private static HBox createHBox(Node icon) { private static HBox createHBox(Node icon, String styleClass) {
HBox hBox = new HBox(); HBox hBox = new HBox();
hBox.getStyleClass().setAll(styleClass);
icon.setMouseTransparent(true); icon.setMouseTransparent(true);
Label textLabel = new Label(); Label textLabel = new Label();
textLabel.setId("label"); textLabel.setId("label");
textLabel.setAlignment(Pos.CENTER);
textLabel.setMouseTransparent(true); textLabel.setMouseTransparent(true);
hBox.getChildren().addAll(icon, textLabel); hBox.getChildren().addAll(icon, textLabel);
hBox.setStyle("-fx-padding: 10 16 10 16; -fx-spacing: 10; -fx-font-size: 14;");
hBox.setAlignment(Pos.CENTER_LEFT);
return hBox; return hBox;
} }
public Label getLabel() { public Label getLabel() {
return label; return label;
} }
public IconedItem setClickedAction(Runnable r) {
setOnMouseClicked(e -> r.run());
return this;
}
} }

View File

@ -24,16 +24,22 @@ import com.jfoenix.controls.JFXPopup;
import com.jfoenix.controls.JFXRadioButton; import com.jfoenix.controls.JFXRadioButton;
import com.jfoenix.effects.JFXDepthManager; import com.jfoenix.effects.JFXDepthManager;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.SkinBase; import javafx.scene.control.SkinBase;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.ui.construct.IconedItem;
import org.jackhuang.hmcl.ui.construct.TwoLineListItem; import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
import java.util.function.Consumer;
import java.util.function.Function;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public class GameListItemSkin extends SkinBase<GameListItem> { public class GameListItemSkin extends SkinBase<GameListItem> {
@ -68,42 +74,30 @@ public class GameListItemSkin extends SkinBase<GameListItem> {
center.getChildren().setAll(imageView, item); center.getChildren().setAll(imageView, item);
root.setCenter(center); root.setCenter(center);
JFXListView<String> menu = new JFXListView<>(); VBox menu = new VBox();
menu.getItems().setAll(
i18n("settings"),
i18n("version.manage.rename"),
i18n("version.manage.remove"),
i18n("modpack.export"),
i18n("folder.game"),
i18n("version.launch"),
i18n("version.launch_script"));
JFXPopup popup = new JFXPopup(menu); JFXPopup popup = new JFXPopup(menu);
menu.setOnMouseClicked(e -> {
Function<Runnable, Runnable> wrap = r -> () -> {
r.run();
popup.hide(); popup.hide();
switch (menu.getSelectionModel().getSelectedIndex()) { };
case 0:
skinnable.modifyGameSettings(); Function<Node, Node> limitWidth = node -> {
break; StackPane pane = new StackPane(node);
case 1: pane.setAlignment(Pos.CENTER);
skinnable.rename(); FXUtils.setLimitWidth(pane, 14);
break; FXUtils.setLimitHeight(pane, 14);
case 2: return pane;
skinnable.remove(); };
break;
case 3: menu.getChildren().setAll(
skinnable.export(); new IconedItem(limitWidth.apply(SVG.gear(Theme.blackFillBinding(), 14, 14)), i18n("settings"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::modifyGameSettings)),
break; new IconedItem(limitWidth.apply(SVG.pencil(Theme.blackFillBinding(), 14, 14)), i18n("version.manage.rename"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::rename)),
case 4: new IconedItem(limitWidth.apply(SVG.delete(Theme.blackFillBinding(), 14, 14)), i18n("version.manage.remove"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::remove)),
skinnable.browse(); new IconedItem(limitWidth.apply(SVG.export(Theme.blackFillBinding(), 14, 14)), i18n("modpack.export"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::export)),
break; new IconedItem(limitWidth.apply(SVG.folderOpen(Theme.blackFillBinding(), 14, 14)), i18n("folder.game"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::browse)),
case 5: new IconedItem(limitWidth.apply(SVG.launch(Theme.blackFillBinding(), 14, 14)), i18n("version.launch"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::launch)),
skinnable.launch(); new IconedItem(limitWidth.apply(SVG.script(Theme.blackFillBinding(), 14, 14)), i18n("version.launch_script"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::generateLaunchScript)));
break;
case 6:
skinnable.generateLaunchScript();
break;
}
});
HBox right = new HBox(); HBox right = new HBox();
right.setAlignment(Pos.CENTER_RIGHT); right.setAlignment(Pos.CENTER_RIGHT);
@ -118,7 +112,6 @@ public class GameListItemSkin extends SkinBase<GameListItem> {
JFXButton btnManage = new JFXButton(); JFXButton btnManage = new JFXButton();
btnManage.setOnMouseClicked(e -> { btnManage.setOnMouseClicked(e -> {
menu.getSelectionModel().select(-1);
popup.show(root, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, 0, root.getHeight()); popup.show(root, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, 0, root.getHeight());
}); });
btnManage.getStyleClass().add("toggle-icon4"); btnManage.getStyleClass().add("toggle-icon4");