Extract IconedMenuItem

This commit is contained in:
huangyuhui
2018-09-03 22:30:22 +08:00
parent e4e521c2ef
commit 1145e31162
4 changed files with 47 additions and 20 deletions

View File

@@ -26,19 +26,20 @@ public class IconedItem extends RipplerContainer {
private Label label;
public IconedItem(Node icon, String text, String styleClass) {
this(icon, styleClass);
public IconedItem(Node icon, String text) {
this(icon);
label.setText(text);
}
public IconedItem(Node icon, String styleClass) {
super(createHBox(icon, styleClass));
public IconedItem(Node icon) {
super(createHBox(icon));
label = ((Label) lookup("#label"));
getStyleClass().setAll("iconed-item");
}
private static HBox createHBox(Node icon, String styleClass) {
private static HBox createHBox(Node icon) {
HBox hBox = new HBox();
hBox.getStyleClass().setAll(styleClass);
hBox.getStyleClass().setAll("iconed-item-container");
icon.setMouseTransparent(true);
Label textLabel = new Label();
textLabel.setId("label");
@@ -50,9 +51,4 @@ public class IconedItem extends RipplerContainer {
public Label getLabel() {
return label;
}
public IconedItem setClickedAction(Runnable r) {
setOnMouseClicked(e -> r.run());
return this;
}
}

View File

@@ -0,0 +1,30 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2017 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hmcl.ui.construct;
import javafx.scene.Node;
public class IconedMenuItem extends IconedItem {
public IconedMenuItem(Node node, String text, Runnable action) {
super(node, text);
getStyleClass().setAll("iconed-menu-item");
setOnMouseClicked(e -> action.run());
}
}

View File

@@ -35,6 +35,7 @@ import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.ui.construct.IconedItem;
import org.jackhuang.hmcl.ui.construct.IconedMenuItem;
import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
import java.util.function.Consumer;
@@ -91,13 +92,13 @@ public class GameListItemSkin extends SkinBase<GameListItem> {
};
menu.getChildren().setAll(
new IconedItem(limitWidth.apply(SVG.gear(Theme.blackFillBinding(), 14, 14)), i18n("settings"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::modifyGameSettings)),
new IconedItem(limitWidth.apply(SVG.pencil(Theme.blackFillBinding(), 14, 14)), i18n("version.manage.rename"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::rename)),
new IconedItem(limitWidth.apply(SVG.delete(Theme.blackFillBinding(), 14, 14)), i18n("version.manage.remove"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::remove)),
new IconedItem(limitWidth.apply(SVG.export(Theme.blackFillBinding(), 14, 14)), i18n("modpack.export"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::export)),
new IconedItem(limitWidth.apply(SVG.folderOpen(Theme.blackFillBinding(), 14, 14)), i18n("folder.game"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::browse)),
new IconedItem(limitWidth.apply(SVG.launch(Theme.blackFillBinding(), 14, 14)), i18n("version.launch"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::launch)),
new IconedItem(limitWidth.apply(SVG.script(Theme.blackFillBinding(), 14, 14)), i18n("version.launch_script"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::generateLaunchScript)));
new IconedMenuItem(limitWidth.apply(SVG.gear(Theme.blackFillBinding(), 14, 14)), i18n("settings"), wrap.apply(skinnable::modifyGameSettings)),
new IconedMenuItem(limitWidth.apply(SVG.pencil(Theme.blackFillBinding(), 14, 14)), i18n("version.manage.rename"), wrap.apply(skinnable::rename)),
new IconedMenuItem(limitWidth.apply(SVG.delete(Theme.blackFillBinding(), 14, 14)), i18n("version.manage.remove"), wrap.apply(skinnable::remove)),
new IconedMenuItem(limitWidth.apply(SVG.export(Theme.blackFillBinding(), 14, 14)), i18n("modpack.export"), wrap.apply(skinnable::export)),
new IconedMenuItem(limitWidth.apply(SVG.folderOpen(Theme.blackFillBinding(), 14, 14)), i18n("folder.game"), wrap.apply(skinnable::browse)),
new IconedMenuItem(limitWidth.apply(SVG.launch(Theme.blackFillBinding(), 14, 14)), i18n("version.launch"), wrap.apply(skinnable::launch)),
new IconedMenuItem(limitWidth.apply(SVG.script(Theme.blackFillBinding(), 14, 14)), i18n("version.launch_script"), wrap.apply(skinnable::generateLaunchScript)));
HBox right = new HBox();
right.setAlignment(Pos.CENTER_RIGHT);

View File

@@ -59,14 +59,14 @@
-fx-padding: 20 0 20 0;
}
.iconed-item {
.iconed-item .iconed-item-container {
-fx-padding: 10 16 10 16;
-fx-spacing: 10;
-fx-font-size: 14;
-fx-alignment: CENTER_LEFT;
}
.menu-iconed-item {
.iconed-menu-item .iconed-item-container {
-fx-padding: 10 16 10 16;
-fx-spacing: 10;
-fx-font-size: 12;