From 6f45b5347d6880ab9c05a5d2315365ce8ab36d93 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:57:12 -0500 Subject: [PATCH] fix(input): the layout editor draws controls at their real size in portrait (#2949) The editor is a dialog that starts at the default dialog size and is then stretched to the full screen, so its preview could be laid out at a size it was never measured at. Controls took their size from the earlier pass and their position from the new one: in portrait, pills came out several times taller and round buttons slid down. Each control is now sized from where the canvas actually lays it out. --- .../com/droiddeck/launcher/ui/InputSurfaceView.kt | 6 +++++- .../droiddeck/launcher/ui/InputSurfaceTouchTest.kt | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/InputSurfaceView.kt b/app/src/main/java/com/droiddeck/launcher/ui/InputSurfaceView.kt index 198f929e0..9aae41232 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/InputSurfaceView.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/InputSurfaceView.kt @@ -206,7 +206,11 @@ class InputSurfaceView( val e = layout[i] val child = getChildAt(i) val x = (width * e.x).toInt(); val y = (height * e.y).toInt() - child.layout(x, y, x + child.measuredWidth, y + child.measuredHeight) + // A dialog resized after its first pass can lay this out at a size it was never measured at. + val w = (width * e.width).toInt(); val h = (height * e.height).toInt() + if (child.measuredWidth != w || child.measuredHeight != h) + child.measure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY)) + child.layout(x, y, x + w, y + h) } } } diff --git a/app/src/test/java/com/droiddeck/launcher/ui/InputSurfaceTouchTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/InputSurfaceTouchTest.kt index eaf9d6528..76006670f 100644 --- a/app/src/test/java/com/droiddeck/launcher/ui/InputSurfaceTouchTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ui/InputSurfaceTouchTest.kt @@ -63,6 +63,19 @@ class InputSurfaceTouchTest { private fun state() = JoyConPadTest.RecordingWriter.pads[0] ?: PadState() + @Test fun controlsTakeTheSizeTheyAreLaidOutAtEvenIfMeasuredAtAnother() { + val element = InputSurfaceElement(InputControl.LT, .1f, .1f, .2f, .05f, kind = InputElementKind.TRIGGER, buttonShape = InputButtonShape.PILL) + val surface = InputSurfaceView(context).apply { updateCustomLayout(listOf(element)) } + surface.measure(View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(3000, View.MeasureSpec.EXACTLY)) + surface.layout(0, 0, 1000, 3000) + val canvas = descendants(surface).first { it.tag == element }.parent as View + canvas.layout(0, 0, 1000, 1000) + val control = descendants(surface).first { it.tag == element } + assertEquals(100, control.top) + assertEquals(200, control.width) + assertEquals(50, control.height) + } + @Test fun aFingerSlidingBetweenButtonsMovesThePress() { touch(MotionEvent.ACTION_DOWN, 1 to (800f to 240f)) assertTrue(state().isDown(PadState.A))