Skip to content

Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.

Old ClearPDF's liquid glass, a faster desk, and a cleaner Settings

chethan616a0e98dce4571
diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts
index 8d3b799..70199ba 100644
--- a/android/app/build.gradle.kts
+++ b/android/app/build.gradle.kts
@@ -171,7 +171,7 @@ abstract class LucideIconsTask : DefaultTask() {
sb.appendLine("package com.chethan616.clearpdf.ui\n")
sb.appendLine("import androidx.compose.ui.graphics.vector.ImageVector\n")
sb.appendLine("/** Lucide icons (ISC, Lucide Contributors; assets/icons/LICENSE-lucide.txt). */")
- sb.appendLine("object LucideIcons {")
+ sb.appendLine("object LucideSet {")
val files = iconsDir.get().asFile.listFiles { f -> f.extension == "svg" }.orEmpty().sortedBy { it.name }
for (f in files) {
val paths = mutableListOf<String>()
@@ -370,6 +370,7 @@ dependencies {
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.graphics)
implementation(libs.androidx.compose.material3)
+ implementation(libs.androidx.compose.material.icons.extended)
implementation(libs.androidx.compose.foundation)
implementation(project(":backdrop"))
implementation(libs.kyant.shapes)
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/MainActivity.kt b/android/app/src/main/java/com/chethan616/clearpdf/MainActivity.kt
index 7e1f7f0..28ce189 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/MainActivity.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/MainActivity.kt
@@ -34,6 +34,15 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
class MainActivity : ComponentActivity() {
+
+ // where the last touch went down: a document opened by it zooms out of that spot
+ override fun dispatchTouchEvent(ev: android.view.MotionEvent): Boolean {
+ if (ev.actionMasked == android.view.MotionEvent.ACTION_DOWN) {
+ com.chethan616.clearpdf.ui.LastTouch.x = ev.rawX
+ com.chethan616.clearpdf.ui.LastTouch.y = ev.rawY
+ }
+ return super.dispatchTouchEvent(ev)
+ }
companion object {
/** Set by Quick Preview's Expand: the document came from another app through the preview. */
const val EXTRA_FROM_PREVIEW = "com.chethan616.clearpdf.FROM_PREVIEW"
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/preview/QuickPreview.kt b/android/app/src/main/java/com/chethan616/clearpdf/preview/QuickPreview.kt
index c0bee96..e63c14f 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/preview/QuickPreview.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/preview/QuickPreview.kt
@@ -84,8 +84,8 @@ import com.chethan616.clearpdf.ui.theme.clear
import com.chethan616.clearpdf.ui.viewer.CanvasLook
import com.chethan616.clearpdf.ui.viewer.PageCanvas
import com.chethan616.clearpdf.ui.viewer.formatSize
-import com.kyant.shapes.Capsule
-import com.kyant.shapes.RoundedRectangle
+import com.chethan616.clearpdf.ui.glass.Capsule
+import com.chethan616.clearpdf.ui.glass.RoundedRectangle
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@@ -112,8 +112,15 @@ internal fun QuickPreviewScreen(
setBlur: (Int) -> Unit,
) {
val overlays = remember { GlassOverlayHost() }
- ClearTheme(ThemeChoice.System) {
- PdfcraftTheme(ThemeChoice.System) {
+ // the theme chosen in the app's Settings (the same "app" preference the app reads), not the system's
+ val context = androidx.compose.ui.platform.LocalContext.current
+ val theme = remember {
+ runCatching {
+ ThemeChoice.valueOf(context.getSharedPreferences("app", android.content.Context.MODE_PRIVATE).getString("theme", "System") ?: "System")
+ }.getOrDefault(ThemeChoice.System)
+ }
+ ClearTheme(theme) {
+ PdfcraftTheme(theme) {
ProvideGlassHaptics {
CompositionLocalProvider(LocalGlassOverlayHost provides overlays) {
Preview(state, onClose, onExpand, onShare, onOpenWith, onSaveCopy, onPassword, setBlur)
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/AppIcons.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/AppIcons.kt
new file mode 100644
index 0000000..7c044f2
--- /dev/null
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/AppIcons.kt
@@ -0,0 +1,132 @@
+package com.chethan616.clearpdf.ui
+
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.rounded.*
+import androidx.compose.material.icons.rounded.*
+import androidx.compose.ui.graphics.vector.ImageVector
+
+/**
+ * The app's icons: Material Symbols, Rounded (the old ClearPDF's set), under the names the code has
+ * always used. Anything Material has no fit for stays the Lucide drawing in [LucideSet].
+ */
+@Suppress("DEPRECATION")
+object LucideIcons {
+ val AArrowDown: ImageVector get() = Icons.Rounded.TextDecrease
+ val AArrowUp: ImageVector get() = Icons.Rounded.TextIncrease
+ val ALargeSmall: ImageVector get() = Icons.Rounded.FormatSize
+ val AlignCenter: ImageVector get() = Icons.Rounded.FormatAlignCenter
+ val AlignJustify: ImageVector get() = Icons.Rounded.FormatAlignJustify
+ val AlignLeft: ImageVector get() = Icons.AutoMirrored.Rounded.FormatAlignLeft
+ val AlignRight: ImageVector get() = Icons.AutoMirrored.Rounded.FormatAlignRight
+ val ArrowUpDown: ImageVector get() = Icons.Rounded.SwapVert
+ val AudioLines: ImageVector get() = Icons.Rounded.GraphicEq
+ val Bold: ImageVector get() = Icons.Rounded.FormatBold
+ val BookOpenText: ImageVector get() = Icons.AutoMirrored.Rounded.MenuBook
+ val Bookmark: ImageVector get() = Icons.Rounded.Bookmark
+ val BookmarkMinus: ImageVector get() = Icons.Rounded.BookmarkRemove
+ val BookmarkPlus: ImageVector get() = Icons.Rounded.BookmarkAdd
+ val BrushCleaning: ImageVector get() = Icons.Rounded.CleaningServices
+ val Camera: ImageVector get() = Icons.Rounded.PhotoCamera
+ val Check: ImageVector get() = Icons.Rounded.Check
+ val ChevronDown: ImageVector get() = Icons.Rounded.KeyboardArrowDown
+ val ChevronLeft: ImageVector get() = Icons.AutoMirrored.Rounded.KeyboardArrowLeft
+ val ChevronRight: ImageVector get() = Icons.AutoMirrored.Rounded.KeyboardArrowRight
+ val ChevronUp: ImageVector get() = Icons.Rounded.KeyboardArrowUp
+ val Circle: ImageVector get() = Icons.Rounded.RadioButtonUnchecked
+ val CircleCheck: ImageVector get() = Icons.Rounded.CheckCircle
+ val CircleDashed: ImageVector get() = Icons.Rounded.RadioButtonUnchecked
+ val CircleDot: ImageVector get() = Icons.Rounded.RadioButtonChecked
+ val CircleMinus: ImageVector get() = Icons.Rounded.RemoveCircle
+ val CircleX: ImageVector get() = Icons.Rounded.Cancel
+ val CodeXml: ImageVector get() = Icons.Rounded.Code
+ val Combine: ImageVector get() = Icons.AutoMirrored.Rounded.MergeType
+ val Compass: ImageVector get() = Icons.Rounded.Explore
+ val Copy: ImageVector get() = Icons.Rounded.ContentCopy
+ val Crop: ImageVector get() = Icons.Rounded.Crop
+ val Ellipsis: ImageVector get() = Icons.Rounded.MoreHoriz
+ val EllipsisVertical: ImageVector get() = Icons.Rounded.MoreVert
+ val ExternalLink: ImageVector get() = Icons.AutoMirrored.Rounded.OpenInNew
+ val Eye: ImageVector get() = Icons.Rounded.Visibility
+ val EyeOff: ImageVector get() = Icons.Rounded.VisibilityOff
+ val File: ImageVector get() = Icons.AutoMirrored.Rounded.InsertDriveFile
+ val FileArchive: ImageVector get() = Icons.Rounded.FolderZip
+ val FileDown: ImageVector get() = Icons.Rounded.FileDownload
+ val FileLock2: ImageVector get() = Icons.Rounded.Lock
+ val FileOutput: ImageVector get() = Icons.Rounded.FileUpload
+ val FilePenLine: ImageVector get() = Icons.Rounded.EditNote
+ val FilePlus: ImageVector get() = Icons.AutoMirrored.Rounded.NoteAdd
+ val FilePlus2: ImageVector get() = Icons.AutoMirrored.Rounded.NoteAdd
+ val FileStack: ImageVector get() = Icons.Rounded.FileCopy
+ val FileText: ImageVector get() = Icons.Rounded.Description
+ val FolderOpen: ImageVector get() = Icons.Rounded.FolderOpen
+ val FolderPlus: ImageVector get() = Icons.Rounded.CreateNewFolder
+ val GalleryVerticalEnd: ImageVector get() = Icons.Rounded.ViewDay
+ val Glasses: ImageVector get() = Icons.Rounded.AutoStories
+ val GripVertical: ImageVector get() = Icons.Rounded.DragIndicator
+ val Hash: ImageVector get() = Icons.Rounded.Tag
+ val Heading: ImageVector get() = Icons.Rounded.Title
+ val Highlighter: ImageVector get() = Icons.Rounded.Highlight
+ val ImagePlus: ImageVector get() = Icons.Rounded.AddPhotoAlternate
+ val Images: ImageVector get() = Icons.Rounded.PhotoLibrary
+ val Info: ImageVector get() = Icons.Rounded.Info
+ val Layers: ImageVector get() = Icons.Rounded.Layers
+ val LayoutGrid: ImageVector get() = Icons.Rounded.GridView
+ val Link: ImageVector get() = Icons.Rounded.Link
+ val List: ImageVector get() = Icons.AutoMirrored.Rounded.List
+ val ListChecks: ImageVector get() = Icons.Rounded.Checklist
+ val Lock: ImageVector get() = Icons.Rounded.Lock
+ val LockOpen: ImageVector get() = Icons.Rounded.LockOpen
+ val Maximize: ImageVector get() = Icons.Rounded.OpenInFull
+ val Menu: ImageVector get() = Icons.Rounded.Menu
+ val MessageSquare: ImageVector get() = Icons.Rounded.ChatBubble
+ val MessageSquarePlus: ImageVector get() = Icons.Rounded.AddComment
+ val MessageSquareText: ImageVector get() = Icons.AutoMirrored.Rounded.Comment
+ val MessagesSquare: ImageVector get() = Icons.Rounded.Forum
+ val Mic: ImageVector get() = Icons.Rounded.Mic
+ val MicAudioLines: ImageVector get() = Icons.Rounded.KeyboardVoice
+ val Minus: ImageVector get() = Icons.Rounded.Remove
+ val Moon: ImageVector get() = Icons.Rounded.DarkMode
+ val Palette: ImageVector get() = Icons.Rounded.Palette
+ val PanelsTopLeft: ImageVector get() = Icons.Rounded.Preview
+ val Paperclip: ImageVector get() = Icons.Rounded.AttachFile
+ val Pause: ImageVector get() = Icons.Rounded.Pause
+ val PenLine: ImageVector get() = Icons.Rounded.Draw
+ val Pencil: ImageVector get() = Icons.Rounded.Edit
+ val Pin: ImageVector get() = Icons.Rounded.PushPin
+ val Play: ImageVector get() = Icons.Rounded.PlayArrow
+ val Plus: ImageVector get() = Icons.Rounded.Add
+ val Printer: ImageVector get() = Icons.Rounded.Print
+ val RectangleHorizontal: ImageVector get() = Icons.Rounded.CropLandscape
+ val Redo2: ImageVector get() = Icons.AutoMirrored.Rounded.Redo
+ val RotateCcw: ImageVector get() = Icons.Rounded.RotateLeft
+ val RotateCw: ImageVector get() = Icons.Rounded.RotateRight
+ val Save: ImageVector get() = Icons.Rounded.Save
+ val ScanText: ImageVector get() = Icons.Rounded.DocumentScanner
+ val ScrollText: ImageVector get() = Icons.AutoMirrored.Rounded.Article
+ val Search: ImageVector get() = Icons.Rounded.Search
+ val Send: ImageVector get() = Icons.AutoMirrored.Rounded.Send
+ val Settings: ImageVector get() = Icons.Rounded.Settings
+ val Shapes: ImageVector get() = Icons.Rounded.Category
+ val Share2: ImageVector get() = Icons.Rounded.Share
+ val ShieldCheck: ImageVector get() = Icons.Rounded.VerifiedUser
+ val Signature: ImageVector get() = Icons.Rounded.Gesture
+ val SlidersHorizontal: ImageVector get() = Icons.Rounded.Tune
+ val Smartphone: ImageVector get() = Icons.Rounded.Smartphone
+ val Sparkles: ImageVector get() = Icons.Rounded.AutoAwesome
+ val Square: ImageVector get() = Icons.Rounded.CheckBoxOutlineBlank
+ val SquarePen: ImageVector get() = Icons.Rounded.EditNote
+ val SquareTerminal: ImageVector get() = Icons.Rounded.Terminal
+ val Star: ImageVector get() = Icons.Rounded.Star
+ val Strikethrough: ImageVector get() = Icons.Rounded.FormatStrikethrough
+ val Sun: ImageVector get() = Icons.Rounded.LightMode
+ val TextCursorInput: ImageVector get() = Icons.Rounded.TextFields
+ val Trash2: ImageVector get() = Icons.Rounded.Delete
+ val TriangleAlert: ImageVector get() = Icons.Rounded.Warning
+ val Type: ImageVector get() = Icons.Rounded.TextFields
+ val Underline: ImageVector get() = Icons.Rounded.FormatUnderlined
+ val Undo2: ImageVector get() = Icons.AutoMirrored.Rounded.Undo
+ val UserRound: ImageVector get() = Icons.Rounded.Person
+ val Volume2: ImageVector get() = Icons.AutoMirrored.Rounded.VolumeUp
+ val Wrench: ImageVector get() = Icons.Rounded.Build
+ val X: ImageVector get() = Icons.Rounded.Close
+}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/AppViewModel.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/AppViewModel.kt
index b5d16ab..7a176d1 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/AppViewModel.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/AppViewModel.kt
@@ -2380,6 +2380,9 @@ class AppViewModel(app: Application, private val saved: SavedStateHandle) : Andr
/** The note toolbar's glass, measured, for the dock to become. */
var noteBarSize by mutableStateOf(androidx.compose.ui.unit.IntSize.Zero)
+ /** Where the note's toolbar ends, in window px (it rides up with the keyboard). Read while drawing. */
+ var noteBarBottom by androidx.compose.runtime.mutableFloatStateOf(0f)
+
/** Files other apps open show in Quick Preview's floating card first (else straight in the viewer). */
var quickPreview by mutableStateOf(appPrefs.getBoolean("quickPreview", true))
private set
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.kt
index 8545138..d47fdf3 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
@@ -50,6 +50,9 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.layout.positionInWindow
+import androidx.compose.ui.layout.onGloballyPositioned
+import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawWithContent
import com.chethan616.clearpdf.ui.glass.Fluid
@@ -111,7 +114,7 @@ import com.chethan616.clearpdf.ui.viewer.IdPasswordDialog
import com.chethan616.clearpdf.ui.viewer.SignFieldChoiceDialog
import com.chethan616.clearpdf.ui.viewer.SignaturePadScreen
import com.chethan616.clearpdf.ui.viewer.ViewerScreen
-import com.kyant.shapes.RoundedRectangle
+import com.chethan616.clearpdf.ui.glass.RoundedRectangle
import kotlinx.coroutines.delay
/** The whole app: the glass stage with the tabs (or a document, or Settings), the dock, and every dialog. */
@@ -231,7 +234,16 @@ private fun Shell(vm: AppViewModel, onBrowse: () -> Unit, onPickSignatureImage:
)
if (doc == null) vm.fileSheet?.let { (r, recent) -> FileActionsSheet(vm, r, recent) { vm.fileSheet = null } }
- if (vm.opening) Spinner()
+ // the loader only for an open that takes a while: a quick one shouldn't flash a spinner first
+ var slowOpen by remember { mutableStateOf(false) }
+ LaunchedEffect(vm.opening) {
+ slowOpen = false
+ if (vm.opening) {
+ kotlinx.coroutines.delay(350)
+ slowOpen = true
+ }
+ }
+ if (vm.opening && slowOpen) Spinner()
Dialogs(vm)
}
@@ -244,7 +256,7 @@ private fun Viewer(vm: AppViewModel, doc: OpenDocument) {
Modifier.fillMaxSize().windowInsetsPadding(
if (fullWidth) WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal) else WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal),
).then(if (fullWidth) Modifier else Modifier.background(pdfColors.surface)),
- ) { ViewerScreen(vm, doc) }
+ ) { com.chethan616.clearpdf.ui.glass.ProvideScreenInk { ViewerScreen(vm, doc) } }
}
}
@@ -334,6 +346,12 @@ private val BlockTouches = Modifier.pointerInput(Unit) {
}
}
+/** Where the last touch went down, in window pixels (MainActivity records it). */
+object LastTouch {
+ @JvmField var x = Float.NaN
+ @JvmField var y = Float.NaN
+}
+
/** How far a document has risen over the desk: 0 gone, 1 covering it. */
@androidx.compose.runtime.Stable
private class RevealState {
@@ -352,8 +370,17 @@ private fun <T : Any> Reveal(value: T?, state: RevealState, content: @Composable
val last = remember { arrayOfNulls<Any>(1) }
if (value != null) last[0] = value
val p = state.progress
+ // the spot it grows out of: where the finger was when it was opened, kept for the way back
+ val from = remember { floatArrayOf(Float.NaN, Float.NaN) }
LaunchedEffect(value != null) {
- if (value != null) p.animateTo(1f, Fluid.rise()) else p.animateTo(0f, Fluid.dismiss())
+ if (value != null) {
+ from[0] = LastTouch.x
+ from[1] = LastTouch.y
+ // a soft spring that never overshoots: the page lands, it doesn't bounce
+ p.animateTo(1f, androidx.compose.animation.core.spring(1f, com.chethan616.clearpdf.ui.glass.MotionSettings.stiffness(260f), 0.001f))
+ } else {
+ p.animateTo(0f, Fluid.dismiss())
+ }
if (value == null) last[0] = null
}
// read through a derived state: the content recomposes when it's gone, not on every frame
@@ -361,13 +388,26 @@ private fun <T : Any> Reveal(value: T?, state: RevealState, content: @Composable
@Suppress("UNCHECKED_CAST")
val shown = last[0] as T? ?: return
if (gone && value == null) return
+ val origin = remember { arrayOf(Offset.Zero) }
Box(
- Modifier.fillMaxSize().graphicsLayer {
- val v = p.value
- translationY = (1f - v) * size.height * 0.07f
- alpha = (v * 1.8f).coerceIn(0f, 1f)
- compositingStrategy = CompositingStrategy.ModulateAlpha
- },
+ Modifier.fillMaxSize()
+ .onGloballyPositioned { origin[0] = it.positionInWindow() }
+ .graphicsLayer {
+ val v = p.value.coerceIn(0f, 1f)
+ // zooms out of the touch, iOS's way of opening from what was tapped; with no touch
+ // (opened from elsewhere) from the middle
+ val fx = if (from[0].isNaN() || size.width <= 0f) 0.5f else ((from[0] - origin[0].x) / size.width).coerceIn(0f, 1f)
+ val fy = if (from[1].isNaN() || size.height <= 0f) 0.5f else ((from[1] - origin[0].y) / size.height).coerceIn(0f, 1f)
+ transformOrigin = androidx.compose.ui.graphics.TransformOrigin(fx, fy)
+ val s = 0.3f + 0.7f * v
+ scaleX = s
+ scaleY = s
+ alpha = (v * 2.5f).coerceIn(0f, 1f)
+ // corners round while it's small, square once it fills the screen (a rounded rect:
+ // the GPU clips it for nothing)
+ shape = androidx.compose.foundation.shape.RoundedCornerShape(((1f - v) * 44f).dp)
+ clip = v < 1f
+ },
) { content(shown) }
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/Components.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/Components.kt
index e7978b0..0d73f73 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/Components.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/Components.kt
@@ -98,8 +98,8 @@ import com.chethan616.clearpdf.ui.glass.pressable
import com.chethan616.clearpdf.ui.theme.Candy
import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.clear
-import com.kyant.shapes.Capsule
-import com.kyant.shapes.RoundedRectangle
+import com.chethan616.clearpdf.ui.glass.Capsule
+import com.chethan616.clearpdf.ui.glass.RoundedRectangle
import kotlin.math.roundToInt
import kotlinx.coroutines.launch
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/ToolScreens.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/ToolScreens.kt
index a3a6078..6de7d23 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/ToolScreens.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/ToolScreens.kt
@@ -136,11 +136,7 @@ private fun GlassToolBackground(content: @Composable () -> Unit) {
/** A tool's Back: the round glass Back of every screen, leaving a beat after the tap. */
@Composable
private fun GlassBack(onBack: () -> Unit) {
- com.chethan616.clearpdf.ui.glass.GlassCircle(
- onClick = com.chethan616.clearpdf.ui.glass.rememberBeat(onBack),
- size = 48.dp,
- label = stringResource(R.string.common_back),
- ) { com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.ChevronLeft, null, Modifier.size(23.dp)) }
+ com.chethan616.clearpdf.ui.glass.GlassBackButton(onBack)
}
/** A file as the tools show it: an icon, its name and size. */
@@ -204,11 +200,12 @@ fun ToolPage(
/** A small action on a tool's screen: a glass chip, faint while it can't be used. */
@Composable
-private fun GlassTextButton(onClick: () -> Unit, enabled: Boolean = true, content: @Composable () -> Unit) {
+private fun GlassTextButton(onClick: () -> Unit, enabled: Boolean = true, modifier: Modifier = Modifier, content: @Composable () -> Unit) {
com.chethan616.clearpdf.ui.glass.GlassChip(
onClick = { if (enabled) onClick() },
- modifier = Modifier.alpha(if (enabled) 1f else 0.5f),
+ modifier = modifier.alpha(if (enabled) 1f else 0.5f),
height = 42.dp,
+ contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 12.dp),
) { content() }
}
@@ -326,7 +323,7 @@ fun ProtectScreen(vm: AppViewModel, doc: OpenDocument) {
val mismatch = confirm.isNotEmpty() && confirm != pw
ToolPage(stringResource(R.string.common_tool_set_password), { vm.toolScreen = null }, stringResource(R.string.common_tool_set_password), pw.isNotEmpty() && confirm.isNotEmpty() && !bad && !mismatch, { vm.protect(doc, pw) },
trailing = {
- com.chethan616.clearpdf.ui.glass.GlassCircle({ info = true }, size = 44.dp, label = stringResource(R.string.tools_about_passwords)) {
+ com.chethan616.clearpdf.ui.glass.GlassCircle({ info = true }, label = stringResource(R.string.tools_about_passwords)) {
com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.Info, null, Modifier.size(20.dp))
}
}) {
@@ -471,7 +468,7 @@ fun CombineScreen(vm: AppViewModel) {
Modifier.fillMaxWidth().height(62.dp)
.offset { IntOffset(0, if (dragIndex == i) dragOffset.roundToInt() else 0) }
.then(com.chethan616.clearpdf.ui.glass.washPanel())
- .then(if (dragIndex == i) Modifier.border(2.dp, com.chethan616.clearpdf.ui.theme.Candy.Sky, com.kyant.shapes.RoundedRectangle(20.dp)) else Modifier),
+ .then(if (dragIndex == i) Modifier.border(2.dp, com.chethan616.clearpdf.ui.theme.Candy.Sky, com.chethan616.clearpdf.ui.glass.RoundedRectangle(20.dp)) else Modifier),
verticalAlignment = Alignment.CenterVertically,
) {
Box(
@@ -655,14 +652,14 @@ fun CropScreen(vm: AppViewModel, doc: OpenDocument) {
// the page in a glass pill, glass arrows either side when cropping them all
val ink = com.chethan616.clearpdf.ui.theme.clear
Row(Modifier.fillMaxWidth().height(76.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp, Alignment.CenterHorizontally)) {
- if (allPages) com.chethan616.clearpdf.ui.glass.GlassCircle({ page = (page - 1).coerceAtLeast(0) }, size = 44.dp, label = stringResource(R.string.tools_previous_page)) {
+ if (allPages) com.chethan616.clearpdf.ui.glass.GlassCircle({ page = (page - 1).coerceAtLeast(0) }, label = stringResource(R.string.tools_previous_page)) {
com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.ChevronLeft, null, Modifier.size(20.dp).alpha(if (page > 0) 1f else 0.35f))
}
Box(
Modifier.widthIn(min = 110.dp).height(40.dp).glassBar().padding(horizontal = 18.dp),
contentAlignment = Alignment.Center,
) { Text(stringResource(R.string.tools_page_number, page + 1), style = com.chethan616.clearpdf.ui.theme.ClearType.BodyStrong, color = ink.ink) }
- if (allPages) com.chethan616.clearpdf.ui.glass.GlassCircle({ page = (page + 1).coerceAtMost(doc.pageCount - 1) }, size = 44.dp, label = stringResource(R.string.tools_next_page)) {
+ if (allPages) com.chethan616.clearpdf.ui.glass.GlassCircle({ page = (page + 1).coerceAtMost(doc.pageCount - 1) }, label = stringResource(R.string.tools_next_page)) {
com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.ChevronRight, null, Modifier.size(20.dp).alpha(if (page < doc.pageCount - 1) 1f else 0.35f))
}
}
@@ -759,13 +756,13 @@ fun ScanScreen(vm: AppViewModel) {
pages.forEachIndexed { i, p ->
Image(
p.thumb, stringResource(R.string.tools_page_number, i + 1),
- modifier = Modifier.size(56.dp, 72.dp).clip(com.kyant.shapes.RoundedRectangle(12.dp))
- .border(2.5.dp, if (i == current) com.chethan616.clearpdf.ui.theme.Candy.Sky else Color.Transparent, com.kyant.shapes.RoundedRectangle(12.dp))
+ modifier = Modifier.size(56.dp, 72.dp).clip(com.chethan616.clearpdf.ui.glass.RoundedRectangle(12.dp))
+ .border(2.5.dp, if (i == current) com.chethan616.clearpdf.ui.theme.Candy.Sky else Color.Transparent, com.chethan616.clearpdf.ui.glass.RoundedRectangle(12.dp))
.clickable { current = i },
contentScale = ContentScale.Crop,
)
}
- com.chethan616.clearpdf.ui.glass.GlassCircle(onClick = { vm.takeScanPhoto() }, size = 56.dp, label = addPageLabel) {
+ com.chethan616.clearpdf.ui.glass.GlassCircle(onClick = { vm.takeScanPhoto() }, size = 48.dp, label = addPageLabel) {
com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.Plus, null, Modifier.size(24.dp))
}
}
@@ -777,17 +774,17 @@ fun ScanScreen(vm: AppViewModel) {
ScanFilter.entries.forEach { f -> com.chethan616.clearpdf.ui.home.DeskChip(stringResource(f.label), f == filter) { filter = f } }
}
Row(Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp), horizontalArrangement = Arrangement.spacedBy(10.dp, Alignment.CenterHorizontally)) {
- GlassTextButton(onClick = { vm.retakeScan(current) }, enabled = pages.isNotEmpty()) {
+ GlassTextButton(onClick = { vm.retakeScan(current) }, enabled = pages.isNotEmpty(), modifier = Modifier.weight(1f)) {
com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.Camera, null, Modifier.size(18.dp))
- Text(stringResource(R.string.tools_retake), color = ink)
+ Text(stringResource(R.string.tools_retake), color = ink, maxLines = 1, softWrap = false, overflow = TextOverflow.Ellipsis)
}
- GlassTextButton(onClick = { cropping = pages.getOrNull(current.coerceAtMost(pages.lastIndex))?.file }, enabled = pages.isNotEmpty()) {
+ GlassTextButton(onClick = { cropping = pages.getOrNull(current.coerceAtMost(pages.lastIndex))?.file }, enabled = pages.isNotEmpty(), modifier = Modifier.weight(1f)) {
com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.Crop, null, Modifier.size(18.dp))
- Text(stringResource(R.string.tools_crop), color = ink)
+ Text(stringResource(R.string.tools_crop), color = ink, maxLines = 1, softWrap = false, overflow = TextOverflow.Ellipsis)
}
- GlassTextButton(onClick = { if (pages.isNotEmpty()) { pages.removeAt(current.coerceAtMost(pages.lastIndex)); current = (current - 1).coerceAtLeast(0) } }, enabled = pages.isNotEmpty()) {
+ GlassTextButton(onClick = { if (pages.isNotEmpty()) { pages.removeAt(current.coerceAtMost(pages.lastIndex)); current = (current - 1).coerceAtLeast(0) } }, enabled = pages.isNotEmpty(), modifier = Modifier.weight(1f)) {
com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.Trash2, null, Modifier.size(18.dp), tint = com.chethan616.clearpdf.ui.theme.Candy.Tomato)
- Text(stringResource(R.string.common_delete), color = ink)
+ Text(stringResource(R.string.common_delete), color = ink, maxLines = 1, softWrap = false, overflow = TextOverflow.Ellipsis)
}
}
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/Common.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/Common.kt
index 7cb9aba..0932eae 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/Common.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/Common.kt
@@ -64,7 +64,7 @@ import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.clear
import com.chethan616.clearpdf.ui.theme.glowing
import com.chethan616.clearpdf.ui.viewer.formatSize
-import com.kyant.shapes.RoundedRectangle
+import com.chethan616.clearpdf.ui.glass.RoundedRectangle
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@@ -144,14 +144,7 @@ fun ScreenHeader(eyebrow: String?, title: String, modifier: Modifier = Modifier,
Column(modifier.fillMaxWidth().padding(start = 16.dp, end = 16.dp)) {
if (onBack != null) {
Row(Modifier.fillMaxWidth().padding(bottom = 18.dp), verticalAlignment = Alignment.CenterVertically) {
- // the same plain glass as every glass button (it was a dark, ringed disc). The screen
- // leaves a beat after the tap, so the glass is seen to swell and spring back first
- com.chethan616.clearpdf.ui.glass.HeaderGlassButton(
- onClick = com.chethan616.clearpdf.ui.glass.rememberBeat(onBack),
- label = stringResource(R.string.common_back),
- ) {
- GlassIcon(LucideIcons.ChevronLeft, null, Modifier.size(24.dp))
- }
+ com.chethan616.clearpdf.ui.glass.GlassBackButton(onBack)
Spacer(Modifier.weight(1f))
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) { trailing() }
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/FilesScreen.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/FilesScreen.kt
index f9cdafb..8cb22e1 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/FilesScreen.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/FilesScreen.kt
@@ -66,7 +66,7 @@ import com.chethan616.clearpdf.ui.home.dayBucket
import com.chethan616.clearpdf.ui.theme.Candy
import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.clear
-import com.kyant.shapes.Capsule
+import com.chethan616.clearpdf.ui.glass.Capsule
import kotlinx.coroutines.delay
/** At most this many rows share one panel, so a long folder isn't one giant item. */
@@ -128,7 +128,7 @@ fun FilesScreen(vm: AppViewModel, onBrowse: () -> Unit) {
com.chethan616.clearpdf.ui.glass.HeaderGlassButton(
onClick = { menuOpen = true }, label = stringResource(R.string.common_more_options),
modifier = Modifier.onGloballyPositioned { menuAnchor = it.boundsInWindow() },
- ) { GlassIcon(LucideIcons.Ellipsis, null, Modifier.size(22.dp)) }
+ ) { GlassIcon(LucideIcons.Ellipsis, null, Modifier.size(20.dp)) }
}
}
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/GlassMotionSettings.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/GlassMotionSettings.kt
index 4f6cd9d..47d87ce 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/GlassMotionSettings.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/GlassMotionSettings.kt
@@ -35,6 +35,17 @@ import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.foundation.layout.Box
+import com.chethan616.clearpdf.ui.glass.pressable
+import androidx.compose.material3.Icon
+import androidx.compose.foundation.layout.width
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.draw.drawBehind
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
+import androidx.compose.foundation.layout.heightIn
+import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
@@ -69,7 +80,7 @@ import com.chethan616.clearpdf.ui.LucideIcons
import com.chethan616.clearpdf.ui.theme.Candy
import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.clear
-import com.kyant.shapes.RoundedRectangle
+import com.chethan616.clearpdf.ui.glass.RoundedRectangle
import java.util.Locale
import kotlin.math.cos
import kotlin.math.exp
@@ -102,14 +113,10 @@ fun GlassMotionPage(onBack: () -> Unit) {
item(key = "glass") { Section(stringResource(R.string.gm_glass_look), custom = g !in GlassStyle.Presets) }
item(key = "glasstabs") {
- GlassTabs(
- glassPresetNames().mapIndexed { i, n -> GlassTab(n, accent = listOf(Candy.Sky, Candy.Mint, Candy.Grape, Candy.Tangerine)[i]) },
- selected = GlassStyle.Presets.indexOf(g).coerceAtLeast(0), onSelect = { glass(GlassStyle.Presets[it]) },
- modifier = Modifier.padding(horizontal = 16.dp).fillMaxWidth(), height = 48.dp,
- )
+ PresetTiles(glassPresetNames(), GlassStyle.Presets.indexOf(g), { glass(GlassStyle.Presets[it]) }) { i -> drawGlassSwatch(i) }
}
item(key = "glassvalues") {
- Panel {
+ FineTune {
SliderRow(stringResource(R.string.gm_blur), g.blur, 0f..3f, Candy.Sky) { glass(g.copy(blur = it)) }
SliderRow(stringResource(R.string.gm_lens_height), g.refractionHeight, 0f..2.5f, Candy.Grape) { glass(g.copy(refractionHeight = it)) }
SliderRow(stringResource(R.string.gm_lens_amount), g.refractionAmount, 0f..2.5f, Candy.Grape) { glass(g.copy(refractionAmount = it)) }
@@ -124,17 +131,13 @@ fun GlassMotionPage(onBack: () -> Unit) {
item(key = "motion") { Section(stringResource(R.string.settings_motion), custom = m !in MotionStyle.Presets) }
item(key = "motiontabs") {
- GlassTabs(
- motionPresetNames().mapIndexed { i, n -> GlassTab(n, accent = listOf(Candy.Mint, Candy.Sky, Candy.Bubblegum, Candy.Tomato)[i]) },
- selected = MotionStyle.Presets.indexOf(m).coerceAtLeast(0), onSelect = { motion(MotionStyle.Presets[it]) },
- modifier = Modifier.padding(horizontal = 16.dp).fillMaxWidth(), height = 48.dp,
- )
+ PresetTiles(motionPresetNames(), MotionStyle.Presets.indexOf(m), { motion(MotionStyle.Presets[it]) }) { i -> drawSpringSwatch(MotionStyle.Presets[i].bounce) }
}
item(key = "spring") {
GraphCard(stringResource(R.string.gm_spring), stringResource(R.string.gm_spring_body)) { SpringGraph() }
}
item(key = "motionvalues") {
- Panel {
+ FineTune {
SliderRow(stringResource(R.string.gm_bounce), m.bounce, 0f..1f, Candy.Bubblegum) { motion(m.copy(bounce = it)) }
SliderRow(stringResource(R.string.gm_speed), m.speed, 0.4f..2.5f, Candy.Sky, times) { motion(m.copy(speed = it)) }
SliderRow(stringResource(R.string.gm_press), m.press, 0f..2.5f, Candy.Grape, times) { motion(m.copy(press = it)) }
@@ -168,13 +171,14 @@ fun GlassMotionPage(onBack: () -> Unit) {
}
}
item(key = "reset") {
- Row(Modifier.fillMaxWidth().padding(16.dp), horizontalArrangement = Arrangement.Center) {
- GlassPill(onClick = {
+ Spacer(Modifier.height(18.dp))
+ Panel {
+ SettingRow(LucideIcons.RotateCcw, Candy.Tomato, stringResource(R.string.gm_reset), {
glass(GlassStyle.Default)
motion(MotionStyle.Default)
MotionSettings.updateCurve(context, EaseCurve.Drawer)
MotionSettings.updateDuration(context, 1f)
- }) { Text(stringResource(R.string.gm_reset), style = ClearType.BodyStrong, color = clear.ink) }
+ }, first = true)
}
}
item { Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars)) }
@@ -223,6 +227,122 @@ private fun PreviewStage() {
}
}
+/**
+ * Four presets as tiles, each with a little picture of itself ([swatch]): the chosen one ringed and
+ * ticked. A hand-tuned style chooses none.
+ */
+@Composable
+private fun PresetTiles(names: List<String>, selected: Int, onSelect: (Int) -> Unit, swatch: androidx.compose.ui.graphics.drawscope.DrawScope.(Int) -> Unit) {
+ val c = clear
+ Row(Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 4.dp), horizontalArrangement = Arrangement.spacedBy(10.dp)) {
+ names.forEachIndexed { i, name ->
+ val on = i == selected
+ Column(
+ Modifier.weight(1f).pressable({ onSelect(i) }, pressedScale = 0.94f),
+ horizontalAlignment = Alignment.CenterHorizontally,
+ ) {
+ Box(
+ Modifier.fillMaxWidth().aspectRatio(1f)
+ .border(if (on) 2.5.dp else 1.dp, if (on) Candy.Sky else c.ink.copy(alpha = 0.12f), RoundedRectangle(18.dp))
+ .padding(4.dp)
+ .clip(RoundedRectangle(14.dp))
+ .drawBehind { swatch(i) },
+ ) {
+ if (on) Box(
+ Modifier.align(Alignment.BottomEnd).padding(5.dp).size(18.dp).clip(androidx.compose.foundation.shape.CircleShape).background(Candy.Sky),
+ contentAlignment = Alignment.Center,
+ ) { Icon(LucideIcons.Check, null, tint = Color.White, modifier = Modifier.size(12.dp)) }
+ }
+ Spacer(Modifier.height(6.dp))
+ Text(name, style = if (on) ClearType.BodyStrong else ClearType.Label, color = if (on) c.ink else c.inkSoft, maxLines = 1)
+ }
+ }
+ }
+}
+
+/** A glass preset in miniature: candy stripes behind a disc of that glass. */
+private fun androidx.compose.ui.graphics.drawscope.DrawScope.drawGlassSwatch(i: Int) {
+ val stripes = listOf(Candy.Sky, Candy.Bubblegum, Candy.Lemon, Candy.Mint)
+ val band = size.width / 6f
+ for (k in -2..8) {
+ val x = k * band
+ drawPath(
+ androidx.compose.ui.graphics.Path().apply { moveTo(x, 0f); lineTo(x + band, 0f); lineTo(x + band - size.height, size.height); lineTo(x - size.height, size.height); close() },
+ stripes[(k + 8) % stripes.size],
+ )
+ }
+ val center = androidx.compose.ui.geometry.Offset(size.width / 2f, size.height / 2f)
+ val r = size.minDimension * 0.34f
+ val (fill, rim) = when (i) {
+ 1 -> Color.White.copy(alpha = 0.62f) to 0.9f // frosted
+ 2 -> Color.White.copy(alpha = 0.10f) to 1f // crystal
+ 3 -> Color(0xFFEDEAF7).copy(alpha = 0.85f) to 0f // lite
+ else -> Color.White.copy(alpha = 0.28f) to 0.8f // clear
+ }
+ drawCircle(fill, r, center)
+ if (i == 2) {
+ drawCircle(
+ androidx.compose.ui.graphics.Brush.sweepGradient(listOf(Color(0xFFFF6B9A), Color(0xFFFFD84D), Color(0xFF5BE3B0), Color(0xFF5AA9FF), Color(0xFFB36BFF), Color(0xFFFF6B9A)), center),
+ r, center, style = androidx.compose.ui.graphics.drawscope.Stroke(2.5.dp.toPx()),
+ )
+ } else if (rim > 0f) {
+ drawCircle(Color.White.copy(alpha = rim), r, center, style = androidx.compose.ui.graphics.drawscope.Stroke(1.5.dp.toPx()))
+ }
+}
+
+/** A motion preset in miniature: its spring's swing from start to rest. */
+private fun androidx.compose.ui.graphics.drawscope.DrawScope.drawSpringSwatch(bounce: Float) {
+ drawRect(androidx.compose.ui.graphics.Brush.verticalGradient(listOf(Color(0xFF2A2350), Color(0xFF1A1636))))
+ val damping = (1f - bounce).coerceIn(0.12f, 1f)
+ val w = size.width
+ val h = size.height
+ val rest = h * 0.32f
+ val start = h * 0.82f
+ drawLine(Color.White.copy(alpha = 0.18f), androidx.compose.ui.geometry.Offset(w * 0.08f, rest), androidx.compose.ui.geometry.Offset(w * 0.92f, rest), 1.dp.toPx())
+ val path = androidx.compose.ui.graphics.Path()
+ val omega = 14f
+ for (k in 0..60) {
+ val t = k / 60f
+ val x = w * 0.08f + t * w * 0.84f
+ val d = damping
+ val v = if (d >= 1f) 1f - (1f + omega * t) * kotlin.math.exp(-omega * t)
+ else {
+ val wd = omega * kotlin.math.sqrt(1f - d * d)
+ 1f - kotlin.math.exp(-d * omega * t) * (kotlin.math.cos(wd * t) + d * omega / wd * kotlin.math.sin(wd * t))
+ }
+ val y = start + (rest - start) * v
+ if (k == 0) path.moveTo(x, y) else path.lineTo(x, y)
+ }
+ drawPath(path, Candy.Bubblegum, style = androidx.compose.ui.graphics.drawscope.Stroke(2.5.dp.toPx(), cap = androidx.compose.ui.graphics.StrokeCap.Round))
+}
+
+/** Fine-tuning folded away under one row, so the page leads with the presets. */
+@Composable
+private fun FineTune(content: @Composable androidx.compose.foundation.layout.ColumnScope.() -> Unit) {
+ val c = clear
+ var open by remember { mutableStateOf(false) }
+ val turn by androidx.compose.animation.core.animateFloatAsState(if (open) 180f else 0f, com.chethan616.clearpdf.ui.glass.GlassMotion.settle(), label = "fine")
+ Spacer(Modifier.height(8.dp))
+ Panel {
+ Row(
+ Modifier.fillMaxWidth().pressable({ open = !open }).heightIn(min = 52.dp).padding(horizontal = 16.dp, vertical = 8.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Box(Modifier.size(30.dp).clip(RoundedRectangle(8.dp)).background(Candy.Grape), contentAlignment = Alignment.Center) {
+ Icon(LucideIcons.SlidersHorizontal, null, tint = Color.White, modifier = Modifier.size(17.dp))
+ }
+ Spacer(Modifier.width(14.dp))
+ Text(stringResource(R.string.gm_fine_tune), style = ClearType.Body, color = c.ink, modifier = Modifier.weight(1f))
+ Icon(LucideIcons.ChevronDown, null, tint = c.inkFaint, modifier = Modifier.size(18.dp).graphicsLayer { rotationZ = turn })
+ }
+ androidx.compose.animation.AnimatedVisibility(
+ open,
+ enter = androidx.compose.animation.expandVertically(com.chethan616.clearpdf.ui.glass.GlassMotion.settle()) + androidx.compose.animation.fadeIn(),
+ exit = androidx.compose.animation.shrinkVertically(com.chethan616.clearpdf.ui.glass.GlassMotion.settle()) + androidx.compose.animation.fadeOut(),
+ ) { Column { content() } }
+ }
+}
+
/** A setting's name and value above its glass slider. */
@Composable
private fun SliderRow(
@@ -236,7 +356,7 @@ private fun SliderRow(
val c = clear
Column(Modifier.fillMaxWidth().padding(horizontal = 18.dp, vertical = 8.dp)) {
Row(verticalAlignment = Alignment.CenterVertically) {
- Text(label, style = ClearType.BodyStrong, color = c.ink, modifier = Modifier.weight(1f))
+ Text(label, style = ClearType.Body, color = c.ink, modifier = Modifier.weight(1f))
Text(format(value), style = ClearType.Label.copy(fontFamily = FontFamily.Monospace), color = c.inkSoft)
}
Spacer(Modifier.height(6.dp))
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/SettingsScreen.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/SettingsScreen.kt
index a71668b..57fd353 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/SettingsScreen.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/SettingsScreen.kt
@@ -31,6 +31,18 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import kotlinx.coroutines.launch
+import androidx.compose.foundation.border
+import androidx.compose.ui.graphics.drawscope.clipPath
+import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.foundation.layout.aspectRatio
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.widthIn
+import androidx.compose.foundation.layout.heightIn
+import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
@@ -66,7 +78,7 @@ import com.chethan616.clearpdf.ui.glass.pressable
import com.chethan616.clearpdf.ui.theme.Candy
import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.clear
-import com.kyant.shapes.RoundedRectangle
+import com.chethan616.clearpdf.ui.glass.RoundedRectangle
/** Artefact's repository: help, issues and source. */
const val CLEARPDF_REPO = "https://github.com/Chethan616/ClearPDF"
@@ -109,50 +121,28 @@ private fun SettingsRoot(vm: AppViewModel, openLicences: () -> Unit, openGlass:
Spacer(Modifier.height(14.dp))
ScreenHeader(null, stringResource(R.string.home_settings), onBack = { vm.settingsOpen = false })
}
- item(key = "hero") { AppCard(vm) }
+ // what people change most comes first: how the app looks and feels
item(key = "look") { Section(stringResource(R.string.settings_look)) }
- item(key = "theme") {
- Choice(stringResource(R.string.settings_theme)) {
- val options = listOf(ThemeChoice.System, ThemeChoice.Light, ThemeChoice.Dark)
- GlassTabs(
- listOf(
- GlassTab(stringResource(R.string.settings_theme_system), LucideIcons.Contrast, Candy.Grape),
- GlassTab(stringResource(R.string.settings_theme_light), LucideIcons.Sun, Candy.Tangerine),
- GlassTab(stringResource(R.string.settings_theme_dark), LucideIcons.Moon, Candy.Sky),
- ),
- selected = options.indexOf(vm.theme).coerceAtLeast(0), onSelect = { vm.setThemeChoice(options[it]) },
- modifier = Modifier.fillMaxWidth(), height = 64.dp,
- )
- }
- }
- item(key = "glassmotion") {
- // everything about the glass and how it moves lives on a page of its own
+ item(key = "lookpanel") {
val custom = stringResource(R.string.settings_custom)
val glassName = GlassStyle.Presets.indexOf(GlassSettings.style).let { if (it < 0) custom else glassPresetNames()[it] }
val motionName = MotionStyle.Presets.indexOf(MotionSettings.style).let { if (it < 0) custom else motionPresetNames()[it] }
Panel {
- GlassRow(
- stringResource(R.string.settings_glass_motion), openGlass, icon = LucideIcons.Sparkles, accent = Candy.Grape,
- value = "$glassName · $motionName",
- trailing = { Icon(LucideIcons.ChevronRight, null, tint = c.inkFaint, modifier = Modifier.padding(start = 4.dp).size(18.dp)) },
- )
+ ThemePicker(vm.theme) { vm.setThemeChoice(it) }
+ SettingRow(LucideIcons.Sparkles, Candy.Grape, stringResource(R.string.settings_glass_motion), openGlass, value = "$glassName · $motionName", chevron = true)
+ ToggleRow(LucideIcons.Smartphone, Candy.Bubblegum, stringResource(R.string.settings_haptics), null, GlassSettings.haptics) { GlassSettings.updateHaptics(context, it) }
}
}
- item(key = "general") { Section(stringResource(R.string.settings_general)) }
- item(key = "feel") {
- Panel {
- ToggleRow(LucideIcons.Sparkles, Candy.Bubblegum, stringResource(R.string.settings_haptics), null, GlassSettings.haptics) { GlassSettings.updateHaptics(context, it) }
- GlassRow(stringResource(R.string.settings_show_welcome), { vm.showWelcomeAgain() }, icon = LucideIcons.Compass, accent = Candy.Sky)
- }
- }
+ item(key = "personal") { Section(stringResource(R.string.settings_personalization)) }
+ item(key = "personalpanel") { Panel { WallpaperPicker(context) } }
item(key = "reading") { Section(stringResource(R.string.settings_reading)) }
item(key = "readingpanel") {
Panel {
- ToggleRow(LucideIcons.PanelsTopLeft, Candy.Sky, stringResource(R.string.settings_quick_preview), stringResource(R.string.settings_quick_preview_body), vm.quickPreview) { vm.updateQuickPreview(it) }
- ToggleRow(LucideIcons.Sun, Candy.Lemon, stringResource(R.string.home_keep_screen_on), stringResource(R.string.home_keep_screen_on_body), vm.keepScreenOn) { vm.updateKeepScreenOn(it) }
+ ToggleRow(LucideIcons.PanelsTopLeft, Candy.Sky, stringResource(R.string.settings_quick_preview), stringResource(R.string.settings_quick_preview_body), vm.quickPreview, first = true) { vm.updateQuickPreview(it) }
+ ToggleRow(LucideIcons.Sun, Candy.Tangerine, stringResource(R.string.home_keep_screen_on), stringResource(R.string.home_keep_screen_on_body), vm.keepScreenOn) { vm.updateKeepScreenOn(it) }
ToggleRow(LucideIcons.Smartphone, Candy.Sky, stringResource(R.string.home_status_bar_in_documents), stringResource(R.string.home_status_bar_in_documents_body), vm.statusBarInDocuments) { vm.updateStatusBarInDocuments(it) }
ToggleRow(LucideIcons.Hash, Candy.Mint, stringResource(R.string.home_search_count), stringResource(R.string.home_search_count_body), vm.searchCount) { vm.updateSearchCount(it) }
ToggleRow(LucideIcons.SquareTerminal, Candy.Grape, stringResource(R.string.home_keyboard_shortcuts), stringResource(R.string.home_keyboard_shortcuts_body), vm.keyboardShortcuts) { vm.updateKeyboardShortcuts(it) }
@@ -162,34 +152,26 @@ private fun SettingsRoot(vm: AppViewModel, openLicences: () -> Unit, openGlass:
item(key = "forms") { Section(stringResource(R.string.settings_forms)) }
item(key = "formspanel") {
Panel {
- ToggleRow(LucideIcons.TextCursorInput, Candy.Tangerine, stringResource(R.string.home_offer_suggestions), null, vm.formSuggestions) { vm.updateFormSuggestions(it) }
- GlassRow(stringResource(R.string.home_clear_suggestions), { vm.clearFormSuggestions() }, icon = LucideIcons.BrushCleaning, accent = Candy.Tomato)
- GlassRow(
- stringResource(R.string.home_author_title), { authorDialog = true }, icon = LucideIcons.UserRound, accent = Candy.Sky,
- value = vm.toolPrefs.author.ifBlank { stringResource(R.string.home_author_hint) },
+ SettingRow(
+ LucideIcons.UserRound, Candy.Sky, stringResource(R.string.home_author_title), { authorDialog = true },
+ value = vm.toolPrefs.author.ifBlank { stringResource(R.string.home_author_hint) }, chevron = true, first = true,
)
+ ToggleRow(LucideIcons.TextCursorInput, Candy.Tangerine, stringResource(R.string.home_offer_suggestions), null, vm.formSuggestions) { vm.updateFormSuggestions(it) }
+ SettingRow(LucideIcons.BrushCleaning, Candy.Tomato, stringResource(R.string.home_clear_suggestions), { vm.clearFormSuggestions() })
}
}
item(key = "about") { Section(stringResource(R.string.settings_about)) }
item(key = "aboutpanel") {
Panel {
- GlassRow(stringResource(R.string.home_report_problem), { leaving = "$CLEARPDF_REPO/issues" }, icon = LucideIcons.MessageSquare, accent = Candy.Tomato)
- GlassRow(stringResource(R.string.home_source_code), { uri.openUri(CLEARPDF_REPO) }, icon = LucideIcons.CodeXml, accent = Candy.Grape)
- GlassRow(stringResource(R.string.home_engine), { uri.openUri("https://github.com/storytold/pdfcraft") }, icon = LucideIcons.Wrench, accent = Candy.Tangerine)
- GlassRow(stringResource(R.string.home_licences), openLicences, icon = LucideIcons.ScrollText, accent = Candy.Mint)
- }
- }
- item(key = "credits") {
- // a footnote, as iOS ends its settings: no card of its own
- Column(Modifier.padding(start = 26.dp, end = 26.dp, top = 18.dp)) {
- Text(stringResource(R.string.settings_credits_title), style = ClearType.BodyStrong, color = c.inkSoft)
- Spacer(Modifier.height(4.dp))
- Text(stringResource(R.string.settings_credits_body), style = ClearType.Caption, color = c.inkSoft)
- Spacer(Modifier.height(10.dp))
- Text(stringResource(R.string.home_legal_notice), style = ClearType.Caption, color = c.inkFaint)
+ SettingRow(LucideIcons.Compass, Candy.Sky, stringResource(R.string.settings_show_welcome), { vm.showWelcomeAgain() }, first = true)
+ SettingRow(LucideIcons.MessageSquare, Candy.Tomato, stringResource(R.string.home_report_problem), { leaving = "$CLEARPDF_REPO/issues" }, chevron = true)
+ SettingRow(LucideIcons.CodeXml, Candy.Grape, stringResource(R.string.home_source_code), { uri.openUri(CLEARPDF_REPO) }, chevron = true)
+ SettingRow(LucideIcons.Wrench, Candy.Tangerine, stringResource(R.string.home_engine), { uri.openUri("https://github.com/storytold/pdfcraft") }, chevron = true)
+ SettingRow(LucideIcons.ScrollText, Candy.Mint, stringResource(R.string.home_licences), openLicences, chevron = true)
}
}
+ item(key = "credits") { AppFooter(vm) }
item { Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars)) }
}
leaving?.let { url ->
@@ -208,36 +190,35 @@ private fun SettingsRoot(vm: AppViewModel, openLicences: () -> Unit, openGlass:
}
}
-/** The app's own card: its icon, its name, the version (long-press copies it). */
+/** The settings' foot: the mark, name and version (a long press copies it), the credits and notice. */
@Composable
-private fun AppCard(vm: AppViewModel) {
+private fun AppFooter(vm: AppViewModel) {
val c = clear
val clipboard = LocalClipboardManager.current
val version = stringResource(R.string.home_version, vm.appVersion, com.chethan616.clearpdf.core.engineVersion())
val copied = stringResource(R.string.home_version_copied)
- GlassCard(
- Modifier.padding(horizontal = 16.dp, vertical = 16.dp).fillMaxWidth()
+ Column(
+ Modifier.fillMaxWidth().padding(start = 32.dp, end = 32.dp, top = 28.dp)
.pointerInput(version) { detectTapGestures(onLongPress = { clipboard.setText(AnnotatedString(version)); vm.tell(copied) }) },
- shape = RoundedRectangle(30.dp),
+ horizontalAlignment = Alignment.CenterHorizontally,
) {
- Row(Modifier.padding(18.dp), verticalAlignment = Alignment.CenterVertically) {
- Image(painterResource(R.drawable.artefact_logo), null, Modifier.size(64.dp))
- Spacer(Modifier.width(16.dp))
- Column {
- Text(stringResource(R.string.app_name), style = ClearType.Headline, color = c.ink)
- Spacer(Modifier.height(2.dp))
- Text(version, style = ClearType.Caption, color = c.inkSoft)
- }
- }
+ Image(painterResource(R.drawable.artefact_logo), null, Modifier.size(44.dp))
+ Spacer(Modifier.height(8.dp))
+ Text(stringResource(R.string.app_name), style = ClearType.BodyStrong, color = c.ink)
+ Text(version, style = ClearType.Caption, color = c.inkSoft)
+ Spacer(Modifier.height(14.dp))
+ Text(stringResource(R.string.settings_credits_body), style = ClearType.Caption, color = c.inkSoft, textAlign = androidx.compose.ui.text.style.TextAlign.Center)
+ Spacer(Modifier.height(8.dp))
+ Text(stringResource(R.string.home_legal_notice), style = ClearType.Caption, color = c.inkFaint, textAlign = androidx.compose.ui.text.style.TextAlign.Center)
}
}
/** A group's name, small and quiet over its panel (as iOS's grouped settings), "Custom" when tuned by hand. */
@Composable
internal fun Section(title: String, custom: Boolean = false) {
- Row(Modifier.fillMaxWidth().padding(start = 26.dp, end = 26.dp, top = 26.dp, bottom = 8.dp), verticalAlignment = Alignment.CenterVertically) {
+ Row(Modifier.fillMaxWidth().padding(start = 34.dp, end = 34.dp, top = 24.dp, bottom = 6.dp), verticalAlignment = Alignment.CenterVertically) {
Text(title.uppercase(), style = ClearType.Eyebrow, color = clear.inkSoft, modifier = Modifier.weight(1f))
- if (custom) Text(stringResource(R.string.settings_custom), style = ClearType.Label, color = Candy.Bubblegum)
+ if (custom) Text(stringResource(R.string.settings_custom), style = ClearType.Label, color = clear.inkSoft)
}
}
@@ -252,31 +233,200 @@ private fun Choice(label: String, content: @Composable () -> Unit) {
@Composable
internal fun Panel(content: @Composable ColumnScope.() -> Unit) {
- WashPanel(Modifier.padding(horizontal = 16.dp, vertical = 4.dp).fillMaxWidth()) {
- Spacer(Modifier.height(6.dp))
+ WashPanel(Modifier.padding(horizontal = 16.dp, vertical = 2.dp).fillMaxWidth(), shape = RoundedRectangle(22.dp)) {
+ Spacer(Modifier.height(4.dp))
content()
- Spacer(Modifier.height(6.dp))
+ Spacer(Modifier.height(4.dp))
+ }
+}
+
+/**
+ * The theme as three little desks to pick from: the light one, the dark one, and System split
+ * corner to corner between them. The chosen one is ringed and ticked, and lifts a touch.
+ */
+@Composable
+private fun ThemePicker(current: ThemeChoice, onPick: (ThemeChoice) -> Unit) {
+ val c = clear
+ val choices = listOf(
+ ThemeChoice.System to stringResource(R.string.settings_theme_system),
+ ThemeChoice.Light to stringResource(R.string.settings_theme_light),
+ ThemeChoice.Dark to stringResource(R.string.settings_theme_dark),
+ )
+ Row(Modifier.fillMaxWidth().padding(start = 14.dp, end = 14.dp, top = 12.dp, bottom = 10.dp), horizontalArrangement = Arrangement.spacedBy(12.dp)) {
+ choices.forEach { (choice, label) ->
+ val on = choice == current
+ val lift by androidx.compose.animation.core.animateFloatAsState(if (on) 1f else 0f, com.chethan616.clearpdf.ui.glass.GlassMotion.pop(), label = "theme")
+ Column(
+ Modifier.weight(1f).pressable({ onPick(choice) }, pressedScale = 0.94f).semantics { contentDescription = label },
+ horizontalAlignment = Alignment.CenterHorizontally,
+ ) {
+ Box(
+ Modifier.fillMaxWidth().aspectRatio(0.78f)
+ .graphicsLayer { val s = 0.96f + 0.04f * lift; scaleX = s; scaleY = s }
+ .border(if (on) 2.5.dp else 1.dp, if (on) Candy.Sky else c.ink.copy(alpha = 0.12f), RoundedRectangle(18.dp))
+ .padding(4.dp)
+ .clip(RoundedRectangle(14.dp))
+ .drawBehind { drawThemeDesk(choice) },
+ ) {
+ if (on) Box(
+ Modifier.align(Alignment.BottomEnd).padding(6.dp).size(20.dp).clip(CircleShape).background(Candy.Sky),
+ contentAlignment = Alignment.Center,
+ ) { Icon(LucideIcons.Check, null, tint = Color.White, modifier = Modifier.size(13.dp)) }
+ }
+ Spacer(Modifier.height(8.dp))
+ Text(label, style = if (on) ClearType.BodyStrong else ClearType.Body, color = if (on) c.ink else c.inkSoft, maxLines = 1)
+ }
+ }
+ }
+}
+
+/**
+ * The wallpaper: Aurora (Artefact's own), Liquid (the old ClearPDF's) and a picture from the gallery,
+ * each a thumbnail, the chosen one ringed and ticked like the theme's. Custom picks a new picture
+ * every time it is tapped.
+ */
+@Composable
+private fun WallpaperPicker(context: android.content.Context) {
+ val c = clear
+ val scope = androidx.compose.runtime.rememberCoroutineScope()
+ val current = GlassSettings.wallpaper
+ val custom = GlassSettings.customWallpaper
+ val failed = stringResource(R.string.settings_wallpaper_failed)
+ val pick = androidx.activity.compose.rememberLauncherForActivityResult(androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia()) { uri ->
+ if (uri != null) scope.launch {
+ if (!GlassSettings.setCustomWallpaper(context, uri)) android.widget.Toast.makeText(context, failed, android.widget.Toast.LENGTH_SHORT).show()
+ }
}
+ val choices = listOf(
+ com.chethan616.clearpdf.ui.glass.Wallpaper.Aurora to stringResource(R.string.settings_wallpaper_aurora),
+ com.chethan616.clearpdf.ui.glass.Wallpaper.Liquid to stringResource(R.string.settings_wallpaper_liquid),
+ com.chethan616.clearpdf.ui.glass.Wallpaper.Custom to stringResource(R.string.settings_wallpaper_custom),
+ )
+ Text(stringResource(R.string.settings_wallpaper), style = ClearType.Label, color = c.inkSoft, modifier = Modifier.padding(start = 18.dp, top = 10.dp))
+ Row(Modifier.fillMaxWidth().padding(start = 14.dp, end = 14.dp, top = 8.dp, bottom = 12.dp), horizontalArrangement = Arrangement.spacedBy(10.dp)) {
+ choices.forEach { (w, label) ->
+ val on = w == current
+ val tap = {
+ if (w == com.chethan616.clearpdf.ui.glass.Wallpaper.Custom) {
+ pick.launch(androidx.activity.result.PickVisualMediaRequest(androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia.ImageOnly))
+ } else GlassSettings.updateWallpaper(context, w)
+ }
+ Column(Modifier.weight(1f).pressable(tap, pressedScale = 0.94f).semantics { contentDescription = label }, horizontalAlignment = Alignment.CenterHorizontally) {
+ Box(
+ Modifier.fillMaxWidth().aspectRatio(0.62f)
+ .border(if (on) 2.5.dp else 1.dp, if (on) Candy.Sky else c.ink.copy(alpha = 0.12f), RoundedRectangle(18.dp))
+ .padding(4.dp).clip(RoundedRectangle(14.dp)),
+ ) {
+ when (w) {
+ com.chethan616.clearpdf.ui.glass.Wallpaper.Liquid ->
+ Image(painterResource(if (c.dark) R.drawable.wallpaper_liquid_dark else R.drawable.wallpaper_liquid_light), null, Modifier.fillMaxSize(), contentScale = androidx.compose.ui.layout.ContentScale.Crop)
+ com.chethan616.clearpdf.ui.glass.Wallpaper.Custom ->
+ if (custom != null) Image(custom, null, Modifier.fillMaxSize(), contentScale = androidx.compose.ui.layout.ContentScale.Crop)
+ else Box(Modifier.fillMaxSize().background(c.ink.copy(alpha = 0.06f)), contentAlignment = Alignment.Center) {
+ Icon(LucideIcons.ImagePlus, null, tint = c.inkSoft, modifier = Modifier.size(26.dp))
+ }
+ else -> Box(Modifier.fillMaxSize().drawBehind {
+ drawRect(androidx.compose.ui.graphics.Brush.verticalGradient(if (c.dark) listOf(Color(0xFF231A3D), Color(0xFF15122A)) else listOf(Color(0xFFDCD8F6), Color(0xFFC9C4EE))))
+ drawCircle(androidx.compose.ui.graphics.Brush.radialGradient(listOf(Color(0xFFB36BFF).copy(alpha = 0.55f), Color.Transparent), androidx.compose.ui.geometry.Offset(size.width * 0.8f, size.height * 0.2f), size.width * 0.7f), size.width * 0.7f, androidx.compose.ui.geometry.Offset(size.width * 0.8f, size.height * 0.2f))
+ drawCircle(androidx.compose.ui.graphics.Brush.radialGradient(listOf(Color(0xFF5AA9FF).copy(alpha = 0.45f), Color.Transparent), androidx.compose.ui.geometry.Offset(size.width * 0.15f, size.height * 0.85f), size.width * 0.7f), size.width * 0.7f, androidx.compose.ui.geometry.Offset(size.width * 0.15f, size.height * 0.85f))
+ })
+ }
+ if (on) Box(
+ Modifier.align(Alignment.BottomEnd).padding(6.dp).size(20.dp).clip(CircleShape).background(Candy.Sky),
+ contentAlignment = Alignment.Center,
+ ) { Icon(LucideIcons.Check, null, tint = Color.White, modifier = Modifier.size(13.dp)) }
+ else if (w == com.chethan616.clearpdf.ui.glass.Wallpaper.Custom && custom != null) Box(
+ Modifier.align(Alignment.BottomEnd).padding(6.dp).size(22.dp).clip(CircleShape).background(Color.Black.copy(alpha = 0.45f)),
+ contentAlignment = Alignment.Center,
+ ) { Icon(LucideIcons.Pencil, null, tint = Color.White, modifier = Modifier.size(13.dp)) }
+ }
+ Spacer(Modifier.height(8.dp))
+ Text(label, style = if (on) ClearType.BodyStrong else ClearType.Body, color = if (on) c.ink else c.inkSoft, maxLines = 1)
+ }
+ }
+ }
+}
+
+/** A tiny desk in a theme's colours: its sky, a bloom, two cards and the dock. */
+private fun androidx.compose.ui.graphics.drawscope.DrawScope.drawThemeDesk(choice: ThemeChoice) {
+ fun desk(dark: Boolean) {
+ val sky = if (dark) listOf(Color(0xFF231A3D), Color(0xFF15122A)) else listOf(Color(0xFFDCD8F6), Color(0xFFC9C4EE))
+ drawRect(androidx.compose.ui.graphics.Brush.verticalGradient(sky))
+ drawCircle(
+ androidx.compose.ui.graphics.Brush.radialGradient(listOf((if (dark) Color(0xFF7B4DDB) else Color(0xFFF2B8E4)).copy(alpha = 0.7f), Color.Transparent), androidx.compose.ui.geometry.Offset(size.width * 0.85f, size.height * 0.15f), size.width * 0.8f),
+ size.width * 0.8f, androidx.compose.ui.geometry.Offset(size.width * 0.85f, size.height * 0.15f),
+ )
+ val ink = if (dark) Color.White else Color(0xFF1C1733)
+ val w = size.width
+ val h = size.height
+ drawRoundRect(ink.copy(alpha = 0.85f), androidx.compose.ui.geometry.Offset(w * 0.12f, h * 0.12f), androidx.compose.ui.geometry.Size(w * 0.5f, h * 0.06f), androidx.compose.ui.geometry.CornerRadius(h * 0.03f))
+ val card1 = if (dark) Color(0xFF3B6E5A) else Color(0xFFBFE8D2)
+ val card2 = if (dark) Color(0xFF4A3F86) else Color(0xFFFFFFFF)
+ drawRoundRect(card1, androidx.compose.ui.geometry.Offset(w * 0.1f, h * 0.27f), androidx.compose.ui.geometry.Size(w * 0.38f, h * 0.4f), androidx.compose.ui.geometry.CornerRadius(w * 0.08f))
+ drawRoundRect(card2, androidx.compose.ui.geometry.Offset(w * 0.52f, h * 0.27f), androidx.compose.ui.geometry.Size(w * 0.38f, h * 0.3f), androidx.compose.ui.geometry.CornerRadius(w * 0.08f))
+ drawRoundRect(ink.copy(alpha = if (dark) 0.22f else 0.12f), androidx.compose.ui.geometry.Offset(w * 0.3f, h * 0.8f), androidx.compose.ui.geometry.Size(w * 0.4f, h * 0.1f), androidx.compose.ui.geometry.CornerRadius(h * 0.05f))
+ drawCircle(Color.White, h * 0.035f, androidx.compose.ui.geometry.Offset(w * 0.42f, h * 0.85f))
+ }
+ when (choice) {
+ ThemeChoice.Light -> desk(false)
+ ThemeChoice.Dark -> desk(true)
+ else -> {
+ desk(false)
+ val half = androidx.compose.ui.graphics.Path().apply { moveTo(size.width, 0f); lineTo(size.width, size.height); lineTo(0f, size.height); close() }
+ clipPath(half) { desk(true) }
+ }
+ }
+}
+
+/** A setting's icon: a small solid tile with a white glyph, as grouped settings draw them. */
+@Composable
+private fun SettingIcon(icon: ImageVector, accent: Color) {
+ Box(Modifier.size(30.dp).clip(RoundedRectangle(8.dp)).background(accent), contentAlignment = Alignment.Center) {
+ Icon(icon, null, tint = Color.White, modifier = Modifier.size(17.dp))
+ }
+}
+
+/** A hairline between rows of a panel, starting where the words do. */
+private fun Modifier.rowDivider(show: Boolean, color: Color): Modifier = if (!show) this else drawBehind {
+ val x = 60.dp.toPx()
+ drawRect(color, androidx.compose.ui.geometry.Offset(x, 0f), androidx.compose.ui.geometry.Size(size.width - x, 0.6.dp.toPx()))
}
-/** A switch row: a candy blob, the setting's name and what it does, and a glass toggle. */
+/** A row of a settings panel: icon, name, then a value and a chevron when it opens something. */
@Composable
-internal fun ToggleRow(icon: ImageVector, accent: Color, label: String, body: String?, checked: Boolean, onChange: (Boolean) -> Unit) {
+internal fun SettingRow(icon: ImageVector, accent: Color, label: String, onClick: () -> Unit, value: String? = null, chevron: Boolean = false, first: Boolean = false) {
val c = clear
Row(
- Modifier.fillMaxWidth().pressable({ onChange(!checked) }).padding(horizontal = 18.dp, vertical = 10.dp),
+ Modifier.fillMaxWidth().rowDivider(!first, c.ink.copy(alpha = 0.08f)).pressable(onClick).heightIn(min = 52.dp).padding(horizontal = 16.dp, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
- Box(Modifier.size(34.dp).clip(RoundedRectangle(11.dp)).background(accent.copy(alpha = if (c.dark) 0.26f else 0.16f)), contentAlignment = Alignment.Center) {
- Icon(icon, null, tint = accent, modifier = Modifier.size(19.dp))
+ SettingIcon(icon, accent)
+ Spacer(Modifier.width(14.dp))
+ // the value under the name, as a subtitle, so neither is ever cut short
+ Column(Modifier.weight(1f)) {
+ Text(label, style = ClearType.Body, color = c.ink, maxLines = 2, overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis)
+ if (value != null) Text(value, style = ClearType.Caption, color = c.inkSoft, maxLines = 1, overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis)
}
+ if (chevron) Icon(LucideIcons.ChevronRight, null, tint = c.inkFaint, modifier = Modifier.padding(start = 4.dp).size(16.dp))
+ }
+}
+
+/** A switch row: icon, the setting's name and (smaller) what it does, and a glass toggle. */
+@Composable
+internal fun ToggleRow(icon: ImageVector, accent: Color, label: String, body: String?, checked: Boolean, first: Boolean = false, onChange: (Boolean) -> Unit) {
+ val c = clear
+ Row(
+ Modifier.fillMaxWidth().rowDivider(!first, c.ink.copy(alpha = 0.08f)).pressable({ onChange(!checked) }).heightIn(min = 52.dp).padding(horizontal = 16.dp, vertical = 8.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ SettingIcon(icon, accent)
Spacer(Modifier.width(14.dp))
Column(Modifier.weight(1f)) {
- Text(label, style = ClearType.BodyStrong, color = c.ink)
- if (body != null) Text(body, style = ClearType.Caption, color = c.inkSoft)
+ Text(label, style = ClearType.Body, color = c.ink)
+ if (body != null) Text(body, style = ClearType.Caption, color = c.inkSoft, maxLines = 2, overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis)
}
Spacer(Modifier.width(12.dp))
- GlassToggle(checked, onChange, accent = accent)
+ GlassToggle(checked, onChange, accent = Candy.Mint)
}
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/AdaptiveInk.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/AdaptiveInk.kt
new file mode 100644
index 0000000..e2c7cab
--- /dev/null
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/AdaptiveInk.kt
@@ -0,0 +1,218 @@
+package com.chethan616.clearpdf.ui.glass
+
+import android.app.Activity
+import android.content.Context
+import android.content.ContextWrapper
+import android.graphics.Bitmap
+import android.os.Build
+import android.os.Handler
+import android.os.Looper
+import android.view.PixelCopy
+import android.view.View
+import android.view.ViewTreeObserver
+import android.view.Window
+import androidx.annotation.RequiresApi
+import androidx.compose.animation.animateColorAsState
+import androidx.compose.animation.core.tween
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.DisposableEffect
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.Stable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableIntStateOf
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberUpdatedState
+import androidx.compose.runtime.setValue
+import androidx.compose.runtime.snapshotFlow
+import androidx.compose.runtime.staticCompositionLocalOf
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.geometry.Rect
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.luminance
+import androidx.compose.ui.layout.boundsInWindow
+import androidx.compose.ui.layout.onGloballyPositioned
+import androidx.compose.ui.platform.LocalDensity
+import androidx.compose.ui.platform.LocalView
+import androidx.compose.ui.unit.dp
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.suspendCancellableCoroutine
+import java.util.concurrent.atomic.AtomicBoolean
+import kotlin.coroutines.resume
+
+/**
+ * Per-control ink for the document viewers. Each icon reads what is really on screen around it
+ * and picks dark or white ink for itself, so two buttons in the same bar can differ (one over a
+ * white page, one over the dark desk beside it, a photo, book mode's letterbox).
+ *
+ * How: while at least one control asks, the window is copied, scaled down, a few times a second,
+ * and only after it actually drew something new. A control samples the corners of its own box,
+ * which sit outside its round or capsule glass, so its own ink never feeds back into the reading.
+ * Before Android 8 (no window PixelCopy) every control keeps the ink its screen gives it.
+ */
+@Stable
+class ScreenInkSampler internal constructor() {
+ internal var frame by mutableStateOf<InkFrame?>(null)
+ internal var users by mutableIntStateOf(0)
+
+ @RequiresApi(Build.VERSION_CODES.O)
+ internal suspend fun run(window: Window, view: View) {
+ val dirty = AtomicBoolean(true)
+ val listener = ViewTreeObserver.OnDrawListener { dirty.set(true) }
+ view.viewTreeObserver.addOnDrawListener(listener)
+ val handler = Handler(Looper.getMainLooper())
+ var bitmap: Bitmap? = null
+ try {
+ while (true) {
+ if (users == 0) {
+ snapshotFlow { users > 0 }.first { it }
+ dirty.set(true)
+ }
+ val decor = window.decorView
+ val w = decor.width
+ val h = decor.height
+ if (w > 0 && h > 0 && dirty.getAndSet(false)) {
+ val bw = (w / SCALE_DOWN).coerceAtLeast(1)
+ val bh = (h / SCALE_DOWN).coerceAtLeast(1)
+ val target = bitmap?.takeIf { it.width == bw && it.height == bh && !it.isRecycled }
+ ?: Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888).also { bitmap = it }
+ val ok = runCatching {
+ suspendCancellableCoroutine { cont ->
+ PixelCopy.request(window, target, { result -> if (cont.isActive) cont.resume(result) }, handler)
+ } == PixelCopy.SUCCESS
+ }.getOrDefault(false)
+ if (ok) {
+ val px = IntArray(bw * bh)
+ target.getPixels(px, 0, bw, 0, 0, bw, bh)
+ frame = InkFrame(px, bw, bh, bw / w.toFloat(), bh / h.toFloat())
+ }
+ }
+ delay(SAMPLE_INTERVAL_MS)
+ }
+ } finally {
+ if (view.viewTreeObserver.isAlive) view.viewTreeObserver.removeOnDrawListener(listener)
+ bitmap?.recycle()
+ }
+ }
+
+ private companion object {
+ const val SCALE_DOWN = 6
+ const val SAMPLE_INTERVAL_MS = 140L
+ }
+}
+
+/** A scaled-down copy of the window; coordinates in and out are window pixels. */
+internal class InkFrame(
+ private val pixels: IntArray,
+ private val width: Int,
+ private val height: Int,
+ private val scaleX: Float,
+ private val scaleY: Float
+) {
+ private fun luminanceAt(x: Float, y: Float): Double {
+ val px = (x * scaleX).toInt().coerceIn(0, width - 1)
+ val py = (y * scaleY).toInt().coerceIn(0, height - 1)
+ val c = pixels[py * width + px]
+ return (0.299 * ((c shr 16) and 0xFF) + 0.587 * ((c shr 8) and 0xFF) + 0.114 * (c and 0xFF)) / 255.0
+ }
+
+ /**
+ * Luminance around [box]: just inside its four corners (outside the rounded glass), plus, at
+ * double weight, just outside its left and right edges level with its centre, where the icon
+ * itself sits. A control straddling a page edge so follows what is beside its glyph.
+ */
+ fun cornerLuminance(box: Rect, inset: Float): Float {
+ val d = inset.coerceAtMost(minOf(box.width, box.height) * 0.14f)
+ val corners = luminanceAt(box.left + d, box.top + d) + luminanceAt(box.right - d, box.top + d) +
+ luminanceAt(box.left + d, box.bottom - d) + luminanceAt(box.right - d, box.bottom - d)
+ val cy = box.center.y
+ val sides = luminanceAt(box.left - d * 0.6f, cy) + luminanceAt(box.right + d * 0.6f, cy)
+ return ((corners + 2 * sides) / 8.0).toFloat()
+ }
+}
+
+val LocalScreenInk = staticCompositionLocalOf<ScreenInkSampler?> { null }
+
+/** Runs one [ScreenInkSampler] for this window (Android 8+); the viewers' controls read from it. */
+@Composable
+fun ProvideScreenInk(content: @Composable () -> Unit) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
+ content()
+ return
+ }
+ val view = LocalView.current
+ val window = remember(view) { view.context.findActivity()?.window }
+ val sampler = remember { ScreenInkSampler() }
+ if (window != null) LaunchedEffect(window, view) { sampler.run(window, view) }
+ CompositionLocalProvider(LocalScreenInk provides if (window != null) sampler else null, content = content)
+}
+
+/** One control's ink: put [modifier] on the control (first, so it measures the resting box). */
+class InkProbe(val modifier: Modifier, val color: Color) {
+ val soft: Color get() = color.copy(alpha = 0.62f)
+}
+
+/** Ink over a light background. */
+val InkOnLight = Color(0xFF15171C)
+
+/**
+ * Ink for one control, from the pixels around it. [fallback] is the ink the screen would use for
+ * the whole bar: it applies until the first reading and on Android 7 and older, and when the
+ * reading agrees with it, it is kept as is (so a screen's own dark ink stays its exact colour).
+ */
+@Composable
+fun rememberAdaptiveInk(fallback: Color): InkProbe {
+ val sampler = LocalScreenInk.current
+ val fallbackOnLight = fallback.luminance() < 0.5f
+ var onLight by remember { mutableStateOf(fallbackOnLight) }
+ var measured by remember { mutableStateOf(false) }
+ val box = remember { arrayOfNulls<Rect>(1) }
+ val currentFallback by rememberUpdatedState(fallbackOnLight)
+ val inset = with(LocalDensity.current) { 5.dp.toPx() }
+ if (sampler != null) {
+ DisposableEffect(sampler) {
+ sampler.users++
+ onDispose { sampler.users-- }
+ }
+ LaunchedEffect(sampler) {
+ snapshotFlow { sampler.frame }.collect { frame ->
+ val b = box[0]
+ if (frame == null || b == null || b.width <= 0f || b.height <= 0f) return@collect
+ val lum = frame.cornerLuminance(b, inset)
+ // Hysteresis, so a control over a mid-grey picture doesn't flicker.
+ onLight = when {
+ !measured -> lum > 0.60f
+ lum > 0.62f -> true
+ lum < 0.58f -> false
+ else -> onLight
+ }
+ measured = true
+ }
+ }
+ }
+ val useLight = if (sampler != null && measured) onLight else currentFallback
+ val target = when {
+ useLight == fallbackOnLight -> fallback
+ useLight -> InkOnLight
+ else -> Color.White
+ }
+ val color by animateColorAsState(target, tween(200), label = "adaptiveInk")
+ val modifier = remember { Modifier.onGloballyPositioned { box[0] = it.boundsInWindow() } }
+ return InkProbe(modifier, color)
+}
+
+private tailrec fun Context.findActivity(): Activity? = when (this) {
+ is Activity -> this
+ is ContextWrapper -> baseContext.findActivity()
+ else -> null
+}
+
+/**
+ * [rememberAdaptiveInk] where a [ScreenInkSampler] runs (the viewer), else [fallback] as it is: the
+ * app's own screens keep their theme ink, glass over a document reads its ink from the page.
+ */
+@Composable
+fun rememberGlassInk(fallback: Color): InkProbe =
+ if (LocalScreenInk.current != null) rememberAdaptiveInk(fallback) else remember(fallback) { InkProbe(Modifier, fallback) }
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Backdrops.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Backdrops.kt
index 86cee71..00b7edb 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Backdrops.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Backdrops.kt
@@ -20,6 +20,7 @@ import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
+import androidx.compose.ui.res.imageResource
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Canvas
@@ -98,6 +99,21 @@ private val OffsetPairConverter = TwoWayConverter<Pair<Offset, Offset>, Animatio
*/
@Composable
fun Aurora(mood: AuroraMood, modifier: Modifier = Modifier) {
+ // the old ClearPDF's glossy blobs: their hard, shaded edges are what the glass's lens bends at
+ // every rim, so the buttons over them read raised, as they did there
+ val custom = GlassSettings.customWallpaper
+ if (GlassSettings.wallpaper == Wallpaper.Liquid || (GlassSettings.wallpaper == Wallpaper.Custom && custom != null)) {
+ val dark = clear.dark
+ val image = if (GlassSettings.wallpaper == Wallpaper.Custom && custom != null) custom else ImageBitmap.imageResource(
+ if (dark) com.chethan616.clearpdf.R.drawable.wallpaper_liquid_dark else com.chethan616.clearpdf.R.drawable.wallpaper_liquid_light
+ )
+ androidx.compose.foundation.Image(
+ image, null, modifier.fillMaxSize(),
+ contentScale = androidx.compose.ui.layout.ContentScale.Crop,
+ filterQuality = FilterQuality.Low,
+ )
+ return
+ }
val colors = clear
val anims = remember { List(5) { i -> Animatable(mood.blobs[i % mood.blobs.size] to Offset(mood.radius, 0f), OffsetPairConverter) } }
LaunchedEffect(mood) {
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Buttons.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Buttons.kt
index 1da9947..97c7fb5 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Buttons.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Buttons.kt
@@ -36,9 +36,11 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.chethan616.clearpdf.ui.theme.clear
import com.kyant.backdrop.drawBackdrop
-import com.kyant.shapes.Capsule
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.ui.graphics.Shape
+import androidx.compose.ui.graphics.SolidColor
+import androidx.compose.ui.graphics.vector.ImageVector
+import androidx.compose.ui.graphics.vector.PathParser
/** The ink drawn on a glass control: white on a candy tint, else the theme's ink. */
val LocalGlassInk = androidx.compose.runtime.compositionLocalOf { Color.Unspecified }
@@ -61,6 +63,7 @@ private fun Modifier.glassControl(
tap: Feel? = Feel.Tap,
bloom: Boolean = true,
tintAt: (() -> Color)? = null,
+ candyBase: Boolean = true,
): Modifier {
val backdrop = LocalBackdrop.current
val scope = rememberCoroutineScope()
@@ -72,13 +75,18 @@ private fun Modifier.glassControl(
if (!hasLongClick) currentHaptics?.play(Feel.Bloom)
})
}
+ // an overlay opening (often by this very press) settles the press at once, so the scene under the
+ // overlay stops changing and isn't redrawn under it frame after frame
+ val overlays = LocalGlassOverlayHost.current
+ if (overlays != null) LaunchedEffect(overlays, highlight) {
+ androidx.compose.runtime.snapshotFlow { overlays.entries.isNotEmpty() }.collect { if (it) highlight.settle() }
+ }
val source = remember { MutableInteractionSource() }
val armed = remember { booleanArrayOf(false) }
val currentLongClick by rememberUpdatedState(onLongClick)
LaunchedEffect(source) {
source.interactions.collect { i ->
when (i) {
- is PressInteraction.Press -> currentHaptics?.play(Feel.Press)
is PressInteraction.Release -> if (armed[0]) { armed[0] = false; currentLongClick?.invoke() }
is PressInteraction.Cancel -> armed[0] = false
}
@@ -98,9 +106,9 @@ private fun Modifier.glassControl(
val t = tintAt?.invoke() ?: tint
if (t.isSpecified) {
// a soft white base first, so the candy comes out vivid over dark and light alike
- drawRect(Color.White.copy(alpha = 0.42f))
+ if (candyBase) drawRect(Color.White.copy(alpha = 0.42f))
drawRect(t, blendMode = BlendMode.Hue)
- drawRect(t.copy(alpha = 0.82f))
+ drawRect(t.copy(alpha = if (candyBase) 0.8f else 0.75f))
}
if (surface.isSpecified) drawRect(surface.glassTint(style))
// read here, while drawing, so a colour animating in changes pixels and recomposes nothing
@@ -153,7 +161,7 @@ fun rememberBeat(action: () -> Unit, millis: Long = BackBeatMillis): () -> Unit
* (Settings ▸ liquid glass), so it shows what's under it, the page in the viewer.
*/
@Composable
-fun Modifier.glassBar(shape: Shape = Capsule, surface: Color = clear.glass, blur: Dp = 6.dp): Modifier {
+fun Modifier.glassBar(shape: Shape = ChromeCapsule, surface: Color = Color.Unspecified, blur: Dp = 2.dp): Modifier {
val backdrop = LocalBackdrop.current
val scope = rememberCoroutineScope()
val highlight = remember(scope) { InteractiveHighlight(scope) }
@@ -180,20 +188,23 @@ fun GlassPill(
onClick: () -> Unit,
modifier: Modifier = Modifier,
tint: Color = Color.Unspecified,
- surface: Color = if (tint.isSpecified) Color.Unspecified else clear.glass,
+ surface: Color = Color.Unspecified,
height: Dp = 48.dp,
blur: Dp = 2.dp,
- horizontalPadding: Dp = 18.dp,
+ horizontalPadding: Dp = 16.dp,
onLongClick: (() -> Unit)? = null,
label: String? = null,
tintAt: (() -> Color)? = null,
+ tap: Feel? = Feel.Tap,
content: @Composable RowScope.() -> Unit,
) {
- val ink = if (tint.isSpecified || tintAt != null) Color.White else clear.ink
- CompositionLocalProvider(LocalGlassInk provides ink) {
+ val candy = tint.isSpecified || tintAt != null
+ val probe = if (candy) InkProbe(Modifier, Color.White) else rememberGlassInk(clear.ink)
+ CompositionLocalProvider(LocalGlassInk provides probe.color) {
Row(
modifier
- .glassControl(Capsule, onClick, onLongClick, tint, if (tintAt != null) Color.Unspecified else surface, blur, label, bloom = onLongClick != null, tintAt = tintAt)
+ .then(probe.modifier)
+ .glassControl(ChromeCapsule, onClick, onLongClick, tint, if (tintAt != null) Color.Unspecified else surface, blur, label, tap = tap, bloom = true, tintAt = tintAt)
.height(height)
.padding(horizontal = horizontalPadding),
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterHorizontally),
@@ -215,13 +226,14 @@ fun GlassChip(
onClick: () -> Unit,
modifier: Modifier = Modifier,
height: Dp = 40.dp,
- surface: Color = clear.glass,
+ // natural glass, as the header circles and the old app's chips: no wash of its own
+ surface: Color = Color.Unspecified,
fill: (() -> Color)? = null,
blur: Dp = 2.dp,
contentPadding: PaddingValues = PaddingValues(horizontal = 16.dp),
horizontalArrangement: Arrangement.Horizontal = Arrangement.spacedBy(8.dp, Alignment.CenterHorizontally),
tap: Feel? = Feel.Tap,
- bloom: Boolean = false,
+ bloom: Boolean = true,
onLongClick: (() -> Unit)? = null,
label: String? = null,
ink: Color = clear.ink,
@@ -241,14 +253,36 @@ fun GlassChip(
}
/**
- * The round glass button of a screen's header (Back, More, the desk's menu): 54 dp of the same
- * plain glass every glass button wears, ink in [GlassIcon]s white on the sky. Never ringed or
- * dark-filled: one glass, one lit rim.
+ * The old app's capsule, continuous corners and all, for chrome that stays put (pills, bars): a path
+ * clip costs nothing there. Chips and cards that scroll use the circular [Capsule].
*/
+val ChromeCapsule = com.kyant.shapes.Capsule
+
+/** The old app's header circle: 40 dp of natural glass (no wash), so every header reads the same. */
+val HeaderButtonSize = 40.dp
+
+/** The round glass button of a screen's header (Back, More, the desk's menu). */
@Composable
-fun HeaderGlassButton(onClick: () -> Unit, label: String, modifier: Modifier = Modifier, size: Dp = 54.dp, content: @Composable () -> Unit) {
- GlassCircle(onClick = onClick, modifier = modifier, size = size, label = label) {
- CompositionLocalProvider(LocalGlassInk provides clear.hero) { content() }
+fun HeaderGlassButton(onClick: () -> Unit, label: String, modifier: Modifier = Modifier, size: Dp = HeaderButtonSize, content: @Composable () -> Unit) {
+ GlassCircle(onClick = onClick, modifier = modifier, size = size, label = label, ink = clear.ink) { content() }
+}
+
+/** Material's rounded arrow_back_ios_new, the old app's Back glyph. */
+val BackArrow: ImageVector by lazy {
+ ImageVector.Builder("BackArrow", 24.dp, 24.dp, 24f, 24f).addPath(
+ PathParser().parsePathString(
+ "M16.62,2.99c-0.49,-0.49 -1.28,-0.49 -1.77,0L6.54,11.3c-0.39,0.39 -0.39,1.02 0,1.41l8.31,8.31c0.49,0.49 1.28,0.49 1.77,0 0.49,-0.49 0.49,-1.28 0,-1.77L9.38,12l7.25,-7.25c0.48,-0.48 0.48,-1.28 -0.01,-1.76z"
+ ).toNodes(),
+ fill = SolidColor(Color.Black),
+ ).build()
+}
+
+/** Back, as the old app's: a 40 dp glass circle, a 16 dp arrow, leaving a beat after the press. */
+@Composable
+fun GlassBackButton(onBack: () -> Unit, modifier: Modifier = Modifier, label: String? = null, immediate: Boolean = false) {
+ val beat = rememberBeat(onBack)
+ GlassCircle(onClick = if (immediate) onBack else beat, modifier = modifier, size = HeaderButtonSize, label = label ?: androidx.compose.ui.res.stringResource(com.chethan616.clearpdf.R.string.common_back), ink = clear.ink) {
+ GlassIcon(BackArrow, null, Modifier.size(16.dp))
}
}
@@ -269,17 +303,20 @@ fun BarGlyphButton(onClick: () -> Unit, label: String, modifier: Modifier = Modi
fun GlassCircle(
onClick: () -> Unit,
modifier: Modifier = Modifier,
- size: Dp = 44.dp,
+ size: Dp = HeaderButtonSize,
tint: Color = Color.Unspecified,
- surface: Color = if (tint.isSpecified) Color.Unspecified else clear.glass,
+ surface: Color = Color.Unspecified,
onLongClick: (() -> Unit)? = null,
label: String? = null,
+ ink: Color = Color.Unspecified,
+ tap: Feel? = Feel.Tap,
content: @Composable () -> Unit,
) {
- val ink = if (tint.isSpecified) Color.White else clear.ink
- CompositionLocalProvider(LocalGlassInk provides ink) {
+ // over a document the glyph takes dark or white ink from the page around it, as the old app's
+ val probe = if (tint.isSpecified) InkProbe(Modifier, Color.White) else rememberGlassInk(if (ink.isSpecified) ink else clear.ink)
+ CompositionLocalProvider(LocalGlassInk provides probe.color) {
Box(
- modifier.size(size).glassControl(CircleShape, onClick, onLongClick, tint, surface, 2.dp, label, bloom = onLongClick != null),
+ modifier.then(probe.modifier).size(size).glassControl(CircleShape, onClick, onLongClick, tint, surface, 2.dp, label, tap = tap, bloom = true, candyBase = false),
contentAlignment = Alignment.Center,
) { content() }
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Controls.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Controls.kt
index f0bc639..461d1f8 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Controls.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Controls.kt
@@ -53,7 +53,6 @@ import com.kyant.backdrop.effects.blur
import com.kyant.backdrop.effects.lens
import com.kyant.backdrop.highlight.Highlight
import com.kyant.backdrop.shadow.InnerShadow
-import com.kyant.shapes.Capsule
import kotlin.math.abs
import kotlinx.coroutines.flow.collectLatest
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/MorphMenu.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/MorphMenu.kt
deleted file mode 100644
index 4f35020..0000000
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/MorphMenu.kt
+++ /dev/null
@@ -1,191 +0,0 @@
-package com.chethan616.clearpdf.ui.glass
-
-import androidx.activity.compose.BackHandler
-import androidx.compose.animation.core.Animatable
-import androidx.compose.animation.core.SpringSpec
-import androidx.compose.animation.core.spring
-import androidx.compose.foundation.clickable
-import androidx.compose.foundation.interaction.MutableInteractionSource
-import androidx.compose.foundation.layout.Box
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Row
-import androidx.compose.foundation.layout.Spacer
-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.width
-import androidx.compose.foundation.layout.wrapContentSize
-import androidx.compose.material3.Icon
-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.mutableStateOf
-import androidx.compose.runtime.remember
-import androidx.compose.runtime.rememberUpdatedState
-import androidx.compose.runtime.setValue
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.draw.clip
-import androidx.compose.ui.geometry.Rect
-import androidx.compose.ui.graphics.graphicsLayer
-import androidx.compose.ui.layout.Layout
-import androidx.compose.ui.layout.onSizeChanged
-import androidx.compose.ui.platform.LocalDensity
-import androidx.compose.ui.text.style.TextOverflow
-import androidx.compose.ui.unit.Constraints
-import androidx.compose.ui.unit.Dp
-import androidx.compose.ui.unit.dp
-import androidx.compose.ui.util.lerp
-import com.chethan616.clearpdf.ui.theme.Candy
-import com.chethan616.clearpdf.ui.theme.ClearType
-import com.chethan616.clearpdf.ui.theme.clear
-import com.kyant.backdrop.drawBackdrop
-import com.kyant.shapes.RoundedRectangle
-import kotlin.math.roundToInt
-import kotlinx.coroutines.coroutineScope
-import kotlinx.coroutines.launch
-
-/**
- * A round glass button that morphs into its menu, as the old app's share button morphs into its
- * capsule: the glass itself grows from the circle at [anchor] (its window bounds) into the card, its
- * rim and lens following the shape the whole way, on one glass spring (Settings ▸ Motion, damped
- * enough that a resizing glass doesn't ring on); the [glyph] cross-fades into the rows on a fade that
- * never bounces, and the rows' icons pop in with it. Dismissed, it shrinks back into the circle; an
- * item chosen fades it where it is. Keep the real button hidden from the tap until [onGone].
- */
-@Composable
-fun GlassMorphMenu(
- open: Boolean,
- anchor: Rect,
- onDismiss: () -> Unit,
- onGone: () -> Unit,
- items: List<GlassMenuItem>,
- width: Dp = 236.dp,
- glyph: @Composable () -> Unit,
-) {
- val c = clear
- GlassOverlay {
- BackHandler(enabled = open, onBack = onDismiss)
- val host = LocalGlassOverlayHost.current ?: return@GlassOverlay
- val density = LocalDensity.current
- // 0 = the button, 1 = the menu: the glass's width and height, in layout only
- val grow = remember { Animatable(0f) }
- // the glyph out and the rows in, on the same beat as the glass but never past either end
- val shown = remember { Animatable(0f) }
- val pop = remember { Animatable(0f) }
- val fade = remember { Animatable(1f) }
- var chosen by remember { mutableStateOf(false) }
- val gone by rememberUpdatedState(onGone)
- LaunchedEffect(open) {
- coroutineScope {
- when {
- open -> {
- launch { shown.animateTo(1f, ContentIn) }
- launch { pop.animateTo(1f, GlassMotion.pop()) }
- grow.animateTo(1f, morphSpring())
- }
- chosen -> fade.animateTo(0f, Fluid.fade())
- else -> {
- launch { shown.animateTo(0f, ContentOut) }
- launch { pop.animateTo(0f, ContentOut) }
- grow.animateTo(0f, morphSpring())
- }
- }
- }
- if (!open) gone()
- }
- if (open) Box(Modifier.fillMaxSize().clickable(remember { MutableInteractionSource() }, null, onClick = onDismiss))
- val local = Rect(host.windowToLocal(anchor.topLeft), host.windowToLocal(anchor.bottomRight))
- val right = local.center.x > host.size.width / 2f
- val corner = if (right) Alignment.TopEnd else Alignment.TopStart
- val button = with(density) { local.height.toDp() }
- // half the button's height: a circle at the button's size, the menu's corners at full size
- val shape = RoundedRectangle(button / 2)
- val style = GlassSettings.style
- val backdrop = LocalBackdrop.current
- var fullHeight by remember { mutableFloatStateOf(0f) }
- Layout(
- content = {
- Box(
- Modifier
- .graphicsLayer { alpha = fade.value }
- .drawBackdrop(
- backdrop = backdrop,
- shape = { shape },
- shadow = null,
- effects = { glassEffects(style, 4f.dp.toPx(), 12f.dp.toPx(), 24f.dp.toPx()) },
- highlight = { glassHighlight(style) },
- onDrawSurface = {
- // the button's glass, frosting over as it becomes a menu so the rows read
- drawRect(c.glass.glassTint(style))
- drawRect(c.frost.glassTint(style), alpha = shown.value.coerceIn(0f, 1f) * 0.9f)
- },
- )
- .clip(shape),
- ) {
- Column(
- Modifier
- .wrapContentSize(corner, unbounded = true)
- .width(width)
- .onSizeChanged { fullHeight = it.height.toFloat() }
- .graphicsLayer { alpha = ((shown.value - 0.3f) / 0.7f).coerceIn(0f, 1f) },
- ) {
- Spacer(Modifier.height(6.dp))
- items.forEach { item ->
- Row(
- Modifier.fillMaxWidth()
- .pressable({ if (open) { chosen = true; onDismiss(); item.onClick() } })
- .padding(horizontal = 18.dp, vertical = 12.dp),
- verticalAlignment = Alignment.CenterVertically,
- ) {
- Text(item.label, style = ClearType.BodyStrong, color = if (item.destructive) Candy.Tomato else c.ink, modifier = Modifier.weight(1f), maxLines = 1, overflow = TextOverflow.Ellipsis)
- if (item.icon != null) {
- Icon(
- item.icon, null,
- tint = if (item.destructive) Candy.Tomato else c.inkSoft,
- modifier = Modifier.size(20.dp).graphicsLayer {
- val s = pop.value.coerceAtLeast(0f)
- scaleX = s
- scaleY = s
- },
- )
- }
- }
- }
- Spacer(Modifier.height(6.dp))
- }
- Box(
- Modifier.align(corner).size(button).graphicsLayer { alpha = (1f - shown.value * 2.2f).coerceIn(0f, 1f) },
- contentAlignment = Alignment.Center,
- ) { glyph() }
- }
- },
- modifier = Modifier.fillMaxSize(),
- ) { measurables, constraints ->
- val fullW = width.toPx()
- val fullH = if (fullHeight > 0f) fullHeight else local.height
- val g = grow.value
- // past full size by what the spring throws; never smaller than most of the button
- val w = lerp(local.width, fullW, g).coerceAtLeast(local.width * 0.8f)
- val h = lerp(local.height, fullH, g).coerceAtLeast(local.height * 0.8f)
- val card = measurables.first().measure(Constraints.fixed(w.roundToInt(), h.roundToInt()))
- layout(constraints.maxWidth, constraints.maxHeight) {
- val x = if (right) local.right - w else local.left
- // grows down from the button, or up when there is no room below
- val y = if (local.top + fullH < constraints.maxHeight) local.top else local.bottom - h
- card.place(x.roundToInt(), y.roundToInt())
- }
- }
- }
-}
-
-/** The glass growing or shrinking: the motion setting's spring, with a floor on damping (a resizing glass re-blurs every frame). */
-private fun morphSpring(): SpringSpec<Float> =
- spring(maxOf(MotionSettings.damping(0.75f), 0.62f), MotionSettings.stiffness(480f), visibilityThreshold = 0.002f)
-
-private val ContentIn = spring<Float>(dampingRatio = 1f, stiffness = 380f)
-private val ContentOut = spring<Float>(dampingRatio = 1f, stiffness = 900f)
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Overlays.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Overlays.kt
index 21e83b1..324e526 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Overlays.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Overlays.kt
@@ -73,8 +73,6 @@ import androidx.compose.ui.util.lerp
import com.chethan616.clearpdf.ui.theme.Candy
import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.clear
-import com.kyant.shapes.Capsule
-import com.kyant.shapes.RoundedRectangle
import com.kyant.backdrop.floatingLayer
import kotlin.math.roundToInt
import kotlin.math.tanh
@@ -318,6 +316,9 @@ data class GlassMenuItem(val label: String, val icon: ImageVector? = null, val d
* A popover menu anchored to [anchor] (window bounds of its trigger): unfolds from the trigger's
* corner, width first then height, and folds away on a tap outside or Back.
*/
+/** How long a chosen menu item waits for the menu to fold away (its dismiss tween, about 260 ms). */
+private const val MenuGoneMillis = 220L
+
@Composable
fun GlassMenu(anchor: Rect, onDismiss: () -> Unit, items: List<GlassMenuItem>) {
val c = clear
@@ -359,7 +360,13 @@ fun GlassMenu(anchor: Rect, onDismiss: () -> Unit, items: List<GlassMenuItem>) {
Spacer(Modifier.height(6.dp))
items.forEach { item ->
Row(
- Modifier.fillMaxWidth().pressable({ onDismiss(); item.onClick() }).padding(horizontal = 16.dp, vertical = 11.dp),
+ // the menu folds away first; what was chosen happens once it has gone
+ Modifier.fillMaxWidth().pressable({
+ if (!leaving) {
+ onDismiss()
+ android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({ item.onClick() }, MenuGoneMillis)
+ }
+ }).padding(horizontal = 16.dp, vertical = 11.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text(item.label, style = ClearType.BodyStrong, color = if (item.destructive) Candy.Tomato else c.ink, modifier = Modifier.weight(1f), maxLines = 1, overflow = TextOverflow.Ellipsis)
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Press.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Press.kt
index 93edff7..ce39091 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Press.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Press.kt
@@ -218,6 +218,25 @@ half4 main(float2 coord) {
}
}
+ /**
+ * Settles at once (critically damped, ~150 ms) instead of ringing on: a press that opened a menu or
+ * sheet would otherwise keep the whole scene under it redrawing, and re-blurring, for a second.
+ */
+ fun settle() {
+ if (pressAnim.value == 0f && wobbleAnim.value == 0f && glowAnim.value == 0f && expandAnim.value == 0f) return
+ releaseJob?.cancel()
+ longPressJob?.cancel()
+ val quick = spring<Float>(1f, 1400f, 0.004f)
+ releaseJob = animationScope.launch {
+ launch { wobbleAnim.animateTo(0f, quick) }
+ launch { pressAnim.animateTo(0f, quick) }
+ launch { glowAnim.animateTo(0f, quick) }
+ launch { expandAnim.animateTo(0f, quick) }
+ launch { bloomGlowAnim.animateTo(0f, quick) }
+ launch { positionAnim.snapTo(startPosition) }
+ }
+ }
+
val gestureModifier: Modifier = Modifier.pointerInput(animationScope) {
val longPressMs = viewConfiguration.longPressTimeoutMillis
val slop = viewConfiguration.touchSlop
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Shapes.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Shapes.kt
new file mode 100644
index 0000000..5057ffb
--- /dev/null
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Shapes.kt
@@ -0,0 +1,14 @@
+package com.chethan616.clearpdf.ui.glass
+
+import androidx.compose.ui.unit.Dp
+import com.kyant.shapes.RoundedCornerStyle
+
+// Circular corners, not kyant's default continuous ones: a continuous corner is a path, and a path
+// clip that moves (a card or chip scrolling, a sheet sliding) makes Skia rasterize a fresh software
+// mask and upload it on every frame. A circular one is a rounded rect the GPU clips by itself.
+
+/** A capsule whose ends are half circles. */
+val Capsule = com.kyant.shapes.Capsule(RoundedCornerStyle.Circular)
+
+/** A rounded rectangle with circular corners of [radius]. */
+fun RoundedRectangle(radius: Dp) = com.kyant.shapes.RoundedRectangle(radius, RoundedCornerStyle.Circular)
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Style.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Style.kt
index 8187627..b34548f 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Style.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Style.kt
@@ -6,6 +6,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.asImageBitmap
import com.kyant.backdrop.BackdropEffectScope
import com.kyant.backdrop.effects.blur
import com.kyant.backdrop.effects.colorControls
@@ -41,8 +42,57 @@ data class GlassStyle(
}
}
+/**
+ * What the app stands on: Artefact's soft aurora (the default, as the old ClearPDF started on its
+ * own plain background), the old ClearPDF's liquid blobs, or a picture of the user's own.
+ */
+enum class Wallpaper { Aurora, Liquid, Custom }
+
object GlassSettings {
private const val PREFS = "glass"
+ private const val CUSTOM_FILE = "wallpaper_custom.jpg"
+
+ var wallpaper: Wallpaper by mutableStateOf(Wallpaper.Aurora)
+
+ /** The user's own picture, decoded once (null until one is chosen). */
+ var customWallpaper: androidx.compose.ui.graphics.ImageBitmap? by mutableStateOf(null)
+ private set
+
+ fun updateWallpaper(context: Context, w: Wallpaper) {
+ wallpaper = w
+ context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putString("wallpaper", w.name).apply()
+ }
+
+ /**
+ * Copies a picture from the gallery into the app (upright, at most 1600 px on its long side, so it
+ * stays after the picker's permission lapses) and makes it the wallpaper. Off the main thread.
+ */
+ suspend fun setCustomWallpaper(context: Context, uri: android.net.Uri): Boolean = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) {
+ runCatching {
+ val source = android.graphics.ImageDecoder.createSource(context.contentResolver, uri)
+ val bitmap = android.graphics.ImageDecoder.decodeBitmap(source) { decoder, info, _ ->
+ val w = info.size.width
+ val h = info.size.height
+ val scale = minOf(1f, 1600f / maxOf(w, h))
+ decoder.setTargetSize((w * scale).toInt().coerceAtLeast(1), (h * scale).toInt().coerceAtLeast(1))
+ decoder.allocator = android.graphics.ImageDecoder.ALLOCATOR_SOFTWARE
+ }
+ java.io.File(context.filesDir, CUSTOM_FILE).outputStream().use { bitmap.compress(android.graphics.Bitmap.CompressFormat.JPEG, 90, it) }
+ val image = bitmap.asImageBitmapCompat()
+ kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.Main) {
+ customWallpaper = image
+ updateWallpaper(context, Wallpaper.Custom)
+ }
+ true
+ }.getOrDefault(false)
+ }
+
+ private fun android.graphics.Bitmap.asImageBitmapCompat() = asImageBitmap()
+
+ private fun loadCustom(context: Context) {
+ val f = java.io.File(context.filesDir, CUSTOM_FILE)
+ customWallpaper = if (f.exists()) android.graphics.BitmapFactory.decodeFile(f.path)?.asImageBitmapCompat() else null
+ }
var style: GlassStyle by mutableStateOf(GlassStyle.Default)
var haptics: Boolean by mutableStateOf(true)
@@ -62,6 +112,9 @@ object GlassSettings {
highlight = p.getFloat("highlight", d.highlight),
)
haptics = p.getBoolean("haptics", true)
+ wallpaper = runCatching { Wallpaper.valueOf(p.getString("wallpaper", null) ?: "Aurora") }.getOrDefault(Wallpaper.Aurora)
+ if (wallpaper == Wallpaper.Custom) loadCustom(context)
+ if (wallpaper == Wallpaper.Custom && customWallpaper == null) wallpaper = Wallpaper.Aurora
MotionSettings.load(context)
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Surfaces.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Surfaces.kt
index 976d621..a00e263 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Surfaces.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Surfaces.kt
@@ -31,7 +31,6 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.chethan616.clearpdf.ui.theme.clear
import com.kyant.backdrop.drawBackdrop
-import com.kyant.shapes.RoundedRectangle
/**
* A still glass surface (bars, the dock's body, panels, sheets): refracts [LocalBackdrop] through
@@ -87,11 +86,14 @@ fun GlassCard(
fun GlassHost(
modifier: Modifier = Modifier,
paint: @Composable BoxScope.() -> Unit,
+ opaque: Boolean = false,
content: @Composable BoxScope.() -> Unit,
) {
val below = LocalBackdrop.current
val layer = rememberLayerBackdrop()
- val combined = rememberCombinedBackdrop(below, layer)
+ // an opaque paint hides what's below anyway; sampling only it keeps the glass on it still while
+ // the whole host scrolls (nothing to re-blur), where the wallpaper behind would move every frame
+ val combined = if (opaque) layer else rememberCombinedBackdrop(below, layer)
Box(modifier) {
Box(Modifier.matchParentSize().layerBackdrop(layer), content = paint)
CompositionLocalProvider(LocalBackdrop provides combined) { content() }
@@ -141,7 +143,7 @@ fun Modifier.pressable(
pressedScale: Float = Fluid.PressedScale,
role: Role = Role.Button,
enabled: Boolean = true,
- feel: Feel = Feel.Tap,
+ feel: Feel? = Feel.Tap,
): Modifier {
val source = remember { MutableInteractionSource() }
val jelly = rememberJellyPress(source, pressedScale)
@@ -154,7 +156,7 @@ fun Modifier.pressable(
indication = null,
enabled = enabled,
role = role,
- onClick = { haptics?.play(feel); onClick() },
+ onClick = { if (feel != null) haptics?.play(feel); onClick() },
onLongClick = onLongClick?.let { l -> { haptics?.play(Feel.Bloom); jelly.rest(); l() } },
)
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Tabs.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Tabs.kt
index dcd419f..275bd3c 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Tabs.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Tabs.kt
@@ -67,7 +67,6 @@ import com.kyant.backdrop.effects.lens
import com.kyant.backdrop.effects.vibrancy
import com.kyant.backdrop.highlight.Highlight
import com.kyant.backdrop.shadow.InnerShadow
-import com.kyant.shapes.Capsule
import kotlin.math.abs
import kotlin.math.sign
import kotlinx.coroutines.flow.collectLatest
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/home/Cards.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/home/Cards.kt
index 1695533..69b86f0 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/home/Cards.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/home/Cards.kt
@@ -76,8 +76,8 @@ import com.chethan616.clearpdf.ui.theme.CardTone
import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.Tone
import com.chethan616.clearpdf.ui.theme.clear
-import com.kyant.shapes.Capsule
-import com.kyant.shapes.RoundedRectangle
+import com.chethan616.clearpdf.ui.glass.Capsule
+import com.chethan616.clearpdf.ui.glass.RoundedRectangle
import java.io.File
import java.text.DateFormat
import java.util.Date
@@ -140,6 +140,7 @@ fun ListCard(note: Note, onOpen: () -> Unit, onLong: () -> Unit, onToggle: (Chec
GlassHost(
modifier.pressable(onOpen, onLong, pressedScale = 0.96f),
paint = { Box(Modifier.fillMaxSize().cardPaint(tone, Offset(0.15f, 0.0f))) },
+ opaque = true,
) {
Column(Modifier.padding(start = 12.dp, end = 12.dp, top = 20.dp, bottom = 14.dp)) {
WordFitText(
@@ -488,6 +489,7 @@ fun StackCard(
// a shade over the top so the title reads on a white page or a bright photo
Box(Modifier.fillMaxWidth().height(86.dp).background(Brush.verticalGradient(listOf(Color.Black.copy(alpha = 0.38f), Color.Transparent))))
},
+ opaque = true,
) {
Column(Modifier.padding(start = 16.dp, top = 14.dp, end = 16.dp)) {
Text(title, style = ClearType.Title.copy(fontSize = 17.sp), color = Color.White, maxLines = 1, overflow = TextOverflow.Ellipsis)
@@ -553,6 +555,7 @@ fun RecentCard(vm: AppViewModel, rows: List<FileRow>, onAll: () -> Unit, modifie
}
}
},
+ opaque = true,
) {
Row(Modifier.align(Alignment.BottomStart).padding(12.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
if (rows.size > 1) PhotoChip("+${rows.size - 1}", onAll)
@@ -587,11 +590,18 @@ fun DocCard(vm: AppViewModel, r: FileRow, tone: CardTone, tilt: Float, onLong: (
/** The mock's menu glyph: four dots in a square. */
@Composable
fun FourDots(color: Color, modifier: Modifier = Modifier) {
- Canvas(modifier.size(20.dp)) {
- val r = 2.4.dp.toPx()
- val d = 5.2.dp.toPx()
+ // unspecified: the ink of the glass button it sits on
+ val glassInk = com.chethan616.clearpdf.ui.glass.LocalGlassInk.current
+ val ink = when {
+ color != Color.Unspecified -> color
+ glassInk != Color.Unspecified -> glassInk
+ else -> clear.ink
+ }
+ Canvas(modifier.size(16.dp)) {
+ val r = 2.dp.toPx()
+ val d = 4.2.dp.toPx()
val c = Offset(size.width / 2f, size.height / 2f)
- for (dx in listOf(-d, d)) for (dy in listOf(-d, d)) drawCircle(color, r, c + Offset(dx, dy))
+ for (dx in listOf(-d, d)) for (dy in listOf(-d, d)) drawCircle(ink, r, c + Offset(dx, dy))
}
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/home/CreateDock.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/home/CreateDock.kt
index 25a9103..77a55bb 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/home/CreateDock.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/home/CreateDock.kt
@@ -76,6 +76,8 @@ import com.chethan616.clearpdf.ui.glass.GlassIcon
import com.chethan616.clearpdf.ui.glass.GlassMotion
import com.chethan616.clearpdf.ui.glass.LocalHaptics
import com.chethan616.clearpdf.ui.glass.MotionSettings
+import androidx.compose.ui.layout.onGloballyPositioned
+import androidx.compose.ui.layout.boundsInWindow
import com.chethan616.clearpdf.ui.glass.glass
import com.chethan616.clearpdf.ui.glass.pressable
import com.chethan616.clearpdf.ui.theme.Candy
@@ -83,7 +85,7 @@ import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.clear
import com.chethan616.clearpdf.ui.viewer.VoiceRecorder
import com.chethan616.clearpdf.ui.viewer.clock
-import com.kyant.shapes.Capsule
+import com.chethan616.clearpdf.ui.glass.Capsule
import java.io.File
import kotlin.math.roundToInt
import kotlinx.coroutines.CoroutineScope
@@ -189,19 +191,24 @@ fun BoxScope.CreateDock(
// back into the dock the same way
val into = remember { Animatable(if (fromNote) 1f else 0f) }
val done by androidx.compose.runtime.rememberUpdatedState(onNoteMorphed)
+ // layout follows this spring, so it never rings (every ring would re-blur the glass); the
+ // speed is still Settings ▸ Motion's
+ val handSpring = androidx.compose.animation.core.spring<Float>(maxOf(MotionSettings.damping(0.86f), 0.8f), MotionSettings.stiffness(400f))
+ // where the dock rests, in window px, so it can travel to the toolbar wherever the keyboard put it
+ val dockBottom = remember { floatArrayOf(0f) }
LaunchedEffect(intoNote, fromNote) {
when {
intoNote -> {
val reached = kotlinx.coroutines.CompletableDeferred<Unit>()
launch {
- into.animateTo(1f, GlassMotion.unfold()) { if (value >= 0.96f) reached.complete(Unit) }
+ into.animateTo(1f, handSpring) { if (value >= 0.97f) reached.complete(Unit) }
reached.complete(Unit)
}
- kotlinx.coroutines.withTimeoutOrNull(600L) { reached.await() }
+ kotlinx.coroutines.withTimeoutOrNull(450L) { reached.await() }
done()
}
fromNote -> {
- into.animateTo(0f, GlassMotion.unfold())
+ into.animateTo(0f, handSpring)
done()
}
else -> into.snapTo(0f)
@@ -268,7 +275,7 @@ fun BoxScope.CreateDock(
desk.haptics?.play(if (desk.fanOpen) Feel.Rise else Feel.Fall)
}
GlassCircle(
- onClick = { if (desk.recorder == null) desk.startRecording(vm) }, size = 54.dp, surface = Color.White.copy(alpha = 0.30f),
+ onClick = { if (desk.recorder == null) desk.startRecording(vm) }, tap = null, size = 54.dp, surface = Color.White.copy(alpha = 0.30f),
label = stringResource(R.string.create_voice),
) { GlassIcon(LucideIcons.Mic, null, Modifier.size(22.dp), tint = DockInk) }
}
@@ -294,13 +301,16 @@ fun BoxScope.CreateDock(
scaleX = (1f + swell * 0.06f * k - pinch * 0.2f * k).coerceIn(0.92f, 1.03f)
scaleY = (1f - mid * 0.03f * k - swell * 0.22f * k + pinch * 0.15f * k).coerceIn(0.93f, 1.06f)
transformOrigin = TransformOrigin(0.5f, 1f)
- // the note's toolbar sits 4 dp lower than the dock
- translationY = into.value.coerceIn(0f, 1f) * 4.dp.toPx()
+ // on to the note's toolbar, which the keyboard may have lifted
+ val n = into.value.coerceIn(0f, 1f)
+ val target = vm.noteBarBottom
+ translationY = if (n > 0f && target > 0f && dockBottom[0] > 0f) n * (target - dockBottom[0]) else 0f
}
+ .onGloballyPositioned { if (into.value == 0f) dockBottom[0] = it.boundsInWindow().bottom }
// the very glass of the Back and menu buttons; the recorder darkens it so its white reads
.glass(Capsule, c.glass, blur = 3.dp, lensHeight = 14.dp, lensAmount = 26.dp)
.graphicsLayer { clip = true; shape = Capsule }
- .drawBehind { drawRect(c.capsule, alpha = (lerp(0.5f, 1.9f, morph.value.coerceIn(0f, 1f)) + 0.5f * into.value.coerceIn(0f, 1f)).coerceAtMost(1f)) }
+ .drawBehind { drawRect(c.capsule, alpha = lerp(0.5f, 1.9f, morph.value.coerceIn(0f, 1f)).coerceAtMost(1f)) }
.padding(6.dp),
) { measurables, constraints ->
val loose = constraints.copy(minWidth = 0, minHeight = 0)
@@ -344,7 +354,7 @@ private fun PlusButton(open: Boolean, onClick: () -> Unit) {
val label = stringResource(R.string.dock_create)
Box(
Modifier.size(58.dp)
- .pressable(onClick, pressedScale = 0.9f, feel = Feel.Press)
+ .pressable(onClick, pressedScale = 0.9f, feel = null)
.graphicsLayer { shadowElevation = 4.dp.toPx(); shape = CircleShape; clip = true }
.background(Color.White)
.semantics { contentDescription = label },
@@ -441,7 +451,7 @@ private fun Recording(rec: VoiceRecorder, onCancel: () -> Unit, onStop: () -> Un
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
// the + turns to an x in the dock's near-black; the recorder's x wears the same ink, on a light
// glass so it reads against the dark capsule
- GlassCircle(onClick = onCancel, size = 50.dp, surface = Color.White.copy(alpha = 0.82f), label = stringResource(R.string.common_cancel)) {
+ GlassCircle(onClick = onCancel, tap = null, size = 50.dp, surface = Color.White.copy(alpha = 0.82f), label = stringResource(R.string.common_cancel)) {
GlassIcon(LucideIcons.X, null, Modifier.size(20.dp), tint = DockInk)
}
// the pulse is read in draw: it never recomposes the row
@@ -449,9 +459,9 @@ private fun Recording(rec: VoiceRecorder, onCancel: () -> Unit, onStop: () -> Un
Elapsed(rec)
LiveWave(rec.levels, Modifier.width(112.dp).height(34.dp))
Box(
- Modifier.size(54.dp).pressable(onStop, pressedScale = 0.9f, feel = Feel.Confirm).clip(CircleShape).background(Color.White),
+ Modifier.size(54.dp).pressable(onStop, pressedScale = 0.9f, feel = null).clip(CircleShape).background(Color.White),
contentAlignment = Alignment.Center,
- ) { Box(Modifier.size(18.dp).clip(com.kyant.shapes.RoundedRectangle(5.dp)).background(Candy.Tomato)) }
+ ) { Box(Modifier.size(18.dp).clip(com.chethan616.clearpdf.ui.glass.RoundedRectangle(5.dp)).background(Candy.Tomato)) }
}
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/home/HomeScreen.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/home/HomeScreen.kt
index e8c6f7a..1f88e36 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/home/HomeScreen.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/home/HomeScreen.kt
@@ -90,6 +90,7 @@ import com.chethan616.clearpdf.ui.theme.clear
import com.chethan616.clearpdf.ui.theme.glowing
import com.chethan616.clearpdf.ui.viewer.VoicePlayer
import kotlinx.coroutines.launch
+import com.kyant.backdrop.throttleBackdrops
/** What the desk shows: everything, or one kind. */
enum class DeskFilter(@StringRes val chip: Int, @StringRes val title: Int) {
@@ -200,7 +201,8 @@ fun HomeScreen(vm: AppViewModel, desk: DeskState) {
LazyVerticalStaggeredGrid(
columns = StaggeredGridCells.Fixed(2),
state = grid,
- modifier = Modifier.fillMaxSize(),
+ // glass in the scrolling desk samples the soft wallpaper: while it scrolls, ten times a second is plenty
+ modifier = Modifier.fillMaxSize().throttleBackdrops { grid.isScrollInProgress },
contentPadding = PaddingValues(start = 16.dp, end = 16.dp, bottom = DeskDockClearance + 40.dp),
verticalItemSpacing = 12.dp,
horizontalArrangement = Arrangement.spacedBy(12.dp),
@@ -263,7 +265,6 @@ fun HomeScreen(vm: AppViewModel, desk: DeskState) {
private fun DeskHeader(vm: AppViewModel) {
val c = clear
var menu by remember { mutableStateOf(false) }
- var morphing by remember { mutableStateOf(false) }
var anchor by remember { mutableStateOf(Rect.Zero) }
Row(Modifier.fillMaxWidth().padding(start = 6.dp, top = 14.dp, end = 4.dp), verticalAlignment = Alignment.CenterVertically) {
Image(
@@ -272,26 +273,18 @@ private fun DeskHeader(vm: AppViewModel) {
modifier = Modifier.height(50.dp).width(56.dp),
)
Spacer(Modifier.weight(1f))
- // one glass button, as every other: its own lit rim, no second ring drawn around it
- // the button becomes the menu: hidden while its glass is out in the overlay
HeaderGlassButton(
- onClick = { menu = true; morphing = true },
+ onClick = { menu = true },
label = stringResource(R.string.common_more_options),
- modifier = Modifier.onGloballyPositioned { anchor = it.boundsInWindow() }.graphicsLayer { alpha = if (morphing) 0f else 1f },
- ) { FourDots(c.hero) }
+ modifier = Modifier.onGloballyPositioned { anchor = it.boundsInWindow() },
+ ) { FourDots(androidx.compose.ui.graphics.Color.Unspecified) }
}
- if (morphing) {
- com.chethan616.clearpdf.ui.glass.GlassMorphMenu(
- open = menu,
- anchor = anchor,
- onDismiss = { menu = false },
- onGone = { morphing = false },
- items = listOf(
- GlassMenuItem(stringResource(R.string.home_tab_files), LucideIcons.FolderOpen) { vm.homeTab = HomeTab.Files },
- GlassMenuItem(stringResource(R.string.home_tab_tools), LucideIcons.LayoutGrid) { vm.homeTab = HomeTab.Tools },
- GlassMenuItem(stringResource(R.string.home_settings), LucideIcons.Settings) { vm.settingsOpen = true },
- ),
- ) { FourDots(c.hero) }
+ if (menu) {
+ GlassMenu(anchor, { menu = false }, listOf(
+ GlassMenuItem(stringResource(R.string.home_tab_files), LucideIcons.FolderOpen) { vm.homeTab = HomeTab.Files },
+ GlassMenuItem(stringResource(R.string.home_tab_tools), LucideIcons.LayoutGrid) { vm.homeTab = HomeTab.Tools },
+ GlassMenuItem(stringResource(R.string.home_settings), LucideIcons.Settings) { vm.settingsOpen = true },
+ ))
}
}
@@ -371,7 +364,15 @@ private fun FilterChips(selected: DeskFilter, onSelect: (DeskFilter) -> Unit) {
}
/** A long, eased fade at both edges of a chip row (fade.png): chips dissolve into the sky there. */
-fun Modifier.chipRowFade(): Modifier = graphicsLayer { compositingStrategy = androidx.compose.ui.graphics.CompositingStrategy.Offscreen }
+fun Modifier.chipRowFade(): Modifier = this
+ // the faded layer reaches 14 dp past the row above and below, so a chip that swells or blooms
+ // under the finger is never cut by it; the row still takes only its own height
+ .layout { m, c ->
+ val r = 14.dp.roundToPx()
+ val p = m.measure(c.copy(minHeight = c.minHeight + 2 * r, maxHeight = if (c.hasBoundedHeight) c.maxHeight + 2 * r else c.maxHeight))
+ layout(p.width, (p.height - 2 * r).coerceAtLeast(0)) { p.place(0, -r) }
+ }
+ .graphicsLayer { compositingStrategy = androidx.compose.ui.graphics.CompositingStrategy.Offscreen }
.drawWithContent {
drawContent()
val f = 44.dp.toPx() / size.width
@@ -383,6 +384,7 @@ fun Modifier.chipRowFade(): Modifier = graphicsLayer { compositingStrategy = and
blendMode = androidx.compose.ui.graphics.BlendMode.DstIn,
)
}
+ .padding(vertical = 14.dp)
/**
* A filter chip: real liquid glass (the Back and menu buttons' glass, by Settings ▸ liquid glass and
@@ -484,7 +486,7 @@ private fun NameSheet(vm: AppViewModel, n: Note, onDismiss: () -> Unit) {
modifier = Modifier.fillMaxWidth().focusRequester(focus),
decorationBox = { inner ->
Row(
- Modifier.fillMaxWidth().height(54.dp).clip(com.kyant.shapes.RoundedRectangle(18.dp))
+ Modifier.fillMaxWidth().height(54.dp).clip(com.chethan616.clearpdf.ui.glass.RoundedRectangle(18.dp))
.background(if (c.dark) Color.White.copy(alpha = 0.07f) else Color.White.copy(alpha = 0.7f))
.padding(start = 14.dp, end = 8.dp),
verticalAlignment = Alignment.CenterVertically,
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/NoteEditor.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/NoteEditor.kt
index 4d8e989..8d4ce11 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/NoteEditor.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/NoteEditor.kt
@@ -43,6 +43,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
+import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.geometry.Rect
@@ -92,8 +93,8 @@ import com.chethan616.clearpdf.ui.home.NoteImage
import com.chethan616.clearpdf.ui.theme.Candy
import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.clear
-import com.kyant.shapes.Capsule
-import com.kyant.shapes.RoundedRectangle
+import com.chethan616.clearpdf.ui.glass.Capsule
+import com.chethan616.clearpdf.ui.glass.RoundedRectangle
import java.text.DateFormat
import java.util.Date
@@ -139,14 +140,12 @@ fun NoteEditor(vm: AppViewModel, id: String) {
Column {
Spacer(Modifier.windowInsetsTopHeight(WindowInsets.statusBars))
Row(Modifier.fillMaxWidth().padding(top = 14.dp), verticalAlignment = Alignment.CenterVertically) {
- com.chethan616.clearpdf.ui.glass.HeaderGlassButton(onClick = { vm.closeNote() }, label = stringResource(R.string.common_back)) {
- GlassIcon(LucideIcons.ChevronLeft, null, Modifier.size(24.dp))
- }
+ com.chethan616.clearpdf.ui.glass.GlassBackButton({ vm.closeNote() })
Spacer(Modifier.weight(1f))
com.chethan616.clearpdf.ui.glass.HeaderGlassButton(
onClick = { menu = true }, label = stringResource(R.string.common_more_options),
modifier = Modifier.onGloballyPositioned { anchor = it.boundsInWindow() },
- ) { GlassIcon(LucideIcons.Ellipsis, null, Modifier.size(24.dp)) }
+ ) { GlassIcon(LucideIcons.Ellipsis, null, Modifier.size(20.dp)) }
}
}
}
@@ -260,12 +259,16 @@ fun NoteEditor(vm: AppViewModel, id: String) {
// the toolbar, above the keyboard
// opened from the desk, this is the dock's capsule grown into place: unseen until it has
- val iconsIn by androidx.compose.animation.core.animateFloatAsState(if (vm.noteBarHidden) 0f else 1f, com.chethan616.clearpdf.ui.glass.Fluid.fade(), label = "bar")
+ val iconsIn by androidx.compose.animation.core.animateFloatAsState(if (vm.noteBarHidden) 0f else 1f, com.chethan616.clearpdf.ui.glass.Fluid.quick(), label = "bar")
Row(
Modifier.align(Alignment.BottomCenter).navigationBarsPadding().imePadding().padding(bottom = 14.dp)
- .onGloballyPositioned { vm.noteBarSize = it.size }
+ .onGloballyPositioned { vm.noteBarSize = it.size; vm.noteBarBottom = it.boundsInWindow().bottom }
.graphicsLayer { alpha = if (vm.noteBarHidden) 0f else 1f }
- .glass(Capsule, c.capsule, blur = 10.dp).padding(6.dp)
+ // the very glass of the desk's dock it grew out of: same wash, frost, lens and shade
+ .glass(Capsule, c.glass, blur = 3.dp, lensHeight = 14.dp, lensAmount = 26.dp)
+ .graphicsLayer { clip = true; shape = Capsule }
+ .drawBehind { drawRect(c.capsule, alpha = 0.5f) }
+ .padding(6.dp)
.graphicsLayer { alpha = iconsIn },
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/onboarding/Onboarding.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/onboarding/Onboarding.kt
index 35e59cf..30e95a6 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/onboarding/Onboarding.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/onboarding/Onboarding.kt
@@ -80,8 +80,8 @@ import com.chethan616.clearpdf.ui.theme.Tone
import com.chethan616.clearpdf.ui.theme.clear
import com.chethan616.clearpdf.ui.theme.glowing
import com.kyant.backdrop.throttleBackdrops
-import com.kyant.shapes.Capsule
-import com.kyant.shapes.RoundedRectangle
+import com.chethan616.clearpdf.ui.glass.Capsule
+import com.chethan616.clearpdf.ui.glass.RoundedRectangle
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
@@ -180,6 +180,7 @@ fun Onboarding(vm: AppViewModel, pager: PagerState = rememberPagerState { Welcom
GlassPill(
onClick = { if (last) { haptics?.play(Feel.Confirm); vm.finishOnboarding() } else scope.launch { pager.animateScrollToPage(pager.currentPage + 1, animationSpec = Fluid.push()) } },
tintAt = accent,
+ tap = if (last) null else Feel.Tap,
height = 58.dp,
modifier = Modifier.fillMaxWidth(),
) {
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/CommentList.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/CommentList.kt
index 54ae673..5ebb4e5 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/CommentList.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/CommentList.kt
@@ -146,9 +146,7 @@ fun CommentListScreen(vm: AppViewModel, doc: OpenDocument) {
Modifier.fillMaxWidth().height(TopBarHeight).padding(horizontal = 12.dp),
verticalAlignment = Alignment.CenterVertically,
) {
- com.chethan616.clearpdf.ui.glass.GlassCircle(com.chethan616.clearpdf.ui.glass.rememberBeat(::close), size = 48.dp, label = stringResource(R.string.common_back)) {
- com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.ChevronLeft, null, Modifier.size(23.dp))
- }
+ com.chethan616.clearpdf.ui.glass.GlassBackButton(::close)
Spacer(Modifier.width(14.dp))
Text(
if (list == null) stringResource(R.string.comments_title) else threadsTitle(threads.size, stringResource(R.string.comments_none)) { plural(R.plurals.comments_threads, it, it) },
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/PagesScreen.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/PagesScreen.kt
index 9cf78e8..c985edc 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/PagesScreen.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/PagesScreen.kt
@@ -99,9 +99,11 @@ fun PagesScreen(vm: AppViewModel, doc: OpenDocument, onClose: () -> Unit) {
selected.clear()
onClose()
}
- // the tick leaves organizing for the grid of pages; back from the grid returns to the document
+ // opened straight into organizing (a tool), Back returns to the document; organizing begun
+ // from the grid returns to the grid
+ val openedOrganizing = remember { vm.organizing }
fun back() {
- if (exporting != null) {
+ if (exporting != null || openedOrganizing) {
close()
} else if (organizing) {
vm.organizing = false
@@ -122,15 +124,12 @@ fun PagesScreen(vm: AppViewModel, doc: OpenDocument, onClose: () -> Unit) {
Modifier.fillMaxWidth().height(TopBarHeight).padding(horizontal = 12.dp),
verticalAlignment = Alignment.CenterVertically,
) {
- val goBack = com.chethan616.clearpdf.ui.glass.rememberBeat(::back)
if (organizing) {
- com.chethan616.clearpdf.ui.glass.GlassCircle(goBack, size = 48.dp, tint = com.chethan616.clearpdf.ui.theme.Candy.Sky, label = stringResource(if (picked.isEmpty()) R.string.common_done else R.string.common_back)) {
- com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.Check, null, Modifier.size(22.dp))
+ com.chethan616.clearpdf.ui.glass.GlassCircle(com.chethan616.clearpdf.ui.glass.rememberBeat(::back), tint = com.chethan616.clearpdf.ui.theme.Candy.Sky, label = stringResource(R.string.common_done)) {
+ com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.Check, null, Modifier.size(18.dp))
}
} else {
- com.chethan616.clearpdf.ui.glass.GlassCircle(goBack, size = 48.dp, label = stringResource(R.string.common_back)) {
- com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.ChevronLeft, null, Modifier.size(23.dp))
- }
+ com.chethan616.clearpdf.ui.glass.GlassBackButton(::back)
}
Spacer(Modifier.width(14.dp))
Text(
@@ -224,7 +223,7 @@ fun PagesScreen(vm: AppViewModel, doc: OpenDocument, onClose: () -> Unit) {
) {
Box(
Modifier.size(cardW, 162.dp).then(com.chethan616.clearpdf.ui.glass.washPanel())
- .then(if (highlighted) Modifier.border(2.dp, com.chethan616.clearpdf.ui.theme.Candy.Sky, com.kyant.shapes.RoundedRectangle(20.dp)) else Modifier),
+ .then(if (highlighted) Modifier.border(2.dp, com.chethan616.clearpdf.ui.theme.Candy.Sky, com.chethan616.clearpdf.ui.glass.RoundedRectangle(20.dp)) else Modifier),
contentAlignment = Alignment.Center,
) {
val ratio = (p.width / p.height.coerceAtLeast(1f)).coerceIn(0.2f, 5f)
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/QuickTools.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/QuickTools.kt
index 45736b9..bf6bd6d 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/QuickTools.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/QuickTools.kt
@@ -241,15 +241,15 @@ fun CustomizeToolbar(vm: AppViewModel, onDone: () -> Unit) {
Column {
Row(Modifier.fillMaxWidth().padding(start = 20.dp, end = 8.dp), verticalAlignment = Alignment.CenterVertically) {
Text(stringResource(R.string.toolbar_customize), color = c.text, fontSize = 17.sp, fontWeight = FontWeight.SemiBold, modifier = Modifier.weight(1f))
- com.chethan616.clearpdf.ui.glass.GlassCircle(onDone, size = 42.dp, label = stringResource(R.string.common_cancel)) {
- com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.X, null, Modifier.size(19.dp))
+ com.chethan616.clearpdf.ui.glass.GlassCircle(onDone, label = stringResource(R.string.common_cancel)) {
+ com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.X, null, Modifier.size(18.dp))
}
Spacer(Modifier.width(8.dp))
com.chethan616.clearpdf.ui.glass.GlassCircle({
prefs.save(bar.toList(), grid.toList())
onDone()
- }, size = 42.dp, tint = com.chethan616.clearpdf.ui.theme.Candy.Sky, label = stringResource(R.string.toolbar_save)) {
- com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.Check, null, Modifier.size(19.dp))
+ }, tint = com.chethan616.clearpdf.ui.theme.Candy.Sky, label = stringResource(R.string.toolbar_save)) {
+ com.chethan616.clearpdf.ui.glass.GlassIcon(LucideIcons.Check, null, Modifier.size(18.dp))
}
}
Text(
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerBars.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerBars.kt
index 3485d2e..58ac478 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerBars.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerBars.kt
@@ -78,7 +78,7 @@ import com.chethan616.clearpdf.ui.iconAccent
import com.chethan616.clearpdf.ui.theme.Candy
import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.clear
-import com.kyant.shapes.Capsule
+import com.chethan616.clearpdf.ui.glass.Capsule
import kotlinx.coroutines.flow.first
import com.kyant.backdrop.floatingLayer
@@ -127,19 +127,19 @@ fun ViewerTopBar(
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
if (toolActive && doneIsCheck) {
- GlassCircle(onClick = onBack, size = 48.dp, tint = Candy.Sky, label = stringResource(R.string.common_done)) { GlassIcon(LucideIcons.Check, null, Modifier.size(22.dp)) }
+ GlassCircle(onClick = onBack, tint = Candy.Sky, label = stringResource(R.string.common_done)) { GlassIcon(LucideIcons.Check, null, Modifier.size(18.dp)) }
} else {
- GlassCircle(onClick = com.chethan616.clearpdf.ui.glass.rememberBeat(onBack), size = 48.dp, label = stringResource(R.string.common_back)) { GlassIcon(LucideIcons.ChevronLeft, null, Modifier.size(23.dp)) }
+ com.chethan616.clearpdf.ui.glass.GlassBackButton(onBack)
}
GlassPill(onClick = onTitle, modifier = Modifier.weight(1f), height = 48.dp, horizontalPadding = 16.dp) {
if (toolTitle != null) Box(Modifier.size(9.dp).clip(CircleShape).background(Candy.Sky))
Column(Modifier.weight(1f)) {
- Text(toolTitle ?: title, style = ClearType.Title.copy(fontSize = 15.5.sp, lineHeight = 19.sp), color = c.ink, maxLines = 1, overflow = TextOverflow.Ellipsis)
- if (subtitle != null && toolTitle == null) Text(subtitle, style = ClearType.Caption, color = c.inkSoft, maxLines = 1)
+ Text(toolTitle ?: title, style = ClearType.Title.copy(fontSize = 15.5.sp, lineHeight = 19.sp), color = com.chethan616.clearpdf.ui.glass.LocalGlassInk.current, maxLines = 1, overflow = TextOverflow.Ellipsis)
+ if (subtitle != null && toolTitle == null) Text(subtitle, style = ClearType.Caption, color = com.chethan616.clearpdf.ui.glass.LocalGlassInk.current.copy(alpha = 0.62f), maxLines = 1)
}
if (onSearch != null && !toolActive) {
BarGlyphButton(onSearch, stringResource(R.string.viewer_find_in_document), size = 36.dp) {
- Icon(LucideIcons.Search, null, tint = c.ink, modifier = Modifier.size(19.dp))
+ Icon(LucideIcons.Search, null, tint = com.chethan616.clearpdf.ui.glass.LocalGlassInk.current, modifier = Modifier.size(19.dp))
}
}
}
@@ -147,18 +147,18 @@ fun ViewerTopBar(
if (canUndo || canRedo) {
BarGroup {
BarGlyphButton({ if (canUndo) onUndo() }, stringResource(R.string.common_undo), enabled = canUndo) {
- Icon(LucideIcons.Undo2, null, tint = if (canUndo) c.ink else c.inkFaint, modifier = Modifier.size(20.dp))
+ Icon(LucideIcons.Undo2, null, tint = if (canUndo) com.chethan616.clearpdf.ui.glass.LocalGlassInk.current else com.chethan616.clearpdf.ui.glass.LocalGlassInk.current.copy(alpha = 0.38f), modifier = Modifier.size(20.dp))
}
BarGlyphButton({ if (canRedo) onRedo() }, stringResource(R.string.common_redo), enabled = canRedo) {
- Icon(LucideIcons.Redo2, null, tint = if (canRedo) c.ink else c.inkFaint, modifier = Modifier.size(20.dp))
+ Icon(LucideIcons.Redo2, null, tint = if (canRedo) com.chethan616.clearpdf.ui.glass.LocalGlassInk.current else com.chethan616.clearpdf.ui.glass.LocalGlassInk.current.copy(alpha = 0.38f), modifier = Modifier.size(20.dp))
}
}
}
} else {
BarGroup {
if (canUndo) UndoMenuButton(canUndo, canRedo, onUndo, onRedo, undoLabel, redoLabel)
- BarGlyphButton(onShare, stringResource(R.string.common_share)) { Icon(LucideIcons.Share2, null, tint = c.ink, modifier = Modifier.size(19.dp)) }
- BarGlyphButton(onMore, stringResource(R.string.common_more_options)) { Icon(LucideIcons.Ellipsis, null, tint = c.ink, modifier = Modifier.size(21.dp)) }
+ BarGlyphButton(onShare, stringResource(R.string.common_share)) { Icon(LucideIcons.Share2, null, tint = com.chethan616.clearpdf.ui.glass.LocalGlassInk.current, modifier = Modifier.size(19.dp)) }
+ BarGlyphButton(onMore, stringResource(R.string.common_more_options)) { Icon(LucideIcons.Ellipsis, null, tint = com.chethan616.clearpdf.ui.glass.LocalGlassInk.current, modifier = Modifier.size(21.dp)) }
}
}
}
@@ -196,11 +196,11 @@ fun GlassBars(visible: Boolean, fromTop: Boolean, content: @Composable () -> Uni
/** Bar buttons grouped on one glass capsule, as iOS groups them. */
@Composable
private fun BarGroup(content: @Composable androidx.compose.foundation.layout.RowScope.() -> Unit) {
+ val probe = com.chethan616.clearpdf.ui.glass.rememberGlassInk(clear.ink)
Row(
- Modifier.height(48.dp).glassBar().padding(horizontal = 4.dp),
+ Modifier.then(probe.modifier).height(48.dp).glassBar().padding(horizontal = 4.dp),
verticalAlignment = Alignment.CenterVertically,
- content = content,
- )
+ ) { CompositionLocalProvider(com.chethan616.clearpdf.ui.glass.LocalGlassInk provides probe.color) { content() } }
}
/** Undo in a bar group: a tap opens a menu naming what Undo and Redo would do. */
@@ -212,7 +212,7 @@ fun UndoMenuButton(canUndo: Boolean, canRedo: Boolean, onUndo: () -> Unit, onRed
{ if (canUndo || canRedo) open = true },
stringResource(R.string.viewer_undo_or_redo),
modifier = Modifier.onGloballyPositioned { anchor = it.boundsInWindow() },
- ) { Icon(LucideIcons.Undo2, null, tint = clear.ink, modifier = Modifier.size(20.dp)) }
+ ) { Icon(LucideIcons.Undo2, null, tint = com.chethan616.clearpdf.ui.glass.LocalGlassInk.current, modifier = Modifier.size(20.dp)) }
if (open) {
val items = buildList {
if (canUndo) add(GlassMenuItem(undoLabel?.let { stringResource(R.string.viewer_undo_named, it) } ?: stringResource(R.string.common_undo), LucideIcons.Undo2, onClick = onUndo))
@@ -228,6 +228,7 @@ fun UndoMenuButton(canUndo: Boolean, canRedo: Boolean, onUndo: () -> Unit, onRed
*/
@Composable
fun SearchBar(
+ progress: () -> Float,
query: String,
onQuery: (String) -> Unit,
canStep: Boolean,
@@ -243,25 +244,27 @@ fun SearchBar(
val keyboard = LocalSoftwareKeyboardController.current
val findLabel = stringResource(R.string.viewer_find_in_document)
LaunchedEffect(Unit) { focus.requestFocus() }
- // the field grows out of the title pill on the glass spring (Settings ▸ Motion), its words a beat behind
- val grow = remember { androidx.compose.animation.core.Animatable(0f) }
- LaunchedEffect(Unit) { grow.animateTo(1f, GlassMotion.morph()) }
+ // the field is the title pill stretched over Share and More (their group and its gap, 96 dp), on
+ // the glass spring (Settings ▸ Motion); its words come in once it has room and leave first
Row(
Modifier.fillMaxWidth().height(TopBarHeight).padding(horizontal = 12.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
- GlassCircle(onClick = onClose, size = 48.dp, label = stringResource(R.string.viewer_collapse)) { GlassIcon(LucideIcons.ChevronLeft, null, Modifier.size(23.dp)) }
+ Box(Modifier.graphicsLayer { alpha = progress().coerceIn(0f, 1f) }) {
+ com.chethan616.clearpdf.ui.glass.GlassBackButton(onClose, label = stringResource(R.string.viewer_collapse), immediate = true)
+ }
Row(
Modifier.weight(1f).height(48.dp)
.layout { m, cs ->
val full = cs.maxWidth
- val w = (full * (0.55f + 0.45f * grow.value)).toInt().coerceIn(1, full)
+ val start = (full - 96.dp.roundToPx()).coerceAtLeast(full / 2)
+ val w = (start + (full - start) * progress()).toInt().coerceIn(1, full + 24.dp.roundToPx())
val p = m.measure(cs.copy(minWidth = w, maxWidth = w))
layout(full, p.height) { p.place(0, 0) }
}
.glassBar().padding(start = 16.dp, end = 4.dp)
- .graphicsLayer { alpha = ((grow.value - 0.25f) / 0.5f).coerceIn(0f, 1f) },
+ .graphicsLayer { alpha = ((progress() - 0.35f) / 0.45f).coerceIn(0f, 1f) },
verticalAlignment = Alignment.CenterVertically,
) {
Icon(LucideIcons.Search, null, tint = c.inkSoft, modifier = Modifier.size(18.dp))
@@ -329,8 +332,11 @@ fun QuickToolbar(
) {
// iOS 26's toolbar: one glass capsule of plain glyphs in the glass's ink (no rainbow, no captions:
// each glyph names itself to TalkBack), More tools in a glass bubble of its own beside it
- Row(Modifier.weight(1f).fillMaxHeight().glassBar().padding(horizontal = 6.dp), verticalAlignment = Alignment.CenterVertically) {
- for (t in shown) DockItem(t.icon, stringResource(t.label)) { onTool(t) }
+ val probe = com.chethan616.clearpdf.ui.glass.rememberGlassInk(clear.ink)
+ Row(Modifier.weight(1f).then(probe.modifier).fillMaxHeight().glassBar().padding(horizontal = 6.dp), verticalAlignment = Alignment.CenterVertically) {
+ CompositionLocalProvider(com.chethan616.clearpdf.ui.glass.LocalGlassInk provides probe.color) {
+ for (t in shown) DockItem(t.icon, stringResource(t.label)) { onTool(t) }
+ }
}
GlassCircle(onClick = onMoreTools, size = 60.dp, label = stringResource(R.string.common_tool_more_tools)) {
GlassIcon(LucideIcons.LayoutGrid, null, Modifier.size(23.dp).androidxRotate(turn))
@@ -359,11 +365,12 @@ fun Modifier.barTopLine(): Modifier = this
fun SubToolbar(content: @Composable () -> Unit) {
val scroll = rememberScrollState()
BoxWithConstraints(Modifier.fillMaxWidth().height(BottomBarHeight).padding(horizontal = 12.dp, vertical = 8.dp), contentAlignment = Alignment.Center) {
+ val probe = com.chethan616.clearpdf.ui.glass.rememberGlassInk(clear.ink)
Row(
- Modifier.widthIn(max = maxWidth).fillMaxHeight().glassBar().horizontalScroll(scroll).padding(horizontal = 8.dp),
+ Modifier.widthIn(max = maxWidth).then(probe.modifier).fillMaxHeight().glassBar().horizontalScroll(scroll).padding(horizontal = 8.dp),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
- ) { CompositionLocalProvider(LocalSubToolbarScroll provides scroll) { content() } }
+ ) { CompositionLocalProvider(LocalSubToolbarScroll provides scroll, com.chethan616.clearpdf.ui.glass.LocalGlassInk provides probe.color) { content() } }
}
}
@@ -431,7 +438,7 @@ private fun SubFace(description: String, selected: Boolean, onClick: () -> Unit,
val disc by animateColorAsState(
when {
vivid -> Candy.Sky
- selected -> c.ink.copy(alpha = 0.10f)
+ selected -> (com.chethan616.clearpdf.ui.glass.LocalGlassInk.current.takeIf { it != Color.Unspecified } ?: c.ink).copy(alpha = 0.10f)
else -> Color.Transparent
},
GlassMotion.settle(), label = "sub",
@@ -441,7 +448,8 @@ private fun SubFace(description: String, selected: Boolean, onClick: () -> Unit,
contentAlignment = Alignment.Center,
) {
Box(Modifier.size(42.dp).clip(CircleShape).background(disc))
- glyph(if (!enabled) c.inkFaint else if (vivid) Color.White else c.ink)
+ val ink = com.chethan616.clearpdf.ui.glass.LocalGlassInk.current.takeIf { it != Color.Unspecified } ?: c.ink
+ glyph(if (!enabled) ink.copy(alpha = 0.38f) else if (vivid) Color.White else ink)
}
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerScreen.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerScreen.kt
index 25d8f9f..d347f3d 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerScreen.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerScreen.kt
@@ -42,6 +42,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.foundation.magnifier
import androidx.compose.ui.draw.clip
import androidx.compose.foundation.layout.imePadding
@@ -360,31 +362,23 @@ fun ViewerScreen(vm: AppViewModel, doc: OpenDocument) {
// the pages run up under the camera and the glass row: no band of their own up there
Spacer(Modifier.fillMaxWidth().height(with(density) { statusPx.toDp() }))
GlassBars(ctl.barsVisible, fromTop = true) {
+ // Find grows out of the title pill over Share and More, and shrinks back into it
+ val sp = remember { androidx.compose.animation.core.Animatable(if (ctl.searching) 1f else 0f) }
+ LaunchedEffect(ctl.searching) {
+ sp.animateTo(
+ if (ctl.searching) 1f else 0f,
+ if (ctl.searching) com.chethan616.clearpdf.ui.glass.GlassMotion.morph() else com.chethan616.clearpdf.ui.glass.GlassMotion.settle(),
+ )
+ }
+ val searchShown by remember { androidx.compose.runtime.derivedStateOf { ctl.searching || sp.value > 0.002f } }
+ val barShown by remember { androidx.compose.runtime.derivedStateOf { !ctl.searching || sp.value < 0.998f } }
Box(barSides) {
- if (ctl.searching) {
- var query by remember { mutableStateOf(search.query) }
- SearchBar(
- query = query,
- onQuery = {
- query = it
- if (it.isEmpty()) search.clear()
- },
- canStep = search.hits.size > 1,
- onSubmit = { runSearch(vm, doc, query.trim()) },
- onClear = {
- query = ""
- search.clear()
- },
- onClose = { closeSearch(doc) },
- onPrev = { search.step(false)?.let { showHit(doc, it) } },
- onNext = { search.step(true)?.let { showHit(doc, it) } },
- // Extra Features: which result is on screen, of how many (still growing while
- // the rest of a long document is searched)
- count = if (vm.searchCount && search.hits.isNotEmpty()) {
- stringResource(R.string.viewer_search_count, (search.current + 1).coerceAtLeast(1), search.hits.size)
- } else null,
- )
- } else {
+ if (barShown) Box(
+ Modifier.graphicsLayer { alpha = (1f - sp.value * 1.8f).coerceIn(0f, 1f) }
+ .then(if (ctl.searching) Modifier.pointerInput(Unit) {
+ awaitPointerEventScope { while (true) awaitPointerEvent(androidx.compose.ui.input.pointer.PointerEventPass.Initial).changes.forEach { it.consume() } }
+ } else Modifier),
+ ) {
val fa = vm.fieldActions
if (fa != null) FieldTopBar(fa) else ViewerTopBar(
title = doc.title,
@@ -392,14 +386,12 @@ fun ViewerScreen(vm: AppViewModel, doc: OpenDocument) {
toolTitle = if (ctl.tool == ViewerTool.Edit) stringResource(R.string.common_tool_edit_pdf) else null,
toolActive = ctl.tool != ViewerTool.None,
doneIsCheck = ctl.tool != ViewerTool.Comment,
- // while drawing, the strokes not yet added have their own undo and redo
canUndo = doc.localUndo?.canUndo?.invoke() ?: (doc.info.undo != null),
canRedo = doc.localUndo?.canRedo?.invoke() ?: (doc.info.redo != null),
onBack = { if (ctl.tool != ViewerTool.None) vm.leaveTool(doc) else vm.closeDocument() },
onUndo = { vm.undo(doc) },
onRedo = { vm.redo(doc) },
onTitle = { ctl.sheet = if (ctl.sheet == ViewerSheet.More) ViewerSheet.None else ViewerSheet.More },
- // Reading Mode has no search, as the reference's bar shows
onSearch = if (vm.readingMode) null else ({
selection.clear()
ctl.searching = true
@@ -410,7 +402,32 @@ fun ViewerScreen(vm: AppViewModel, doc: OpenDocument) {
undoLabel = if (doc.localUndo != null) stringResource(R.string.viewer_undo_drawing) else doc.info.undo,
redoLabel = if (doc.localUndo != null) stringResource(R.string.viewer_undo_drawing) else doc.info.redo,
)
- }
+ }
+ if (searchShown) {
+ var query by remember { mutableStateOf(search.query) }
+ SearchBar(
+ progress = { sp.value },
+ query = query,
+ onQuery = {
+ query = it
+ if (it.isEmpty()) search.clear()
+ },
+ canStep = search.hits.size > 1,
+ onSubmit = { runSearch(vm, doc, query.trim()) },
+ onClear = {
+ query = ""
+ search.clear()
+ },
+ onClose = { closeSearch(doc) },
+ onPrev = { search.step(false)?.let { showHit(doc, it) } },
+ onNext = { search.step(true)?.let { showHit(doc, it) } },
+ // Extra Features: which result is on screen, of how many (still growing while
+ // the rest of a long document is searched)
+ count = if (vm.searchCount && search.hits.isNotEmpty()) {
+ stringResource(R.string.viewer_search_count, (search.current + 1).coerceAtLeast(1), search.hits.size)
+ } else null,
+ )
+ }
}
}
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerSheets.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerSheets.kt
index 61636f6..063898b 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerSheets.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerSheets.kt
@@ -70,8 +70,8 @@ import com.chethan616.clearpdf.ui.glass.pressable
import com.chethan616.clearpdf.ui.theme.Candy
import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.clear
-import com.kyant.shapes.Capsule
-import com.kyant.shapes.RoundedRectangle
+import com.chethan616.clearpdf.ui.glass.Capsule
+import com.chethan616.clearpdf.ui.glass.RoundedRectangle
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.boundsInWindow
import androidx.compose.ui.layout.onGloballyPositioned
diff --git a/android/app/src/main/res/drawable/wallpaper_liquid_dark.jpg b/android/app/src/main/res/drawable/wallpaper_liquid_dark.jpg
new file mode 100644
index 0000000..c0071d2
Binary files /dev/null and b/android/app/src/main/res/drawable/wallpaper_liquid_dark.jpg differ
diff --git a/android/app/src/main/res/drawable/wallpaper_liquid_light.jpg b/android/app/src/main/res/drawable/wallpaper_liquid_light.jpg
new file mode 100644
index 0000000..bf41e07
Binary files /dev/null and b/android/app/src/main/res/drawable/wallpaper_liquid_light.jpg differ
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index f52ef26..a0a14e3 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -1170,6 +1170,13 @@
<string name="settings_motion_jelly">Jelly</string>
<string name="settings_custom">Custom</string>
<string name="settings_general">General</string>
+ <string name="settings_wallpaper">Wallpaper</string>
+ <string name="settings_wallpaper_liquid">Liquid</string>
+ <string name="settings_wallpaper_aurora">Aurora</string>
+ <string name="settings_wallpaper_custom">Gallery</string>
+ <string name="settings_wallpaper_failed">Couldn\'t use that picture</string>
+ <string name="settings_personalization">Personalization</string>
+ <string name="gm_fine_tune">Fine-tune</string>
<string name="settings_glass_motion">Liquid glass &amp; motion</string>
<string name="gm_preview_body">These buttons move the way you set them below. Press and hold them.</string>
<string name="gm_press_me">Press me</string>
diff --git a/android/backdrop/src/main/java/com/kyant/backdrop/Backdrop.kt b/android/backdrop/src/main/java/com/kyant/backdrop/Backdrop.kt
index cfb3c32..a41aea4 100644
--- a/android/backdrop/src/main/java/com/kyant/backdrop/Backdrop.kt
+++ b/android/backdrop/src/main/java/com/kyant/backdrop/Backdrop.kt
@@ -1,23 +1,36 @@
-/*
- * Adapted from AndroidLiquidGlass by kyant0.
- * Source: https://github.com/Kyant0/AndroidLiquidGlass
- * Licensed under the Apache License, Version 2.0.
- */
-
-package com.kyant.backdrop
-
-import androidx.compose.ui.graphics.GraphicsLayerScope
-import androidx.compose.ui.graphics.drawscope.DrawScope
-import androidx.compose.ui.layout.LayoutCoordinates
-import androidx.compose.ui.unit.Density
-
-interface Backdrop {
-
- val isCoordinatesDependent: Boolean
-
- fun DrawScope.drawBackdrop(
- density: Density,
- coordinates: LayoutCoordinates?,
- layerBlock: (GraphicsLayerScope.() -> Unit)? = null
- )
-}
+/*
+ * Adapted from AndroidLiquidGlass by kyant0.
+ * Source: https://github.com/Kyant0/AndroidLiquidGlass
+ * Licensed under the Apache License, Version 2.0.
+ */
+
+package com.kyant.backdrop
+
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.unit.Density
+
+interface Backdrop {
+
+ val isCoordinatesDependent: Boolean
+
+ fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)? = null
+ )
+
+ /**
+ * Where [coordinates] sit relative to what this backdrop draws, as a key: equal keys draw the same
+ * pixels, so a glass node that moved but kept its key (a chip on a card being scrolled with the
+ * card) needn't re-blur. [UnknownPosition] when it can't tell: always redraw.
+ */
+ fun positionKey(coordinates: LayoutCoordinates): Long = UnknownPosition
+}
+
+const val UnknownPosition: Long = Long.MIN_VALUE
+
+/** Two keys as one, unknown if either is. */
+fun mixPositionKeys(a: Long, b: Long): Long =
+ if (a == UnknownPosition || b == UnknownPosition) UnknownPosition else a * 31 + b
diff --git a/android/backdrop/src/main/java/com/kyant/backdrop/DrawBackdropModifier.kt b/android/backdrop/src/main/java/com/kyant/backdrop/DrawBackdropModifier.kt
index 06a4b01..ca399bc 100644
--- a/android/backdrop/src/main/java/com/kyant/backdrop/DrawBackdropModifier.kt
+++ b/android/backdrop/src/main/java/com/kyant/backdrop/DrawBackdropModifier.kt
@@ -1,440 +1,447 @@
-/*
- * Adapted from AndroidLiquidGlass by kyant0.
- * Source: https://github.com/Kyant0/AndroidLiquidGlass
- * Licensed under the Apache License, Version 2.0.
- */
-
-package com.kyant.backdrop
-
-import android.os.Build
-import android.os.SystemClock
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableFloatStateOf
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.neverEqualPolicy
-import androidx.compose.runtime.setValue
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.GraphicsLayerScope
-import androidx.compose.ui.graphics.Shape
-import androidx.compose.ui.graphics.asComposeRenderEffect
-import androidx.compose.ui.graphics.drawscope.ContentDrawScope
-import androidx.compose.ui.graphics.drawscope.DrawScope
-import androidx.compose.ui.graphics.graphicsLayer
-import androidx.compose.ui.graphics.layer.GraphicsLayer
-import androidx.compose.ui.graphics.layer.drawLayer
-import androidx.compose.ui.layout.LayoutCoordinates
-import androidx.compose.ui.layout.Measurable
-import androidx.compose.ui.layout.MeasureResult
-import androidx.compose.ui.layout.MeasureScope
-import androidx.compose.ui.node.DrawModifierNode
-import androidx.compose.ui.node.GlobalPositionAwareModifierNode
-import androidx.compose.ui.node.LayoutModifierNode
-import androidx.compose.ui.node.ModifierNodeElement
-import androidx.compose.ui.node.ObserverModifierNode
-import androidx.compose.ui.node.observeReads
-import androidx.compose.ui.node.requireGraphicsContext
-import androidx.compose.ui.platform.InspectorInfo
-import androidx.compose.ui.unit.Constraints
-import androidx.compose.ui.unit.IntOffset
-import androidx.compose.ui.unit.IntSize
-import com.kyant.backdrop.backdrops.LayerBackdrop
-import com.kyant.backdrop.highlight.Highlight
-import com.kyant.backdrop.highlight.HighlightElement
-import com.kyant.backdrop.shadow.InnerShadow
-import com.kyant.backdrop.shadow.InnerShadowElement
-import com.kyant.backdrop.shadow.Shadow
-import com.kyant.backdrop.shadow.ShadowElement
-import kotlinx.coroutines.Job
-import kotlinx.coroutines.delay
-import kotlinx.coroutines.launch
-
-private const val ThrottleIntervalMs = 100L
-
-private val DefaultHighlight = { Highlight.Default }
-private val DefaultShadow = { Shadow.Default }
-private val DefaultOnDrawBackdrop: DrawScope.(DrawScope.() -> Unit) -> Unit = { it() }
-
-fun Modifier.drawPlainBackdrop(
- backdrop: Backdrop,
- shape: () -> Shape,
- effects: BackdropEffectScope.() -> Unit,
- layerBlock: (GraphicsLayerScope.() -> Unit)? = null,
- exportedBackdrop: LayerBackdrop? = null,
- onDrawBehind: (DrawScope.() -> Unit)? = null,
- onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit = DefaultOnDrawBackdrop,
- onDrawSurface: (DrawScope.() -> Unit)? = null,
- onDrawFront: (DrawScope.() -> Unit)? = null
-): Modifier {
- val shapeProvider = ShapeProvider(shape)
- return this
- .then(
- if (layerBlock != null) {
- Modifier.graphicsLayer(layerBlock)
- } else {
- Modifier
- }
- )
- .then(
- DrawBackdropElement(
- backdrop = backdrop,
- shapeProvider = shapeProvider,
- effects = effects,
- layerBlock = layerBlock,
- exportedBackdrop = exportedBackdrop,
- onDrawBehind = onDrawBehind,
- onDrawBackdrop = onDrawBackdrop,
- onDrawSurface = onDrawSurface,
- onDrawFront = onDrawFront
- )
- )
-}
-
-fun Modifier.drawBackdrop(
- backdrop: Backdrop,
- shape: () -> Shape,
- effects: BackdropEffectScope.() -> Unit,
- highlight: (() -> Highlight?)? = DefaultHighlight,
- shadow: (() -> Shadow?)? = DefaultShadow,
- innerShadow: (() -> InnerShadow?)? = null,
- layerBlock: (GraphicsLayerScope.() -> Unit)? = null,
- exportedBackdrop: LayerBackdrop? = null,
- onDrawBehind: (DrawScope.() -> Unit)? = null,
- onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit = DefaultOnDrawBackdrop,
- onDrawSurface: (DrawScope.() -> Unit)? = null,
- onDrawFront: (DrawScope.() -> Unit)? = null
-): Modifier {
- val shapeProvider = ShapeProvider(shape)
- return this
- .then(
- if (layerBlock != null) {
- Modifier.graphicsLayer(layerBlock)
- } else {
- Modifier
- }
- )
- .then(
- if (innerShadow != null) {
- InnerShadowElement(
- shapeProvider = shapeProvider,
- shadow = innerShadow
- )
- } else {
- Modifier
- }
- )
- .then(
- if (shadow != null) {
- ShadowElement(
- shapeProvider = shapeProvider,
- shadow = shadow
- )
- } else {
- Modifier
- }
- )
- .then(
- if (highlight != null) {
- HighlightElement(
- shapeProvider = shapeProvider,
- highlight = highlight
- )
- } else {
- Modifier
- }
- )
- .then(
- DrawBackdropElement(
- backdrop = backdrop,
- shapeProvider = shapeProvider,
- effects = effects,
- layerBlock = layerBlock,
- exportedBackdrop = exportedBackdrop,
- onDrawBehind = onDrawBehind,
- onDrawBackdrop = onDrawBackdrop,
- onDrawSurface = onDrawSurface,
- onDrawFront = onDrawFront
- )
- )
-}
-
-private class DrawBackdropElement(
- val backdrop: Backdrop,
- val shapeProvider: ShapeProvider,
- val effects: BackdropEffectScope.() -> Unit,
- val layerBlock: (GraphicsLayerScope.() -> Unit)?,
- val exportedBackdrop: LayerBackdrop?,
- val onDrawBehind: (DrawScope.() -> Unit)?,
- val onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit,
- val onDrawSurface: (DrawScope.() -> Unit)?,
- val onDrawFront: (DrawScope.() -> Unit)?
-) : ModifierNodeElement<DrawBackdropNode>() {
-
- override fun create(): DrawBackdropNode {
- return DrawBackdropNode(
- backdrop = backdrop,
- shapeProvider = shapeProvider,
- effects = effects,
- layerBlock = layerBlock,
- exportedBackdrop = exportedBackdrop,
- onDrawBehind = onDrawBehind,
- onDrawBackdrop = onDrawBackdrop,
- onDrawSurface = onDrawSurface,
- onDrawFront = onDrawFront
- )
- }
-
- override fun update(node: DrawBackdropNode) {
- node.backdrop = backdrop
- node.shapeProvider = shapeProvider
- node.effects = effects
- node.layerBlock = layerBlock
- if (node.exportedBackdrop != exportedBackdrop) {
- node.exportedBackdrop?.layerCoordinates = null
- node.exportedBackdrop = exportedBackdrop
- }
- node.onDrawBehind = onDrawBehind
- node.onDrawBackdrop = onDrawBackdrop
- node.onDrawSurface = onDrawSurface
- node.onDrawFront = onDrawFront
- node.invalidateDrawCache()
- }
-
- override fun InspectorInfo.inspectableProperties() {
- name = "drawBackdrop"
- properties["backdrop"] = backdrop
- properties["shapeProvider"] = shapeProvider
- properties["effects"] = effects
- properties["layerBlock"] = layerBlock
- properties["exportedBackdrop"] = exportedBackdrop
- properties["onDrawBehind"] = onDrawBehind
- properties["onDrawBackdrop"] = onDrawBackdrop
- properties["onDrawSurface"] = onDrawSurface
- properties["onDrawFront"] = onDrawFront
- }
-
- override fun equals(other: Any?): Boolean {
- if (this === other) return true
- if (other !is DrawBackdropElement) return false
-
- if (backdrop != other.backdrop) return false
- if (shapeProvider != other.shapeProvider) return false
- if (effects != other.effects) return false
- if (layerBlock != other.layerBlock) return false
- if (exportedBackdrop != other.exportedBackdrop) return false
- if (onDrawBehind != other.onDrawBehind) return false
- if (onDrawBackdrop != other.onDrawBackdrop) return false
- if (onDrawSurface != other.onDrawSurface) return false
- if (onDrawFront != other.onDrawFront) return false
-
- return true
- }
-
- override fun hashCode(): Int {
- var result = backdrop.hashCode()
- result = 31 * result + shapeProvider.hashCode()
- result = 31 * result + effects.hashCode()
- result = 31 * result + (layerBlock?.hashCode() ?: 0)
- result = 31 * result + (exportedBackdrop?.hashCode() ?: 0)
- result = 31 * result + (onDrawBehind?.hashCode() ?: 0)
- result = 31 * result + onDrawBackdrop.hashCode()
- result = 31 * result + (onDrawSurface?.hashCode() ?: 0)
- result = 31 * result + (onDrawFront?.hashCode() ?: 0)
- return result
- }
-}
-
-private class DrawBackdropNode(
- var backdrop: Backdrop,
- var shapeProvider: ShapeProvider,
- var effects: BackdropEffectScope.() -> Unit,
- var layerBlock: (GraphicsLayerScope.() -> Unit)?,
- var exportedBackdrop: LayerBackdrop?,
- var onDrawBehind: (DrawScope.() -> Unit)?,
- var onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit,
- var onDrawSurface: (DrawScope.() -> Unit)?,
- var onDrawFront: (DrawScope.() -> Unit)?
-) : LayoutModifierNode, DrawModifierNode, GlobalPositionAwareModifierNode, ObserverModifierNode, Modifier.Node() {
-
- private val effectScope =
- object : BackdropEffectScopeImpl() {
-
- override val shape: Shape get() = shapeProvider.innerShape
- }
-
- private var graphicsLayer: GraphicsLayer? = null
-
- private val layoutLayerBlock: GraphicsLayerScope.() -> Unit = {
- clip = true
- shape = shapeProvider.shape
- compositingStrategy = androidx.compose.ui.graphics.CompositingStrategy.Offscreen
- }
-
- private var layoutCoordinates: LayoutCoordinates? by mutableStateOf(null, neverEqualPolicy())
-
- private var padding by mutableFloatStateOf(0f)
-
- private val recordBackdropBlock: (DrawScope.() -> Unit) = {
- val canvas = drawContext.canvas
- val padding = padding
-
- if (padding != 0f) {
- canvas.translate(padding, padding)
- }
- onDrawBackdrop {
- with(backdrop) {
- drawBackdrop(
- density = effectScope,
- coordinates = layoutCoordinates,
- layerBlock = layerBlock
- )
- }
- }
- if (padding != 0f) {
- canvas.translate(-padding, -padding)
- }
- }
-
- private val drawBackdropLayer: DrawScope.() -> Unit = {
- val layer = graphicsLayer
- if (layer != null) {
- val padding = padding
-
- recordLayer(
- layer,
- size = IntSize(
- size.width.toInt() + padding.toInt() * 2,
- size.height.toInt() + padding.toInt() * 2
- ),
- block = recordBackdropBlock
- )
-
- layer.topLeft =
- if (padding != 0f) IntOffset(-padding.toInt(), -padding.toInt())
- else IntOffset.Zero
- drawLayer(layer)
- }
- }
-
- override fun MeasureScope.measure(
- measurable: Measurable,
- constraints: Constraints
- ): MeasureResult {
- val placeable = measurable.measure(constraints)
- return layout(placeable.width, placeable.height) {
- placeable.placeWithLayer(IntOffset.Zero, layerBlock = layoutLayerBlock)
- }
- }
-
- override fun ContentDrawScope.draw() {
- if (effectScope.update(this)) {
- updateEffects()
- }
-
- onDrawBehind?.invoke(this)
- drawBackdropLayer()
- onDrawSurface?.invoke(this)
- drawContent()
- onDrawFront?.invoke(this)
-
- exportedBackdrop?.graphicsLayer?.let { layer ->
- recordLayer(layer) {
- onDrawBehind?.invoke(this)
- drawBackdropLayer()
- onDrawSurface?.invoke(this)
- onDrawFront?.invoke(this)
- }
- }
- }
-
- private var throttle: ThrottleBackdropsNode? = null
- private var throttleLooked = false
- private var lastCoordinatesWrite = 0L
- private var pendingCoordinates: LayoutCoordinates? = null
- private var settleJob: Job? = null
-
- private fun publishCoordinates(coordinates: LayoutCoordinates) {
- if (!throttleLooked) {
- throttle = findBackdropThrottle()
- throttleLooked = true
- }
- val now = SystemClock.uptimeMillis()
- val gate = throttle
- if (gate == null || layoutCoordinates == null || !gate.moving() ||
- now - lastCoordinatesWrite >= ThrottleIntervalMs
- ) {
- layoutCoordinates = coordinates
- lastCoordinatesWrite = now
- pendingCoordinates = null
- return
- }
- pendingCoordinates = coordinates
- if (settleJob == null) {
- settleJob = coroutineScope.launch {
- delay((lastCoordinatesWrite + ThrottleIntervalMs - now).coerceAtLeast(1L))
- settleJob = null
- val latest = pendingCoordinates
- pendingCoordinates = null
- if (latest != null && latest.isAttached) {
- layoutCoordinates = latest
- lastCoordinatesWrite = SystemClock.uptimeMillis()
- }
- }
- }
- }
-
- override fun onGloballyPositioned(coordinates: LayoutCoordinates) {
- if (coordinates.isAttached) {
- if (backdrop.isCoordinatesDependent) {
- publishCoordinates(coordinates)
- } else {
- if (layoutCoordinates != null) {
- layoutCoordinates = null
- }
- }
- exportedBackdrop?.layerCoordinates = coordinates
- }
- }
-
- override fun onObservedReadsChanged() {
- invalidateDrawCache()
- }
-
- fun invalidateDrawCache() {
- observeEffects()
- }
-
- private fun observeEffects() {
- observeReads { updateEffects() }
- }
-
- private fun updateEffects() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
- effectScope.apply(effects)
- graphicsLayer?.renderEffect = effectScope.renderEffect?.asComposeRenderEffect()
- padding = effectScope.padding
- }
- }
-
- override fun onAttach() {
- val graphicsContext = requireGraphicsContext()
- graphicsLayer = graphicsContext.createGraphicsLayer()
-
- observeEffects()
- }
-
- override fun onDetach() {
- val graphicsContext = requireGraphicsContext()
- graphicsLayer?.let { layer ->
- graphicsContext.releaseGraphicsLayer(layer)
- graphicsLayer = null
- }
-
- effectScope.reset()
- settleJob = null
- pendingCoordinates = null
- throttle = null
- throttleLooked = false
- layoutCoordinates = null
- exportedBackdrop?.layerCoordinates = null
- }
-}
+/*
+ * Adapted from AndroidLiquidGlass by kyant0.
+ * Source: https://github.com/Kyant0/AndroidLiquidGlass
+ * Licensed under the Apache License, Version 2.0.
+ */
+
+package com.kyant.backdrop
+
+import android.os.Build
+import android.os.SystemClock
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableFloatStateOf
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.neverEqualPolicy
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.Shape
+import androidx.compose.ui.graphics.asComposeRenderEffect
+import androidx.compose.ui.graphics.drawscope.ContentDrawScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.graphics.layer.GraphicsLayer
+import androidx.compose.ui.graphics.layer.drawLayer
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.layout.Measurable
+import androidx.compose.ui.layout.MeasureResult
+import androidx.compose.ui.layout.MeasureScope
+import androidx.compose.ui.node.DrawModifierNode
+import androidx.compose.ui.node.GlobalPositionAwareModifierNode
+import androidx.compose.ui.node.LayoutModifierNode
+import androidx.compose.ui.node.ModifierNodeElement
+import androidx.compose.ui.node.ObserverModifierNode
+import androidx.compose.ui.node.observeReads
+import androidx.compose.ui.node.requireGraphicsContext
+import androidx.compose.ui.platform.InspectorInfo
+import androidx.compose.ui.unit.Constraints
+import androidx.compose.ui.unit.IntOffset
+import androidx.compose.ui.unit.IntSize
+import com.kyant.backdrop.backdrops.LayerBackdrop
+import com.kyant.backdrop.highlight.Highlight
+import com.kyant.backdrop.highlight.HighlightElement
+import com.kyant.backdrop.shadow.InnerShadow
+import com.kyant.backdrop.shadow.InnerShadowElement
+import com.kyant.backdrop.shadow.Shadow
+import com.kyant.backdrop.shadow.ShadowElement
+import kotlinx.coroutines.Job
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
+
+private const val ThrottleIntervalMs = 100L
+
+private val DefaultHighlight = { Highlight.Default }
+private val DefaultShadow = { Shadow.Default }
+private val DefaultOnDrawBackdrop: DrawScope.(DrawScope.() -> Unit) -> Unit = { it() }
+
+fun Modifier.drawPlainBackdrop(
+ backdrop: Backdrop,
+ shape: () -> Shape,
+ effects: BackdropEffectScope.() -> Unit,
+ layerBlock: (GraphicsLayerScope.() -> Unit)? = null,
+ exportedBackdrop: LayerBackdrop? = null,
+ onDrawBehind: (DrawScope.() -> Unit)? = null,
+ onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit = DefaultOnDrawBackdrop,
+ onDrawSurface: (DrawScope.() -> Unit)? = null,
+ onDrawFront: (DrawScope.() -> Unit)? = null
+): Modifier {
+ val shapeProvider = ShapeProvider(shape)
+ return this
+ .then(
+ if (layerBlock != null) {
+ Modifier.graphicsLayer(layerBlock)
+ } else {
+ Modifier
+ }
+ )
+ .then(
+ DrawBackdropElement(
+ backdrop = backdrop,
+ shapeProvider = shapeProvider,
+ effects = effects,
+ layerBlock = layerBlock,
+ exportedBackdrop = exportedBackdrop,
+ onDrawBehind = onDrawBehind,
+ onDrawBackdrop = onDrawBackdrop,
+ onDrawSurface = onDrawSurface,
+ onDrawFront = onDrawFront
+ )
+ )
+}
+
+fun Modifier.drawBackdrop(
+ backdrop: Backdrop,
+ shape: () -> Shape,
+ effects: BackdropEffectScope.() -> Unit,
+ highlight: (() -> Highlight?)? = DefaultHighlight,
+ shadow: (() -> Shadow?)? = DefaultShadow,
+ innerShadow: (() -> InnerShadow?)? = null,
+ layerBlock: (GraphicsLayerScope.() -> Unit)? = null,
+ exportedBackdrop: LayerBackdrop? = null,
+ onDrawBehind: (DrawScope.() -> Unit)? = null,
+ onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit = DefaultOnDrawBackdrop,
+ onDrawSurface: (DrawScope.() -> Unit)? = null,
+ onDrawFront: (DrawScope.() -> Unit)? = null
+): Modifier {
+ val shapeProvider = ShapeProvider(shape)
+ return this
+ .then(
+ if (layerBlock != null) {
+ Modifier.graphicsLayer(layerBlock)
+ } else {
+ Modifier
+ }
+ )
+ .then(
+ if (innerShadow != null) {
+ InnerShadowElement(
+ shapeProvider = shapeProvider,
+ shadow = innerShadow
+ )
+ } else {
+ Modifier
+ }
+ )
+ .then(
+ if (shadow != null) {
+ ShadowElement(
+ shapeProvider = shapeProvider,
+ shadow = shadow
+ )
+ } else {
+ Modifier
+ }
+ )
+ .then(
+ if (highlight != null) {
+ HighlightElement(
+ shapeProvider = shapeProvider,
+ highlight = highlight
+ )
+ } else {
+ Modifier
+ }
+ )
+ .then(
+ DrawBackdropElement(
+ backdrop = backdrop,
+ shapeProvider = shapeProvider,
+ effects = effects,
+ layerBlock = layerBlock,
+ exportedBackdrop = exportedBackdrop,
+ onDrawBehind = onDrawBehind,
+ onDrawBackdrop = onDrawBackdrop,
+ onDrawSurface = onDrawSurface,
+ onDrawFront = onDrawFront
+ )
+ )
+}
+
+private class DrawBackdropElement(
+ val backdrop: Backdrop,
+ val shapeProvider: ShapeProvider,
+ val effects: BackdropEffectScope.() -> Unit,
+ val layerBlock: (GraphicsLayerScope.() -> Unit)?,
+ val exportedBackdrop: LayerBackdrop?,
+ val onDrawBehind: (DrawScope.() -> Unit)?,
+ val onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit,
+ val onDrawSurface: (DrawScope.() -> Unit)?,
+ val onDrawFront: (DrawScope.() -> Unit)?
+) : ModifierNodeElement<DrawBackdropNode>() {
+
+ override fun create(): DrawBackdropNode {
+ return DrawBackdropNode(
+ backdrop = backdrop,
+ shapeProvider = shapeProvider,
+ effects = effects,
+ layerBlock = layerBlock,
+ exportedBackdrop = exportedBackdrop,
+ onDrawBehind = onDrawBehind,
+ onDrawBackdrop = onDrawBackdrop,
+ onDrawSurface = onDrawSurface,
+ onDrawFront = onDrawFront
+ )
+ }
+
+ override fun update(node: DrawBackdropNode) {
+ node.backdrop = backdrop
+ node.shapeProvider = shapeProvider
+ node.effects = effects
+ node.layerBlock = layerBlock
+ if (node.exportedBackdrop != exportedBackdrop) {
+ node.exportedBackdrop?.layerCoordinates = null
+ node.exportedBackdrop = exportedBackdrop
+ }
+ node.onDrawBehind = onDrawBehind
+ node.onDrawBackdrop = onDrawBackdrop
+ node.onDrawSurface = onDrawSurface
+ node.onDrawFront = onDrawFront
+ node.invalidateDrawCache()
+ }
+
+ override fun InspectorInfo.inspectableProperties() {
+ name = "drawBackdrop"
+ properties["backdrop"] = backdrop
+ properties["shapeProvider"] = shapeProvider
+ properties["effects"] = effects
+ properties["layerBlock"] = layerBlock
+ properties["exportedBackdrop"] = exportedBackdrop
+ properties["onDrawBehind"] = onDrawBehind
+ properties["onDrawBackdrop"] = onDrawBackdrop
+ properties["onDrawSurface"] = onDrawSurface
+ properties["onDrawFront"] = onDrawFront
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (other !is DrawBackdropElement) return false
+
+ if (backdrop != other.backdrop) return false
+ if (shapeProvider != other.shapeProvider) return false
+ if (effects != other.effects) return false
+ if (layerBlock != other.layerBlock) return false
+ if (exportedBackdrop != other.exportedBackdrop) return false
+ if (onDrawBehind != other.onDrawBehind) return false
+ if (onDrawBackdrop != other.onDrawBackdrop) return false
+ if (onDrawSurface != other.onDrawSurface) return false
+ if (onDrawFront != other.onDrawFront) return false
+
+ return true
+ }
+
+ override fun hashCode(): Int {
+ var result = backdrop.hashCode()
+ result = 31 * result + shapeProvider.hashCode()
+ result = 31 * result + effects.hashCode()
+ result = 31 * result + (layerBlock?.hashCode() ?: 0)
+ result = 31 * result + (exportedBackdrop?.hashCode() ?: 0)
+ result = 31 * result + (onDrawBehind?.hashCode() ?: 0)
+ result = 31 * result + onDrawBackdrop.hashCode()
+ result = 31 * result + (onDrawSurface?.hashCode() ?: 0)
+ result = 31 * result + (onDrawFront?.hashCode() ?: 0)
+ return result
+ }
+}
+
+private class DrawBackdropNode(
+ var backdrop: Backdrop,
+ var shapeProvider: ShapeProvider,
+ var effects: BackdropEffectScope.() -> Unit,
+ var layerBlock: (GraphicsLayerScope.() -> Unit)?,
+ var exportedBackdrop: LayerBackdrop?,
+ var onDrawBehind: (DrawScope.() -> Unit)?,
+ var onDrawBackdrop: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit,
+ var onDrawSurface: (DrawScope.() -> Unit)?,
+ var onDrawFront: (DrawScope.() -> Unit)?
+) : LayoutModifierNode, DrawModifierNode, GlobalPositionAwareModifierNode, ObserverModifierNode, Modifier.Node() {
+
+ private val effectScope =
+ object : BackdropEffectScopeImpl() {
+
+ override val shape: Shape get() = shapeProvider.innerShape
+ }
+
+ private var graphicsLayer: GraphicsLayer? = null
+
+ private val layoutLayerBlock: GraphicsLayerScope.() -> Unit = {
+ clip = true
+ shape = shapeProvider.shape
+ compositingStrategy = androidx.compose.ui.graphics.CompositingStrategy.Offscreen
+ }
+
+ private var layoutCoordinates: LayoutCoordinates? by mutableStateOf(null, neverEqualPolicy())
+
+ private var padding by mutableFloatStateOf(0f)
+
+ private val recordBackdropBlock: (DrawScope.() -> Unit) = {
+ val canvas = drawContext.canvas
+ val padding = padding
+
+ if (padding != 0f) {
+ canvas.translate(padding, padding)
+ }
+ onDrawBackdrop {
+ with(backdrop) {
+ drawBackdrop(
+ density = effectScope,
+ coordinates = layoutCoordinates,
+ layerBlock = layerBlock
+ )
+ }
+ }
+ if (padding != 0f) {
+ canvas.translate(-padding, -padding)
+ }
+ }
+
+ private val drawBackdropLayer: DrawScope.() -> Unit = {
+ val layer = graphicsLayer
+ if (layer != null) {
+ val padding = padding
+
+ recordLayer(
+ layer,
+ size = IntSize(
+ size.width.toInt() + padding.toInt() * 2,
+ size.height.toInt() + padding.toInt() * 2
+ ),
+ block = recordBackdropBlock
+ )
+
+ layer.topLeft =
+ if (padding != 0f) IntOffset(-padding.toInt(), -padding.toInt())
+ else IntOffset.Zero
+ drawLayer(layer)
+ }
+ }
+
+ override fun MeasureScope.measure(
+ measurable: Measurable,
+ constraints: Constraints
+ ): MeasureResult {
+ val placeable = measurable.measure(constraints)
+ return layout(placeable.width, placeable.height) {
+ placeable.placeWithLayer(IntOffset.Zero, layerBlock = layoutLayerBlock)
+ }
+ }
+
+ override fun ContentDrawScope.draw() {
+ if (effectScope.update(this)) {
+ updateEffects()
+ }
+
+ onDrawBehind?.invoke(this)
+ drawBackdropLayer()
+ onDrawSurface?.invoke(this)
+ drawContent()
+ onDrawFront?.invoke(this)
+
+ exportedBackdrop?.graphicsLayer?.let { layer ->
+ recordLayer(layer) {
+ onDrawBehind?.invoke(this)
+ drawBackdropLayer()
+ onDrawSurface?.invoke(this)
+ onDrawFront?.invoke(this)
+ }
+ }
+ }
+
+ private var throttle: ThrottleBackdropsNode? = null
+ private var throttleLooked = false
+ private var lastCoordinatesWrite = 0L
+ private var pendingCoordinates: LayoutCoordinates? = null
+ private var settleJob: Job? = null
+ private var lastPositionKey = UnknownPosition
+
+ private fun publishCoordinates(coordinates: LayoutCoordinates) {
+ // moved, but not against what it samples (a chip scrolled with its card): the blur it holds
+ // is still right, so don't re-record it
+ val key = backdrop.positionKey(coordinates)
+ if (key != UnknownPosition && key == lastPositionKey && layoutCoordinates != null && pendingCoordinates == null) return
+ lastPositionKey = key
+ if (!throttleLooked) {
+ throttle = findBackdropThrottle()
+ throttleLooked = true
+ }
+ val now = SystemClock.uptimeMillis()
+ val gate = throttle
+ if (gate == null || layoutCoordinates == null || !gate.moving() ||
+ now - lastCoordinatesWrite >= ThrottleIntervalMs
+ ) {
+ layoutCoordinates = coordinates
+ lastCoordinatesWrite = now
+ pendingCoordinates = null
+ return
+ }
+ pendingCoordinates = coordinates
+ if (settleJob == null) {
+ settleJob = coroutineScope.launch {
+ delay((lastCoordinatesWrite + ThrottleIntervalMs - now).coerceAtLeast(1L))
+ settleJob = null
+ val latest = pendingCoordinates
+ pendingCoordinates = null
+ if (latest != null && latest.isAttached) {
+ layoutCoordinates = latest
+ lastCoordinatesWrite = SystemClock.uptimeMillis()
+ }
+ }
+ }
+ }
+
+ override fun onGloballyPositioned(coordinates: LayoutCoordinates) {
+ if (coordinates.isAttached) {
+ if (backdrop.isCoordinatesDependent) {
+ publishCoordinates(coordinates)
+ } else {
+ if (layoutCoordinates != null) {
+ layoutCoordinates = null
+ }
+ }
+ exportedBackdrop?.layerCoordinates = coordinates
+ }
+ }
+
+ override fun onObservedReadsChanged() {
+ invalidateDrawCache()
+ }
+
+ fun invalidateDrawCache() {
+ observeEffects()
+ }
+
+ private fun observeEffects() {
+ observeReads { updateEffects() }
+ }
+
+ private fun updateEffects() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+ effectScope.apply(effects)
+ graphicsLayer?.renderEffect = effectScope.renderEffect?.asComposeRenderEffect()
+ padding = effectScope.padding
+ }
+ }
+
+ override fun onAttach() {
+ val graphicsContext = requireGraphicsContext()
+ graphicsLayer = graphicsContext.createGraphicsLayer()
+
+ observeEffects()
+ }
+
+ override fun onDetach() {
+ val graphicsContext = requireGraphicsContext()
+ graphicsLayer?.let { layer ->
+ graphicsContext.releaseGraphicsLayer(layer)
+ graphicsLayer = null
+ }
+
+ effectScope.reset()
+ settleJob = null
+ pendingCoordinates = null
+ throttle = null
+ throttleLooked = false
+ lastPositionKey = UnknownPosition
+ layoutCoordinates = null
+ exportedBackdrop?.layerCoordinates = null
+ }
+}
diff --git a/android/backdrop/src/main/java/com/kyant/backdrop/FloatingLayer.kt b/android/backdrop/src/main/java/com/kyant/backdrop/FloatingLayer.kt
index 5f2fe41..f5393a4 100644
--- a/android/backdrop/src/main/java/com/kyant/backdrop/FloatingLayer.kt
+++ b/android/backdrop/src/main/java/com/kyant/backdrop/FloatingLayer.kt
@@ -19,6 +19,10 @@ import androidx.compose.ui.node.requireGraphicsContext
import androidx.compose.ui.node.requireView
import androidx.compose.ui.platform.InspectorInfo
import androidx.compose.ui.unit.toIntSize
+import androidx.compose.ui.unit.IntOffset
+import androidx.compose.ui.unit.IntSize
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.graphics.drawscope.translate
/**
* Moves, scales and fades the content like `graphicsLayer`, but only at draw time: the content is laid
@@ -58,6 +62,7 @@ private class FloatingLayerNode(
private var layer: GraphicsLayer? = null
private val scope = InverseLayerScope()
private var size = Size.Unspecified
+ private var margin = 0
override fun onAttach() {
layer = requireGraphicsContext().createGraphicsLayer().apply { compositingStrategy = CompositingStrategy.Offscreen }
@@ -91,17 +96,18 @@ private class FloatingLayerNode(
layer.translationX = scope.translationX
layer.translationY = scope.translationY
layer.rotationZ = scope.rotationZ
+ val m = margin.toFloat()
val origin = scope.transformOrigin
- layer.pivotOffset = Offset(origin.pivotFractionX * size.width, origin.pivotFractionY * size.height)
+ layer.pivotOffset = Offset(m + origin.pivotFractionX * size.width, m + origin.pivotFractionY * size.height)
// an animated clip is only an outline on the texture: nothing inside is redrawn for it
if (scope.clip) {
when (val o = scope.shape.createOutline(size, requireLayoutDirection(), d)) {
- is Outline.Rectangle -> layer.setRectOutline(o.rect.topLeft, o.rect.size)
+ is Outline.Rectangle -> layer.setRectOutline(o.rect.topLeft + Offset(m, m), o.rect.size)
is Outline.Rounded -> {
val r = o.roundRect
- layer.setRoundRectOutline(Offset(r.left, r.top), Size(r.width, r.height), r.topLeftCornerRadius.x)
+ layer.setRoundRectOutline(Offset(r.left + m, r.top + m), Size(r.width, r.height), r.topLeftCornerRadius.x)
}
- is Outline.Generic -> layer.setPathOutline(o.path)
+ is Outline.Generic -> layer.setPathOutline(o.path.apply { translate(Offset(m, m)) })
}
}
layer.clip = scope.clip
@@ -115,9 +121,16 @@ private class FloatingLayerNode(
}
if (this.size != [email protected]) {
[email protected] = this.size
+ margin = 32.dp.roundToPx()
applyTransform()
}
- layer.record(this.size.toIntSize()) { [email protected]() }
+ // room around the content, so glass that swells or blooms past its bounds isn't cut off
+ val m = margin
+ val s = this.size.toIntSize()
+ layer.topLeft = IntOffset(-m, -m)
+ layer.record(IntSize(s.width + 2 * m, s.height + 2 * m)) {
+ translate(m.toFloat(), m.toFloat()) { [email protected]() }
+ }
drawLayer(layer)
}
}
diff --git a/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/Backdrop.kt b/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/Backdrop.kt
index abbdbe8..e6e46c1 100644
--- a/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/Backdrop.kt
+++ b/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/Backdrop.kt
@@ -1,43 +1,45 @@
-/*
- * Adapted from AndroidLiquidGlass by kyant0.
- * Source: https://github.com/Kyant0/AndroidLiquidGlass
- * Licensed under the Apache License, Version 2.0.
- */
-
-package com.kyant.backdrop.backdrops
-
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.Immutable
-import androidx.compose.runtime.remember
-import androidx.compose.ui.graphics.GraphicsLayerScope
-import androidx.compose.ui.graphics.drawscope.DrawScope
-import androidx.compose.ui.layout.LayoutCoordinates
-import androidx.compose.ui.unit.Density
-import com.kyant.backdrop.Backdrop
-
-@Composable
-fun rememberBackdrop(
- backdrop: Backdrop,
- onDraw: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit
-): Backdrop {
- return remember(backdrop, onDraw) {
- Backdrop(backdrop, onDraw)
- }
-}
-
-@Immutable
-private class Backdrop(
- val backdrop: Backdrop,
- val onDraw: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit
-) : Backdrop {
-
- override val isCoordinatesDependent: Boolean = backdrop.isCoordinatesDependent
-
- override fun DrawScope.drawBackdrop(
- density: Density,
- coordinates: LayoutCoordinates?,
- layerBlock: (GraphicsLayerScope.() -> Unit)?
- ) {
- onDraw { with(backdrop) { drawBackdrop(density, coordinates, layerBlock) } }
- }
-}
+/*
+ * Adapted from AndroidLiquidGlass by kyant0.
+ * Source: https://github.com/Kyant0/AndroidLiquidGlass
+ * Licensed under the Apache License, Version 2.0.
+ */
+
+package com.kyant.backdrop.backdrops
+
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.remember
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.unit.Density
+import com.kyant.backdrop.Backdrop
+
+@Composable
+fun rememberBackdrop(
+ backdrop: Backdrop,
+ onDraw: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit
+): Backdrop {
+ return remember(backdrop, onDraw) {
+ Backdrop(backdrop, onDraw)
+ }
+}
+
+@Immutable
+private class Backdrop(
+ val backdrop: Backdrop,
+ val onDraw: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit
+) : Backdrop {
+
+ override val isCoordinatesDependent: Boolean = backdrop.isCoordinatesDependent
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ onDraw { with(backdrop) { drawBackdrop(density, coordinates, layerBlock) } }
+ }
+
+ override fun positionKey(coordinates: LayoutCoordinates): Long = backdrop.positionKey(coordinates)
+}
diff --git a/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/CanvasBackdrop.kt b/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/CanvasBackdrop.kt
index 5227b15..287df06 100644
--- a/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/CanvasBackdrop.kt
+++ b/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/CanvasBackdrop.kt
@@ -1,41 +1,43 @@
-/*
- * Adapted from AndroidLiquidGlass by kyant0.
- * Source: https://github.com/Kyant0/AndroidLiquidGlass
- * Licensed under the Apache License, Version 2.0.
- */
-
-package com.kyant.backdrop.backdrops
-
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.Immutable
-import androidx.compose.runtime.remember
-import androidx.compose.ui.graphics.GraphicsLayerScope
-import androidx.compose.ui.graphics.drawscope.DrawScope
-import androidx.compose.ui.layout.LayoutCoordinates
-import androidx.compose.ui.unit.Density
-import com.kyant.backdrop.Backdrop
-
-@Composable
-fun rememberCanvasBackdrop(
- onDraw: DrawScope.() -> Unit
-): Backdrop {
- return remember(onDraw) {
- CanvasBackdrop(onDraw)
- }
-}
-
-@Immutable
-private class CanvasBackdrop(
- val onDraw: DrawScope.() -> Unit
-) : Backdrop {
-
- override val isCoordinatesDependent: Boolean = false
-
- override fun DrawScope.drawBackdrop(
- density: Density,
- coordinates: LayoutCoordinates?,
- layerBlock: (GraphicsLayerScope.() -> Unit)?
- ) {
- onDraw()
- }
-}
+/*
+ * Adapted from AndroidLiquidGlass by kyant0.
+ * Source: https://github.com/Kyant0/AndroidLiquidGlass
+ * Licensed under the Apache License, Version 2.0.
+ */
+
+package com.kyant.backdrop.backdrops
+
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.remember
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.unit.Density
+import com.kyant.backdrop.Backdrop
+
+@Composable
+fun rememberCanvasBackdrop(
+ onDraw: DrawScope.() -> Unit
+): Backdrop {
+ return remember(onDraw) {
+ CanvasBackdrop(onDraw)
+ }
+}
+
+@Immutable
+private class CanvasBackdrop(
+ val onDraw: DrawScope.() -> Unit
+) : Backdrop {
+
+ override val isCoordinatesDependent: Boolean = false
+
+ override fun positionKey(coordinates: androidx.compose.ui.layout.LayoutCoordinates): Long = 0L
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ onDraw()
+ }
+}
diff --git a/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/CombinedBackdrop.kt b/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/CombinedBackdrop.kt
index 44772b9..f5a60a3 100644
--- a/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/CombinedBackdrop.kt
+++ b/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/CombinedBackdrop.kt
@@ -1,105 +1,117 @@
-/*
- * Adapted from AndroidLiquidGlass by kyant0.
- * Source: https://github.com/Kyant0/AndroidLiquidGlass
- * Licensed under the Apache License, Version 2.0.
- */
-
-package com.kyant.backdrop.backdrops
-
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.Immutable
-import androidx.compose.runtime.remember
-import androidx.compose.ui.graphics.GraphicsLayerScope
-import androidx.compose.ui.graphics.drawscope.DrawScope
-import androidx.compose.ui.layout.LayoutCoordinates
-import androidx.compose.ui.unit.Density
-import com.kyant.backdrop.Backdrop
-
-@Composable
-fun rememberCombinedBackdrop(
- backdrop1: Backdrop,
- backdrop2: Backdrop
-): Backdrop {
- return remember(backdrop1, backdrop2) {
- Combined2Backdrops(backdrop1, backdrop2)
- }
-}
-
-@Composable
-fun rememberCombinedBackdrop(
- backdrop1: Backdrop,
- backdrop2: Backdrop,
- backdrop3: Backdrop
-): Backdrop {
- return remember(backdrop1, backdrop2, backdrop3) {
- Combined3Backdrops(backdrop1, backdrop2, backdrop3)
- }
-}
-
-@Composable
-fun rememberCombinedBackdrop(vararg backdrops: Backdrop): Backdrop {
- return remember(*backdrops) {
- CombinedBackdrops(*backdrops)
- }
-}
-
-@Immutable
-private class Combined2Backdrops(
- val backdrop1: Backdrop,
- val backdrop2: Backdrop
-) : Backdrop {
-
- override val isCoordinatesDependent: Boolean =
- backdrop1.isCoordinatesDependent || backdrop2.isCoordinatesDependent
-
- override fun DrawScope.drawBackdrop(
- density: Density,
- coordinates: LayoutCoordinates?,
- layerBlock: (GraphicsLayerScope.() -> Unit)?
- ) {
- with(backdrop1) { drawBackdrop(density, coordinates, layerBlock) }
- with(backdrop2) { drawBackdrop(density, coordinates, layerBlock) }
- }
-}
-
-@Immutable
-private class Combined3Backdrops(
- val backdrop1: Backdrop,
- val backdrop2: Backdrop,
- val backdrop3: Backdrop
-) : Backdrop {
-
- override val isCoordinatesDependent: Boolean =
- backdrop1.isCoordinatesDependent ||
- backdrop2.isCoordinatesDependent ||
- backdrop3.isCoordinatesDependent
-
- override fun DrawScope.drawBackdrop(
- density: Density,
- coordinates: LayoutCoordinates?,
- layerBlock: (GraphicsLayerScope.() -> Unit)?
- ) {
- with(backdrop1) { drawBackdrop(density, coordinates, layerBlock) }
- with(backdrop2) { drawBackdrop(density, coordinates, layerBlock) }
- with(backdrop3) { drawBackdrop(density, coordinates, layerBlock) }
- }
-}
-
-@Immutable
-private class CombinedBackdrops(
- vararg val backdrops: Backdrop
-) : Backdrop {
-
- override val isCoordinatesDependent: Boolean =
- backdrops.any { it.isCoordinatesDependent }
-
- override fun DrawScope.drawBackdrop(
- density: Density,
- coordinates: LayoutCoordinates?,
- layerBlock: (GraphicsLayerScope.() -> Unit)?
- ) {
- backdrops.forEach { backdrop ->
- with(backdrop) { drawBackdrop(density, coordinates, layerBlock) }
- }
- }
-}
+/*
+ * Adapted from AndroidLiquidGlass by kyant0.
+ * Source: https://github.com/Kyant0/AndroidLiquidGlass
+ * Licensed under the Apache License, Version 2.0.
+ */
+
+package com.kyant.backdrop.backdrops
+
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.Immutable
+import androidx.compose.runtime.remember
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.unit.Density
+import com.kyant.backdrop.Backdrop
+
+@Composable
+fun rememberCombinedBackdrop(
+ backdrop1: Backdrop,
+ backdrop2: Backdrop
+): Backdrop {
+ return remember(backdrop1, backdrop2) {
+ Combined2Backdrops(backdrop1, backdrop2)
+ }
+}
+
+@Composable
+fun rememberCombinedBackdrop(
+ backdrop1: Backdrop,
+ backdrop2: Backdrop,
+ backdrop3: Backdrop
+): Backdrop {
+ return remember(backdrop1, backdrop2, backdrop3) {
+ Combined3Backdrops(backdrop1, backdrop2, backdrop3)
+ }
+}
+
+@Composable
+fun rememberCombinedBackdrop(vararg backdrops: Backdrop): Backdrop {
+ return remember(*backdrops) {
+ CombinedBackdrops(*backdrops)
+ }
+}
+
+@Immutable
+private class Combined2Backdrops(
+ val backdrop1: Backdrop,
+ val backdrop2: Backdrop
+) : Backdrop {
+
+ override val isCoordinatesDependent: Boolean =
+ backdrop1.isCoordinatesDependent || backdrop2.isCoordinatesDependent
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ with(backdrop1) { drawBackdrop(density, coordinates, layerBlock) }
+ with(backdrop2) { drawBackdrop(density, coordinates, layerBlock) }
+ }
+
+ override fun positionKey(coordinates: LayoutCoordinates): Long =
+ com.kyant.backdrop.mixPositionKeys(backdrop1.positionKey(coordinates), backdrop2.positionKey(coordinates))
+}
+
+@Immutable
+private class Combined3Backdrops(
+ val backdrop1: Backdrop,
+ val backdrop2: Backdrop,
+ val backdrop3: Backdrop
+) : Backdrop {
+
+ override val isCoordinatesDependent: Boolean =
+ backdrop1.isCoordinatesDependent ||
+ backdrop2.isCoordinatesDependent ||
+ backdrop3.isCoordinatesDependent
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ with(backdrop1) { drawBackdrop(density, coordinates, layerBlock) }
+ with(backdrop2) { drawBackdrop(density, coordinates, layerBlock) }
+ with(backdrop3) { drawBackdrop(density, coordinates, layerBlock) }
+ }
+
+ override fun positionKey(coordinates: LayoutCoordinates): Long =
+ com.kyant.backdrop.mixPositionKeys(
+ com.kyant.backdrop.mixPositionKeys(backdrop1.positionKey(coordinates), backdrop2.positionKey(coordinates)),
+ backdrop3.positionKey(coordinates),
+ )
+}
+
+@Immutable
+private class CombinedBackdrops(
+ vararg val backdrops: Backdrop
+) : Backdrop {
+
+ override val isCoordinatesDependent: Boolean =
+ backdrops.any { it.isCoordinatesDependent }
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ backdrops.forEach { backdrop ->
+ with(backdrop) { drawBackdrop(density, coordinates, layerBlock) }
+ }
+ }
+
+ override fun positionKey(coordinates: LayoutCoordinates): Long =
+ backdrops.fold(0L) { k, b -> com.kyant.backdrop.mixPositionKeys(k, b.positionKey(coordinates)) }
+}
diff --git a/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/LayerBackdrop.kt b/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/LayerBackdrop.kt
index 5167954..003e7cd 100644
--- a/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/LayerBackdrop.kt
+++ b/android/backdrop/src/main/java/com/kyant/backdrop/backdrops/LayerBackdrop.kt
@@ -1,80 +1,92 @@
-/*
- * Adapted from AndroidLiquidGlass by kyant0.
- * Source: https://github.com/Kyant0/AndroidLiquidGlass
- * Licensed under the Apache License, Version 2.0.
- */
-
-package com.kyant.backdrop.backdrops
-
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.Stable
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.remember
-import androidx.compose.runtime.setValue
-import androidx.compose.ui.graphics.GraphicsLayerScope
-import androidx.compose.ui.graphics.drawscope.ContentDrawScope
-import androidx.compose.ui.graphics.drawscope.DrawScope
-import androidx.compose.ui.graphics.drawscope.withTransform
-import androidx.compose.ui.graphics.layer.GraphicsLayer
-import androidx.compose.ui.graphics.layer.drawLayer
-import androidx.compose.ui.graphics.rememberGraphicsLayer
-import androidx.compose.ui.layout.LayoutCoordinates
-import androidx.compose.ui.layout.positionInWindow
-import androidx.compose.ui.unit.Density
-import com.kyant.backdrop.Backdrop
-import com.kyant.backdrop.InverseLayerScope
-
-private val DefaultOnDraw: ContentDrawScope.() -> Unit = { drawContent() }
-
-@Composable
-fun rememberLayerBackdrop(
- graphicsLayer: GraphicsLayer = rememberGraphicsLayer(),
- onDraw: ContentDrawScope.() -> Unit = DefaultOnDraw
-): LayerBackdrop {
- return remember(graphicsLayer, onDraw) {
- LayerBackdrop(graphicsLayer, onDraw)
- }
-}
-
-@Stable
-class LayerBackdrop internal constructor(
- val graphicsLayer: GraphicsLayer,
- internal val onDraw: ContentDrawScope.() -> Unit
-) : Backdrop {
-
- override val isCoordinatesDependent: Boolean = true
-
- internal var layerCoordinates: LayoutCoordinates? by mutableStateOf(null)
-
- private var inverseLayerScope: InverseLayerScope? = null
-
- override fun DrawScope.drawBackdrop(
- density: Density,
- coordinates: LayoutCoordinates?,
- layerBlock: (GraphicsLayerScope.() -> Unit)?
- ) {
- val coordinates = coordinates ?: return
- val layerCoordinates = layerCoordinates ?: return
- withTransform({
- if (layerBlock != null) {
- with(obtainInverseLayerScope()) { inverseTransform(density, layerBlock) }
- }
- val offset =
- try {
- layerCoordinates.localPositionOf(coordinates)
- } catch (_: Exception) {
- // TODO: outer transformations lead to wrong position calculation
- coordinates.positionInWindow() - layerCoordinates.positionInWindow()
- }
- translate(-offset.x, -offset.y)
- }) {
- drawLayer(graphicsLayer)
- }
- }
-
- private fun obtainInverseLayerScope(): InverseLayerScope {
- return inverseLayerScope?.apply { reset() }
- ?: InverseLayerScope().also { inverseLayerScope = it }
- }
-}
+/*
+ * Adapted from AndroidLiquidGlass by kyant0.
+ * Source: https://github.com/Kyant0/AndroidLiquidGlass
+ * Licensed under the Apache License, Version 2.0.
+ */
+
+package com.kyant.backdrop.backdrops
+
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.Stable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.drawscope.ContentDrawScope
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.graphics.drawscope.withTransform
+import androidx.compose.ui.graphics.layer.GraphicsLayer
+import androidx.compose.ui.graphics.layer.drawLayer
+import androidx.compose.ui.graphics.rememberGraphicsLayer
+import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.layout.positionInWindow
+import androidx.compose.ui.unit.Density
+import com.kyant.backdrop.Backdrop
+import com.kyant.backdrop.InverseLayerScope
+
+private val DefaultOnDraw: ContentDrawScope.() -> Unit = { drawContent() }
+
+@Composable
+fun rememberLayerBackdrop(
+ graphicsLayer: GraphicsLayer = rememberGraphicsLayer(),
+ onDraw: ContentDrawScope.() -> Unit = DefaultOnDraw
+): LayerBackdrop {
+ return remember(graphicsLayer, onDraw) {
+ LayerBackdrop(graphicsLayer, onDraw)
+ }
+}
+
+@Stable
+class LayerBackdrop internal constructor(
+ val graphicsLayer: GraphicsLayer,
+ internal val onDraw: ContentDrawScope.() -> Unit
+) : Backdrop {
+
+ override val isCoordinatesDependent: Boolean = true
+
+ internal var layerCoordinates: LayoutCoordinates? by mutableStateOf(null)
+
+ private var inverseLayerScope: InverseLayerScope? = null
+
+ override fun DrawScope.drawBackdrop(
+ density: Density,
+ coordinates: LayoutCoordinates?,
+ layerBlock: (GraphicsLayerScope.() -> Unit)?
+ ) {
+ val coordinates = coordinates ?: return
+ val layerCoordinates = layerCoordinates ?: return
+ withTransform({
+ if (layerBlock != null) {
+ with(obtainInverseLayerScope()) { inverseTransform(density, layerBlock) }
+ }
+ val offset =
+ try {
+ layerCoordinates.localPositionOf(coordinates)
+ } catch (_: Exception) {
+ // TODO: outer transformations lead to wrong position calculation
+ coordinates.positionInWindow() - layerCoordinates.positionInWindow()
+ }
+ translate(-offset.x, -offset.y)
+ }) {
+ drawLayer(graphicsLayer)
+ }
+ }
+
+ override fun positionKey(coordinates: LayoutCoordinates): Long {
+ val layer = layerCoordinates ?: return com.kyant.backdrop.UnknownPosition
+ if (!layer.isAttached || !coordinates.isAttached) return com.kyant.backdrop.UnknownPosition
+ val o = try {
+ layer.localPositionOf(coordinates)
+ } catch (_: Exception) {
+ return com.kyant.backdrop.UnknownPosition
+ }
+ // to a quarter pixel: closer than that draws the same
+ return (Math.round(o.x * 4f).toLong() shl 32) or (Math.round(o.y * 4f).toLong() and 0xffffffffL)
+ }
+
+ private fun obtainInverseLayerScope(): InverseLayerScope {
+ return inverseLayerScope?.apply { reset() }
+ ?: InverseLayerScope().also { inverseLayerScope = it }
+ }
+}
diff --git a/android/gradle/libs.versions.toml b/android/gradle/libs.versions.toml
index f90af89..bb9ed93 100644
--- a/android/gradle/libs.versions.toml
+++ b/android/gradle/libs.versions.toml
@@ -4,6 +4,7 @@ kotlin = "2.3.21"
composeBom = "2026.09.00"
# Material 3 Expressive (LoadingIndicator, MaterialShapes): the beta, ahead of the BOM's stable
material3 = "1.5.0-beta02"
+materialIconsExtended = "1.7.8"
coreKtx = "1.17.0"
lifecycle = "2.9.4"
activityCompose = "1.11.0"
@@ -25,6 +26,7 @@ androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation" }
kyant-shapes = { group = "io.github.kyant0", name = "shapes", version.ref = "kyantShapes" }
androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
+androidx-compose-material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended", version.ref = "materialIconsExtended" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" }
kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinxCoroutines" }
jna = { group = "net.java.dev.jna", name = "jna", version.ref = "jna" }