diff options
author | Joe Baker-Malone <jbakermalone@google.com> | 2022-01-31 14:19:15 -0800 |
---|---|---|
committer | Joe Baker-Malone <jbakermalone@google.com> | 2022-01-31 23:49:46 +0000 |
commit | 79166f3b0d3487232fdec1b4e4d6fe16c180ffc2 (patch) | |
tree | 4ebe7b0616e9e262df2fd5d5fba534c0bcebfa03 /layout-inspector/src | |
parent | e11b359cd2f5c27eacbb4e16448667108e806a99 (diff) | |
download | idea-79166f3b0d3487232fdec1b4e4d6fe16c180ffc2.tar.gz |
Use smaller window bounds in 2d mode
In 3d mode we need to have larger bounds to allow for rotating and
changes to rendering size when the number of visible views changes.
In 2d we don't need to worry about that, so use smaller bounds.
Fixes: 175395343
Test: updated existing tests
Change-Id: Id8b001916e0343da162905e29fa8cf01360611d0
Diffstat (limited to 'layout-inspector/src')
-rw-r--r-- | layout-inspector/src/com/android/tools/idea/layoutinspector/ui/DeviceViewContentPanel.kt | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/ui/DeviceViewContentPanel.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/ui/DeviceViewContentPanel.kt index 563fb911530..761cc6fd34a 100644 --- a/layout-inspector/src/com/android/tools/idea/layoutinspector/ui/DeviceViewContentPanel.kt +++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/ui/DeviceViewContentPanel.kt @@ -255,12 +255,17 @@ class DeviceViewContentPanel( } } - override fun getPreferredSize() = - if (inspectorModel.isEmpty) Dimension(0, 0) - // Give twice the needed size, so we have room to move the view around a little. Otherwise things can jump around - // when the number of layers changes and the canvas size adjusts to smaller than the viewport size. - else Dimension((model.maxWidth * viewSettings.scaleFraction + JBUIScale.scale(MARGIN)).toInt() * 2, - (model.maxHeight * viewSettings.scaleFraction + JBUIScale.scale(MARGIN)).toInt() * 2) + override fun getPreferredSize(): Dimension { + val (desiredWidth, desiredHeight) = when { + inspectorModel.isEmpty -> Pair(0, 0) + // If rotated, give twice the needed size, so we have room to move the view around a little. Otherwise things can jump around + // when the number of layers changes and the canvas size adjusts to smaller than the viewport size. + model.isRotated -> Pair(model.maxWidth * 2, model.maxHeight * 2) + else -> inspectorModel.root.transitiveBounds.run { Pair(width, height) } + } + return Dimension((desiredWidth * viewSettings.scaleFraction).toInt() + JBUIScale.scale(MARGIN) * 2, + (desiredHeight * viewSettings.scaleFraction).toInt() + JBUIScale.scale(MARGIN) * 2) + } private fun autoScrollAndRepaint(origin: SelectionOrigin) { val selection = inspectorModel.selection |