Skip to content

Commit

Permalink
laf stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Dec 10, 2023
1 parent cd6848b commit 4f89d55
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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);
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 4f89d55

Please sign in to comment.