Browse Source

Derive selection color from accent color (on windows)

pull/235/head
weisj 4 years ago
parent
commit
d398cb91aa
  1. 1
      core/src/test/java/ui/ComponentDemo.java
  2. 1
      windows/src/main/cpp/ThemeInfo.cpp
  3. 17
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsThemePreferenceProvider.java

1
core/src/test/java/ui/ComponentDemo.java

@ -63,6 +63,7 @@ public interface ComponentDemo {
static void showDemo(final ComponentDemo demo, final boolean asDialog) { static void showDemo(final ComponentDemo demo, final boolean asDialog) {
LafManager.enabledPreferenceChangeReporting(false); LafManager.enabledPreferenceChangeReporting(false);
LafManager.addThemePreferenceChangeListener(LafManager::installTheme);
LafManager.setDecorationsEnabled(true); LafManager.setDecorationsEnabled(true);
LafManager.setLogLevel(Level.FINE); LafManager.setLogLevel(Level.FINE);
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {

1
windows/src/main/cpp/ThemeInfo.cpp

@ -24,7 +24,6 @@
*/ */
#include "com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows.h" #include "com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows.h"
#include <iostream>
#include <string> #include <string>
#include <thread> #include <thread>
#include <atomic> #include <atomic>

17
windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsThemePreferenceProvider.java

@ -24,6 +24,7 @@ package com.github.weisj.darklaf.platform.windows;
import java.awt.*; import java.awt.*;
import java.util.function.Consumer; import java.util.function.Consumer;
import com.github.weisj.darklaf.color.DarkColorModelHSB;
import com.github.weisj.darklaf.theme.info.*; import com.github.weisj.darklaf.theme.info.*;
public class WindowsThemePreferenceProvider implements ThemePreferenceProvider { public class WindowsThemePreferenceProvider implements ThemePreferenceProvider {
@ -48,10 +49,18 @@ public class WindowsThemePreferenceProvider implements ThemePreferenceProvider {
ContrastRule contrastRule = highContrast ? ContrastRule.HIGH_CONTRAST : ContrastRule.STANDARD; ContrastRule contrastRule = highContrast ? ContrastRule.HIGH_CONTRAST : ContrastRule.STANDARD;
ColorToneRule toneRule = darkMode ? ColorToneRule.DARK : ColorToneRule.LIGHT; ColorToneRule toneRule = darkMode ? ColorToneRule.DARK : ColorToneRule.LIGHT;
FontSizeRule fontSizeRule = FontSizeRule.relativeAdjustment(fontScaling / 100f); FontSizeRule fontSizeRule = FontSizeRule.relativeAdjustment(fontScaling / 100f);
AccentColorRule accentColorRule = AccentColorRule.fromColor(createColorFromRGB(accentColorRGB)); Color accentColor = createColorFromRGB(accentColorRGB);
Color selectionColor = deriveSelectionColor(accentColor);
AccentColorRule accentColorRule = AccentColorRule.fromColor(accentColor, selectionColor);
return new PreferredThemeStyle(contrastRule, toneRule, accentColorRule, fontSizeRule); return new PreferredThemeStyle(contrastRule, toneRule, accentColorRule, fontSizeRule);
} }
private Color deriveSelectionColor(final Color color) {
if (color == null) return null;
double[] hsb = DarkColorModelHSB.RGBtoHSBValues(color.getRed(), color.getGreen(), color.getBlue());
return DarkColorModelHSB.getColorFromHSBValues(hsb[0], hsb[1] / 2.5, Math.min(1, hsb[2] * 1.2));
}
private Color createColorFromRGB(final int rgb) { private Color createColorFromRGB(final int rgb) {
if (rgb == 0) return null; if (rgb == 0) return null;
return new Color(rgb); return new Color(rgb);
@ -98,6 +107,12 @@ public class WindowsThemePreferenceProvider implements ThemePreferenceProvider {
return WindowsLibrary.get().isLoaded(); return WindowsLibrary.get().isLoaded();
} }
@Override
public boolean supportsNativeSelectionColor() {
// Depends on accent color as it is derived from it.
return supportsNativeAccentColor();
}
@Override @Override
public boolean supportsNativeFontSize() { public boolean supportsNativeFontSize() {
return WindowsLibrary.get().isLoaded(); return WindowsLibrary.get().isLoaded();

Loading…
Cancel
Save