Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.
Rust androiddocument-scannerdocximage-editorjetpack-composekotlinliquid-glassofflineopen-sourcepdfpdf-compressorpdf-editorpdf-mergerpdf-readerpdf-splitterpdf-toolspdf-viewerpptxspreadsheet-editorxlsx
feat(ui): redesign photo editor with liquid glass, remove dial circle marks, fix navbar overlay, and add beat delay to cancel/done
chethan6163d10480c73e6
diff --git a/.gitignore b/.gitignoreindex 85506fc..63ba5cb 100644--- a/.gitignore+++ b/.gitignore@@ -15,3 +15,4 @@# reference screenshots shared while working, never committed/t[0-9].png+/artefact_demo/diff --git a/README.md b/README.mdindex a04f8c3..7e81489 100644--- a/README.md+++ b/README.md@@ -51,7 +51,7 @@ ClearPDF / Artefact was featured by HowToMen — [watch from 9:08 →](https://w<img src="docs/media/artefact-demo.gif" width="70%" alt="Artefact walkthrough demo"></a><br>- <sub>▶ Click animation to open full MP4 video (or view <a href="docs/media/artefact-demo.mp4">artefact-demo.mp4</a>)</sub>+ <sub>No need to open the app — tap a PDF, Word doc or spreadsheet in WhatsApp, Gmail or any app and it surfaces as a floating glass card, right over your chat. Like Apple's Quick Look on Android. Swipe up to open it fully in Artefact.</sub></p><table align="center">diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/ClearApp.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/ClearApp.ktindex 9460927..4f55a44 100644--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/ClearApp.kt+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/ClearApp.kt@@ -159,6 +159,7 @@ private fun Shell(vm: AppViewModel, onBrowse: () -> Unit, onPickSignatureImage:}BackHandler(enabled = doc != null && vm.toolScreen == null) { vm.closeDocument() }BackHandler(enabled = doc == null && vm.onboarded && !vm.settingsOpen && vm.openNote == null && vm.homeTab != HomeTab.Home && vm.toolScreen == null) { vm.homeTab = HomeTab.Home }+ BackHandler(enabled = vm.editingPhoto != null) { vm.editingPhoto = null }val route = when {!vm.onboarded -> "welcome"@@ -166,7 +167,7 @@ private fun Shell(vm: AppViewModel, onBrowse: () -> Unit, onPickSignatureImage:vm.openNote != null -> "note:" + vm.openNoteelse -> vm.homeTab.name}- val onDesk = doc == null && route == HomeTab.Home.name && vm.toolScreen == null && vm.signaturePad == null && vm.certSign == null && !vm.idCreate+ val onDesk = doc == null && route == HomeTab.Home.name && vm.toolScreen == null && vm.signaturePad == null && vm.certSign == null && !vm.idCreate && vm.editingPhoto == null && vm.presenting == nullval desk = remember { DeskState(scope) }var dockIntoNote by remember { mutableStateOf(false) }var dockFromNote by remember { mutableStateOf(false) }@@ -237,7 +238,7 @@ private fun Shell(vm: AppViewModel, onBrowse: () -> Unit, onPickSignatureImage:if (vm.noteBarHidden != (intoNote || fromNote)) vm.noteBarHidden = intoNote || fromNotelastRoute[0] = route}- if (onDesk || dockIntoNote) {+ if ((onDesk || dockIntoNote) && vm.editingPhoto == null && vm.presenting == null) {CreateDock(vm, desk, onBrowse, intoNote = !onDesk, fromNote = onDesk && dockFromNote) {dockIntoNote = falsedockFromNote = falsediff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/PhotoEditor.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/PhotoEditor.ktindex f408862..6e21f31 100644--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/PhotoEditor.kt+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/PhotoEditor.kt@@ -1,5 +1,11 @@package com.chethan616.clearpdf.ui.notes+import androidx.activity.compose.BackHandler+import androidx.compose.animation.AnimatedVisibility+import androidx.compose.animation.fadeIn+import androidx.compose.animation.fadeOut+import androidx.compose.animation.slideInVertically+import androidx.compose.animation.slideOutVerticallyimport androidx.compose.foundation.Canvasimport androidx.compose.foundation.Imageimport androidx.compose.foundation.background@@ -9,6 +15,7 @@ import androidx.compose.foundation.horizontalScrollimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.PaddingValuesimport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.Spacerimport androidx.compose.foundation.layout.WindowInsets@@ -39,17 +46,17 @@ import androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clipimport androidx.compose.ui.geometry.Offset-import androidx.compose.ui.geometry.Sizeimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.graphics.ImageBitmapimport androidx.compose.ui.graphics.StrokeCapimport androidx.compose.ui.graphics.asImageBitmap-import androidx.compose.ui.graphics.drawscope.Strokeimport androidx.compose.ui.graphics.vector.ImageVectorimport androidx.compose.ui.input.pointer.pointerInputimport androidx.compose.ui.layout.ContentScaleimport androidx.compose.ui.res.stringResourceimport androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.text.style.TextOverflowimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.spimport com.chethan616.clearpdf.R@@ -57,14 +64,18 @@ import com.chethan616.clearpdf.core.PhotoEditorimport com.chethan616.clearpdf.engine.toBitmapimport com.chethan616.clearpdf.ui.AppViewModelimport com.chethan616.clearpdf.ui.LucideIcons+import com.chethan616.clearpdf.ui.glass.ChromeCapsuleimport com.chethan616.clearpdf.ui.glass.Feel+import com.chethan616.clearpdf.ui.glass.Fluidimport com.chethan616.clearpdf.ui.glass.GlassCircleimport com.chethan616.clearpdf.ui.glass.GlassIconimport com.chethan616.clearpdf.ui.glass.GlassPillimport com.chethan616.clearpdf.ui.glass.LocalBackdropimport com.chethan616.clearpdf.ui.glass.LocalHapticsimport com.chethan616.clearpdf.ui.glass.RoundedRectangle-import com.chethan616.clearpdf.ui.glass.pressable+import com.chethan616.clearpdf.ui.glass.glass+import com.chethan616.clearpdf.ui.glass.glassBar+import com.chethan616.clearpdf.ui.glass.rememberBeatimport com.chethan616.clearpdf.ui.theme.Candyimport com.chethan616.clearpdf.ui.theme.ClearTypeimport com.kyant.backdrop.backdrops.layerBackdrop@@ -78,7 +89,15 @@ import java.io.Fileimport kotlin.math.abs/** One adjustment of LightCraft's develop settings: where it lives, its name, glyph and range. */-private enum class Adjust(val section: String, val field: String, val label: Int, val icon: ImageVector, val min: Float, val max: Float, val decimals: Int) {+private enum class Adjust(+ val section: String,+ val field: String,+ val label: Int,+ val icon: ImageVector,+ val min: Float,+ val max: Float,+ val decimals: Int,+) {Exposure("light", "exposure", R.string.photo_exposure, LucideIcons.Sun, -3f, 3f, 2),Contrast("light", "contrast", R.string.photo_contrast, LucideIcons.Contrast, -100f, 100f, 0),Highlights("light", "highlights", R.string.photo_highlights, LucideIcons.Highlights, -100f, 100f, 0),@@ -99,10 +118,13 @@ private fun shown(a: Adjust, v: Float): String {}/**- * A picture developed with LightCraft, the way Photos edits one: the picture large (hold it to see- * the original), the chosen adjustment's name and value, a ruler to drag it along (it catches at- * zero), and the adjustments as a row of glass dials, each ringed by how far it has moved. Rotate- * and Reset at the top; Done saves the developed picture in place of the note's.+ * A photo editor built completely on Artefact's liquid-glass design system:+ * - Edge-to-edge photo canvas with touch-and-hold to view original+ * - Floating liquid-glass header with beat-delayed Cancel (X) and Save (Tick)+ * - Pure liquid glass controls with NO canvas circle marks+ * - Zero-snap precision ruler with haptic feedback+ * - Deep integration with GlassSettings & MotionSettings+ * - Proper BackHandler ensuring swipe-back never closes the app*/@Composablefun PhotoEditScreen(vm: AppViewModel, noteId: String, name: String, onClose: () -> Unit) {@@ -121,98 +143,288 @@ fun PhotoEditScreen(vm: AppViewModel, noteId: String, name: String, onClose: ()fun settings(withValues: Boolean = true): String {val o = JSONObject()- if (withValues) for ((a, v) in values) if (v != 0f) (o.optJSONObject(a.section) ?: JSONObject().also { o.put(a.section, it) }).put(a.field, v.toDouble())+ if (withValues) for ((a, v) in values) if (v != 0f) {+ (o.optJSONObject(a.section) ?: JSONObject().also { o.put(a.section, it) }).put(a.field, v.toDouble())+ }if (turn != 0) o.put("orientation", TURNS[turn])return o.toString()}- // re-develop as the ruler moves; a newer value cancels the render still running+ // Beat delay for Cancel (X): plays the liquid glass spring press before dismissing+ val beatClose = rememberBeat(onClose)++ // Beat delay for Done (Tick): plays the spring press, exports the image, and closes cleanly+ val beatDone = rememberBeat({+ if (saving) return@rememberBeat+ if (!edited) {+ onClose()+ return@rememberBeat+ }+ saving = true+ scope.launch {+ val out = File(source.parentFile, "edited-${System.currentTimeMillis()}.jpg")+ val ok = withContext(Dispatchers.Default) {+ runCatching {+ editor.exportJpeg(source.absolutePath, settings(), out.absolutePath, 92u)+ }.isSuccess+ }+ if (ok) {+ vm.notes.get(noteId)?.let { n ->+ vm.notes.put(n.copy(images = n.images.map { if (it == name) out.name else it }))+ }+ } else {+ vm.tell(com.chethan616.clearpdf.text(R.string.photo_not_saved))+ }+ saving = false+ onClose()+ }+ })++ // Intercept back gesture / button: closes photo editor safely instead of closing the app!+ BackHandler(enabled = true) {+ beatClose()+ }++ // Re-develop as the ruler moves; a newer value cancels the render still runningLaunchedEffect(Unit) {snapshotFlow { values.toMap() to turn }.collectLatest {val json = settings()- shown = withContext(Dispatchers.Default) { runCatching { editor.render(source.absolutePath, json, 1600u).toBitmap().asImageBitmap() }.getOrNull() } ?: shown+ shown = withContext(Dispatchers.Default) {+ runCatching {+ editor.render(source.absolutePath, json, 1600u).toBitmap().asImageBitmap()+ }.getOrNull()+ } ?: shown}}- // the picture as shot (turned as the edit is), for holding to compare++ // The picture as shot (turned as the edit is), for holding to compareLaunchedEffect(turn) {val json = settings(withValues = false)- original = withContext(Dispatchers.Default) { runCatching { editor.render(source.absolutePath, json, 1600u).toBitmap().asImageBitmap() }.getOrNull() }+ original = withContext(Dispatchers.Default) {+ runCatching {+ editor.render(source.absolutePath, json, 1600u).toBitmap().asImageBitmap()+ }.getOrNull()+ }}val backdrop = rememberLayerBackdrop()- Box(Modifier.fillMaxSize().background(Color.Black)) {- Column(Modifier.fillMaxSize().layerBackdrop(backdrop)) {++ Box(+ Modifier+ .fillMaxSize()+ .background(Color(0xFF090A0F)),+ ) {+ // ── Photo Canvas Layer ───────────────────────────────────────────────+ Column(+ Modifier+ .fillMaxSize()+ .layerBackdrop(backdrop),+ ) {Spacer(Modifier.windowInsetsTopHeight(WindowInsets.statusBars))- Spacer(Modifier.height(72.dp))+ Spacer(Modifier.height(64.dp))Box(- Modifier.weight(1f).fillMaxWidth().padding(horizontal = 16.dp).pointerInput(Unit) {- detectTapGestures(onPress = {- comparing = true- tryAwaitRelease()- comparing = false- })- },+ Modifier+ .weight(1f)+ .fillMaxWidth()+ .padding(horizontal = 16.dp, vertical = 8.dp)+ .pointerInput(Unit) {+ detectTapGestures(onPress = {+ comparing = true+ tryAwaitRelease()+ comparing = false+ })+ },contentAlignment = Alignment.Center,) {(if (comparing) original ?: shown else shown)?.let {- Image(it, null, Modifier.clip(RoundedRectangle(14.dp)), contentScale = ContentScale.Fit)+ Image(+ it,+ null,+ Modifier+ .clip(RoundedRectangle(20.dp))+ .fillMaxSize(),+ contentScale = ContentScale.Fit,+ )+ }++ // "ORIGINAL" indicator when user holds down on the photo+ AnimatedVisibility(+ visible = comparing,+ enter = fadeIn(Fluid.fade()),+ exit = fadeOut(Fluid.fade()),+ modifier = Modifier.align(Alignment.TopCenter),+ ) {+ Box(+ Modifier+ .padding(top = 12.dp)+ .background(Color.Black.copy(alpha = 0.55f), ChromeCapsule)+ .padding(horizontal = 14.dp, vertical = 6.dp),+ ) {+ Text(+ stringResource(R.string.photo_original).uppercase(),+ style = ClearType.Label.copy(+ fontSize = 11.sp,+ letterSpacing = 1.4.sp,+ fontWeight = FontWeight.SemiBold,+ ),+ color = Color.White,+ )+ }}- if (comparing) Text(- stringResource(R.string.photo_original), style = ClearType.Label, color = Color.White,- modifier = Modifier.align(Alignment.TopCenter).padding(top = 10.dp).background(Color.Black.copy(alpha = 0.45f), RoundedRectangle(10.dp)).padding(horizontal = 10.dp, vertical = 4.dp),- )}- Spacer(Modifier.height(250.dp))+ // Room for the bottom liquid glass deck+ Spacer(Modifier.height(240.dp))+ Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars))}+ // ── Liquid Glass Chrome Layer ─────────────────────────────────────────CompositionLocalProvider(LocalBackdrop provides backdrop) {- // the top row: cancel, reset (once something changed), rotate, done- Column(Modifier.fillMaxWidth().align(Alignment.TopCenter)) {+ // ── Top Navigation Bar ────────────────────────────────────────────+ Column(+ Modifier+ .fillMaxWidth()+ .align(Alignment.TopCenter),+ ) {Spacer(Modifier.windowInsetsTopHeight(WindowInsets.statusBars))- Row(Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 10.dp), verticalAlignment = Alignment.CenterVertically) {- GlassCircle(onClick = onClose, label = stringResource(R.string.common_cancel), ink = Color.White) { GlassIcon(LucideIcons.X, null, Modifier.size(20.dp)) }+ Row(+ Modifier+ .fillMaxWidth()+ .padding(horizontal = 16.dp, vertical = 8.dp),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ // Close / Cancel (X) button with beat delay+ GlassCircle(+ onClick = beatClose,+ label = stringResource(R.string.common_cancel),+ size = 42.dp,+ surface = Color.White.copy(alpha = 0.12f),+ ink = Color.White,+ ) {+ GlassIcon(LucideIcons.X, null, Modifier.size(18.dp))+ }+Spacer(Modifier.weight(1f))- if (edited) GlassPill(onClick = { values.clear(); turn = 0 }, height = 40.dp, horizontalPadding = 16.dp) {- Text(stringResource(R.string.photo_reset), style = ClearType.Label.copy(fontSize = 14.sp), color = Candy.Lemon)++ // Reset button — animates in only when edits exist+ AnimatedVisibility(+ visible = edited,+ enter = fadeIn(Fluid.quick()) + slideInVertically(Fluid.quick()) { -it / 2 },+ exit = fadeOut(Fluid.quick()) + slideOutVertically(Fluid.quick()) { -it / 2 },+ ) {+ GlassPill(+ onClick = {+ values.clear()+ turn = 0+ },+ height = 42.dp,+ horizontalPadding = 16.dp,+ surface = Color.White.copy(alpha = 0.12f),+ tap = Feel.Tap,+ ) {+ Text(+ stringResource(R.string.photo_reset),+ style = ClearType.Label.copy(fontSize = 13.sp, fontWeight = FontWeight.SemiBold),+ color = Candy.Lemon,+ )+ }}++ if (edited) Spacer(Modifier.width(10.dp))++ // Rotate CW+ GlassCircle(+ onClick = { turn = (turn + 1) % 4 },+ label = stringResource(R.string.photo_rotate),+ size = 42.dp,+ surface = Color.White.copy(alpha = 0.12f),+ ink = Color.White,+ ) {+ GlassIcon(LucideIcons.RotateCw, null, Modifier.size(18.dp))+ }+Spacer(Modifier.width(10.dp))- GlassCircle(onClick = { turn = (turn + 1) % 4 }, label = stringResource(R.string.photo_rotate), ink = Color.White) { GlassIcon(LucideIcons.RotateCw, null, Modifier.size(20.dp)) }- Spacer(Modifier.width(10.dp))++ // Done / Save (Tick) button with beat delayGlassCircle(- onClick = {- if (saving) return@GlassCircle- if (!edited) { onClose(); return@GlassCircle }- saving = true- scope.launch {- val out = File(source.parentFile, "edited-${System.currentTimeMillis()}.jpg")- val ok = withContext(Dispatchers.Default) { runCatching { editor.exportJpeg(source.absolutePath, settings(), out.absolutePath, 92u) }.isSuccess }- if (ok) vm.notes.get(noteId)?.let { n -> vm.notes.put(n.copy(images = n.images.map { if (it == name) out.name else it })) }- else vm.tell(com.chethan616.clearpdf.text(R.string.photo_not_saved))- saving = false- onClose()- }- },- tint = Candy.Sky, label = stringResource(R.string.common_done),- ) { GlassIcon(LucideIcons.Check, null, Modifier.size(20.dp)) }+ onClick = beatDone,+ label = stringResource(R.string.common_done),+ size = 42.dp,+ tint = if (edited) Candy.Sky else Color.Unspecified,+ surface = if (edited) Candy.Sky.copy(alpha = 0.32f) else Color.White.copy(alpha = 0.12f),+ ink = if (edited) Color.White else Color.White.copy(alpha = 0.7f),+ ) {+ GlassIcon(LucideIcons.Check, null, Modifier.size(20.dp))+ }}}- // the controls: the chosen adjustment's value, its ruler, the dials- Column(Modifier.fillMaxWidth().align(Alignment.BottomCenter), horizontalAlignment = Alignment.CenterHorizontally) {+ // ── Bottom Liquid Glass Control Center ────────────────────────────+ Column(+ Modifier+ .fillMaxWidth()+ .align(Alignment.BottomCenter)+ .padding(horizontal = 14.dp, vertical = 8.dp),+ horizontalAlignment = Alignment.CenterHorizontally,+ ) {val v = values[chosen] ?: 0f- Text(stringResource(chosen.label).uppercase(), style = ClearType.Label.copy(fontSize = 12.sp, letterSpacing = 1.4.sp), color = Color.White.copy(alpha = 0.6f))- Spacer(Modifier.height(4.dp))- Text(shown(chosen, v), style = ClearType.Title.copy(fontSize = 22.sp, fontWeight = FontWeight.SemiBold), color = if (v != 0f) Candy.Lemon else Color.White)- Spacer(Modifier.height(10.dp))- Ruler(chosen, v) { values[chosen] = it }- Spacer(Modifier.height(18.dp))- Row(- Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()).padding(horizontal = 20.dp),- horizontalArrangement = Arrangement.spacedBy(14.dp),++ // Floating glass control deck enclosing readout, ruler, and dials+ Box(+ Modifier+ .fillMaxWidth()+ .glass(+ shape = RoundedRectangle(28.dp),+ wash = Color(0x33101524),+ blur = 18.dp,+ lensHeight = 14.dp,+ lensAmount = 22.dp,+ )+ .padding(top = 16.dp, bottom = 14.dp),) {- for (a in Adjust.entries) Dial(a, values[a] ?: 0f, a == chosen) { chosen = a }+ Column(+ Modifier.fillMaxWidth(),+ horizontalAlignment = Alignment.CenterHorizontally,+ ) {+ // Title + Value display+ Text(+ stringResource(chosen.label).uppercase(),+ style = ClearType.Label.copy(fontSize = 11.sp, letterSpacing = 1.8.sp),+ color = Color.White.copy(alpha = 0.5f),+ )+ Spacer(Modifier.height(2.dp))+ Text(+ shown(chosen, v),+ style = ClearType.Title.copy(fontSize = 24.sp, fontWeight = FontWeight.Bold),+ color = if (v != 0f) Candy.Lemon else Color.White,+ )++ Spacer(Modifier.height(10.dp))++ // Precision Ruler+ Ruler(chosen, v) { values[chosen] = it }++ Spacer(Modifier.height(16.dp))++ // Liquid Glass Dials Row (no circle marks!)+ Row(+ Modifier+ .fillMaxWidth()+ .horizontalScroll(rememberScrollState())+ .padding(horizontal = 12.dp),+ horizontalArrangement = Arrangement.spacedBy(8.dp),+ ) {+ for (a in Adjust.entries) {+ Dial(+ a = a,+ value = values[a] ?: 0f,+ chosen = a == chosen,+ onClick = { chosen = a },+ )+ }+ }+ }}- Spacer(Modifier.height(18.dp))+Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars))}}@@ -220,31 +432,54 @@ fun PhotoEditScreen(vm: AppViewModel, noteId: String, name: String, onClose: ()}/**- * An adjustment as a round glass button: its glyph, a ring that fills by how far it has moved (the- * chosen one lit in lemon), as Photos draws its adjustment dials.+ * An adjustment dial: pure liquid glass component with responsive fluid press,+ * squish and bloom. NO canvas circle marks or outer rings.*/@Composable-private fun Dial(a: Adjust, value: Float, chosen: Boolean, onClick: () -> Unit) {- val span = maxOf(abs(a.min), abs(a.max))- val part = (value / span).coerceIn(-1f, 1f)- // the app's glass button, its ring drawn round it- Box(Modifier.size(62.dp), contentAlignment = Alignment.Center) {- GlassCircle(onClick = onClick, size = 52.dp, label = stringResource(a.label), ink = Color.White) {- GlassIcon(a.icon, null, Modifier.size(21.dp), tint = if (chosen) Candy.Lemon else Color.White)- }- Canvas(Modifier.size(62.dp)) {- val stroke = 2.4.dp.toPx()- val inset = stroke / 2- val box = Size(size.width - stroke, size.height - stroke)- drawArc(Color.White.copy(alpha = if (chosen) 0.35f else 0.14f), 0f, 360f, false, Offset(inset, inset), box, style = Stroke(stroke))- if (part != 0f) drawArc(if (chosen) Candy.Lemon else Color.White, -90f, 360f * part, false, Offset(inset, inset), box, style = Stroke(stroke, cap = StrokeCap.Round))+private fun Dial(+ a: Adjust,+ value: Float,+ chosen: Boolean,+ onClick: () -> Unit,+) {+ val nonZero = value != 0f+ Column(+ horizontalAlignment = Alignment.CenterHorizontally,+ modifier = Modifier.width(62.dp),+ ) {+ GlassCircle(+ onClick = onClick,+ size = 50.dp,+ label = stringResource(a.label),+ ink = if (chosen) Candy.Lemon else Color.White,+ tint = if (chosen) Candy.Lemon.copy(alpha = 0.28f) else Color.Unspecified,+ surface = if (chosen) Candy.Lemon.copy(alpha = 0.18f) else Color.White.copy(alpha = 0.10f),+ ) {+ GlassIcon(+ a.icon,+ null,+ Modifier.size(22.dp),+ tint = if (chosen) Candy.Lemon else Color.White,+ )}+ Spacer(Modifier.height(6.dp))+ Text(+ if (nonZero) shown(a, value) else stringResource(a.label),+ style = ClearType.Label.copy(+ fontSize = 11.sp,+ fontWeight = if (chosen || nonZero) FontWeight.SemiBold else FontWeight.Normal,+ ),+ color = if (chosen || nonZero) Candy.Lemon else Color.White.copy(alpha = 0.6f),+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ textAlign = TextAlign.Center,+ )}}/**- * The value's ruler: ticks across the whole range, the value under the fixed centre line; dragging- * moves the ruler, and it catches at zero with a tick of the haptics.+ * The value's ruler: ticks across the range with edge-fade, zero catch with haptics,+ * and a center indicator in Lemon.*/@Composableprivate fun Ruler(a: Adjust, value: Float, onChange: (Float) -> Unit) {@@ -252,37 +487,50 @@ private fun Ruler(a: Adjust, value: Float, onChange: (Float) -> Unit) {val range = a.max - a.minvar drag by remember(a) { mutableStateOf(value) }LaunchedEffect(value) { drag = value }+Canvas(- Modifier.fillMaxWidth().height(44.dp).pointerInput(a) {- // the whole range spans three screen widths- val perPx = range / (size.width * 3f)- detectHorizontalDragGestures { change, dx ->- change.consume()- val before = drag- var next = (drag - dx * perPx).coerceIn(a.min, a.max)- // a catch at zero- if (abs(next) < range * 0.012f) next = 0f- if ((before != 0f && next == 0f)) haptics?.play(Feel.Tick)- drag = next- onChange(next)- }- },+ Modifier+ .fillMaxWidth()+ .height(44.dp)+ .pointerInput(a) {+ val perPx = range / (size.width * 3f)+ detectHorizontalDragGestures { change, dx ->+ change.consume()+ val before = drag+ var next = (drag - dx * perPx).coerceIn(a.min, a.max)+ // catch at zero+ if (abs(next) < range * 0.012f) next = 0f+ if (before != 0f && next == 0f) haptics?.play(Feel.Tick)+ drag = next+ onChange(next)+ }+ },) {val w = size.width * 3fval mid = size.width / 2val t = (drag - a.min) / rangeval ticks = 60+for (i in 0..ticks) {val x = mid + (i.toFloat() / ticks - t) * wif (x < -4 || x > size.width + 4) continueval major = i % 10 == 0val h = if (major) size.height * 0.55f else size.height * 0.32f- val fade = (1f - abs(x - mid) / mid).coerceIn(0.15f, 1f)- drawLine(Color.White.copy(alpha = (if (major) 0.8f else 0.45f) * fade), Offset(x, (size.height - h) / 2), Offset(x, (size.height + h) / 2), 1.6.dp.toPx(), StrokeCap.Round)+ val fade = (1f - abs(x - mid) / mid).coerceIn(0.12f, 1f)+ drawLine(+ Color.White.copy(alpha = (if (major) 0.8f else 0.4f) * fade),+ Offset(x, (size.height - h) / 2),+ Offset(x, (size.height + h) / 2),+ 1.5.dp.toPx(),+ StrokeCap.Round,+ )}- // zero's mark, and the centre line the value sits under++ // zero indicator mark & center needleval zx = mid + ((0f - a.min) / range - t) * w- if (zx in 0f..size.width) drawCircle(Candy.Lemon, 2.4.dp.toPx(), Offset(zx, size.height - 2.dp.toPx()))- drawLine(Candy.Lemon, Offset(mid, 0f), Offset(mid, size.height), 2.4.dp.toPx(), StrokeCap.Round)+ if (zx in 0f..size.width) {+ drawCircle(Candy.Lemon, 2.5.dp.toPx(), Offset(zx, size.height - 2.dp.toPx()))+ }+ drawLine(Candy.Lemon, Offset(mid, 0f), Offset(mid, size.height), 2.dp.toPx(), StrokeCap.Round)}}