mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 07:17:13 -06:00
ScrollBar: use derived colors for track and thumb (issue #103)
This commit is contained in:
@@ -610,15 +610,17 @@ class UIDefaultsLoader
|
||||
}
|
||||
|
||||
// parse base color
|
||||
ColorUIResource baseColor = (ColorUIResource) parseColorOrFunction( resolver.apply( colorStr ), resolver, reportError );
|
||||
String resolvedColorStr = resolver.apply( colorStr );
|
||||
ColorUIResource baseColor = (ColorUIResource) parseColorOrFunction( resolvedColorStr, resolver, reportError );
|
||||
|
||||
// apply this function to base color
|
||||
Color newColor = ColorFunctions.applyFunctions( baseColor, function );
|
||||
|
||||
if( derived ) {
|
||||
ColorFunction[] functions;
|
||||
if( baseColor instanceof DerivedColor ) {
|
||||
if( baseColor instanceof DerivedColor && resolvedColorStr == colorStr ) {
|
||||
// if the base color is also derived, join the color functions
|
||||
// but only if base color function is specified directly in this function
|
||||
ColorFunction[] baseFunctions = ((DerivedColor)baseColor).getFunctions();
|
||||
functions = new ColorFunction[baseFunctions.length + 1];
|
||||
System.arraycopy( baseFunctions, 0, functions, 0, baseFunctions.length );
|
||||
|
||||
@@ -113,6 +113,10 @@ public class FlatArrowButton
|
||||
this.yOffset = yOffset;
|
||||
}
|
||||
|
||||
protected Color deriveHoverBackground( Color hoverBackground ) {
|
||||
return hoverBackground;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return scale( super.getPreferredSize() );
|
||||
@@ -134,7 +138,7 @@ public class FlatArrowButton
|
||||
|
||||
// paint hover background
|
||||
if( enabled && isHover() && hoverBackground != null ) {
|
||||
g.setColor( hoverBackground );
|
||||
g.setColor( deriveHoverBackground( hoverBackground ) );
|
||||
g.fillRect( 0, 0, width, height );
|
||||
}
|
||||
|
||||
|
||||
@@ -191,6 +191,11 @@ public class FlatScrollBarUI
|
||||
FlatArrowButton button = new FlatArrowButton( orientation,
|
||||
arrowType, buttonArrowColor, buttonDisabledArrowColor, null, hoverTrackColor )
|
||||
{
|
||||
@Override
|
||||
protected Color deriveHoverBackground( Color hoverBackground ) {
|
||||
return getTrackColor( scrollbar, true ) ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
if( isShowButtons() ) {
|
||||
@@ -231,7 +236,7 @@ public class FlatScrollBarUI
|
||||
|
||||
@Override
|
||||
protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) {
|
||||
g.setColor( hoverTrack ? hoverTrackColor : trackColor );
|
||||
g.setColor( getTrackColor( c, hoverTrack ) );
|
||||
paintTrackOrThumb( g, c, trackBounds, trackInsets, trackArc );
|
||||
}
|
||||
|
||||
@@ -240,7 +245,7 @@ public class FlatScrollBarUI
|
||||
if( thumbBounds.isEmpty() || !scrollbar.isEnabled() )
|
||||
return;
|
||||
|
||||
g.setColor( hoverThumb ? hoverThumbColor : thumbColor );
|
||||
g.setColor( getThumbColor( c, hoverThumb ) );
|
||||
paintTrackOrThumb( g, c, thumbBounds, thumbInsets, thumbArc );
|
||||
}
|
||||
|
||||
@@ -272,6 +277,17 @@ public class FlatScrollBarUI
|
||||
// do not paint
|
||||
}
|
||||
|
||||
protected Color getTrackColor( JComponent c, boolean hover ) {
|
||||
Color trackColor = FlatUIUtils.deriveColor( this.trackColor, c.getBackground() );
|
||||
return hover ? FlatUIUtils.deriveColor( hoverTrackColor, trackColor ) : trackColor;
|
||||
}
|
||||
|
||||
protected Color getThumbColor( JComponent c, boolean hover ) {
|
||||
Color trackColor = FlatUIUtils.deriveColor( this.trackColor, c.getBackground() );
|
||||
Color thumbColor = FlatUIUtils.deriveColor( this.thumbColor, trackColor );
|
||||
return hover ? FlatUIUtils.deriveColor( hoverThumbColor, thumbColor ) : thumbColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dimension getMinimumThumbSize() {
|
||||
return UIScale.scale( super.getMinimumThumbSize() );
|
||||
|
||||
@@ -41,7 +41,7 @@ public class DerivedColor
|
||||
}
|
||||
|
||||
public Color derive( Color baseColor ) {
|
||||
if( hasBaseOfDefaultColor && baseOfDefaultColorRGB == baseColor.getRGB() )
|
||||
if( (hasBaseOfDefaultColor && baseOfDefaultColorRGB == baseColor.getRGB()) || baseColor == this )
|
||||
return this; // return default color
|
||||
|
||||
Color result = ColorFunctions.applyFunctions( baseColor, functions );
|
||||
|
||||
@@ -217,10 +217,10 @@ ProgressBar.selectionBackground=@foreground
|
||||
|
||||
#---- ScrollBar ----
|
||||
|
||||
ScrollBar.track=#3F4244
|
||||
ScrollBar.thumb=lighten($ScrollBar.track,10%)
|
||||
ScrollBar.hoverTrackColor=lighten($ScrollBar.track,4%)
|
||||
ScrollBar.hoverThumbColor=lighten($ScrollBar.thumb,10%)
|
||||
ScrollBar.track=lighten(@background,1%,derived noAutoInverse)
|
||||
ScrollBar.thumb=lighten($ScrollBar.track,10%,derived noAutoInverse)
|
||||
ScrollBar.hoverTrackColor=lighten($ScrollBar.track,4%,derived noAutoInverse)
|
||||
ScrollBar.hoverThumbColor=lighten($ScrollBar.thumb,10%,derived noAutoInverse)
|
||||
|
||||
|
||||
#---- Separator ----
|
||||
|
||||
@@ -224,10 +224,10 @@ ProgressBar.selectionBackground=@foreground
|
||||
|
||||
#---- ScrollBar ----
|
||||
|
||||
ScrollBar.track=#F5F5F5
|
||||
ScrollBar.thumb=darken($ScrollBar.track,10%)
|
||||
ScrollBar.hoverTrackColor=darken($ScrollBar.track,3%)
|
||||
ScrollBar.hoverThumbColor=darken($ScrollBar.thumb,10%)
|
||||
ScrollBar.track=lighten(@background,1%,derived noAutoInverse)
|
||||
ScrollBar.thumb=darken($ScrollBar.track,10%,derived noAutoInverse)
|
||||
ScrollBar.hoverTrackColor=darken($ScrollBar.track,3%,derived noAutoInverse)
|
||||
ScrollBar.hoverThumbColor=darken($ScrollBar.thumb,10%,derived noAutoInverse)
|
||||
|
||||
|
||||
#---- Separator ----
|
||||
|
||||
Reference in New Issue
Block a user