mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Slider: replaced Slider.thumbWidth with Slider.thumbSize to support non-square sized thumbs (as used in Windows 10)
This commit is contained in:
@@ -53,7 +53,7 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
* <!-- FlatSliderUI -->
|
||||
*
|
||||
* @uiDefault Slider.trackWidth int
|
||||
* @uiDefault Slider.thumbWidth int
|
||||
* @uiDefault Slider.thumbSize Dimension
|
||||
* @uiDefault Slider.focusWidth int
|
||||
* @uiDefault Slider.trackValueColor Color optional; defaults to Slider.thumbColor
|
||||
* @uiDefault Slider.trackColor Color
|
||||
@@ -73,7 +73,7 @@ public class FlatSliderUI
|
||||
extends BasicSliderUI
|
||||
{
|
||||
protected int trackWidth;
|
||||
protected int thumbWidth;
|
||||
protected Dimension thumbSize;
|
||||
protected int focusWidth;
|
||||
|
||||
protected Color trackValueColor;
|
||||
@@ -106,7 +106,12 @@ public class FlatSliderUI
|
||||
LookAndFeel.installProperty( slider, "opaque", false );
|
||||
|
||||
trackWidth = UIManager.getInt( "Slider.trackWidth" );
|
||||
thumbWidth = UIManager.getInt( "Slider.thumbWidth" );
|
||||
thumbSize = UIManager.getDimension( "Slider.thumbSize" );
|
||||
if( thumbSize == null ) {
|
||||
// fallback for compatibility with old versions
|
||||
int thumbWidth = UIManager.getInt( "Slider.thumbWidth" );
|
||||
thumbSize = new Dimension( thumbWidth, thumbWidth );
|
||||
}
|
||||
focusWidth = FlatUIUtils.getUIInt( "Slider.focusWidth", 4 );
|
||||
|
||||
trackValueColor = FlatUIUtils.getUIColor( "Slider.trackValueColor", "Slider.thumbColor" );
|
||||
@@ -187,9 +192,16 @@ public class FlatSliderUI
|
||||
|
||||
@Override
|
||||
protected Dimension getThumbSize() {
|
||||
return calcThumbSize( slider, thumbSize, focusWidth );
|
||||
}
|
||||
|
||||
public static Dimension calcThumbSize( JSlider slider, Dimension thumbSize, int focusWidth ) {
|
||||
int fw = UIScale.scale( focusWidth );
|
||||
int w = UIScale.scale( thumbWidth ) + fw + fw;
|
||||
return new Dimension( w, w );
|
||||
int w = UIScale.scale( thumbSize.width ) + fw + fw;
|
||||
int h = UIScale.scale( thumbSize.height ) + fw + fw;
|
||||
return (slider.getOrientation() == JSlider.HORIZONTAL)
|
||||
? new Dimension( w, h )
|
||||
: new Dimension( h, w );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -285,23 +297,23 @@ debug*/
|
||||
// paint thumb focus border
|
||||
if( focused ) {
|
||||
g.setColor( focusedColor );
|
||||
g.fillOval( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height );
|
||||
((Graphics2D)g).fill( createRoundThumbShape( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height ) );
|
||||
}
|
||||
|
||||
if( thumbBorderColor != null ) {
|
||||
// paint thumb border
|
||||
g.setColor( thumbBorderColor );
|
||||
g.fillOval( x, y, width, height );
|
||||
((Graphics2D)g).fill( createRoundThumbShape( x, y, width, height ) );
|
||||
|
||||
// paint thumb background
|
||||
float lw = UIScale.scale( 1f );
|
||||
g.setColor( thumbColor );
|
||||
((Graphics2D)g).fill( new Ellipse2D.Float( x + lw, y + lw,
|
||||
((Graphics2D)g).fill( createRoundThumbShape( x + lw, y + lw,
|
||||
width - lw - lw, height - lw - lw ) );
|
||||
} else {
|
||||
// paint thumb background
|
||||
g.setColor( thumbColor );
|
||||
g.fillOval( x, y, width, height );
|
||||
((Graphics2D)g).fill( createRoundThumbShape( x, y, width, height ) );
|
||||
}
|
||||
} else {
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
@@ -315,13 +327,17 @@ debug*/
|
||||
g2.translate( thumbRect.width, 0 );
|
||||
g2.rotate( Math.toRadians( 90 ) );
|
||||
}
|
||||
|
||||
int temp = width;
|
||||
width = height;
|
||||
height = temp;
|
||||
}
|
||||
|
||||
// paint thumb focus border
|
||||
if( focused ) {
|
||||
g2.setColor( focusedColor );
|
||||
g2.fill( createDirectionalThumbShape( 0, 0,
|
||||
thumbRect.width, thumbRect.height + (fw * 0.4142f), fw ) );
|
||||
width + fw + fw, height + fw + fw + (fw * 0.4142f), fw ) );
|
||||
}
|
||||
|
||||
if( thumbBorderColor != null ) {
|
||||
@@ -345,8 +361,17 @@ debug*/
|
||||
}
|
||||
}
|
||||
|
||||
public static Shape createDirectionalThumbShape( double x, double y, double w, double h, double arc ) {
|
||||
double wh = w / 2;
|
||||
public static Shape createRoundThumbShape( float x, float y, float w, float h ) {
|
||||
if( w == h )
|
||||
return new Ellipse2D.Float( x, y, w, h );
|
||||
else {
|
||||
float arc = Math.min( w, h );
|
||||
return new RoundRectangle2D.Float( x, y, w, h, arc, arc );
|
||||
}
|
||||
}
|
||||
|
||||
public static Shape createDirectionalThumbShape( float x, float y, float w, float h, float arc ) {
|
||||
float wh = w / 2;
|
||||
|
||||
Path2D path = new Path2D.Float();
|
||||
path.moveTo( x + wh, y + h );
|
||||
|
||||
@@ -507,7 +507,7 @@ Separator.stripeIndent=1
|
||||
|
||||
Slider.focusInsets=0,0,0,0
|
||||
Slider.trackWidth=2
|
||||
Slider.thumbWidth=12
|
||||
Slider.thumbSize=12,12
|
||||
Slider.focusWidth=4
|
||||
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class FlatRangeSliderUI
|
||||
extends BasicRangeSliderUI
|
||||
{
|
||||
protected int trackWidth;
|
||||
protected int thumbWidth;
|
||||
protected Dimension thumbSize;
|
||||
protected int focusWidth;
|
||||
|
||||
protected Color trackValueColor;
|
||||
@@ -105,7 +105,7 @@ public class FlatRangeSliderUI
|
||||
LookAndFeel.installProperty( slider, "opaque", false );
|
||||
|
||||
trackWidth = UIManager.getInt( "Slider.trackWidth" );
|
||||
thumbWidth = UIManager.getInt( "Slider.thumbWidth" );
|
||||
thumbSize = UIManager.getDimension( "Slider.thumbSize" );
|
||||
focusWidth = FlatUIUtils.getUIInt( "Slider.focusWidth", 4 );
|
||||
|
||||
trackValueColor = FlatUIUtils.getUIColor( "Slider.trackValueColor", "Slider.thumbColor" );
|
||||
@@ -185,9 +185,7 @@ public class FlatRangeSliderUI
|
||||
|
||||
@Override
|
||||
protected Dimension getThumbSize() {
|
||||
int fw = UIScale.scale( focusWidth );
|
||||
int w = UIScale.scale( thumbWidth ) + fw + fw;
|
||||
return new Dimension( w, w );
|
||||
return FlatSliderUI.calcThumbSize( slider, thumbSize, focusWidth );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -858,7 +858,7 @@ Slider.onlyLeftMouseButtonDrag true
|
||||
Slider.pressedThumbColor #2e6296 com.formdev.flatlaf.util.DerivedColor [UI] darken(15% autoInverse)
|
||||
Slider.shadow #646464 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.thumbColor #4a88c7 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.thumbWidth 12
|
||||
Slider.thumbSize 12,12 javax.swing.plaf.DimensionUIResource [UI]
|
||||
Slider.tickColor #888888 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.trackColor #646464 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.trackValueColor #4a88c7 javax.swing.plaf.ColorUIResource [UI]
|
||||
|
||||
@@ -863,7 +863,7 @@ Slider.onlyLeftMouseButtonDrag true
|
||||
Slider.pressedThumbColor #125ca5 com.formdev.flatlaf.util.DerivedColor [UI] lighten(15% autoInverse)
|
||||
Slider.shadow #c4c4c4 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.thumbColor #1e82e6 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.thumbWidth 12
|
||||
Slider.thumbSize 12,12 javax.swing.plaf.DimensionUIResource [UI]
|
||||
Slider.tickColor #888888 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.trackColor #c4c4c4 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.trackValueColor #1e82e6 javax.swing.plaf.ColorUIResource [UI]
|
||||
|
||||
@@ -853,7 +853,7 @@ Slider.pressedTrackColor #88ff88 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.shadow #a0a0a0 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.thumbBorderColor #ff0000 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.thumbColor #ffaaaa javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.thumbWidth 12
|
||||
Slider.thumbSize 12,12 javax.swing.plaf.DimensionUIResource [UI]
|
||||
Slider.tickColor #ff0000 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.trackColor #88ff88 javax.swing.plaf.ColorUIResource [UI]
|
||||
Slider.trackWidth 2
|
||||
|
||||
@@ -600,7 +600,7 @@ Slider.onlyLeftMouseButtonDrag
|
||||
Slider.pressedThumbColor
|
||||
Slider.shadow
|
||||
Slider.thumbColor
|
||||
Slider.thumbWidth
|
||||
Slider.thumbSize
|
||||
Slider.tickColor
|
||||
Slider.trackColor
|
||||
Slider.trackValueColor
|
||||
|
||||
Reference in New Issue
Block a user