From 4f89d5528395f32622557cb90c1a224557f22739 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sat, 9 Dec 2023 23:04:12 -0600 Subject: [PATCH] laf stuff --- .../java/org/quiltmc/enigma/gui/config/Config.java | 11 ++++++++++- .../org/quiltmc/enigma/gui/config/theme/Themes.java | 1 + .../enigma/gui/docker/component/DockerButton.java | 2 +- .../java/org/quiltmc/enigma/gui/element/MenuBar.java | 2 -- .../java/org/quiltmc/enigma/gui/util/ScaleUtil.java | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java index d448897fe..3626e2c05 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -52,8 +52,16 @@ public final class Config extends ReflectiveConfig { public final StatsSection stats = new StatsSection(); + /** + * The look and feel stored in the config: do not use this unless setting! Use {@link #activeLookAndFeel} instead, + * since look and feel is final once loaded. + */ @SerializedName("look_and_feel") public final TrackedValue lookAndFeel = this.value(LookAndFeel.DEFAULT); + /** + * Look and feel is not modifiable at runtime. I have tried and failed multiple times to get this running. + */ + public static LookAndFeel activeLookAndFeel; @SerializedName("default_theme") public final Theme defaultTheme = new Theme(LookAndFeel.DEFAULT); @@ -66,6 +74,7 @@ public final class Config extends ReflectiveConfig { @SerializedName("none_theme") public final Theme noneTheme = new Theme(LookAndFeel.NONE); + @SuppressWarnings("all") public static Config main() { return MAIN; } @@ -87,7 +96,7 @@ public static DecompilerConfig decompiler() { } public static Theme currentTheme() { - return switch (MAIN.lookAndFeel.value()) { + return switch (activeLookAndFeel) { case DEFAULT -> MAIN.defaultTheme; case DARCULA -> MAIN.darculaTheme; case METAL -> MAIN.metalTheme; diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java index 691d9d7ee..2ac0d20cd 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java @@ -21,6 +21,7 @@ public class Themes { // theme settings) is currently not functional. public static void setupTheme() { LookAndFeel laf = Config.main().lookAndFeel.value(); + Config.activeLookAndFeel = laf; laf.setGlobalLAF(); Config.currentColors().configure(LookAndFeel.isDarkLaf()); Themes.setFonts(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java index 21dc0cc83..75353dc9e 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java @@ -122,7 +122,7 @@ public void paint(Graphics g) { // setup text String translatedText = this.textSupplier.get(); Font font = Config.currentFonts().defaultFont.value(); - if (Config.main().lookAndFeel.value().equals(LookAndFeel.SYSTEM)) { + if (Config.activeLookAndFeel.equals(LookAndFeel.SYSTEM)) { font = font.deriveFont(Font.BOLD); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java index dbb7492ea..e345e5c65 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java @@ -5,7 +5,6 @@ import org.quiltmc.enigma.gui.NotificationManager; import org.quiltmc.enigma.gui.config.Decompiler; import org.quiltmc.enigma.gui.config.theme.LookAndFeel; -import org.quiltmc.enigma.gui.config.theme.Themes; import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.config.keybind.KeyBinds; import org.quiltmc.enigma.gui.dialog.AboutDialog; @@ -586,7 +585,6 @@ private static void prepareThemesMenu(JMenu themesMenu, Gui gui) { themeButton.addActionListener(e -> { Config.main().lookAndFeel.setValue(lookAndFeel, true); - Themes.setupTheme(); ChangeDialog.show(gui.getFrame()); }); themesMenu.add(themeButton); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java index e6fc889f2..c5b7ec3b7 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java @@ -89,7 +89,7 @@ public static int invert(int i) { public static void applyScaling() { double scale = Config.main().scaleFactor.value(); - if (Config.main().lookAndFeel.value().needsScaling()) { + if (Config.activeLookAndFeel.needsScaling()) { UiDefaultsScaler.updateAndApplyGlobalScaling((int) (100 * scale), true); }