Restore min width when keeping window size small

Restore minimum width after closing sidebar when keeping window size but
window size was too small.

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-05-07 22:48:28 +02:00
parent 2d968a832d
commit 186adf6130

View File

@@ -151,13 +151,10 @@ public class ContainableFrame extends JFrame
} }
revalidateMinimumSize(); revalidateMinimumSize();
if (expandResizeType == ExpandResizeType.KEEP_GAME_SIZE)
{
final int newWindowWidth = getWidth() - value;
final Rectangle screenBounds = getGraphicsConfiguration().getBounds(); final Rectangle screenBounds = getGraphicsConfiguration().getBounds();
final boolean wasCloseToLeftEdge = Math.abs(getX() - screenBounds.getX()) <= SCREEN_EDGE_CLOSE_DISTANCE; final boolean wasCloseToLeftEdge = Math.abs(getX() - screenBounds.getX()) <= SCREEN_EDGE_CLOSE_DISTANCE;
int newWindowX = getX(); int newWindowX = getX();
int newWindowWidth = getWidth() - value;
if (isFrameCloseToRightEdge() && (expandedClientOppositeDirection || !wasCloseToLeftEdge)) if (isFrameCloseToRightEdge() && (expandedClientOppositeDirection || !wasCloseToLeftEdge))
{ {
@@ -165,9 +162,14 @@ public class ContainableFrame extends JFrame
newWindowX += value; newWindowX += value;
} }
setBounds(newWindowX, getY(), newWindowWidth, getHeight()); if (expandResizeType == ExpandResizeType.KEEP_WINDOW_SIZE && newWindowWidth > getMinimumSize().width)
{
// The sidebar fits inside the window, do not resize and move
newWindowWidth = getWidth();
newWindowX = getX();
} }
setBounds(newWindowX, getY(), newWindowWidth, getHeight());
expandedClientOppositeDirection = false; expandedClientOppositeDirection = false;
} }