Accent color:

- added `Component.accentColor`
- dark themes: changed threshold for contrast() from 39% down to 25% for better readability of text
- Demo: added "Default" accent color and changed "Blue" to lighter color

(issue #233)
This commit is contained in:
Karl Tauber
2021-09-28 11:12:17 +02:00
parent e31e4dfe3a
commit bb5c2eea10
8 changed files with 19 additions and 6 deletions

View File

@@ -35,7 +35,7 @@
@background = #3c3f41 @background = #3c3f41
@foreground = #bbb @foreground = #bbb
@selectionBackground = @accentSelectionBackground @selectionBackground = @accentSelectionBackground
@selectionForeground = contrast(@selectionBackground,@background,@foreground,39%) @selectionForeground = contrast(@selectionBackground,@background,@foreground,25%)
@selectionInactiveBackground = spin(saturate(shade(@selectionBackground,70%),20%),-15) @selectionInactiveBackground = spin(saturate(shade(@selectionBackground,70%),20%),-15)
@selectionInactiveForeground = @foreground @selectionInactiveForeground = @foreground
@disabledText = #888 @disabledText = #888
@@ -164,6 +164,7 @@ Component.disabledBorderColor = $Component.borderColor
Component.focusedBorderColor = lighten($Component.focusColor,5%) Component.focusedBorderColor = lighten($Component.focusColor,5%)
Component.focusColor = @accentFocusColor Component.focusColor = @accentFocusColor
Component.linkColor = @accentLinkColor Component.linkColor = @accentLinkColor
Component.accentColor = if(@accentColor, @accentColor, @accentBaseColor)
Component.grayFilter = -20,-70,100 Component.grayFilter = -20,-70,100
Component.error.borderColor = desaturate($Component.error.focusedBorderColor,25%) Component.error.borderColor = desaturate($Component.error.focusedBorderColor,25%)
@@ -242,7 +243,7 @@ PopupMenu.borderColor = #5e5e5e
ProgressBar.background = #555 ProgressBar.background = #555
ProgressBar.foreground = @accentSliderColor ProgressBar.foreground = @accentSliderColor
ProgressBar.selectionBackground = @foreground ProgressBar.selectionBackground = @foreground
ProgressBar.selectionForeground = contrast($ProgressBar.foreground,@background,@foreground,39%) ProgressBar.selectionForeground = contrast($ProgressBar.foreground,@background,@foreground,25%)
#---- RootPane ---- #---- RootPane ----

View File

@@ -171,6 +171,7 @@ Component.disabledBorderColor = lighten($Component.borderColor,4%)
Component.focusedBorderColor = shade($Component.focusColor,10%) Component.focusedBorderColor = shade($Component.focusColor,10%)
Component.focusColor = @accentFocusColor Component.focusColor = @accentFocusColor
Component.linkColor = @accentLinkColor Component.linkColor = @accentLinkColor
Component.accentColor = if(@accentColor, @accentColor, @accentBaseColor)
Component.grayFilter = 25,-25,100 Component.grayFilter = 25,-25,100
Component.error.borderColor = lighten(desaturate($Component.error.focusedBorderColor,20%),25%) Component.error.borderColor = lighten(desaturate($Component.error.focusedBorderColor,20%),25%)

View File

@@ -336,9 +336,12 @@ class DemoFrame
// flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatLightLaf.properties and // flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatLightLaf.properties and
// flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatDarkLaf.properties // flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatDarkLaf.properties
private static String[] accentColorKeys = { private static String[] accentColorKeys = {
"Demo.accent.blue", "Demo.accent.purple", "Demo.accent.red", "Demo.accent.default", "Demo.accent.blue", "Demo.accent.purple", "Demo.accent.red",
"Demo.accent.orange", "Demo.accent.yellow", "Demo.accent.green", "Demo.accent.orange", "Demo.accent.yellow", "Demo.accent.green",
}; };
private static String[] accentColorNames = {
"Default", "Blue", "Purple", "Red", "Orange", "Yellow", "Green",
};
private final JToggleButton[] accentColorButtons = new JToggleButton[accentColorKeys.length]; private final JToggleButton[] accentColorButtons = new JToggleButton[accentColorKeys.length];
private JLabel accentColorLabel; private JLabel accentColorLabel;
@@ -351,6 +354,7 @@ class DemoFrame
ButtonGroup group = new ButtonGroup(); ButtonGroup group = new ButtonGroup();
for( int i = 0; i < accentColorButtons.length; i++ ) { for( int i = 0; i < accentColorButtons.length; i++ ) {
accentColorButtons[i] = new JToggleButton( new AccentColorIcon( accentColorKeys[i] ) ); accentColorButtons[i] = new JToggleButton( new AccentColorIcon( accentColorKeys[i] ) );
accentColorButtons[i].setToolTipText( accentColorNames[i] );
accentColorButtons[i].addActionListener( this::accentColorChanged ); accentColorButtons[i].addActionListener( this::accentColorChanged );
toolBar.add( accentColorButtons[i] ); toolBar.add( accentColorButtons[i] );
group.add( accentColorButtons[i] ); group.add( accentColorButtons[i] );

View File

@@ -16,9 +16,11 @@
#---- Demo.accent ---- #---- Demo.accent ----
Demo.accent.blue = #4B6EAF # accent colors from https://github.com/89netraM/SystemColors/blob/master/src/net/asberg/macos/AccentColor.java
Demo.accent.default = #4B6EAF
Demo.accent.blue = #0A84FF
Demo.accent.purple = #BF5AF2 Demo.accent.purple = #BF5AF2
Demo.accent.red = #e81123 Demo.accent.red = #FF453A
Demo.accent.orange = #FF9F0A Demo.accent.orange = #FF9F0A
Demo.accent.yellow = #FFCC00 Demo.accent.yellow = #FFCC00
Demo.accent.green = #32D74B Demo.accent.green = #32D74B

View File

@@ -16,7 +16,9 @@
#---- Demo.accent ---- #---- Demo.accent ----
Demo.accent.blue = #2675BF # accent colors from https://github.com/89netraM/SystemColors/blob/master/src/net/asberg/macos/AccentColor.java
Demo.accent.default = #2675BF
Demo.accent.blue = #007AFF
Demo.accent.purple = #BF5AF2 Demo.accent.purple = #BF5AF2
Demo.accent.red = #FF3B30 Demo.accent.red = #FF3B30
Demo.accent.orange = #FF9500 Demo.accent.orange = #FF9500

View File

@@ -216,6 +216,7 @@ ComboBoxUI com.formdev.flatlaf.ui.FlatComboBoxUI
#---- Component ---- #---- Component ----
Component.accentColor #4b6eaf HSL 219 40 49 javax.swing.plaf.ColorUIResource [UI]
Component.arc 5 Component.arc 5
Component.arrowType chevron Component.arrowType chevron
Component.borderColor #646464 HSL 0 0 39 javax.swing.plaf.ColorUIResource [UI] Component.borderColor #646464 HSL 0 0 39 javax.swing.plaf.ColorUIResource [UI]

View File

@@ -220,6 +220,7 @@ ComboBoxUI com.formdev.flatlaf.ui.FlatComboBoxUI
#---- Component ---- #---- Component ----
Component.accentColor #2675bf HSL 209 67 45 javax.swing.plaf.ColorUIResource [UI]
Component.arc 5 Component.arc 5
Component.arrowType chevron Component.arrowType chevron
Component.borderColor #c4c4c4 HSL 0 0 77 javax.swing.plaf.ColorUIResource [UI] Component.borderColor #c4c4c4 HSL 0 0 77 javax.swing.plaf.ColorUIResource [UI]

View File

@@ -172,6 +172,7 @@ ComboBox.selectionBackground
ComboBox.selectionForeground ComboBox.selectionForeground
ComboBox.timeFactor ComboBox.timeFactor
ComboBoxUI ComboBoxUI
Component.accentColor
Component.arc Component.arc
Component.arrowType Component.arrowType
Component.borderColor Component.borderColor