From c7a893b02d64689558191b751c6f7c2f1e0031ef Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Tue, 21 Sep 2021 19:38:34 +0800 Subject: [PATCH] feat: clicking blanks area also controls the toggle button. --- .../hmcl/ui/construct/ComponentList.java | 3 + .../hmcl/ui/construct/OptionToggleButton.java | 84 +++++++++++++ .../hmcl/ui/versions/VersionSettingsPage.java | 114 +++++------------- HMCL/src/main/resources/assets/css/root.css | 4 + 4 files changed, 121 insertions(+), 84 deletions(-) create mode 100644 HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/OptionToggleButton.java diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentList.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentList.java index b387eb4d6..395d3c455 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentList.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentList.java @@ -137,6 +137,9 @@ public class ComponentList extends Control { if (node.getProperties().containsKey("ComponentList.vgrow")) { VBox.setVgrow(cell, (Priority) node.getProperties().get("ComponentList.vgrow")); } + if (node.getProperties().containsKey("ComponentList.noPadding")) { + cell.getStyleClass().add("no-padding"); + } return cell; }); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/OptionToggleButton.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/OptionToggleButton.java new file mode 100644 index 000000000..188abfacc --- /dev/null +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/OptionToggleButton.java @@ -0,0 +1,84 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2021 huangyuhui and contributors + * + * 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 . + */ +package org.jackhuang.hmcl.ui.construct; + +import com.jfoenix.controls.JFXToggleButton; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.control.Label; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.StackPane; +import org.jackhuang.hmcl.ui.FXUtils; + +public class OptionToggleButton extends StackPane { + private final StringProperty title = new SimpleStringProperty(); + private final BooleanProperty selected = new SimpleBooleanProperty(); + + public OptionToggleButton() { + getProperties().put("ComponentList.noPadding", true); + + BorderPane pane = new BorderPane(); + pane.setPadding(new Insets(8, 8, 8, 16)); + RipplerContainer container = new RipplerContainer(pane); + getChildren().setAll(container); + + Label label = new Label(); + label.setMouseTransparent(true); + label.textProperty().bind(title); + pane.setLeft(label); + BorderPane.setAlignment(label, Pos.CENTER_LEFT); + + JFXToggleButton toggleButton = new JFXToggleButton(); + pane.setRight(toggleButton); + toggleButton.selectedProperty().bindBidirectional(selected); + toggleButton.setSize(8); + FXUtils.setLimitHeight(toggleButton, 30); + + container.setOnMouseClicked(e -> { + toggleButton.setSelected(!toggleButton.isSelected()); + }); + } + + public String getTitle() { + return title.get(); + } + + public StringProperty titleProperty() { + return title; + } + + public void setTitle(String title) { + this.title.set(title); + } + + public boolean isSelected() { + return selected.get(); + } + + public BooleanProperty selectedProperty() { + return selected; + } + + public void setSelected(boolean selected) { + this.selected.set(selected); + } +} diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java index 5c5ac5092..a3da13348 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java @@ -89,11 +89,11 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag private final JFXComboBox cboLauncherVisibility; private final JFXCheckBox chkAutoAllocate; private final JFXCheckBox chkFullscreen; - private final JFXToggleButton chkNoJVMArgs; - private final JFXToggleButton chkNoGameCheck; - private final JFXToggleButton chkNoJVMCheck; - private final JFXToggleButton chkUseNativeGLFW; - private final JFXToggleButton chkUseNativeOpenAL; + private final OptionToggleButton noJVMArgsPane; + private final OptionToggleButton noGameCheckPane; + private final OptionToggleButton noJVMCheckPane; + private final OptionToggleButton useNativeGLFWPane; + private final OptionToggleButton useNativeOpenALPane; private final MultiFileItem javaItem; private final MultiFileItem.FileOption javaCustomOption; private final MultiFileItem gameDirItem; @@ -101,7 +101,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag private final MultiFileItem nativesDirItem; private final MultiFileItem.FileOption nativesDirCustomOption; private final JFXComboBox cboProcessPriority; - private final JFXToggleButton chkShowLogs; + private final OptionToggleButton showLogsPane; private final ImagePickerItem iconPickerItem; private final JFXCheckBox chkEnableSpecificSettings; private final BorderPane settingsTypePane; @@ -328,17 +328,8 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag } } - BorderPane showLogsPane = new BorderPane(); - { - Label label = new Label(i18n("settings.show_log")); - showLogsPane.setLeft(label); - BorderPane.setAlignment(label, Pos.CENTER_LEFT); - - chkShowLogs = new JFXToggleButton(); - showLogsPane.setRight(chkShowLogs); - chkShowLogs.setSize(8); - FXUtils.setLimitHeight(chkShowLogs, 20); - } + showLogsPane = new OptionToggleButton(); + showLogsPane.setTitle(i18n("settings.show_log")); BorderPane processPriorityPane = new BorderPane(); { @@ -459,65 +450,20 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag nativesDirCustomOption )); - BorderPane noJVMArgsPane = new BorderPane(); - { - Label label = new Label(i18n("settings.advanced.no_jvm_args")); - noJVMArgsPane.setLeft(label); - BorderPane.setAlignment(label, Pos.CENTER_LEFT); + noJVMArgsPane = new OptionToggleButton(); + noJVMArgsPane.setTitle(i18n("settings.advanced.no_jvm_args")); - chkNoJVMArgs = new JFXToggleButton(); - noJVMArgsPane.setRight(chkNoJVMArgs); - chkNoJVMArgs.setSize(8); - FXUtils.setLimitHeight(chkNoJVMArgs, 20); - } + noGameCheckPane = new OptionToggleButton(); + noGameCheckPane.setTitle(i18n("settings.advanced.dont_check_game_completeness")); - BorderPane noGameCheckPane = new BorderPane(); - { - Label label = new Label(i18n("settings.advanced.dont_check_game_completeness")); - noGameCheckPane.setLeft(label); - BorderPane.setAlignment(label, Pos.CENTER_LEFT); + noJVMCheckPane = new OptionToggleButton(); + noJVMCheckPane.setTitle(i18n("settings.advanced.dont_check_jvm_validity")); - chkNoGameCheck = new JFXToggleButton(); - noGameCheckPane.setRight(chkNoGameCheck); - chkNoGameCheck.setSize(8); - FXUtils.setLimitHeight(chkNoGameCheck, 20); - } + useNativeGLFWPane = new OptionToggleButton(); + useNativeGLFWPane.setTitle(i18n("settings.advanced.use_native_glfw")); - BorderPane noJVMCheckPane = new BorderPane(); - { - Label label = new Label(i18n("settings.advanced.dont_check_jvm_validity")); - noJVMCheckPane.setLeft(label); - BorderPane.setAlignment(label, Pos.CENTER_LEFT); - - chkNoJVMCheck = new JFXToggleButton(); - noJVMCheckPane.setRight(chkNoJVMCheck); - chkNoJVMCheck.setSize(8); - FXUtils.setLimitHeight(chkNoJVMCheck, 20); - } - - BorderPane useNativeGLFWPane = new BorderPane(); - { - Label label = new Label(i18n("settings.advanced.use_native_glfw")); - useNativeGLFWPane.setLeft(label); - BorderPane.setAlignment(label, Pos.CENTER_LEFT); - - chkUseNativeGLFW = new JFXToggleButton(); - useNativeGLFWPane.setRight(chkUseNativeGLFW); - chkUseNativeGLFW.setSize(8); - FXUtils.setLimitHeight(chkUseNativeGLFW, 20); - } - - BorderPane useNativeOpenALPane = new BorderPane(); - { - Label label = new Label(i18n("settings.advanced.use_native_openal")); - useNativeOpenALPane.setLeft(label); - BorderPane.setAlignment(label, Pos.CENTER_LEFT); - - chkUseNativeOpenAL = new JFXToggleButton(); - useNativeOpenALPane.setRight(chkUseNativeOpenAL); - chkUseNativeOpenAL.setSize(8); - FXUtils.setLimitHeight(chkUseNativeOpenAL, 20); - } + useNativeOpenALPane = new OptionToggleButton(); + useNativeOpenALPane.setTitle(i18n("settings.advanced.use_native_openal")); workaroundPane.getContent().setAll(nativesDirItem, noJVMArgsPane, noGameCheckPane, noJVMCheckPane, useNativeGLFWPane, useNativeOpenALPane); } @@ -614,12 +560,12 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag FXUtils.unbindString(txtServerIP, lastVersionSetting.serverIpProperty()); FXUtils.unbindBoolean(chkAutoAllocate, lastVersionSetting.autoMemoryProperty()); FXUtils.unbindBoolean(chkFullscreen, lastVersionSetting.fullscreenProperty()); - FXUtils.unbindBoolean(chkNoGameCheck, lastVersionSetting.notCheckGameProperty()); - FXUtils.unbindBoolean(chkNoJVMCheck, lastVersionSetting.notCheckJVMProperty()); - FXUtils.unbindBoolean(chkNoJVMArgs, lastVersionSetting.noJVMArgsProperty()); - FXUtils.unbindBoolean(chkShowLogs, lastVersionSetting.showLogsProperty()); - FXUtils.unbindBoolean(chkUseNativeGLFW, lastVersionSetting.useNativeGLFWProperty()); - FXUtils.unbindBoolean(chkUseNativeOpenAL, lastVersionSetting.useNativeOpenALProperty()); + noGameCheckPane.selectedProperty().unbindBidirectional(lastVersionSetting.notCheckGameProperty()); + noJVMCheckPane.selectedProperty().unbindBidirectional(lastVersionSetting.notCheckJVMProperty()); + noJVMArgsPane.selectedProperty().unbindBidirectional(lastVersionSetting.noJVMArgsProperty()); + showLogsPane.selectedProperty().unbindBidirectional(lastVersionSetting.showLogsProperty()); + useNativeGLFWPane.selectedProperty().unbindBidirectional(lastVersionSetting.useNativeGLFWProperty()); + useNativeOpenALPane.selectedProperty().unbindBidirectional(lastVersionSetting.useNativeOpenALProperty()); FXUtils.unbindEnum(cboLauncherVisibility); FXUtils.unbindEnum(cboProcessPriority); @@ -653,12 +599,12 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag FXUtils.bindString(txtServerIP, versionSetting.serverIpProperty()); FXUtils.bindBoolean(chkAutoAllocate, versionSetting.autoMemoryProperty()); FXUtils.bindBoolean(chkFullscreen, versionSetting.fullscreenProperty()); - FXUtils.bindBoolean(chkNoGameCheck, versionSetting.notCheckGameProperty()); - FXUtils.bindBoolean(chkNoJVMCheck, versionSetting.notCheckJVMProperty()); - FXUtils.bindBoolean(chkNoJVMArgs, versionSetting.noJVMArgsProperty()); - FXUtils.bindBoolean(chkShowLogs, versionSetting.showLogsProperty()); - FXUtils.bindBoolean(chkUseNativeGLFW, versionSetting.useNativeGLFWProperty()); - FXUtils.bindBoolean(chkUseNativeOpenAL, versionSetting.useNativeOpenALProperty()); + noGameCheckPane.selectedProperty().bindBidirectional(versionSetting.notCheckGameProperty()); + noJVMCheckPane.selectedProperty().bindBidirectional(versionSetting.notCheckJVMProperty()); + noJVMArgsPane.selectedProperty().bindBidirectional(versionSetting.noJVMArgsProperty()); + showLogsPane.selectedProperty().bindBidirectional(versionSetting.showLogsProperty()); + useNativeGLFWPane.selectedProperty().bindBidirectional(versionSetting.useNativeGLFWProperty()); + useNativeOpenALPane.selectedProperty().bindBidirectional(versionSetting.useNativeOpenALProperty()); FXUtils.bindEnum(cboLauncherVisibility, versionSetting.launcherVisibilityProperty()); FXUtils.bindEnum(cboProcessPriority, versionSetting.processPriorityProperty()); diff --git a/HMCL/src/main/resources/assets/css/root.css b/HMCL/src/main/resources/assets/css/root.css index a9d39b2dd..c72825e65 100644 --- a/HMCL/src/main/resources/assets/css/root.css +++ b/HMCL/src/main/resources/assets/css/root.css @@ -831,6 +831,10 @@ -fx-font-size: 12; } +.options-list-item.no-padding { + -fx-padding: 0; +} + .no-padding .options-list-item { -fx-padding: 0; }