From a639fbb1c8d45702e728dc1034793c2346fcf90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=AB=E4=B9=90=E5=87=A4=E7=88=AA=E7=8E=8B?= <165921128+KSSJW@users.noreply.github.com> Date: Tue, 3 Nov 2026 20:57:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=20JFXSwitch=20?= =?UTF-8?q?=E6=94=B9=E8=BF=9B=20ModInfoListCell=20(#7173)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmcl/ui/instances/ModListPage.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) 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());