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.

A liquid-glass lens over the text while a selection handle is dragged, and a glass selection menu

chethan6165065af91b562
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerOverlays.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerOverlays.kt
index b2066ac..4d1f892 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerOverlays.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerOverlays.kt
@@ -64,6 +64,8 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
+import com.chethan616.clearpdf.ui.glass.glass
+import com.chethan616.clearpdf.ui.theme.clear
import com.chethan616.clearpdf.R
import com.chethan616.clearpdf.core.CommentInfo
import com.chethan616.clearpdf.ui.AppViewModel
@@ -186,7 +188,6 @@ fun GoToPageDialog(doc: OpenDocument, onDismiss: () -> Unit) {
*/
@Composable
fun BoxScope.SelectionMenu(vm: AppViewModel, doc: OpenDocument, sel: Selection) {
- val c = pdfColors
val density = LocalDensity.current
val page = sel.range.page.toInt()
val first = sel.rects.firstOrNull() ?: return
@@ -209,20 +210,21 @@ fun BoxScope.SelectionMenu(vm: AppViewModel, doc: OpenDocument, sel: Selection)
Modifier
.offset { IntOffset(x.roundToInt(), y.roundToInt()) }
.onSizeChanged { menuSize = it }
- .width(209.dp)
- .shadow(6.dp, RoundedCornerShape(4.dp))
- .background(c.menu, RoundedCornerShape(4.dp)),
+ .width(220.dp)
+ // a liquid-glass popover over the pages, as every menu in the app
+ .glass(com.chethan616.clearpdf.ui.glass.RoundedRectangle(26.dp)),
) {
- Row(Modifier.fillMaxWidth().height(61.dp), horizontalArrangement = Arrangement.SpaceEvenly, verticalAlignment = Alignment.CenterVertically) {
+ // a Word document or presentation opens for reading: no markup, no Edit text
+ if (!doc.isOffice) Row(Modifier.fillMaxWidth().height(61.dp), horizontalArrangement = Arrangement.SpaceEvenly, verticalAlignment = Alignment.CenterVertically) {
MenuIcon(LucideIcons.MessageSquarePlus, stringResource(R.string.viewer_add_comment), allowed) { vm.notePrompt = NotePrompt(doc, null, sel) }
MenuIcon(LucideIcons.Highlighter, stringResource(R.string.common_tool_highlight), allowed) { markup(TextMarkup.Highlight) }
MenuIcon(LucideIcons.Underline, stringResource(R.string.common_tool_underline), allowed) { markup(TextMarkup.Underline) }
MenuIcon(LucideIcons.Strikethrough, stringResource(R.string.viewer_strikethrough), allowed) { markup(TextMarkup.Strikethrough) }
}
- // an inset divider, then the rows with 8 dp above and below, as the reference's menu
- Box(Modifier.fillMaxWidth().padding(horizontal = 4.dp).height(1.dp).background(c.divider))
+ // an inset divider, then the rows with 8 dp above and below
+ if (!doc.isOffice) Box(Modifier.fillMaxWidth().padding(horizontal = 16.dp).height(1.dp).background(clear.ink.copy(alpha = 0.12f)))
Spacer(Modifier.height(8.dp))
- if (doc.writable || doc.source == null) MenuRow(LucideIcons.FilePenLine, stringResource(R.string.viewer_edit_text)) {
+ if (!doc.isOffice && (doc.writable || doc.source == null)) MenuRow(LucideIcons.FilePenLine, stringResource(R.string.viewer_edit_text)) {
doc.selection.clear()
vm.enterTool(doc, ViewerTool.Edit)
}
@@ -238,22 +240,22 @@ fun BoxScope.SelectionMenu(vm: AppViewModel, doc: OpenDocument, sel: Selection)
@Composable
private fun MenuIcon(icon: ImageVector, label: String, enabled: Boolean, onClick: () -> Unit) {
- val c = pdfColors
+ val ink = clear.ink
Box(
Modifier.size(48.dp).clickable(enabled = enabled, role = Role.Button, onClick = onClick).semantics { contentDescription = label },
contentAlignment = Alignment.Center,
) {
- Icon(icon, null, tint = if (enabled) c.icon else c.icon.copy(alpha = 0.35f), modifier = Modifier.size(24.dp))
+ Icon(icon, null, tint = if (enabled) ink else ink.copy(alpha = 0.35f), modifier = Modifier.size(24.dp))
}
}
@Composable
private fun MenuRow(icon: ImageVector, label: String, onClick: () -> Unit) {
- val c = pdfColors
- Row(Modifier.fillMaxWidth().height(41.dp).clickable(onClick = onClick).padding(horizontal = 14.dp), verticalAlignment = Alignment.CenterVertically) {
- Icon(icon, null, tint = c.icon, modifier = Modifier.size(22.dp))
- Spacer(Modifier.width(21.dp))
- Text(label, color = c.text, fontSize = 15.sp)
+ val ink = clear.ink
+ Row(Modifier.fillMaxWidth().height(44.dp).clickable(onClick = onClick).padding(horizontal = 18.dp), verticalAlignment = Alignment.CenterVertically) {
+ Icon(icon, null, tint = ink, modifier = Modifier.size(22.dp))
+ Spacer(Modifier.width(16.dp))
+ Text(label, color = ink, style = com.chethan616.clearpdf.ui.theme.ClearType.Body.copy(fontSize = 15.sp))
}
}
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 8a16681..3478bfc 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
@@ -44,7 +44,6 @@ 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
import com.chethan616.clearpdf.ui.LucideIcons
@@ -60,7 +59,11 @@ import androidx.compose.material3.Text
import androidx.compose.ui.unit.sp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.graphics.drawscope.scale
import androidx.compose.ui.graphics.drawscope.translate
+import androidx.compose.ui.layout.layout
+import com.kyant.backdrop.drawBackdrop
+import com.kyant.backdrop.effects.lens
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
@@ -202,18 +205,9 @@ fun ViewerScreen(vm: AppViewModel, doc: OpenDocument) {
// The pages are recorded as the viewer's own backdrop: every glass control over them (the top
// row, the dock, a tool's bar) refracts the document, never the desk's wallpaper beneath it.
val pagesBackdrop = com.kyant.backdrop.backdrops.rememberLayerBackdrop()
- // a magnifier over the text while a selection handle is dragged, as the reference shows one
// no fill of its own: the page canvas paints the desk (every full-screen fill under the pages
// costs bandwidth on every frame of a scroll)
- Box(
- Modifier.fillMaxSize().magnifier(
- sourceCenter = { selection.magnifierAt ?: Offset.Unspecified },
- magnifierCenter = { selection.magnifierAt?.let { it - Offset(0f, with(density) { 56.dp.toPx() }) } ?: Offset.Unspecified },
- zoom = 1.25f,
- size = androidx.compose.ui.unit.DpSize(120.dp, 44.dp),
- cornerRadius = 22.dp,
- ),
- ) {
+ Box(Modifier.fillMaxSize()) {
val gesturesForTool = ctl.tool == ViewerTool.None || ctl.tool == ViewerTool.Edit
// (Reading Mode's text has no ground of its own: the desk goes in under it, inside the backdrop)
Box(Modifier.fillMaxSize().layerBackdrop(pagesBackdrop).then(if (vm.readingMode) Modifier.background(c.desk) else Modifier)) {
@@ -456,9 +450,10 @@ fun ViewerScreen(vm: AppViewModel, doc: OpenDocument) {
// The active tool's sheets, over everything.
ToolSheets(vm, doc)
- // Text selection's menu.
+ // Text selection's menu, and the glass lens over the text while a handle is dragged.
selection.selection?.let { sel ->
SelectionHandles(doc, sel)
+ selection.magnifierAt?.let { at -> SelectionLens(pagesBackdrop, at) }
// out of the way while a handle is dragged; back where the selection ends
if (selection.magnifierAt == null) SelectionMenu(vm, doc, sel)
}
@@ -702,3 +697,41 @@ private fun SuccessBannerView(b: com.chethan616.clearpdf.ui.SuccessBanner, onClo
}
}
}
+
+
+/**
+ * The magnifier over the text while a selection handle is dragged: a liquid-glass capsule above the
+ * finger that shows the pages under it enlarged, refracted at its rim (the platform magnifier
+ * copies the window, where the pages are a backdrop layer: it showed nothing).
+ */
+@Composable
+private fun SelectionLens(pages: com.kyant.backdrop.Backdrop, at: Offset) {
+ val density = androidx.compose.ui.platform.LocalDensity.current
+ val (w, h, lift) = with(density) { Triple(132.dp.toPx(), 52.dp.toPx(), 64.dp.toPx()) }
+ val zoom = 1.4f
+ Box(
+ Modifier
+ .layout { m, _ ->
+ val p = m.measure(androidx.compose.ui.unit.Constraints.fixed(w.toInt(), h.toInt()))
+ layout(p.width, p.height) { p.place(0, 0) }
+ }
+ .graphicsLayer {
+ translationX = at.x - w / 2f
+ translationY = at.y - lift - h / 2f
+ }
+ .drawBackdrop(
+ backdrop = pages,
+ shape = { com.chethan616.clearpdf.ui.glass.Capsule },
+ effects = { lens(10.dp.toPx(), 18.dp.toPx()) },
+ highlight = { com.chethan616.clearpdf.ui.glass.glassHighlight(com.chethan616.clearpdf.ui.glass.GlassSettings.style) },
+ onDrawBackdrop = { draw ->
+ // the finger's point (lift below the centre) drawn at the centre, enlarged
+ translate(size.width / 2f, size.height / 2f) {
+ scale(zoom, zoom, pivot = Offset.Zero) {
+ translate(-size.width / 2f, -size.height / 2f - lift) { draw() }
+ }
+ }
+ },
+ ),
+ )
+}