Android log-in: thinner sea glass, the shader glowing through

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

13 files +62 -25
Message
{commit_body(@commit)}

Files changed

modified android/app/src/main/java/org/neiam/vigil/app/auth/login/Glass.kt
+60 −23
@@ -13,7 +13,9 @@ import androidx.compose.ui.graphics.Shape
13 13 import androidx.compose.ui.graphics.drawOutline
14 14 import androidx.compose.ui.graphics.drawscope.DrawScope
15 15 import androidx.compose.ui.graphics.drawscope.Stroke
16 +import androidx.compose.ui.graphics.drawscope.scale
16 17 import androidx.compose.ui.graphics.drawscope.translate
18 +import androidx.compose.ui.graphics.lerp
17 19 import androidx.compose.ui.graphics.luminance
18 20 import androidx.compose.ui.unit.dp
19 21 import dev.chrisbanes.haze.HazeState
@@ -29,10 +31,11 @@ import dev.chrisbanes.haze.hazeEffect
29 31 * With a [HazeState] the backdrop is really blurred: haze redraws the
30 32 * `hazeSource` behind (the shader and its veil) blurred by [Glass.BLUR],
31 33 * 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.
34 + * shader's bokeh and swirls; with a fine grain ([Glass.NOISE]); under a
35 + * milky white wash and a thin [fill], thicker behind the words in the
36 + * middle (the core, [Glass.CORE]). Haze blurs from API 32; below that, and
37 + * with no state, [fill] and the core are drawn translucent over whatever is
38 + * behind. Saturation has no haze equivalent and is left out.
36 39 *
37 40 * Over it goes a worn edge: 1dp, bright at the top-left and fading to [edge]
38 41 * and on to almost nothing at the bottom-right; and, with [highlight], a
@@ -83,7 +86,9 @@ fun Modifier.glass(
83 86 start = Offset.Zero,
84 87 end = Offset(size.width * 0.6f, size.height * 0.6f),
85 88 )
89 + val core = core(fill)
86 90 onDrawWithContent {
91 + drawCore(core)
87 92 if (highlight) {
88 93 drawOutline(outline, sheen)
89 94 drawOutline(outline, glow)
@@ -128,17 +133,35 @@ fun Modifier.glassSheet(shape: Shape, edge: Color, offsetY: () -> Float): Modifi
128 133 }
129 134
130 135 /**
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.
136 + * The card's tints: a white wash, then [fill] over it. The wash is
137 + * stronger on a light page ([Glass.FROST_LIGHT_ALPHA]), where it also lifts
138 + * the ground under the dark text, than on a dark one ([Glass.FROST_ALPHA]),
139 + * where it would cost the light text its contrast.
135 140 */
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 +private fun frosted(fill: Color, background: Color): List<HazeTint> {
142 + val frost = if (background.luminance() > 0.5f) Glass.FROST_LIGHT_ALPHA else Glass.FROST_ALPHA
143 + return listOf(HazeTint(Color.White.copy(alpha = frost)), HazeTint(fill))
144 +}
145 +
146 +/**
147 + * The core: [fill] again at [Glass.CORE] of its alpha, an ellipse the
148 + * card's shape, full to [Glass.CORE_SPREAD] of the way out and fading to
149 + * nothing at the edges. The cards' words sit in the middle, so the glass is
150 + * thicker behind them and clearest at the rim, like a worn pebble.
151 + */
152 +private fun core(fill: Color): Brush = Brush.radialGradient(
153 + 0f to fill.copy(alpha = fill.alpha * Glass.CORE),
154 + Glass.CORE_SPREAD to fill.copy(alpha = fill.alpha * Glass.CORE),
155 + 1f to Color.Transparent,
156 +)
157 +
158 +/** [core] stretched from a circle the card's height to an ellipse its shape. */
159 +private fun DrawScope.drawCore(core: Brush) {
160 + if (size.height <= 0f) return
161 + scale(scaleX = size.width / size.height, scaleY = 1f, pivot = center) {
162 + drawCircle(core, radius = size.height / 2f * 1.15f, center = center)
141 163 }
164 +}
142 165
143 166 /**
144 167 * The worn edge's brush over [size]: white at [Glass.EDGE_SHINE_ALPHA] at
@@ -159,21 +182,35 @@ private fun DrawScope.drawRim(inner: Outline, rim: Brush, stroke: Float) {
159 182
160 183 object Glass {
161 184 /** The backdrop's blur: enough to melt the shader's shapes into colour. */
162 − val BLUR = 32.dp
185 + val BLUR = 36.dp
163 186
164 187 /** Haze's grain over the blur: the frosted texture. */
165 − const val NOISE = 0.12f
188 + const val NOISE = 0.07f
189 +
190 + /** A white wash under the card's tint, for a milky body: stronger on a
191 + * light page than on a dark one. */
192 + const val FROST_ALPHA = 0.02f
193 + const val FROST_LIGHT_ALPHA = 0.10f
194 +
195 + /** The cards' tint over the frosted blur, at the rim. */
196 + const val CARD_ALPHA = 0.22f
197 +
198 + /** The core behind the words: the tint again at this share of its alpha,
199 + * full out to [CORE_SPREAD] of the way to the rim, then fading. */
200 + const val CORE = 1.0f
201 + const val CORE_SPREAD = 0.55f
166 202
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
203 + /** A card that can't be used: fainter, so it reads as off (the old 0.38
204 + * against 0.68, scaled to [CARD_ALPHA]). */
205 + const val DISABLED_ALPHA = 0.12f
171 206
172 − /** The cards' tint over the frosted blur. */
173 − const val CARD_ALPHA = 0.68f
207 + /** How far a card's secondary text and its icon move towards onSurface
208 + * ([ink]): the glass is thinner than the card it replaced. */
209 + const val INK_LIFT = 0.30f
210 + const val ICON_LIFT = 0.20f
174 211
175 − /** A card that can't be used: fainter, so it reads as off. */
176 − const val DISABLED_ALPHA = 0.38f
212 + /** [colour] on the glass: lifted by [lift] towards [content]. */
213 + fun ink(colour: Color, content: Color, lift: Float = INK_LIFT): Color = lerp(colour, content, lift)
177 214
178 215 /**
179 216 * The sheets. A sheet is a window of its own, so haze can't blur behind
modified android/app/src/main/java/org/neiam/vigil/app/auth/login/LoginScreen.kt
+2 −2
@@ -344,14 +344,14 @@ private fun MethodButton(
344 344 icon,
345 345 contentDescription = null,
346 346 modifier = Modifier.size(iconSize),
347 − tint = if (enabled) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurfaceVariant,
347 + tint = if (enabled) Glass.ink(scheme.primary, scheme.onSurface, Glass.ICON_LIFT) else scheme.onSurfaceVariant,
348 348 )
349 349 Spacer(Modifier.height(if (compact) 4.dp else 8.dp))
350 350 Text(title, style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.SemiBold)
351 351 Text(
352 352 line,
353 353 style = MaterialTheme.typography.bodyMedium,
354 − color = if (enabled) MaterialTheme.colorScheme.onSurfaceVariant else MaterialTheme.colorScheme.error,
354 + color = if (enabled) Glass.ink(scheme.onSurfaceVariant, scheme.onSurface) else scheme.error,
355 355 textAlign = TextAlign.Center,
356 356 maxLines = if (compact) 1 else 2,
357 357 overflow = TextOverflow.Ellipsis,

Parents: fa318dc