Fixed detached windows growing every time they get shown

This commit is contained in:
dragonmacher 2025-09-12 12:39:44 -04:00
parent 970c8fbdd5
commit fe4bb30704
2 changed files with 19 additions and 14 deletions

View file

@ -83,10 +83,26 @@ class DetachedWindowNode extends WindowNode {
child = processChildElement(childElement, mgr, this, list); child = processChildElement(childElement, mgr, this, list);
} }
void setInitialBounds(Rectangle r) { // Set the bounds for the component that is being placed in this window when the window is first
// created. This is useful when dragging a component provider out of an existing window into
// its own window.
void setWindowContentsBounds(Rectangle r) {
// The rectangle will be empty when there is no size information for the component being
// added to this window node.
if (r == null) { if (r == null) {
r = new Rectangle(); r = new Rectangle();
} }
if (!r.isEmpty()) {
// We need to create window bounds from the given component bounds. The window has
// extra size for the toolbar and menus.
int nonComponentWidth = 12;
int nonComponentHeight = 120;
r.width += nonComponentWidth;
r.height += nonComponentHeight;
}
restoreBounds = r; restoreBounds = r;
} }
@ -372,6 +388,7 @@ class DetachedWindowNode extends WindowNode {
private Rectangle getNewBounds(Window newWindow) { private Rectangle getNewBounds(Window newWindow) {
Rectangle updatedBounds = new Rectangle(restoreBounds); Rectangle updatedBounds = new Rectangle(restoreBounds);
restoreBounds = null;
if (updatedBounds.isEmpty()) { if (updatedBounds.isEmpty()) {
// No bounds to restore; pick something reasonable // No bounds to restore; pick something reasonable
window.pack(); window.pack();
@ -379,20 +396,8 @@ class DetachedWindowNode extends WindowNode {
updatedBounds.height = d.height; updatedBounds.height = d.height;
updatedBounds.width = d.width; updatedBounds.width = d.width;
} }
else {
// Update the desired window bounds for the size of the component. The window size
// has to account for things like the menu and toolbars. These value were picked
// through trial-and-error.
int nonComponentWidth = 12;
int nonComponentHeight = 120;
updatedBounds.width += nonComponentWidth;
updatedBounds.height += nonComponentHeight;
}
ensureValidLocation(updatedBounds); ensureValidLocation(updatedBounds);
WindowUtilities.ensureEntirelyOnScreen(newWindow, updatedBounds); WindowUtilities.ensureEntirelyOnScreen(newWindow, updatedBounds);
return updatedBounds; return updatedBounds;

View file

@ -241,7 +241,7 @@ class RootNode extends WindowNode {
Point location = loc == null ? new Point() : loc; Point location = loc == null ? new Point() : loc;
Dimension size = placeholderSize == null ? new Dimension() : placeholderSize; Dimension size = placeholderSize == null ? new Dimension() : placeholderSize;
windowNode.setInitialBounds(new Rectangle(location, size)); windowNode.setWindowContentsBounds(new Rectangle(location, size));
detachedWindows.add(windowNode); detachedWindows.add(windowNode);
placeholder.getNode().add(placeholder); placeholder.getNode().add(placeholder);