fix(input): the layout editor shows the same placement as the session (#2783)

* fix(input): the layout editor shows the same placement as the session

Editing a layout stored for one orientation while the editor is open in
the other drew raw stored coordinates, so elements turned into flat,
overlapping bars. Route the editor through OnScreenLayout like the
on-screen controls: matched layouts are regenerated for the current
screen, everything else follows the same fit, and the dirty check
compares against what was shown when the editor opened.

* fix(input): reset and scale in the editor frame the session saves

The editor draft now carries the frame it was rebased to: the gamepad
scaler is rebuilt with the editor surface's real dimensions when edits
begin, so reset regenerates legacy controls for the display the user is
editing instead of the primary display. Stock default positions keep
their own frame aspect and are refitted into the draft frame before
being applied, so reset on a differently shaped display lands where the
editor shows and no longer marks an untouched layout as changed.

* fix(input): refit only the default positions on reset and update the test callers

---------

Co-authored-by: maxjivi05 <maxjividen@gmail.com>
This commit is contained in:
kingokksaandmaxjivi05 authored and GitHub committed 2026-11-18 12:57:15 -05:00
1 parent cca84f7b6b
commit fc5dd7f3c5
5 files changed
+29 -18

No files matched your search

@@ -138,16 +138,16 @@ object InputLibraries {
update(context) { library -> library.layouts.firstOrNull { it.id == layoutId && it.editable }?.let { library.withLayout(it.withQuickButton(button, shown)) } ?: library }
}.isSuccess
fun defaultPositions(context: Context, library: InputLibrary, layout: SavedInputLayout): List<InputSurfaceElement>? {
fun defaultPositions(context: Context, library: InputLibrary, layout: SavedInputLayout): Pair<List<InputSurfaceElement>, Float>? {
val origin = layout.origin ?: layout.id
InputStockLayouts.layouts().firstOrNull { it.id == origin }?.let { return it.elements }
InputStockLayouts.layouts().firstOrNull { it.id == origin }?.let { return it.elements to it.aspect }
if (origin == OVERLAY || origin.startsWith("migrated.layout.")) {
val (surfaceContext, metrics) = primaryDisplay(context)
val size = if (origin == OVERLAY) listOf(metrics.widthPixels, metrics.heightPixels)
else origin.removePrefix("migrated.layout.").split('x').mapNotNull { it.toIntOrNull() }
return size.takeIf { it.size == 2 && it.all { side -> side > 0 } }?.let { LegacyGamepadLayout(surfaceContext, it[0], it[1]).elements() }
return size.takeIf { it.size == 2 && it.all { side -> side > 0 } }?.let { LegacyGamepadLayout(surfaceContext, it[0], it[1]).elements() to it[0].toFloat() / it[1] }
}
return library.layouts.firstOrNull { it.id == origin && it.id != layout.id }?.elements
return library.layouts.firstOrNull { it.id == origin && it.id != layout.id }?.let { it.elements to it.aspect }
}
@Suppress("DEPRECATION")