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.

Menus and the Files list wear the Liquid glass preset (#158)

chethan6166b00e2452e96
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/AdaptiveGlass.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/AdaptiveGlass.kt
index 2dd013f..d71077f 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/AdaptiveGlass.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/AdaptiveGlass.kt
@@ -180,10 +180,11 @@ internal fun backdropStats(px: IntArray, side: Int): BackdropStats? {
/**
* The neighbour step at which a backdrop starts to count as busy, and where it is fully so. Measured on
- * a phone: a page of print behind a menu steps 0.14-0.18, the desk (title, chips, card edges) 0.06-0.10.
+ * a phone: a page of print behind a menu steps 0.14-0.18, the desk (title, chips, card edges) 0.06-0.10,
+ * which should keep its clear glass.
*/
-private const val BusyFrom = 0.03
-private const val BusyTo = 0.14
+private const val BusyFrom = 0.06
+private const val BusyTo = 0.15
/**
* A luminance reading for one glass surface, or null when [enabled] is false. Pass it to [glass] (or
@@ -278,11 +279,12 @@ fun lightEdge(luminance: Float): Color {
}
/**
- * How much an open menu dims the page around it ([open] 0 … 1): over a light page a little (at most 16%
- * black), so the white menu stands off a white page; over anything darker not at all (#158).
+ * How much an open menu dims the page around it ([open] 0 … 1): over a light page of print a little (at
+ * most 16% black), so the white menu stands off a white page; over the wallpaper, or anything darker,
+ * not at all (#158).
*/
-fun menuScrimAlpha(luminance: Float, open: Float): Float =
- 0.16f * open.coerceIn(0f, 1f) * ((luminance - 0.5f) / 0.25f).coerceIn(0f, 1f)
+fun menuScrimAlpha(luminance: Float, open: Float, busy: Float): Float =
+ 0.16f * open.coerceIn(0f, 1f) * ((luminance - 0.5f) / 0.25f).coerceIn(0f, 1f) * busy.coerceIn(0f, 1f)
/** The tallest a menu grows: its own most, or 72% of the screen, so its last row is never off-screen. */
@Composable
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/LiquidMorph.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/LiquidMorph.kt
index 1786c9f..7f6fcec 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/LiquidMorph.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/LiquidMorph.kt
@@ -363,7 +363,7 @@ internal fun LiquidMorphSurface(
val frame = remember { intArrayOf(0) }
// a breath of dim on the page around the open menu, over a light page only
if (luminance != null) androidx.compose.foundation.layout.Box(
- Modifier.fillMaxSize().drawBehind { drawRect(Color.Black, alpha = menuScrimAlpha(luminance.value, washIn()) * fade.value) },
+ Modifier.fillMaxSize().drawBehind { drawRect(Color.Black, alpha = menuScrimAlpha(luminance.value, washIn(), luminance.busy) * fade.value) },
)
fun RuntimeShader.shapeUniforms(g: Geo) {
@@ -408,9 +408,10 @@ internal fun LiquidMorphSurface(
val w = washIn()
val lum = luminance?.value ?: if (dark) 0.14f else 0.86f
// the milk or smoke a menu wears, thicker than a button's, so its rows read
- // and thicker again over a page of print, so it never shows through as ghost text
- val busyAlpha = adaptiveWash(lum, luminance?.busy ?: 0f).alpha
- val menuWash = adaptiveWash(lum).let { it.copy(alpha = maxOf((it.alpha * 1.7f).coerceAtMost(0.55f), busyAlpha)) }.glassTint(style)
+ // at the user's tint, and thicker over a page of print (that part not the preset's
+ // to thin: it is what keeps the rows from ghost text behind them)
+ val busyAlpha = (adaptiveWash(lum, luminance?.busy ?: 0f).alpha - adaptiveWash(lum).alpha).coerceAtLeast(0f)
+ val menuWash = adaptiveWash(lum).glassTint(style).let { it.copy(alpha = (it.alpha + busyAlpha).coerceAtMost(0.75f)) }
val plain = menuWash.let { it.copy(alpha = it.alpha * w) }
val wash = when {
tint.isSpecified -> androidx.compose.ui.graphics.lerp(tint.copy(alpha = 0.75f), plain, w)
@@ -539,7 +540,12 @@ private fun signedLum(luminance: Float): Float = (luminance * 2f - 1f).let { kot
private fun com.kyant.backdrop.BackdropEffectScope.morphEffects(style: GlassStyle, luminance: Float, dark: Boolean, open: Float, motion: Float, dp: Float, buttonLuminance: Float? = null, busy: Float = 0f) {
val l = signedLum(luminance.coerceIn(0f, 1f))
val o = open.coerceIn(0f, 1f)
- val menuBrightness = if (l > 0f) lerp(0.08f, 0.3f, l) else lerp(if (dark) -0.12f else 0.04f, -0.24f, -l)
+ val k = busy.coerceIn(0f, 1f)
+ // The open menu is the user's own glass (Settings ▸ Liquid glass: Crystal stays clear and bent,
+ // Frosted frosted), lifted only a little over light. Frost, milk and flattening come in with what
+ // is behind it: over a page of print ([busy]) they rise until the rows read, over the calm
+ // aurora they stay away, so the menu is liquid glass rather than a frosted card (#158).
+ val menuBrightness = if (l > 0f) lerp(0.04f, lerp(0.12f, 0.3f, k), l) else lerp(if (dark) -0.12f else 0.04f, -0.24f, -l)
// the button's end: plain glass, or (Adaptive luminance) the adaptive button's own colour and frost,
// as adaptiveGlassEffects sets them from the reading around the button
val b = buttonLuminance?.let { signedLum(it.coerceIn(0f, 1f)) }
@@ -547,10 +553,10 @@ private fun com.kyant.backdrop.BackdropEffectScope.morphEffects(style: GlassStyl
val buttonContrast = if (b != null && b > 0f) lerp(1f, 0.25f, b) else 1f
colorControls(
brightness = lerp(buttonBrightness, menuBrightness, o),
- contrast = lerp(buttonContrast, if (l > 0f) lerp(1f, 0.5f, l) else 1f, o),
- saturation = lerp(style.saturation, 1.25f, o),
+ contrast = lerp(buttonContrast, if (l > 0f) lerp(1f, lerp(0.85f, 0.5f, k), l) else 1f, o),
+ saturation = style.saturation,
)
val buttonBlur = 2f * dp * style.blur * (if (b == null) 1f else if (b > 0f) lerp(1f, 1.5f, b) else lerp(1f, 0.6f, -b))
- val menuBlur = 22f * dp * (if (l > 0f) lerp(1f, 1.35f, l) else lerp(1f, 0.75f, -l)) * (1f + 0.4f * busy.coerceIn(0f, 1f))
+ val menuBlur = 16f * dp * style.blur * (if (l > 0f) lerp(1f, 1.35f, l) else lerp(1f, 0.75f, -l)) + 18f * dp * k
blur(lerp(buttonBlur, menuBlur, o) + 5f * dp * motion.coerceIn(0f, 1f))
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/MorphButton.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/MorphButton.kt
index 0159009..cc2d6d4 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/MorphButton.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/MorphButton.kt
@@ -322,7 +322,7 @@ private fun RectMorphSurface(
val luminance = rememberGlassLuminance(enabled = true)
val inkColor = adaptiveInk(luminance, clear.ink)
// a breath of dim on the page around the open menu, over a light page only
- if (luminance != null) Box(Modifier.fillMaxSize().drawBehind { drawRect(Color.Black, alpha = menuScrimAlpha(luminance.value, tall.value) * fade.value) })
+ if (luminance != null) Box(Modifier.fillMaxSize().drawBehind { drawRect(Color.Black, alpha = menuScrimAlpha(luminance.value, tall.value, luminance.busy) * fade.value) })
Layout(
content = {
CompositionLocalProvider(LocalGlassInk provides inkColor, LocalMenuInk provides inkColor) {
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 1ec1061..3e87b95 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
@@ -340,14 +340,19 @@ private val MenuDarkWash = Color(0xFF101014).copy(alpha = 0.54f)
fun MenuCard(modifier: Modifier = Modifier, shape: androidx.compose.ui.graphics.Shape = RoundedRectangle(24.dp), content: @Composable ColumnScope.() -> Unit) {
val c = clear
val luminance = rememberGlassLuminance()
+ // Adaptive luminance off: still read what is behind, but only to frost over print (#158)
+ val assist = if (luminance == null) rememberGlassLuminance(enabled = true) else null
GlassCard(
// unseen for the frame or two it takes to read what is behind it (see [GlassLuminance])
modifier.graphicsLayer { alpha = if (luminance == null || luminance.measured) 1f else 0f },
shape = shape,
wash = if (c.dark) MenuDarkWash else MenuLightWash,
blur = 16.dp,
- styleOverride = if (c.dark) GlassStyle.MenuFrostDark else GlassStyle.MenuFrost,
+ // the user's own glass (Settings ▸ Liquid glass), lifted or dimmed a touch for its ink, as every
+ // other surface; over print the assist frosts it (it used to be a fixed frost of its own)
+ styleOverride = GlassSettings.style.copy(brightness = GlassSettings.style.brightness + if (c.dark) -0.3f else 0.08f),
luminance = luminance,
+ assist = assist,
) {
val ink = adaptiveInk(luminance, c.ink)
CompositionLocalProvider(LocalGlassInk provides ink, LocalMenuInk provides ink) { content() }
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 221bf90..394618b 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
@@ -83,8 +83,14 @@ fun Modifier.glass(
* guarantees the words on this glass their contrast, so it is not the preset's to thin out (#158).
*/
dim: Color = Color.Unspecified,
+ /**
+ * A reading of what is behind, used only to add frost and milk over print ([GlassLuminance.busy]),
+ * not to change the glass's colour or ink (that is [luminance], Adaptive luminance's).
+ */
+ assist: GlassLuminance? = null,
): Modifier {
if (clear.clean) return clip(shape).background(clear.solidPanel)
+ val clearDark = clear.dark
val backdrop = LocalBackdrop.current
val style = styleOverride ?: GlassSettings.style
// adaptive: the glass answers what is behind it instead of wearing the theme's wash
@@ -121,11 +127,16 @@ fun Modifier.glass(
backdrop = backdrop,
shape = { shape },
shadow = null,
- effects = { glassEffects(style, blur.toPx(), lensHeight.toPx(), lensAmount.toPx()) },
+ effects = {
+ glassEffects(style, blur.toPx(), lensHeight.toPx(), lensAmount.toPx())
+ if (assist != null && assist.busy > 0.01f) blur(18.dp.toPx() * assist.busy)
+ },
highlight = { glassHighlight(style) },
+ onDrawBackdrop = assist?.recorder ?: { it() },
onDrawSurface = {
if (wash.isSpecified) drawRect(wash.glassTint(style))
if (dim.isSpecified) drawRect(dim)
+ if (assist != null && assist.busy > 0.01f) drawRect(if (clearDark) Color.Black else Color.White, alpha = 0.5f * assist.busy)
},
)
}
@@ -137,9 +148,14 @@ fun Modifier.glass(
* rows (the Files list); light is a bar's (search, tabs). The blur, lens and rim stay the preset's.
*/
@Composable
-fun glassDim(heavy: Boolean = false): Color =
- if (clear.dark) Color(0xFF0B0F1A).copy(alpha = if (heavy) 0.50f else 0.36f)
- else Color.White.copy(alpha = if (heavy) 0.56f else 0.40f)
+fun glassDim(heavy: Boolean = false): Color {
+ // A picture of the user's own can be as busy as it likes, so it gets the whole dim. The app's own
+ // wallpapers are calm: there the dim is a breath, at the preset's tint, and the glass stays clear
+ // liquid glass rather than a frosted card.
+ val k = if (GlassSettings.wallpaper == Wallpaper.Custom) 1f else 0.4f * GlassSettings.style.tint.coerceIn(0.5f, 1.8f)
+ return if (clear.dark) Color(0xFF0B0F1A).copy(alpha = (if (heavy) 0.50f else 0.36f) * k)
+ else Color.White.copy(alpha = (if (heavy) 0.56f else 0.40f) * k)
+}
/**
* A panel of rows on the same liquid glass as the search bar above it (#158): the wallpaper refracts
@@ -163,13 +179,14 @@ fun GlassCard(
blur: Dp = 8.dp,
styleOverride: GlassStyle? = null,
luminance: GlassLuminance? = null,
+ assist: GlassLuminance? = null,
content: @Composable ColumnScope.() -> Unit,
) {
val below = LocalBackdrop.current
val layer = rememberLayerBackdrop()
val combined = rememberCombinedBackdrop(below, layer)
Box(modifier) {
- Box(Modifier.matchParentSize().layerBackdrop(layer).glass(shape, wash, blur, styleOverride = styleOverride, luminance = luminance))
+ Box(Modifier.matchParentSize().layerBackdrop(layer).glass(shape, wash, blur, styleOverride = styleOverride, luminance = luminance, assist = assist))
CompositionLocalProvider(LocalBackdrop provides combined) { Column(content = content) }
}
}
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 0190306..4f7d0f1 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
@@ -252,9 +252,11 @@ fun GlassTabs(
},
highlight = { Highlight.Default.copy(alpha = drag.pressProgress * GlassSettings.style.highlight.coerceIn(0f, 1f)) },
// the chosen pill: near-solid white with a breath of the tab's candy
+ // (in the light theme a white pill vanished into the light bar: its candy shows more there,
+ // a pale pink or blue that still keeps the dark label at well over 4.5:1)
onDrawSurface = {
drawRect(SelectedPill)
- drawRect(accent.copy(alpha = 0.10f))
+ drawRect(accent.copy(alpha = if (c.dark) 0.10f else 0.24f))
},
)
.height(inner)