summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Perez <diegoperez@google.com>2015-08-03 09:32:12 +0100
committerDiego Perez <diegoperez@google.com>2015-08-04 15:12:44 +0100
commit96d3ef65e3a24ed9f0555301885aeaa44e21cfbb (patch)
tree8c222773a386932daf45ded31cedce96c43c482f
parentf9a37740b48c714df09b1c9539a0ca9d4e43b308 (diff)
downloadidea-96d3ef65e3a24ed9f0555301885aeaa44e21cfbb.tar.gz
Only setting height to 1 when we are reducing the width
This was part of the original patch but, since layoutlib was fixed, it wasn't necessary anymore. However, I ran into the issue today again when using an old layoutlib so I think it is safer to add it right now. When passing 1 to the height, in some cases, layoutlib will not correctly recalculate the size and will be stuck at a height 0, causing it to stop rendering. Change-Id: If482d688d1a29e2f948262049bcfd4cad9cb36fe
-rw-r--r--android/src/com/android/tools/swing/layoutlib/AndroidPreviewPanel.java13
1 files changed, 10 insertions, 3 deletions
diff --git a/android/src/com/android/tools/swing/layoutlib/AndroidPreviewPanel.java b/android/src/com/android/tools/swing/layoutlib/AndroidPreviewPanel.java
index 7a12d14441c..005fa2ed61a 100644
--- a/android/src/com/android/tools/swing/layoutlib/AndroidPreviewPanel.java
+++ b/android/src/com/android/tools/swing/layoutlib/AndroidPreviewPanel.java
@@ -116,6 +116,7 @@ public class AndroidPreviewPanel extends JComponent implements Scrollable {
private double myScale = 1.0;
private Dimension myLastRenderedSize;
private Dimension myCachedPreferredSize;
+ private int myCurrentWidth;
public AndroidPreviewPanel(@NotNull Configuration configuration) {
myConfiguration = configuration;
@@ -134,9 +135,15 @@ public class AndroidPreviewPanel extends JComponent implements Scrollable {
Dimension currentSize = getSize();
synchronized (myGraphicsLayoutRendererLock) {
if (myGraphicsLayoutRenderer != null && !currentSize.equals(previousSize)) {
- // Because we use GraphicsLayoutRender in vertical scroll mode, the height passed it's only a minimum. If the actual rendering results
- // in a bigger size, the GraphicsLayoutRenderer.getPreferredSize() call will return the correct size.
- myGraphicsLayoutRenderer.setSize(width, 1);
+ // Because we use GraphicsLayoutRender in vertical scroll mode, the height passed it's only a minimum.
+ // If the actual rendering results in a bigger size, the GraphicsLayoutRenderer.getPreferredSize()
+ // call will return the correct size.
+
+ // Older versions of layoutlib do not handle correctly when 1 is passed and don't always recalculate
+ // the height if the width hasn't decreased.
+ // We workaround that by keep track of the last known width and passing height 1 when it decreases.
+ myGraphicsLayoutRenderer.setSize(width, (myCurrentWidth < width) ? 1 : height);
+ myCurrentWidth = width;
}
}
}