diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/instances/ModListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/instances/ModListPage.java index 0886a21315..a4d344de29 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/instances/ModListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/instances/ModListPage.java @@ -66,7 +66,6 @@ import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; -import java.util.Objects; import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.locks.ReentrantLock; @@ -726,14 +725,14 @@ public final class ModListPage extends ListPageBase i private final ModListPage page; - private final JFXCheckBox checkBox = new JFXCheckBox(); private final ImageContainer imageContainer = new ImageContainer(32); private final TwoLineListItem content = new TwoLineListItem(); private final JFXButton restoreButton = FXUtils.newToggleButton4(SVG.RESTORE); - private final JFXButton infoButton = FXUtils.newToggleButton4(SVG.INFO); private final JFXButton revealButton = FXUtils.newToggleButton4(SVG.FOLDER); + private final JFXButton infoButton = FXUtils.newToggleButton4(SVG.INFO); + private final JFXSwitch activeSwitch = new JFXSwitch(); - private final InvalidationListener activeListener = obs -> checkBox.setSelected(getItem().getModInfo().isActive()); + private final InvalidationListener activeListener = obs -> activeSwitch.setSelected(getItem().getModInfo().isActive()); private final WeakInvalidationListener weakActiveListener = new WeakInvalidationListener(activeListener); private @Nullable ReadOnlyBooleanProperty observedActiveProperty; @@ -749,6 +748,7 @@ public final class ModListPage extends ListPageBase i HBox container = new HBox(8); container.setPickOnBounds(false); container.setAlignment(Pos.CENTER_LEFT); + container.setPadding(new Insets(0, 8, 0, 8)); HBox.setHgrow(content, Priority.ALWAYS); setSelectable(); @@ -756,7 +756,17 @@ public final class ModListPage extends ListPageBase i FXUtils.installFastTooltip(restoreButton, i18n("mods.restore")); - container.getChildren().setAll(checkBox, imageContainer, content, restoreButton, revealButton, infoButton); + HBox actions = new HBox(); + actions.setAlignment(Pos.CENTER); + actions.getChildren().setAll(restoreButton, revealButton, infoButton, activeSwitch); + + activeSwitch.setSize(24); + activeSwitch.setMinSize(30, 30); + activeSwitch.setPrefSize(30, 30); + activeSwitch.setMaxSize(30, 30); + HBox.setMargin(activeSwitch, new Insets(0, 0, 0, 8)); + + container.getChildren().setAll(imageContainer, content, actions); StackPane.setMargin(container, new Insets(8)); getContainer().getChildren().setAll(container); @@ -832,15 +842,15 @@ public final class ModListPage extends ListPageBase i content.getTags().setAll(tags); (observedActiveProperty = modInfo.activeProperty()).addListener(weakActiveListener); - checkBox.setSelected(modInfo.isActive()); - checkBox.setOnAction(event -> { + activeSwitch.setSelected(modInfo.isActive()); + activeSwitch.setOnAction(event -> { try { - modInfo.setActive(checkBox.isSelected()); + modInfo.setActive(activeSwitch.isSelected()); } catch (IOException e) { LOG.warning("Unable to change state of mod file " + modInfo.getFile(), e); Controllers.showToast(i18n("mods.toggle.failed")); } finally { - checkBox.setSelected(modInfo.isActive()); + activeSwitch.setSelected(modInfo.isActive()); } }); restoreButton.setVisible(!modInfo.getMod().getOldFiles().isEmpty());