mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 15:07:11 -06:00
UIDefaultsLoader: added over() color function to convert a translucent color into a solid color based on any background color
This commit is contained in:
@@ -466,6 +466,10 @@ class UIDefaultsLoader
|
|||||||
if( knownValueTypes == null ) {
|
if( knownValueTypes == null ) {
|
||||||
// create lazy
|
// create lazy
|
||||||
knownValueTypes = new HashMap<>();
|
knownValueTypes = new HashMap<>();
|
||||||
|
// system colors
|
||||||
|
knownValueTypes.put( "activeCaptionBorder", ValueType.COLOR );
|
||||||
|
knownValueTypes.put( "inactiveCaptionBorder", ValueType.COLOR );
|
||||||
|
knownValueTypes.put( "windowBorder", ValueType.COLOR );
|
||||||
// SplitPane
|
// SplitPane
|
||||||
knownValueTypes.put( "SplitPane.dividerSize", ValueType.INTEGER );
|
knownValueTypes.put( "SplitPane.dividerSize", ValueType.INTEGER );
|
||||||
knownValueTypes.put( "SplitPaneDivider.gripDotSize", ValueType.INTEGER );
|
knownValueTypes.put( "SplitPaneDivider.gripDotSize", ValueType.INTEGER );
|
||||||
@@ -780,6 +784,7 @@ class UIDefaultsLoader
|
|||||||
case "tint": return parseColorMix( "#fff", params, resolver, reportError );
|
case "tint": return parseColorMix( "#fff", params, resolver, reportError );
|
||||||
case "shade": return parseColorMix( "#000", params, resolver, reportError );
|
case "shade": return parseColorMix( "#000", params, resolver, reportError );
|
||||||
case "contrast": return parseColorContrast( params, resolver, reportError );
|
case "contrast": return parseColorContrast( params, resolver, reportError );
|
||||||
|
case "over": return parseColorOver( params, resolver, reportError );
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
parseColorDepth--;
|
parseColorDepth--;
|
||||||
@@ -847,7 +852,7 @@ class UIDefaultsLoader
|
|||||||
int lightness = parsePercentage( params.get( 2 ) );
|
int lightness = parsePercentage( params.get( 2 ) );
|
||||||
int alpha = hasAlpha ? parsePercentage( params.get( 3 ) ) : 100;
|
int alpha = hasAlpha ? parsePercentage( params.get( 3 ) ) : 100;
|
||||||
|
|
||||||
float[] hsl = new float[] { hue, saturation, lightness };
|
float[] hsl = { hue, saturation, lightness };
|
||||||
return new ColorUIResource( HSLColor.toRGB( hsl, alpha / 100f ) );
|
return new ColorUIResource( HSLColor.toRGB( hsl, alpha / 100f ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1041,6 +1046,33 @@ class UIDefaultsLoader
|
|||||||
return parseColorOrFunction( resolver.apply( darkOrLightColor ), resolver, reportError );
|
return parseColorOrFunction( resolver.apply( darkOrLightColor ), resolver, reportError );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Syntax: over(foreground,background)
|
||||||
|
* - foreground: a foreground color (e.g. #f00) or a color function;
|
||||||
|
* the alpha of this color is used as weight to mix the two colors
|
||||||
|
* - background: a background color (e.g. #f00) or a color function
|
||||||
|
*/
|
||||||
|
private static Object parseColorOver( List<String> params, Function<String, String> resolver, boolean reportError ) {
|
||||||
|
String foregroundStr = params.get( 0 );
|
||||||
|
String backgroundStr = params.get( 1 );
|
||||||
|
|
||||||
|
// parse foreground color
|
||||||
|
ColorUIResource foreground = (ColorUIResource) parseColorOrFunction( resolver.apply( foregroundStr ), resolver, reportError );
|
||||||
|
if( foreground == null || foreground.getAlpha() == 255 )
|
||||||
|
return foreground;
|
||||||
|
|
||||||
|
Color foreground2 = new Color( foreground.getRGB() );
|
||||||
|
|
||||||
|
// parse background color
|
||||||
|
ColorUIResource background = (ColorUIResource) parseColorOrFunction( resolver.apply( backgroundStr ), resolver, reportError );
|
||||||
|
if( background == null )
|
||||||
|
return foreground2;
|
||||||
|
|
||||||
|
// create new color
|
||||||
|
float weight = foreground.getAlpha() / 255f;
|
||||||
|
return new ColorUIResource( ColorFunctions.mix( foreground2, background, weight ) );
|
||||||
|
}
|
||||||
|
|
||||||
private static Object parseFunctionBaseColor( String colorStr, ColorFunction function,
|
private static Object parseFunctionBaseColor( String colorStr, ColorFunction function,
|
||||||
boolean derived, Function<String, String> resolver, boolean reportError )
|
boolean derived, Function<String, String> resolver, boolean reportError )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -482,6 +482,10 @@ class FlatCompletionProvider
|
|||||||
"dark", colorParamDesc,
|
"dark", colorParamDesc,
|
||||||
"light", colorParamDesc,
|
"light", colorParamDesc,
|
||||||
"threshold", "(optional) 0-100%, default is 43%" );
|
"threshold", "(optional) 0-100%, default is 43%" );
|
||||||
|
|
||||||
|
addFunction( "over",
|
||||||
|
"foreground", colorParamDesc,
|
||||||
|
"background", colorParamDesc );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addFunction( String name, String... paramNamesAndDescs ) {
|
private void addFunction( String name, String... paramNamesAndDescs ) {
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public class FlatThemeTokenMaker
|
|||||||
tokenMap.put( "tint", TOKEN_FUNCTION );
|
tokenMap.put( "tint", TOKEN_FUNCTION );
|
||||||
tokenMap.put( "shade", TOKEN_FUNCTION );
|
tokenMap.put( "shade", TOKEN_FUNCTION );
|
||||||
tokenMap.put( "contrast", TOKEN_FUNCTION );
|
tokenMap.put( "contrast", TOKEN_FUNCTION );
|
||||||
|
tokenMap.put( "over", TOKEN_FUNCTION );
|
||||||
|
|
||||||
// function options
|
// function options
|
||||||
tokenMap.put( "relative", Token.RESERVED_WORD );
|
tokenMap.put( "relative", Token.RESERVED_WORD );
|
||||||
|
|||||||
@@ -118,6 +118,12 @@ Prop.6.selectionForeground = contrast($Prop.6.selectionBackground,#000,#fff)
|
|||||||
Prop.7.selectionBackground = #FF9500
|
Prop.7.selectionBackground = #FF9500
|
||||||
Prop.7.selectionForeground = contrast($Prop.7.selectionBackground,#000,#fff)
|
Prop.7.selectionForeground = contrast($Prop.7.selectionBackground,#000,#fff)
|
||||||
|
|
||||||
|
Prop.colorFunc60 = over(#fff8,#f00)
|
||||||
|
Prop.colorFunc61 = over(#fff8,#0f0)
|
||||||
|
Prop.colorFunc62 = over(#f000,#0f0)
|
||||||
|
Prop.colorFunc63 = over(#f00,#0f0)
|
||||||
|
Prop.colorFunc64 = over(#f008,null)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@varStyle1 = #f0f
|
@varStyle1 = #f0f
|
||||||
|
|||||||
Reference in New Issue
Block a user