From 7680b4d771133da87c5bf9685f4ec0289740fb31 Mon Sep 17 00:00:00 2001 From: DeathKhan Date: Wed, 18 Nov 2026 13:05:30 -0600 Subject: [PATCH] fix(ui): fit the color picker on landscape screens (#2542) * fix(ui): lay the color picker out side by side on wide screens On a landscape screen the single column was taller than the screen. The wheel and swatches now sit beside the sliders and the hex field, so the whole picker is visible without scrolling. * fix(ui): give the landscape color picker a larger wheel and one closing row On a wide screen the picker still reached both screen edges: three sliders, the hex field and the buttons were stacked beside a small wheel. The wheel now fills the height of the sliders, and the comparison chip, the hex field, Cancel and OK share one row under them, so the dialog keeps a margin. OK is centered in both layouts. * fix(ui): keep the column color picker in landscape windows narrower than 600 dp The side by side layout needs 382 dp for its closing row before the hex field gets any width, so a small landscape window could squeeze the field to nothing. * fix(ui): fit the side by side color picker on short landscape screens On a 740 x 360 dp phone the closing row sat below the screen and had to be scrolled to. The wheel now takes its size from the screen height (up to the old 216 dp), and on a short screen the sliders get a shorter track and tighter spacing, so the whole dialog fits down to about 360 dp. Screens 468 dp tall and up, such as the Odin 3, look as before. ColorPickerLayoutTest now also checks that OK is on screen without scrolling at 740 x 360, 800 x 384 and in portrait. * chore: drop the added comments --------- Co-authored-by: maxjivi05 --- .../launcher/ui/ColorPickerDialog.kt | 98 ++++++++++++++----- .../droiddeck/launcher/ui/SettingsWidgets.kt | 7 +- .../launcher/ui/ColorPickerLayoutTest.kt | 54 ++++++++++ 3 files changed, 129 insertions(+), 30 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/ui/ColorPickerLayoutTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ColorPickerDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/ColorPickerDialog.kt index d8b3c61a27..e9ff41cbe9 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ColorPickerDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ColorPickerDialog.kt @@ -10,13 +10,17 @@ import androidx.compose.foundation.hoverable import androidx.compose.foundation.interaction.MutableInteractionSource 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.fillMaxWidth import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -31,12 +35,14 @@ import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.Role import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.droiddeck.launcher.R import kotlin.math.atan2 @@ -77,33 +83,63 @@ internal fun ColorPickerDialog(title: String, initial: Int, onDismiss: () -> Uni hue = h.coerceIn(0f, 360f); sat = s.coerceIn(0f, 1f); value = v.coerceIn(0f, 1f) hexText = ThemeColors.hex(ThemeColors.fromHsv(hue, sat, value)) } - AppDialog(shown, close, "colorPicker", wide = false, maxWidth = 460.dp, scrollState = scroll) { + val screen = LocalConfiguration.current + val beside = screen.screenWidthDp > screen.screenHeightDp && screen.screenWidthDp >= 600 + val wheelSize = if (beside) (screen.screenHeightDp - 176).coerceIn(160, 216).dp else 168.dp + val short = beside && wheelSize < 216.dp + AppDialog(shown, close, "colorPicker", wide = false, maxWidth = if (beside) 680.dp else 460.dp, scrollState = scroll) { DialogTitleRow(title, close) - Row(horizontalArrangement = Arrangement.spacedBy(14.dp), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) { - ColorWheel(hue, sat, value) { h, s -> picked(h = h, s = s) } - Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { - Swatch(Color(initial)) - Swatch(Color(current)) - } + val wheel: @Composable () -> Unit = { ColorWheel(hue, sat, value, wheelSize) { h, s -> picked(h = h, s = s) } } + val track = if (short) 24.dp else 40.dp + val sliders: @Composable () -> Unit = { + ValueSlider(hue.toInt(), 0..360, step = 5, enabled = true, label = stringResource(R.string.theme_color_hue), format = { "$it°" }, + modifier = Modifier.focusRequester(first), track = track) { picked(h = it.toFloat()) } + ValueSlider((sat * 100).toInt(), 0..100, step = 2, enabled = true, label = stringResource(R.string.theme_color_saturation), format = { "$it%" }, + track = track) { picked(s = it / 100f) } + ValueSlider((value * 100).toInt(), 0..100, step = 2, enabled = true, label = stringResource(R.string.theme_color_brightness), format = { "$it%" }, + track = track) { picked(v = it / 100f) } } - ValueSlider(hue.toInt(), 0..360, step = 5, enabled = true, label = stringResource(R.string.theme_color_hue), format = { "$it°" }, - modifier = Modifier.focusRequester(first)) { picked(h = it.toFloat()) } - ValueSlider((sat * 100).toInt(), 0..100, step = 2, enabled = true, label = stringResource(R.string.theme_color_saturation), format = { "$it%" }) { picked(s = it / 100f) } - ValueSlider((value * 100).toInt(), 0..100, step = 2, enabled = true, label = stringResource(R.string.theme_color_brightness), format = { "$it%" }) { picked(v = it / 100f) } - AdbTextField( - value = hexText, - onValueChange = { text -> - hexText = text - ThemeColors.parseHex(text)?.let { argb -> ThemeColors.toHsv(argb).let { hsv -> hue = hsv.h; sat = hsv.s; value = hsv.v } } - }, - label = "", keyboardType = KeyboardType.Ascii, imeAction = ImeAction.Done, placeholder = stringResource(R.string.theme_color_hex), - onFocusChange = { typingHex = it }, - onDone = { ThemeColors.parseHex(hexText)?.let { onApply(it); close() } }, - ) - Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) { - SecondaryButton(stringResource(R.string.common_cancel), modifier = Modifier.weight(1f), onClick = close) - PrimaryButton(stringResource(R.string.common_ok), enabled = ThemeColors.parseHex(hexText) != null, modifier = Modifier.weight(1f)) { - ThemeColors.parseHex(hexText)?.let { onApply(it); close() } + val hex: @Composable (Modifier) -> Unit = { modifier -> + AdbTextField( + value = hexText, + onValueChange = { text -> + hexText = text + ThemeColors.parseHex(text)?.let { argb -> ThemeColors.toHsv(argb).let { hsv -> hue = hsv.h; sat = hsv.s; value = hsv.v } } + }, + label = "", keyboardType = KeyboardType.Ascii, imeAction = ImeAction.Done, placeholder = stringResource(R.string.theme_color_hex), + showLabel = false, compact = beside, modifier = modifier, + onFocusChange = { typingHex = it }, + onDone = { ThemeColors.parseHex(hexText)?.let { onApply(it); close() } }, + ) + } + val ok = { ThemeColors.parseHex(hexText)?.let { onApply(it); close() }; Unit } + val valid = ThemeColors.parseHex(hexText) != null + if (beside) { + Row(horizontalArrangement = Arrangement.spacedBy(20.dp), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) { + wheel() + Column(verticalArrangement = Arrangement.spacedBy(if (short) 2.dp else 8.dp), modifier = Modifier.weight(1f)) { + CompositionLocalProvider(LocalCompactSettings provides true) { sliders() } + } + } + Row(horizontalArrangement = Arrangement.spacedBy(10.dp), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) { + BeforeAfter(Color(initial), Color(current), Modifier.size(96.dp, 44.dp)) + hex(Modifier.weight(1f)) + SecondaryButton(stringResource(R.string.common_cancel), modifier = Modifier.width(128.dp), onClick = close) + PrimaryButton(stringResource(R.string.common_ok), enabled = valid, modifier = Modifier.width(128.dp), fill = true, onClick = ok) + } + } else { + Row(horizontalArrangement = Arrangement.spacedBy(14.dp), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) { + wheel() + Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { + Swatch(Color(initial)) + Swatch(Color(current)) + } + } + sliders() + hex(Modifier) + Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) { + SecondaryButton(stringResource(R.string.common_cancel), modifier = Modifier.weight(1f), onClick = close) + PrimaryButton(stringResource(R.string.common_ok), enabled = valid, modifier = Modifier.weight(1f), fill = true, onClick = ok) } } } @@ -116,9 +152,17 @@ private fun Swatch(color: Color) { } @Composable -private fun ColorWheel(hue: Float, sat: Float, value: Float, onPick: (hue: Float, sat: Float) -> Unit) { +private fun BeforeAfter(before: Color, after: Color, modifier: Modifier) { + val shape = RoundedCornerShape(10.dp) + Row(modifier.clip(shape).border(1.dp, LocalPalette.current.line2, shape)) { + Box(Modifier.weight(1f).fillMaxHeight().background(before)) + Box(Modifier.weight(1f).fillMaxHeight().background(after)) + } +} + +@Composable +private fun ColorWheel(hue: Float, sat: Float, value: Float, size: Dp, onPick: (hue: Float, sat: Float) -> Unit) { val rim = MaterialTheme.colorScheme.onBackground - val size = 168.dp fun at(offset: Offset, side: Float) { val center = side / 2f val dx = offset.x - center diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt b/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt index b5595a52b7..5ebcc3c051 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SettingsWidgets.kt @@ -108,6 +108,7 @@ import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalInputModeManager import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.IntRect import androidx.compose.ui.unit.IntSize @@ -605,7 +606,7 @@ fun SliderRow( @Composable fun ValueSlider( value: Int, range: IntRange, step: Int, enabled: Boolean, label: String?, format: (Int) -> String, - modifier: Modifier = Modifier, onChange: (Int) -> Unit, + modifier: Modifier = Modifier, track: Dp = 40.dp, onChange: (Int) -> Unit, ) { val compact = LocalCompactSettings.current val colors = MaterialTheme.colorScheme @@ -628,7 +629,7 @@ fun ValueSlider( } } Column( - modifier = modifier.fillMaxWidth().heightIn(min = if (compact) 64.dp else 72.dp) + modifier = modifier.fillMaxWidth().heightIn(min = track + if (compact) 24.dp else 32.dp) .clip(shape).background(if (hot) pal.signal.copy(alpha = 0.12f) else Color.Transparent) .glideBorder(hot, shape, pal.signal) .alpha(if (enabled) 1f else 0.5f) @@ -663,7 +664,7 @@ fun ValueSlider( Text(text, fontSize = if (compact) 12.sp else 14.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1) } Canvas( - Modifier.fillMaxWidth().height(40.dp).onSizeChanged { trackPx = it.width } + Modifier.fillMaxWidth().height(track).onSizeChanged { trackPx = it.width } .pointerInput(enabled, range, step, thumbInset) { if (enabled) detectTapGestures { fromX(it.x) } } .pointerInput(enabled, range, step, thumbInset) { if (enabled) detectHorizontalDragGestures { change, _ -> fromX(change.position.x); change.consume() } diff --git a/app/src/test/java/com/droiddeck/launcher/ui/ColorPickerLayoutTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/ColorPickerLayoutTest.kt new file mode 100644 index 0000000000..41c43ad81c --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/ui/ColorPickerLayoutTest.kt @@ -0,0 +1,54 @@ +package com.droiddeck.launcher.ui + +import androidx.compose.ui.test.getUnclippedBoundsInRoot +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.unit.dp +import com.droiddeck.launcher.R +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import org.robolectric.annotation.GraphicsMode + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [34], qualifiers = "w832dp-h468dp-land-369dpi") +@GraphicsMode(GraphicsMode.Mode.NATIVE) +class ColorPickerLayoutTest { + @get:Rule val compose = createRobolectricComposeRule() + + private fun show() { + compose.setContent { + DroidDeckTheme(theme = Themes.GRAPHITE) { ColorPickerDialog("Highlight color", 0xFFE53935.toInt(), onDismiss = {}) {} } + } + compose.mainClock.advanceTimeBy(1_000) + } + + private fun ok() = compose.onNodeWithText(RuntimeEnvironment.getApplication().getString(R.string.common_ok)).getUnclippedBoundsInRoot() + + private fun assertOkOnScreen() { + val height = RuntimeEnvironment.getApplication().resources.configuration.screenHeightDp.dp + val ok = ok() + assertTrue("OK ends at ${ok.bottom} on a $height screen", ok.bottom <= height - 28.dp) + assertTrue("OK starts at ${ok.top}", ok.top >= 0.dp) + } + + @Test fun onALandscapeHandheldThePickerEndsWellAboveTheScreenEdge() { + show() + val ok = ok() + val title = compose.onNodeWithText("Highlight color").getUnclippedBoundsInRoot() + assertTrue("OK ends at ${ok.bottom}, title ${title.top}", ok.bottom <= 468.dp - 40.dp) + assertTrue("title starts at ${title.top}", title.top >= 40.dp) + } + + @Test @Config(qualifiers = "w740dp-h360dp-land-420dpi") + fun onAShortLandscapePhoneOkIsOnScreen() { show(); assertOkOnScreen() } + + @Test @Config(qualifiers = "w800dp-h384dp-land") + fun onAShortWideScreenOkIsOnScreen() { show(); assertOkOnScreen() } + + @Test @Config(qualifiers = "w411dp-h891dp-port-420dpi") + fun inPortraitOkIsOnScreen() { show(); assertOkOnScreen() } +}