mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
UIScale:
- allow scale factors less than 100% for system property `flatlaf.uiScale` - no longer round scale factor of system property `flatlaf.uiScale` to 1/4 - renamed system property `flatlaf.uiDowncale.enabled` to `flatlaf.uiScale.allowScaleDown` - round smaller scale factors to 1/10 - absolute minimum user scale factor is now 0.1
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.formdev.flatlaf;
|
||||
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
/**
|
||||
* Defines/documents own system properties used in FlatLaf.
|
||||
*
|
||||
@@ -32,6 +34,8 @@ public interface FlatSystemProperties
|
||||
* To replace the Java 9+ system scale factor, use system property "sun.java2d.uiScale",
|
||||
* which has the same syntax as this one.
|
||||
* <p>
|
||||
* Since FlatLaf 1.1.2: Scale factors less then 100% are allowed.
|
||||
* <p>
|
||||
* <strong>Allowed Values</strong> e.g. {@code 1.5}, {@code 1.5x}, {@code 150%} or {@code 144dpi} (96dpi is 100%)<br>
|
||||
*/
|
||||
String UI_SCALE = "flatlaf.uiScale";
|
||||
@@ -44,13 +48,16 @@ public interface FlatSystemProperties
|
||||
*/
|
||||
String UI_SCALE_ENABLED = "flatlaf.uiScale.enabled";
|
||||
|
||||
/**
|
||||
* Specifies whether values smaller than 1.0f are allowed for the custom scale factor.
|
||||
/**
|
||||
* Specifies whether values smaller than 100% are allowed for the user scale factor
|
||||
* (see {@link UIScale#getUserScaleFactor()}).
|
||||
* <p>
|
||||
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
|
||||
* <strong>Default</strong> {@code false}
|
||||
*
|
||||
* @since 1.1.2
|
||||
*/
|
||||
String UI_DOWNSCALE_ENABLED = "flatlaf.uiDowncale.enabled";
|
||||
String UI_SCALE_ALLOW_SCALE_DOWN = "flatlaf.uiScale.allowScaleDown";
|
||||
|
||||
/**
|
||||
* Specifies whether Ubuntu font should be used on Ubuntu Linux.
|
||||
|
||||
@@ -180,7 +180,7 @@ public class UIScale
|
||||
// apply custom scale factor specified in system property "flatlaf.uiScale"
|
||||
float customScaleFactor = getCustomScaleFactor();
|
||||
if( customScaleFactor > 0 ) {
|
||||
setUserScaleFactor( customScaleFactor );
|
||||
setUserScaleFactor( customScaleFactor, false );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ public class UIScale
|
||||
} else
|
||||
newScaleFactor = computeScaleFactor( font );
|
||||
|
||||
setUserScaleFactor( newScaleFactor );
|
||||
setUserScaleFactor( newScaleFactor, true );
|
||||
}
|
||||
|
||||
private static float computeScaleFactor( Font font ) {
|
||||
@@ -258,10 +258,6 @@ public class UIScale
|
||||
return FlatSystemProperties.getBoolean( FlatSystemProperties.UI_SCALE_ENABLED, true );
|
||||
}
|
||||
|
||||
private static boolean isDownscalingEnabled() {
|
||||
return FlatSystemProperties.getBoolean( FlatSystemProperties.UI_DOWNSCALE_ENABLED, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a custom scale factor given in system property "flatlaf.uiScale"
|
||||
* to the given font.
|
||||
@@ -278,7 +274,7 @@ public class UIScale
|
||||
if( scaleFactor == fontScaleFactor )
|
||||
return font;
|
||||
|
||||
int newFontSize = Math.round( (font.getSize() / fontScaleFactor) * scaleFactor );
|
||||
int newFontSize = Math.max( Math.round( (font.getSize() / fontScaleFactor) * scaleFactor ), 1 );
|
||||
return new FontUIResource( font.deriveFont( (float) newFontSize ) );
|
||||
}
|
||||
|
||||
@@ -326,11 +322,18 @@ public class UIScale
|
||||
/**
|
||||
* Sets the user scale factor.
|
||||
*/
|
||||
private static void setUserScaleFactor( float scaleFactor ) {
|
||||
if( ( !isDownscalingEnabled() && scaleFactor <= 1f ) || scaleFactor <= 0f )
|
||||
scaleFactor = 1f;
|
||||
else // round scale factor to 1/4
|
||||
scaleFactor = Math.round( scaleFactor * 4f ) / 4f;
|
||||
private static void setUserScaleFactor( float scaleFactor, boolean normalize ) {
|
||||
if( normalize ) {
|
||||
if( scaleFactor < 1f ) {
|
||||
scaleFactor = FlatSystemProperties.getBoolean( FlatSystemProperties.UI_SCALE_ALLOW_SCALE_DOWN, false )
|
||||
? Math.round( scaleFactor * 10f ) / 10f // round small scale factor to 1/10
|
||||
: 1f;
|
||||
} else if( scaleFactor > 1f ) // round scale factor to 1/4
|
||||
scaleFactor = Math.round( scaleFactor * 4f ) / 4f;
|
||||
}
|
||||
|
||||
// minimum scale factor
|
||||
scaleFactor = Math.max( scaleFactor, 0.1f );
|
||||
|
||||
float oldScaleFactor = UIScale.scaleFactor;
|
||||
UIScale.scaleFactor = scaleFactor;
|
||||
|
||||
Reference in New Issue
Block a user