feat(hud): every reading gets its own switch and a row order (#2454)

* feat: every HUD reading has its own switch and a row order

* feat: readings get a reorder dialog of their own

* refactor: drag alone moves a reading

* fix: the readings list is one column with a switch per row

* fix: one scrolling readings list, titled HUD info

* refactor: derive the readings order from the defaults instead of a second list

* fix: the readings dialog loses its doubled title and follows the saved order

* refactor: no title in the readings dialog, its actions sit beside the list

* refactor: readings dialog actions take the free side on landscape, the foot on portrait

* fix: the readings list follows the size it draws and drags with a live gap

* fix: the readings dialog fills the window and keeps scrolling under a held drag

* fix: reset restores every size's order, and the new HUD strings are translated

* refactor: one table for each size's rows and one for its text sizes

* refactor: the readings list swaps rows as the drag passes them, and the list animates the rest

* refactor: give the readings rows test tags for the local UI test

* refactor: HUD readings follow one configurable row table

* refactor: the Strip HUD draws its rows from the same table

* refactor: each size orders its rows by its own table, and the frame graph is a row

* fix: the readings dialog keeps the row order a drag leaves

* fix: each size keeps its own row order, and reset clears only the order

* refactor: the graph's size lives in one place, and the section markers are gone

* fix: a size change and the first save of a legacy config both keep the order

* chore: retrigger the build

* feat: a reading can be grabbed with Y and shuffled with the d-pad

* feat: controller hints float beside the dialog, and a moved row stays in view

* feat: Y grabs on a hold and drops on release, and a touch no longer flips the dialog

* fix: keep the key hints off the rows on narrow windows, and let Enter toggle a row
This commit is contained in:
kingokksa authored and GitHub committed 2026-11-14 14:49:47 -05:00
1 parent d8b3c66b95
commit 269d462825
42 files changed
+1322 -625

No files matched your search

@@ -301,6 +301,9 @@ internal fun rememberShown(onDismiss: () -> Unit): MutableTransitionState<Boolea
return shown
}
private val DIALOG_MARGIN = 12.dp
private val SIDE_GAP = 24.dp
@Composable
internal fun AppDialog(
shown: MutableTransitionState<Boolean>, close: () -> Unit, label: String, wide: Boolean,
@@ -309,17 +312,23 @@ internal fun AppDialog(
back: (() -> Unit)? = null,
scrollable: Boolean = true,
scrollState: androidx.compose.foundation.ScrollState = rememberScrollState(),
side: (@Composable () -> Unit)? = null,
sideRoom: Dp = 0.dp,
content: @Composable ColumnScope.() -> Unit,
) {
val pal = LocalPalette.current
val panelCap = maxWidth ?: if (wide) 860.dp else 560.dp
VeilRing()
Dialog(onDismissRequest = back ?: close, properties = DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = false)) {
CompositionLocalProvider(LocalFrontFocus provides null) {
Box(
BoxWithConstraints(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize().imePadding()
.tapOutside(close),
) {
val panel = (this.maxWidth - DIALOG_MARGIN * 2).coerceAtMost(panelCap)
val free = (this.maxWidth - panel) / 2 - SIDE_GAP
val beside = side != null && free >= sideRoom
AnimatedVisibility(
visibleState = shown,
enter = fadeIn(Motion.tw(180)) + scaleIn(Motion.sp(0.7f), initialScale = 0.94f),
@@ -329,8 +338,8 @@ internal fun AppDialog(
Column(
verticalArrangement = Arrangement.spacedBy(14.dp),
modifier = Modifier
.padding(12.dp)
.widthIn(max = maxWidth ?: if (wide) 860.dp else 560.dp)
.padding(DIALOG_MARGIN)
.widthIn(max = panelCap)
.then(
when {
width != null -> Modifier.width(width)
@@ -348,8 +357,21 @@ internal fun AppDialog(
.then(modifier)
.then(if (scrollable) Modifier.verticalScroll(scrollState) else Modifier)
.padding(horizontal = 18.dp, vertical = 16.dp),
content = content,
)
) {
content()
if (side != null && !beside) side()
}
}
if (side != null && beside) {
AnimatedVisibility(
visibleState = shown,
enter = fadeIn(Motion.tw(180)),
exit = fadeOut(Motion.tw(140)),
modifier = Modifier.align(Alignment.CenterEnd).padding(end = SIDE_GAP),
label = "$label-side",
) {
Box(Modifier.widthIn(max = free).blockTouches()) { side() }
}
}
}
}
@@ -1,5 +1,7 @@
package com.droiddeck.launcher.ui
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -8,7 +10,9 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.sp
import com.droiddeck.launcher.R
import com.droiddeck.launcher.hud.DroidDeckHudConfig
import com.droiddeck.launcher.hud.DroidDeckHudSize
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.session.StripMetric
@@ -55,30 +59,34 @@ internal fun DroidDeckHudSettings(host: MenuHost, a: DrawerActions, track: (Stri
ChoiceRow(host, "hud-outline-color", stringResource(R.string.hud_outline_color), null,
listOf("0" to stringResource(R.string.hud_outline_gray), "1" to stringResource(R.string.hud_outline_theme)),
if (cfg["hudOutlineAccent"] == "0") "0" else "1", chipModifier = track("hud-outline-color")) { a.onHudSetting("hudOutlineAccent", it) }
ToggleRow(host, "hud-fps-decimal", stringResource(R.string.hud_metric_decimal), null, on("fpsDecimal"),
chipModifier = track("hud-fps-decimal")) { a.onHudSetting("fpsDecimal", flag(it)) }
ToggleRow(host, "hud-clock", stringResource(R.string.hud_metric_clock), null, on("showClock"),
chipModifier = track("hud-clock")) { a.onHudSetting("showClock", flag(it)) }
ToggleRow(host, "hud-graph", stringResource(R.string.hud_metric_graph), null, on("showFPSGraph"),
chipModifier = track("hud-graph")) { a.onHudSetting("showFPSGraph", flag(it)) }
}
val size = DroidDeckHudSize.from(cfg["hudSize"])
val chips = size.supportedChips() + EXTRA[size].orEmpty()
var editing by remember { mutableStateOf(false) }
SettingsGroup(stringResource(R.string.hud_group_metrics)) {
for (metric in METRICS) {
if (metric.chip !in chips || metric.chip in HIDDEN[size].orEmpty()) continue
ToggleRow(host, "hud-${metric.key}", stringResource(metric.label), null, on(metric.key),
chipModifier = track("hud-${metric.key}")) { a.onHudSetting(metric.key, flag(it)) }
if (metric.key == "showBattery" && size != DroidDeckHudSize.MINIMAL) {
ToggleRow(host, "hud-showBatteryTime", stringResource(R.string.hud_metric_battery_time), null, on("showBatteryTime"),
chipModifier = track("hud-showBatteryTime")) { a.onHudSetting("showBatteryTime", flag(it)) }
}
}
if (size == DroidDeckHudSize.MINIMAL && "Battery time" in chips &&
"Battery time" !in HIDDEN[size].orEmpty()) {
ToggleRow(host, "hud-showBatteryTime", stringResource(R.string.hud_metric_battery_time), null, on("showBatteryTime"),
chipModifier = track("hud-showBatteryTime")) { a.onHudSetting("showBatteryTime", flag(it)) }
ActionRow(stringResource(R.string.hud_group_metrics), null, stringResource(R.string.common_edit),
onClick = { editing = true }, modifier = track("hud-readings"))
val rows = DroidDeckHudSize.rowsFor(DroidDeckHudSize.from(cfg["hudSize"]), cfg)
SettingsRow(stringResource(R.string.hud_readings_shown), null) {
Text(stringResource(R.string.hud_readings_count, rows.count { on(it) }, rows.size),
fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
if (editing) HudReadingsDialog(
visible = rows,
initialOrder = rows,
initialOn = rows.associateWith { on(it) },
onDismiss = { editing = false },
onSave = { switches, order -> a.onHudOrder(switches, order) },
onReset = a.onHudOrderReset,
)
}
val tempsShown = ("Temp" in chips && on("showTemp")) || ("GPU temp" in chips && on("showGpuTemp"))
if (tempsShown) SettingsGroup(stringResource(R.string.hud_group_temps)) {
if (on("showTemp") || on("showGpuTemp") || on("showBatteryTemp")) SettingsGroup(stringResource(R.string.hud_group_temps)) {
ChoiceRow(host, "hud-temp-unit", stringResource(R.string.hud_temp_unit), null,
listOf("c" to "°C", "f" to "°F"), if (cfg["tempUnit"].equals("f", true)) "f" else "c",
chipModifier = track("hud-temp-unit")) { a.onHudSetting("tempUnit", it) }
@@ -155,37 +163,39 @@ private val BOTTOM_STRIP_ROWS = listOf(
StripMetric.CLOCK to R.string.hud_metric_clock,
)
private val EXTRA = mapOf(DroidDeckHudSize.PILL to setOf("Temp", "Power"))
private class HudMetric(val chip: String, val key: String, val label: Int)
private class HudMetric(val key: String, val label: Int)
// Wrapper and DX version have nothing to show in DroidDeck.
private val METRICS = listOf(
HudMetric("FPS", "showFPS", R.string.drawer_hud_fps),
HudMetric("FPS graph", "showFPSGraph", R.string.hud_metric_graph),
HudMetric("FPS .1", "fpsDecimal", R.string.hud_metric_decimal),
HudMetric("1% low", "showLow1", R.string.hud_metric_low1),
HudMetric("0.1% low", "showLow01", R.string.hud_metric_low01),
HudMetric("0.01% low", "showLow001", R.string.hud_metric_low001),
HudMetric("Engine", "showEngine", R.string.hud_metric_engine),
HudMetric("GPU model", "showGpuModel", R.string.hud_metric_gpu_model),
HudMetric("GPU", "showGPULoad", R.string.hud_metric_gpu),
HudMetric("GPU temp", "showGpuTemp", R.string.hud_metric_gpu_temp),
HudMetric("CPU", "showCPUUsage", R.string.hud_metric_cpu),
HudMetric("Per-core", "showPerCore", R.string.hud_metric_per_core),
HudMetric("Temp", "showTemp", R.string.hud_metric_temp),
HudMetric("RAM", "showRAM", R.string.hud_metric_ram),
HudMetric("VRAM", "showVram", R.string.hud_metric_vram),
HudMetric("Swap", "showSwap", R.string.hud_metric_swap),
HudMetric("Battery", "showBattery", R.string.hud_metric_battery),
HudMetric("Power", "showPower", R.string.hud_metric_power),
HudMetric("Network", "showNet", R.string.hud_metric_network),
HudMetric("Resolution", "showResolution", R.string.hud_metric_resolution),
HudMetric("Proton", "showProton", R.string.hud_metric_proton),
HudMetric("Session", "showSession", R.string.hud_metric_session),
HudMetric("Clock", "showClock", R.string.hud_metric_clock),
HudMetric("showGpuModel", R.string.hud_metric_gpu_model),
HudMetric("showGPULoad", R.string.hud_metric_gpu),
HudMetric("showCPUUsage", R.string.hud_metric_cpu),
HudMetric("showPerCore", R.string.hud_metric_per_core),
HudMetric("showTemp", R.string.hud_metric_temp),
HudMetric("showBatteryTemp", R.string.drawer_hud_battery),
HudMetric("showGpuTemp", R.string.hud_metric_gpu_temp),
HudMetric("showVram", R.string.hud_metric_vram),
HudMetric("showRAM", R.string.hud_metric_ram),
HudMetric("showSwap", R.string.hud_metric_swap),
HudMetric("showBattery", R.string.hud_metric_battery),
HudMetric("showBatteryTime", R.string.hud_metric_battery_time),
HudMetric("showPower", R.string.hud_metric_power),
HudMetric("showFPS", R.string.drawer_hud_fps),
HudMetric("showFPSGraph", R.string.hud_metric_graph),
HudMetric("showLatency", R.string.hud_metric_latency),
HudMetric("showAvg", R.string.hud_metric_avg),
HudMetric("showLow1", R.string.hud_metric_low1),
HudMetric("showLow01", R.string.hud_metric_low01),
HudMetric("showLow001", R.string.hud_metric_low001),
HudMetric("showEngine", R.string.hud_metric_engine),
HudMetric("showDisplay", R.string.hud_metric_display),
HudMetric("showHdr", R.string.hud_metric_hdr),
HudMetric("showNet", R.string.hud_metric_network),
HudMetric("showResolution", R.string.hud_metric_resolution),
HudMetric("showProton", R.string.hud_metric_proton),
HudMetric("showSession", R.string.hud_metric_session),
HudMetric("showClock", R.string.hud_metric_clock),
)
private val HIDDEN = mapOf(
DroidDeckHudSize.PILL to setOf("FPS graph"),
DroidDeckHudSize.TILES to setOf("FPS graph", "0.1% low", "0.01% low"),
)
internal fun hudMetricLabel(key: String): Int? =
METRICS.firstOrNull { it.key == key }?.label
@@ -0,0 +1,389 @@
package com.droiddeck.launcher.ui
import android.view.KeyEvent
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.border
import androidx.compose.foundation.focusable
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DragHandle
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.runtime.withFrameNanos
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.InputMode
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.pointer.PointerEventPass
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.material3.LocalTextStyle
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalInputModeManager
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.PlatformTextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex
import com.droiddeck.launcher.R
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.math.roundToInt
private val ROW_HEIGHT = 44.dp
private val HANDLE_WIDTH = 40.dp
private const val RESET_HOLD_MS = 5_000
private const val TAP_HOLD_MS = 400
private val HINT_LABEL_WIDTH = 92.dp
private val HINT_KEY_SIZE = 18.dp
private val HINT_GAP = 8.dp
private val HINT_LABEL_MIN = 24.dp
private val HINT_ROOM = HINT_LABEL_MIN + HINT_KEY_SIZE + HINT_GAP
@Composable
internal fun ResetHold(held: Boolean, onFire: () -> Unit): Float {
val fill by animateFloatAsState(
if (held) 1f else 0f,
if (held) tween(RESET_HOLD_MS, easing = LinearEasing) else tween(120),
label = "resetHold",
)
LaunchedEffect(held) {
if (!held) return@LaunchedEffect
delay(RESET_HOLD_MS.toLong())
onFire()
}
return fill
}
@Composable
private fun HudKeyHints(grabbed: String?, resetFill: Float) {
Column(
horizontalAlignment = Alignment.End,
verticalArrangement = Arrangement.spacedBy(6.dp),
) {
KeyHint("X", stringResource(R.string.hud_hint_reset), resetFill)
KeyHint("Y", stringResource(if (grabbed != null) R.string.hud_hint_drop else R.string.hud_hint_grab))
KeyHint("B", stringResource(R.string.hud_hint_save))
}
}
@Composable
private fun KeyHint(key: String, label: String, fill: Float = 0f) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(HINT_GAP),
) {
Text(
label,
fontSize = 11.sp,
lineHeight = 14.sp,
textAlign = TextAlign.End,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 2,
modifier = Modifier.widthIn(max = HINT_LABEL_WIDTH),
)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.size(HINT_KEY_SIZE).clip(RoundedCornerShape(5.dp))
.background(
if (fill > 0f) MaterialTheme.colorScheme.primary.copy(alpha = 0.15f + 0.55f * fill)
else MaterialTheme.colorScheme.surfaceVariant,
)
.border(1.dp, MaterialTheme.colorScheme.outline, RoundedCornerShape(5.dp)),
) {
Text(
key,
fontSize = 10.sp,
lineHeight = 10.sp,
textAlign = TextAlign.Center,
fontWeight = FontWeight.SemiBold,
color = MaterialTheme.colorScheme.onSurface,
style = LocalTextStyle.current.copy(
platformStyle = PlatformTextStyle(includeFontPadding = false),
),
)
}
}
}
@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun HudReadingsDialog(
visible: List<String>,
initialOrder: List<String>,
initialOn: Map<String, Boolean>,
onDismiss: () -> Unit,
onSave: (Map<String, Boolean>, List<String>) -> Unit,
onReset: () -> Unit,
controller: Boolean = LocalInputModeManager.current.inputMode == InputMode.Keyboard,
) {
val order = remember { mutableStateListOf<String>().apply { addAll(initialOrder.filter { it in visible }) } }
val enabled = remember { mutableStateMapOf<String, Boolean>() }
remember(initialOn) { for (key in initialOrder) enabled[key] = initialOn[key] == true; true }
val merged = {
val moved = order.toList()
var i = 0
initialOrder.map { if (it in visible) moved[i++] else it }
}
val shown = rememberShown { onDismiss() }
val close = { shown.targetState = false }
val save = { onSave(enabled.toMap(), merged()); close() }
val restore = { onReset(); close() }
val rowPx = with(LocalDensity.current) { ROW_HEIGHT.toPx() }
var pad by remember { mutableStateOf(controller) }
var yHeld by remember { mutableStateOf(false) }
var yLong by remember { mutableStateOf(false) }
var yStartedGrab by remember { mutableStateOf(false) }
LaunchedEffect(yHeld) {
if (!yHeld) return@LaunchedEffect
delay(TAP_HOLD_MS.toLong())
yLong = true
}
var resetHeld by remember { mutableStateOf(false) }
val resetFill = ResetHold(resetHeld, restore)
var dragging by remember { mutableStateOf(-1) }
var dragOffset by remember { mutableFloatStateOf(0f) }
val panelFocus = remember { FocusRequester() }
val firstKey = remember { order.firstOrNull() }
val firstFocus = remember { FocusRequester() }
LaunchedEffect(Unit) {
runCatching { panelFocus.requestFocus() }
repeat(30) {
if (runCatching { firstFocus.requestFocus() }.isSuccess) return@LaunchedEffect
withFrameNanos { }
}
}
var focusedKey by remember { mutableStateOf<String?>(null) }
var grabbed by remember { mutableStateOf<String?>(null) }
val before = remember { mutableStateListOf<String>() }
val grab = {
val target = focusedKey ?: order.firstOrNull()
if (target != null && grabbed == null && dragging < 0) {
before.clear()
before.addAll(order)
grabbed = target
}
}
val cancel = {
val held = grabbed
if (held != null) {
order.clear()
order.addAll(before)
grabbed = null
}
}
AppDialog(
shown, close, "hudReadings", wide = false, scrollable = false,
modifier = Modifier.fillMaxHeight(),
back = { if (grabbed != null) cancel() else if (pad) save() else close() },
side = if (pad) {
{ HudKeyHints(grabbed, resetFill) }
} else {
null
},
sideRoom = HINT_ROOM,
) {
val state = rememberLazyListState()
val scope = rememberCoroutineScope()
val handlePx = with(LocalDensity.current) { HANDLE_WIDTH.toPx() }
Column(
Modifier.fillMaxWidth().weight(1f).focusRequester(panelFocus).focusable()
.onPreviewKeyEvent { event ->
val key = event.nativeKeyEvent
val down = key.action == KeyEvent.ACTION_DOWN
if (down) pad = true
val first = down && key.repeatCount == 0
val held = grabbed
when {
key.keyCode == KeyEvent.KEYCODE_BUTTON_Y -> {
when {
down && first -> {
yHeld = true
yLong = key.flags and KeyEvent.FLAG_LONG_PRESS != 0
yStartedGrab = grabbed == null
if (yStartedGrab) grab()
}
down -> if (key.repeatCount > 0) yLong = true
else -> {
val drop = grabbed != null && (!yStartedGrab || yLong)
yHeld = false
if (drop) grabbed = null
}
}
true
}
key.keyCode == KeyEvent.KEYCODE_BUTTON_X && pad -> {
resetHeld = down
true
}
key.keyCode == KeyEvent.KEYCODE_BUTTON_A ||
key.keyCode == KeyEvent.KEYCODE_ENTER ||
key.keyCode == KeyEvent.KEYCODE_SPACE -> {
val target = focusedKey
when {
held != null -> {
if (first) grabbed = null
true
}
target == null -> false
else -> {
if (first) enabled[target] = !(enabled[target] == true)
true
}
}
}
held == null -> false
key.keyCode == KeyEvent.KEYCODE_DPAD_UP || key.keyCode == KeyEvent.KEYCODE_DPAD_DOWN -> {
if (down) {
val from = order.indexOf(held)
val step = if (key.keyCode == KeyEvent.KEYCODE_DPAD_UP) -1 else 1
val to = (from + step).coerceIn(0, order.lastIndex)
if (to != from) {
order.add(to, order.removeAt(from))
val visible = state.layoutInfo.visibleItemsInfo
if (visible.isNotEmpty()) {
val first = visible.first().index
val last = visible.last().index
val target = when {
to <= first -> to
to > last -> (to - visible.size + 1).coerceAtLeast(0)
else -> null
}
if (target != null) scope.launch { state.animateScrollToItem(target) }
}
}
}
true
}
else -> false
}
},
) {
val list = @Composable { m: Modifier ->
LazyColumn(state = state, modifier = m.pointerInput(Unit) {
awaitEachGesture {
val down = awaitFirstDown(requireUnconsumed = false)
val item = state.layoutInfo.visibleItemsInfo.firstOrNull {
it.offset <= down.position.y && down.position.y < it.offset + it.size
}
if (item == null || down.position.x > handlePx || grabbed != null) return@awaitEachGesture
val start = item.index
dragging = start
dragOffset = 0f
while (true) {
val change = awaitPointerEvent(PointerEventPass.Initial).changes.firstOrNull { it.id == down.id } ?: break
val travel = change.position.y - down.position.y
change.consume()
if (!change.pressed) break
val target = (start + (travel / rowPx).roundToInt()).coerceIn(0, order.lastIndex)
while (target != dragging) {
val step = if (target > dragging) 1 else -1
order.add(dragging + step, order.removeAt(dragging))
dragging += step
}
dragOffset = travel - (dragging - start) * rowPx
}
dragging = -1
dragOffset = 0f
}
}) {
itemsIndexed(order, key = { _, key -> key }) { index, key ->
val held = index == dragging || key == grabbed
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().height(ROW_HEIGHT).testTag("hud-row-$key")
.then(if (key == firstKey) Modifier.focusRequester(firstFocus) else Modifier)
.onFocusChanged { if (it.isFocused) focusedKey = key else if (focusedKey == key) focusedKey = null }
.zIndex(if (held) 1f else 0f)
.graphicsLayer { translationY = if (index == dragging) dragOffset else 0f }
.clip(Shape12)
.background(
if (held) MaterialTheme.colorScheme.surfaceVariant
else MaterialTheme.colorScheme.surface,
)
.then(
if (key == focusedKey) Modifier.border(2.dp, LocalPalette.current.signal, Shape12)
else Modifier,
)
.focusable()
.padding(start = 4.dp, end = 6.dp),
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.size(width = HANDLE_WIDTH, height = ROW_HEIGHT).testTag("hud-handle-$key"),
) {
Icon(
Icons.Filled.DragHandle, null,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.size(20.dp),
)
}
val label = hudMetricLabel(key)
Text(
if (label != null) stringResource(label) else key,
fontSize = 14.sp, color = MaterialTheme.colorScheme.onBackground, maxLines = 1,
modifier = Modifier.weight(1f).padding(start = 2.dp),
)
ToggleSwitch(
enabled[key] == true, true, null,
modifier = Modifier.testTag("hud-switch-$key").focusProperties { canFocus = false },
) { enabled[key] = !(enabled[key] == true) }
}
}
}
}
list(Modifier.weight(1f).fillMaxWidth())
if (!pad) {
Row(Modifier.fillMaxWidth().padding(top = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
Box(Modifier.weight(1f))
PrimaryButton(stringResource(R.string.common_ok), compact = true, onClick = save)
SecondaryButton(stringResource(R.string.hud_reset_button), compact = true, onClick = restore)
}
}
}
}
}
@@ -262,6 +262,8 @@ class DrawerActions(
val selectedSecondScreenDisplay: Int,
val onHud: (Boolean) -> Unit,
val onHudSetting: (String, String) -> Unit = { _, _ -> },
val onHudOrder: (Map<String, Boolean>, List<String>) -> Unit = { _, _ -> },
val onHudOrderReset: () -> Unit = {},
val onHudReset: () -> Unit = {},
val onHudExport: () -> Unit = {},
val onFrameGenPick: (FrameGen.Mode) -> Unit,