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.
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-20 13:57:12 -05:00
1 parent a3e8b44145
commit 6f45b5347d
2 files changed
+18 -1

No files matched your search

@@ -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)
}
}
}
@@ -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))