mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 21:35:59 +00:00
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:
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))
|
||||
|
||||
Reference in new issue
Block a user