Browse Source

Windows: Don't hardcode menubar layout adjustment

pull/336/head
Jannis Weis 2 years ago
parent
commit
2f094edd47
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 9
      core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuBarBorder.java
  2. 6
      platform-base/src/main/java/com/github/weisj/darklaf/platform/CustomTitlePane.java
  3. 13
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java

9
core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuBarBorder.java

@ -27,8 +27,10 @@ import javax.swing.border.Border;
import javax.swing.plaf.InsetsUIResource; import javax.swing.plaf.InsetsUIResource;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import com.github.weisj.darklaf.platform.CustomTitlePane;
/** @author Jannis Weis */ /** @author Jannis Weis */
public class DarkMenuBarBorder implements Border, UIResource { public class DarkMenuBarBorder implements Border, UIResource, CustomTitlePane.BorderCollapseHint {
protected final Color borderColor; protected final Color borderColor;
@ -51,4 +53,9 @@ public class DarkMenuBarBorder implements Border, UIResource {
public boolean isBorderOpaque() { public boolean isBorderOpaque() {
return true; return true;
} }
@Override
public int getBottomCollapse() {
return 1;
}
} }

6
platform-base/src/main/java/com/github/weisj/darklaf/platform/CustomTitlePane.java

@ -1,7 +1,7 @@
/* /*
* MIT License * MIT License
* *
* Copyright (c) 2019-2022 Jannis Weis * Copyright (c) 2019-2023 Jannis Weis
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, * associated documentation files (the "Software"), to deal in the Software without restriction,
@ -24,6 +24,10 @@ import javax.swing.*;
public abstract class CustomTitlePane extends JComponent { public abstract class CustomTitlePane extends JComponent {
public interface BorderCollapseHint {
int getBottomCollapse();
}
protected int decorationStyle; protected int decorationStyle;
public abstract void uninstall(final boolean removeDecorations); public abstract void uninstall(final boolean removeDecorations);

13
windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java

@ -1,7 +1,7 @@
/* /*
* MIT License * MIT License
* *
* Copyright (c) 2019-2022 Jannis Weis * Copyright (c) 2019-2023 Jannis Weis
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, * associated documentation files (the "Software"), to deal in the Software without restriction,
@ -865,7 +865,7 @@ public class WindowsTitlePane extends CustomTitlePane {
int w = getWidth(); int w = getWidth();
int x; int x;
int start = 0; int start = 0;
int y = 0; final int y = 0;
height = computeHeight(); height = computeHeight();
left = 0; left = 0;
right = 0; right = 0;
@ -881,8 +881,13 @@ public class WindowsTitlePane extends CustomTitlePane {
if (menuBarStealer.hasMenuBar()) { if (menuBarStealer.hasMenuBar()) {
int menuWidth = getPreferredMenuSize().width; int menuWidth = getPreferredMenuSize().width;
Insets menuInsets = menuBarStealer.getMenuBar().getInsets(); JMenuBar menuBar = menuBarStealer.getMenuBar();
menuBarStealer.getMenuBar().setBounds(start, y, menuWidth, height + menuInsets.bottom); Border b = menuBar.getBorder();
int menuHeight = height;
if (b instanceof BorderCollapseHint) {
menuHeight += ((BorderCollapseHint) b).getBottomCollapse();
}
menuBarStealer.getMenuBar().setBounds(start, y, menuWidth, menuHeight);
start += menuWidth + PAD; start += menuWidth + PAD;
left += menuWidth; left += menuWidth;
} }

Loading…
Cancel
Save