From 664f5c98e9712a51ebc050921b60d029f08dc153 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Mon, 13 Jun 2022 22:52:10 +0200 Subject: [PATCH] macOS themes: support changing accent and highlight colors (issue #497) --- .../com/formdev/flatlaf/themes/FlatMacDarkLaf.properties | 8 ++++---- .../com/formdev/flatlaf/themes/FlatMacLightLaf.properties | 8 ++++---- .../src/main/java/com/formdev/flatlaf/demo/DemoFrame.java | 6 +++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/themes/FlatMacDarkLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/themes/FlatMacDarkLaf.properties index f07f64b3d..d2f684860 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/themes/FlatMacDarkLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/themes/FlatMacDarkLaf.properties @@ -88,12 +88,12 @@ @menuBackground = lighten(@background,8%) # selection -@selectionBackground = @nsSelectedContentBackgroundColor +@selectionBackground = if(systemColor(accent), shade(spin(systemColor(accent),4),20%), @nsSelectedContentBackgroundColor) @selectionForeground = @nsSelectedMenuItemTextColor @selectionInactiveBackground = @nsUnemphasizedSelectedContentBackgroundColor # text selection -@textSelectionBackground = @nsSelectedTextBackgroundColor +@textSelectionBackground = systemColor(highlight,if(systemColor(accent), darken(desaturate(systemColor(accent),60%),10%), @nsSelectedTextBackgroundColor)) @textSelectionForeground = @nsSelectedTextColor # menu @@ -101,8 +101,8 @@ @menuItemMargin = 3,11,3,11 # accent colors (blueish) -@accentColor = @nsControlAccentColor -@accentFocusColor = @nsKeyboardFocusIndicatorColor +@accentColor = systemColor(accent,@nsControlAccentColor) +@accentFocusColor = if(systemColor(accent), fade(spin(systemColor(accent),-10),50%), @nsKeyboardFocusIndicatorColor) #---- Button ---- diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/themes/FlatMacLightLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/themes/FlatMacLightLaf.properties index 67e382bf0..5a411a854 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/themes/FlatMacLightLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/themes/FlatMacLightLaf.properties @@ -88,12 +88,12 @@ @menuBackground = darken(@background,4%) # selection -@selectionBackground = @nsSelectedContentBackgroundColor +@selectionBackground = if(systemColor(accent), shade(spin(systemColor(accent),4),10%), @nsSelectedContentBackgroundColor) @selectionForeground = @nsSelectedMenuItemTextColor @selectionInactiveBackground = @nsUnemphasizedSelectedContentBackgroundColor # text selection -@textSelectionBackground = @nsSelectedTextBackgroundColor +@textSelectionBackground = systemColor(highlight,if(systemColor(accent), tint(systemColor(accent),70%), @nsSelectedTextBackgroundColor)) @textSelectionForeground = @foreground # menu @@ -102,8 +102,8 @@ @menuItemMargin = 3,11,3,11 # accent colors (blueish) -@accentColor = @nsControlAccentColor -@accentFocusColor = @nsKeyboardFocusIndicatorColor +@accentColor = systemColor(accent,@nsControlAccentColor) +@accentFocusColor = if(systemColor(accent), fade(spin(systemColor(accent),4),50%), @nsKeyboardFocusIndicatorColor) #---- Button ---- diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java index ed1a9a441..f65def732 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java @@ -44,6 +44,8 @@ import com.formdev.flatlaf.extras.components.FlatButton; import com.formdev.flatlaf.extras.components.FlatButton.ButtonType; import com.formdev.flatlaf.icons.FlatAbstractIcon; +import com.formdev.flatlaf.themes.FlatMacDarkLaf; +import com.formdev.flatlaf.themes.FlatMacLightLaf; import com.formdev.flatlaf.extras.FlatSVGUtils; import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.ui.JBRCustomDecorations; @@ -455,7 +457,9 @@ private void updateAccentColorButtons() { lafClass == FlatLightLaf.class || lafClass == FlatDarkLaf.class || lafClass == FlatIntelliJLaf.class || - lafClass == FlatDarculaLaf.class; + lafClass == FlatDarculaLaf.class || + lafClass == FlatMacLightLaf.class || + lafClass == FlatMacDarkLaf.class; accentColorLabel.setVisible( isAccentColorSupported ); for( int i = 0; i < accentColorButtons.length; i++ )