From 6ee737b314c1afbe6befe98e572882852f780d70 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sat, 9 Jul 2022 10:30:33 +0200 Subject: [PATCH] Window decorations: small area at top of embedded menu bar to resize window --- CHANGELOG.md | 6 ++++ .../com/formdev/flatlaf/ui/FlatTitlePane.java | 33 +++++++++++-------- .../com/formdev/flatlaf/FlatLaf.properties | 1 + .../dumps/uidefaults/FlatDarkLaf_1.8.0.txt | 1 + .../dumps/uidefaults/FlatLightLaf_1.8.0.txt | 1 + .../dumps/uidefaults/FlatTestLaf_1.8.0.txt | 1 + .../flatlaf/themeeditor/FlatLafUIKeys.txt | 1 + 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0181e076..4fbe39b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ FlatLaf Change Log ## 2.4-SNAPSHOT +#### New features and improvements + +- Native window decorations (Windows 10/11 only): + - There is now a small area at top of the embedded menu bar to resize the + window. + #### Fixed bugs - ComboBox: Fixed vertical alignment of text in popup list with text in combo diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java index 4854274f..742f1012 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java @@ -87,6 +87,7 @@ import com.formdev.flatlaf.util.UIScale; * @uiDefault TitlePane.centerTitle boolean * @uiDefault TitlePane.centerTitleIfMenuBarEmbedded boolean * @uiDefault TitlePane.menuBarTitleGap int + * @uiDefault TitlePane.menuBarResizeHeight int * @uiDefault TitlePane.closeIcon Icon * @uiDefault TitlePane.iconifyIcon Icon * @uiDefault TitlePane.maximizeIcon Icon @@ -111,6 +112,7 @@ public class FlatTitlePane protected final boolean centerTitle = UIManager.getBoolean( "TitlePane.centerTitle" ); protected final boolean centerTitleIfMenuBarEmbedded = FlatUIUtils.getUIBoolean( "TitlePane.centerTitleIfMenuBarEmbedded", true ); protected final int menuBarTitleGap = FlatUIUtils.getUIInt( "TitlePane.menuBarTitleGap", 20 ); + /** @since 2.4 */ protected final int menuBarResizeHeight = FlatUIUtils.getUIInt( "TitlePane.menuBarResizeHeight", 4 ); protected final JRootPane rootPane; @@ -233,10 +235,7 @@ public class FlatTitlePane @Override public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); - if( buttonMaximizedHeight > 0 && - window instanceof Frame && - (((Frame)window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0 ) - { + if( buttonMaximizedHeight > 0 && isWindowMaximized() ) { // make title pane height smaller when frame is maximized size = new Dimension( size.width, Math.min( size.height, UIScale.scale( buttonMaximizedHeight ) ) ); } @@ -567,6 +566,11 @@ debug*/ frame.setExtendedState( frame.getExtendedState() | Frame.ICONIFIED ); } + /** @since 2.4 */ + protected boolean isWindowMaximized() { + return window instanceof Frame && (((Frame)window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0; + } + /** * Maximizes the window. */ @@ -741,9 +745,7 @@ debug*/ // if frame is maximized, increase icon bounds to upper-left corner // of window to allow closing window via double-click in upper-left corner - if( window instanceof Frame && - (((Frame)window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0 ) - { + if( isWindowMaximized() ) { iconBounds.height += iconBounds.y; iconBounds.y = 0; @@ -768,6 +770,15 @@ debug*/ if( hasVisibleEmbeddedMenuBar( menuBar ) ) { r = getNativeHitTestSpot( menuBar ); if( r != null ) { + // if frame is not maximized, make menu bar hit test spot smaller at top + // to have a small area above the menu bar to resize the window + if( !isWindowMaximized() ) { + // limit to 8, because Windows does not use a larger height + int resizeHeight = UIScale.scale( Math.min( menuBarResizeHeight, 8 ) ); + r.y += resizeHeight; + r.height -= resizeHeight; + } + Component horizontalGlue = findHorizontalGlue( menuBar ); if( horizontalGlue != null ) { // If menu bar is embedded and contains a horizontal glue component, @@ -854,7 +865,7 @@ debug*/ } else if( borderColor != null && (rootPane.getJMenuBar() == null || !rootPane.getJMenuBar().isVisible()) ) insets.bottom += UIScale.scale( 1 ); - if( !SystemInfo.isWindows_11_orLater && hasNativeCustomDecoration() && !isWindowMaximized( c ) ) + if( !SystemInfo.isWindows_11_orLater && hasNativeCustomDecoration() && !isWindowMaximized() ) insets = FlatUIUtils.addInsets( insets, WindowTopBorder.getInstance().getBorderInsets() ); return insets; @@ -873,7 +884,7 @@ debug*/ FlatUIUtils.paintFilledRectangle( g, borderColor, x, y + height - lineHeight, width, lineHeight ); } - if( !SystemInfo.isWindows_11_orLater && hasNativeCustomDecoration() && !isWindowMaximized( c ) ) + if( !SystemInfo.isWindows_11_orLater && hasNativeCustomDecoration() && !isWindowMaximized() ) WindowTopBorder.getInstance().paintBorder( c, g, x, y, width, height ); } @@ -881,10 +892,6 @@ debug*/ JMenuBar menuBar = rootPane.getJMenuBar(); return hasVisibleEmbeddedMenuBar( menuBar ) ? menuBar.getBorder() : null; } - - protected boolean isWindowMaximized( Component c ) { - return window instanceof Frame && (((Frame) window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0; - } } //---- class FlatTitleLabelUI --------------------------------------------- diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties index 5939219c..621e6473 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -794,6 +794,7 @@ TitlePane.buttonMaximizedHeight = 22 TitlePane.centerTitle = false TitlePane.centerTitleIfMenuBarEmbedded = true TitlePane.menuBarTitleGap = 20 +TitlePane.menuBarResizeHeight = 4 TitlePane.closeIcon = com.formdev.flatlaf.icons.FlatWindowCloseIcon TitlePane.iconifyIcon = com.formdev.flatlaf.icons.FlatWindowIconifyIcon TitlePane.maximizeIcon = com.formdev.flatlaf.icons.FlatWindowMaximizeIcon diff --git a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt index 18ee11f2..628f7fd9 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt @@ -1233,6 +1233,7 @@ TitlePane.inactiveBackground #303234 HSL 210 4 20 javax.swing.plaf.Colo TitlePane.inactiveForeground #8c8c8c HSL 0 0 55 javax.swing.plaf.ColorUIResource [UI] TitlePane.maximizeIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowMaximizeIcon [UI] TitlePane.menuBarEmbedded true +TitlePane.menuBarResizeHeight 4 TitlePane.menuBarTitleGap 20 TitlePane.noIconLeftGap 8 TitlePane.restoreIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowRestoreIcon [UI] diff --git a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt index 13731937..17e0d6cd 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt @@ -1238,6 +1238,7 @@ TitlePane.inactiveBackground #ffffff HSL 0 0 100 javax.swing.plaf.Colo TitlePane.inactiveForeground #8c8c8c HSL 0 0 55 javax.swing.plaf.ColorUIResource [UI] TitlePane.maximizeIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowMaximizeIcon [UI] TitlePane.menuBarEmbedded true +TitlePane.menuBarResizeHeight 4 TitlePane.menuBarTitleGap 20 TitlePane.noIconLeftGap 8 TitlePane.restoreIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowRestoreIcon [UI] diff --git a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt index 8900a298..4c691646 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt @@ -1266,6 +1266,7 @@ TitlePane.inactiveBackground #008800 HSL 120 100 27 javax.swing.plaf.Colo TitlePane.inactiveForeground #ffffff HSL 0 0 100 javax.swing.plaf.ColorUIResource [UI] TitlePane.maximizeIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowMaximizeIcon [UI] TitlePane.menuBarEmbedded true +TitlePane.menuBarResizeHeight 4 TitlePane.menuBarTitleGap 20 TitlePane.noIconLeftGap 8 TitlePane.restoreIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowRestoreIcon [UI] diff --git a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt index 1ce4fc69..1c6fa061 100644 --- a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt +++ b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt @@ -999,6 +999,7 @@ TitlePane.inactiveBackground TitlePane.inactiveForeground TitlePane.maximizeIcon TitlePane.menuBarEmbedded +TitlePane.menuBarResizeHeight TitlePane.menuBarTitleGap TitlePane.noIconLeftGap TitlePane.restoreIcon