Android log-in: sea glass, frosted, instead of a clear pane

fa318dc · gmorell · 2026-12-04 03:31

13 files +134 -44
Message
{commit_body(@commit)}

Files changed

modified android/app/src/main/java/org/neiam/vigil/app/auth/login/Glass.kt
+122 −40
@@ -1,17 +1,20 @@
1 1 package org.neiam.vigil.app.auth.login
2 2
3 −import androidx.compose.foundation.border
3 +import android.os.Build
4 4 import androidx.compose.ui.Modifier
5 5 import androidx.compose.ui.draw.clip
6 6 import androidx.compose.ui.draw.drawWithCache
7 7 import androidx.compose.ui.geometry.Offset
8 +import androidx.compose.ui.geometry.Size
8 9 import androidx.compose.ui.graphics.Brush
9 10 import androidx.compose.ui.graphics.Color
11 +import androidx.compose.ui.graphics.Outline
10 12 import androidx.compose.ui.graphics.Shape
11 13 import androidx.compose.ui.graphics.drawOutline
14 +import androidx.compose.ui.graphics.drawscope.DrawScope
12 15 import androidx.compose.ui.graphics.drawscope.Stroke
13 16 import androidx.compose.ui.graphics.drawscope.translate
14 −import androidx.compose.ui.geometry.Size
17 +import androidx.compose.ui.graphics.luminance
15 18 import androidx.compose.ui.unit.dp
16 19 import dev.chrisbanes.haze.HazeState
17 20 import dev.chrisbanes.haze.HazeStyle
@@ -19,15 +22,22 @@ import dev.chrisbanes.haze.HazeTint
19 22 import dev.chrisbanes.haze.hazeEffect
20 23
21 24 /**
22 − * The web's glass panel (base-100 at 0.72 over a 10px backdrop blur,
23 − * saturate 1.1, a soft drop shadow) for the log-in page's cards and sheets.
25 + * Sea glass for the log-in page's cards and sheets, after the web's glass
26 + * panel (base-100 at 0.72 over blur(10px) saturate(1.1)), but frosted: the
27 + * shader's colour and light come through softly, its shapes don't.
24 28 *
25 29 * With a [HazeState] the backdrop is really blurred: haze redraws the
26 − * `hazeSource` behind (the shader and its veil) blurred, tinted with
27 − * [fill]. Haze blurs from API 32; below that, and with no state, [fill] is
28 − * simply drawn translucent over whatever is behind. Saturation has no haze
29 − * equivalent and is left out. Over either goes a light 1dp edge and,
30 − * with [highlight], a faint white sheen from the top-left corner.
30 + * `hazeSource` behind (the shader and its veil) blurred by [Glass.BLUR],
31 + * far more than the web's 10px, since a phone card is small next to the
32 + * shader's bokeh and swirls; with a fine grain ([Glass.NOISE]); under
33 + * [fill] and a milky white wash. Haze blurs from API 32; below that, and
34 + * with no state, [fill] is drawn translucent over whatever is behind.
35 + * Saturation has no haze equivalent and is left out.
36 + *
37 + * Over it goes a worn edge: 1dp, bright at the top-left and fading to [edge]
38 + * and on to almost nothing at the bottom-right; and, with [highlight], a
39 + * soft glow down from the top edge and a faint sheen from the top-left
40 + * corner. A disabled card passes highlight false and gets a flat [edge].
31 41 *
32 42 * No shadow: under a translucent shape it shows through as a dark smudge.
33 43 * Give the shape's own container [Color.Transparent]; this draws it.
@@ -45,9 +55,9 @@ fun Modifier.glass(
45 55 haze,
46 56 HazeStyle(
47 57 backgroundColor = background,
48 − tints = listOf(HazeTint(fill)),
58 + tints = frosted(fill, background),
49 59 blurRadius = Glass.BLUR,
50 − noiseFactor = 0f,
60 + noiseFactor = Glass.NOISE,
51 61 fallbackTint = HazeTint(fill),
52 62 ),
53 63 )
@@ -57,23 +67,38 @@ fun Modifier.glass(
57 67 onDrawBehind { drawOutline(outline, fill) }
58 68 }
59 69 }
60 − return backdrop
61 − .drawWithCache {
62 − val outline = shape.createOutline(size, layoutDirection, this)
63 − val brush = Brush.linearGradient(
64 − listOf(Color.White.copy(alpha = Glass.HIGHLIGHT_ALPHA), Color.Transparent),
65 − start = Offset.Zero,
66 − end = Offset(size.width * 0.6f, size.height * 0.6f),
67 − )
68 − onDrawBehind { if (highlight) drawOutline(outline, brush) }
70 + return backdrop.drawWithCache {
71 + val stroke = 1.dp.toPx()
72 + val outline = shape.createOutline(size, layoutDirection, this)
73 + // Inset by half the stroke, so all of it is on the card.
74 + val inner = shape.createOutline(Size(size.width - stroke, size.height - stroke), layoutDirection, this)
75 + val rim = if (highlight) wornEdge(edge, size) else Brush.linearGradient(listOf(edge, edge))
76 + val glow = Brush.verticalGradient(
77 + listOf(Color.White.copy(alpha = Glass.GLOW_ALPHA), Color.Transparent),
78 + startY = 0f,
79 + endY = Glass.GLOW_DEPTH.toPx(),
80 + )
81 + val sheen = Brush.linearGradient(
82 + listOf(Color.White.copy(alpha = Glass.HIGHLIGHT_ALPHA), Color.Transparent),
83 + start = Offset.Zero,
84 + end = Offset(size.width * 0.6f, size.height * 0.6f),
85 + )
86 + onDrawWithContent {
87 + if (highlight) {
88 + drawOutline(outline, sheen)
89 + drawOutline(outline, glow)
90 + }
91 + drawContent()
92 + drawRim(inner, rim, stroke)
69 93 }
70 − .border(1.dp, edge, shape)
94 + }
71 95 }
72 96
73 97 /**
74 − * The same edge and top highlight for a ModalBottomSheet, whose own
75 − * containerColor is the fill (surface at [Glass.SHEET_ALPHA]). The sheet is
76 − * a window of its own, so haze can't reach the page behind it to blur it.
98 + * The same edge and top glow for a ModalBottomSheet, whose own
99 + * containerColor is the fill (surface at [Glass.sheetAlpha]). The sheet is
100 + * a window of its own, so haze can't reach the page behind it to blur it;
101 + * the page blurs itself instead (see [Glass.SHEET_ALPHA]).
77 102 *
78 103 * A sheet's modifier comes before the modifiers that slide it into place,
79 104 * so this draws [offsetY] (the sheet state's offset) further down, where
@@ -83,46 +108,103 @@ fun Modifier.glass(
83 108 fun Modifier.glassSheet(shape: Shape, edge: Color, offsetY: () -> Float): Modifier =
84 109 drawWithCache {
85 110 val stroke = 1.dp.toPx()
86 − // Inset by half the stroke, so all of it is on the sheet.
87 − val inner = Size(size.width - stroke, size.height - stroke)
88 − val outline = shape.createOutline(inner, layoutDirection, this)
111 + val inner = shape.createOutline(Size(size.width - stroke, size.height - stroke), layoutDirection, this)
89 112 val whole = shape.createOutline(size, layoutDirection, this)
90 − val shine = Brush.verticalGradient(
91 − listOf(Color.White.copy(alpha = Glass.HIGHLIGHT_ALPHA), Color.Transparent),
113 + val glow = Brush.verticalGradient(
114 + listOf(Color.White.copy(alpha = Glass.GLOW_ALPHA), Color.Transparent),
92 115 startY = 0f,
93 − endY = 48.dp.toPx(),
116 + endY = Glass.GLOW_DEPTH.toPx(),
94 117 )
118 + // Across the sheet's top rather than its whole height: the sheet is
119 + // as tall as the screen, and only its top shows above the content.
120 + val rim = wornEdge(edge, Size(size.width, Glass.GLOW_DEPTH.toPx() * 4))
95 121 onDrawWithContent {
96 122 drawContent()
97 123 translate(top = offsetY()) {
98 − drawOutline(whole, shine)
99 − translate(stroke / 2, stroke / 2) { drawOutline(outline, edge, style = Stroke(stroke)) }
124 + drawOutline(whole, glow)
125 + drawRim(inner, rim, stroke)
100 126 }
101 127 }
102 128 }
103 129
130 +/**
131 + * The card's tints: [fill] and a white wash. On a light page the wash
132 + * ([Glass.FROST_LIGHT_ALPHA]) goes over the fill, milky and lifting the
133 + * card clear of the dark text; on a dark one ([Glass.FROST_ALPHA]) under
134 + * it, so the fill keeps the light text's contrast.
135 + */
136 +private fun frosted(fill: Color, background: Color): List<HazeTint> =
137 + if (background.luminance() > 0.5f) {
138 + listOf(HazeTint(fill), HazeTint(Color.White.copy(alpha = Glass.FROST_LIGHT_ALPHA)))
139 + } else {
140 + listOf(HazeTint(Color.White.copy(alpha = Glass.FROST_ALPHA)), HazeTint(fill))
141 + }
142 +
143 +/**
144 + * The worn edge's brush over [size]: white at [Glass.EDGE_SHINE_ALPHA] at
145 + * the top-left, [edge] by the middle, and [edge] at a fifth of its alpha at
146 + * the bottom-right.
147 + */
148 +private fun wornEdge(edge: Color, size: Size): Brush = Brush.linearGradient(
149 + 0f to Color.White.copy(alpha = Glass.EDGE_SHINE_ALPHA),
150 + 0.45f to edge,
151 + 1f to edge.copy(alpha = edge.alpha * 0.2f),
152 + start = Offset.Zero,
153 + end = Offset(size.width, size.height),
154 +)
155 +
156 +private fun DrawScope.drawRim(inner: Outline, rim: Brush, stroke: Float) {
157 + translate(stroke / 2, stroke / 2) { drawOutline(inner, rim, style = Stroke(stroke)) }
158 +}
159 +
104 160 object Glass {
105 − /** The cards' tint over the blur (the web's 0.72, a shade less). */
161 + /** The backdrop's blur: enough to melt the shader's shapes into colour. */
162 + val BLUR = 32.dp
163 +
164 + /** Haze's grain over the blur: the frosted texture. */
165 + const val NOISE = 0.12f
166 +
167 + /** A white wash with the card's tint, for a milky body: under the tint
168 + * on a dark page, over it (and stronger) on a light one. */
169 + const val FROST_ALPHA = 0.04f
170 + const val FROST_LIGHT_ALPHA = 0.25f
171 +
172 + /** The cards' tint over the frosted blur. */
106 173 const val CARD_ALPHA = 0.68f
107 174
108 175 /** A card that can't be used: fainter, so it reads as off. */
109 176 const val DISABLED_ALPHA = 0.38f
110 177
111 − /** The sheets, unblurred, so more opaque than the cards. */
112 − const val SHEET_ALPHA = 0.85f
178 + /**
179 + * The sheets. A sheet is a window of its own, so haze can't blur behind
180 + * it; instead the page under it is blurred whole ([SHEET_BACKDROP_BLUR],
181 + * from API 31) and the sheet is frosted over that. Without the blur the
182 + * cards' text would show through, so it is all but opaque.
183 + */
184 + const val SHEET_ALPHA = 0.88f
185 + const val SHEET_ALPHA_UNBLURRED = 0.97f
186 + val sheetAlpha: Float
187 + get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) SHEET_ALPHA else SHEET_ALPHA_UNBLURRED
113 188
114 − /** The light 1dp edge, onSurface at this alpha. */
189 + /** The page's blur while a sheet is open over it. */
190 + val SHEET_BACKDROP_BLUR = 24.dp
191 +
192 + /** The edge's middle, onSurface at this alpha; it fades from white at
193 + * [EDGE_SHINE_ALPHA] top-left to a fifth of this bottom-right. */
115 194 const val EDGE_ALPHA = 0.22f
195 + const val EDGE_SHINE_ALPHA = 0.40f
116 196 const val DISABLED_EDGE_ALPHA = 0.10f
117 197
118 − const val HIGHLIGHT_ALPHA = 0.10f
198 + /** The sheen from the top-left corner. */
199 + const val HIGHLIGHT_ALPHA = 0.08f
200 +
201 + /** The glow down from the top edge, white fading out over [GLOW_DEPTH]. */
202 + const val GLOW_ALPHA = 0.10f
203 + val GLOW_DEPTH = 20.dp
119 204
120 205 /** The page colour over the shader, so the header stays readable. */
121 206 const val VEIL_ALPHA = 0.55f
122 207
123 208 /** Thicker behind the header's text. */
124 209 const val HEADER_VEIL_ALPHA = 0.8f
125 −
126 − /** The web's backdrop-filter: blur(10px). */
127 − val BLUR = 10.dp
128 210 }
modified android/app/src/main/java/org/neiam/vigil/app/auth/login/LoginScreen.kt
+12 −4
@@ -44,6 +44,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
44 44 import androidx.compose.runtime.setValue
45 45 import androidx.compose.ui.Alignment
46 46 import androidx.compose.ui.Modifier
47 +import androidx.compose.ui.draw.blur
47 48 import androidx.compose.ui.graphics.Brush
48 49 import androidx.compose.ui.graphics.Color
49 50 import androidx.compose.ui.graphics.vector.ImageVector
@@ -133,7 +134,7 @@ fun LoginScreen(
133 134 val m = methods ?: AuthMethods.offline("Checking ${server.removePrefix("https://")}…")
134 135
135 136 val haze = remember { HazeState() }
136 − LoginBackdrop(haze) {
137 + LoginBackdrop(haze, blurred = sheet != null) {
137 138 BoxWithConstraints(Modifier.fillMaxSize().safeDrawingPadding()) {
138 139 // Landscape when it is wider than tall and wide enough for three
139 140 // buttons side by side; a 360dp phone turned sideways qualifies,
@@ -364,16 +365,23 @@ private fun MethodButton(
364 365 * colour, which haze blurs behind the buttons, then [content] over it on a
365 366 * transparent Surface. Touches anywhere on the page are heard, not taken,
366 367 * for the eyes to look at.
368 + *
369 + * [blurred] (a sheet is open) frosts the whole page, cards and all, so the
370 + * sheet over it reads as glass, not a window onto the cards' text.
367 371 */
368 372 @Composable
369 −private fun LoginBackdrop(haze: HazeState, content: @Composable () -> Unit) {
373 +private fun LoginBackdrop(haze: HazeState, blurred: Boolean, content: @Composable () -> Unit) {
370 374 val scheme = MaterialTheme.colorScheme
371 375 val colours = remember(scheme.background, scheme.primary, scheme.secondary, scheme.tertiary) {
372 376 ShaderColours.from(scheme)
373 377 }
374 378 val settings = remember { ShaderSettings() }
375 379 val pointer = remember { ShaderPointer() }
376 − Box(Modifier.fillMaxSize().shaderPointer(pointer, enabled = settings.pattern == "eyes")) {
380 + Box(
381 + Modifier.fillMaxSize()
382 + .shaderPointer(pointer, enabled = settings.pattern == "eyes")
383 + .then(if (blurred) Modifier.blur(Glass.SHEET_BACKDROP_BLUR) else Modifier),
384 + ) {
377 385 BoxWithConstraints(Modifier.fillMaxSize().hazeSource(haze)) {
378 386 ShaderBackground(settings, colours, Modifier.fillMaxSize(), pointer)
379 387 // The page's test for landscape, near enough: this box
@@ -408,7 +416,7 @@ private fun LoginSheetHost(
408 416 onDismissRequest = onDismiss,
409 417 sheetState = state,
410 418 shape = shape,
411 − containerColor = scheme.surface.copy(alpha = Glass.SHEET_ALPHA),
419 + containerColor = scheme.surface.copy(alpha = Glass.sheetAlpha),
412 420 contentColor = scheme.onSurface,
413 421 tonalElevation = 0.dp,
414 422 modifier = Modifier.glassSheet(

Parents: 3208487