We're building ReClaim, a minimalist Android launcher that's on Google Play. The biggest thing on its Home screen is a clock. When the clock has the screen's width to itself, a fixed font size is fine.
But Home also has small optional widgets: habit marks, a practice timer, a block status. They sit in a row on either side of the clock, and the clock gets whatever width is left. With a fixed 64 sp clock and TextOverflow.Ellipsis, a narrow phone with marks on both sides could end up showing something like "10:…". A clock that hides its own minutes isn't much of a clock.
This post walks through the fix: measure the text with Compose's TextMeasurer, binary-search the largest font size that fits, and keep a floor where we stop shrinking. It's a small function, but a few of its choices are easy to get wrong, and some side effects only showed up when we read it closely for this post.
One version note first. This code landed in our repo on November 25, 2026. The Play listing still shows version 0.6.6.0.1, updated October 29, so treat this as the next build's behavior.
1. Where the width comes from
The widget row is a plain Row. The marks keep their natural size, and the clock takes the leftover space through weight(1f):
if (leftOn && (showClock || rightOn)) Spacer(Modifier.width(18.dp))
if (showClock) {
// The marks keep their size. The clock scales down to the width left between them.
Box(Modifier.weight(1f), contentAlignment = Alignment.Center) { clock() }
}
if (rightOn && showClock) Spacer(Modifier.width(18.dp))
That comment is the whole layout contract. The marks are tap targets, and shrinking them would make them harder to hit. The clock can give up some size without losing its meaning.
weight(1f) gives the clock a bounded width, but it doesn't make the text fit. Text lays out at whatever font size you give it, and if that's too wide, Ellipsis cuts the minutes. So the clock needs to know its width before it picks a font size.
When no widgets are on, Home calls the same ClockView without the rail. It runs the same fitting code, but with the full width the preferred size normally fits, so nothing visibly changes.
2. Measuring before drawing
BoxWithConstraints exposes the incoming constraints to its content, and rememberTextMeasurer() gives a TextMeasurer that can lay out text without drawing it. Here is the time line:
val budget = if (constraints.hasBoundedWidth) (constraints.maxWidth - 4).toFloat().coerceAtLeast(0f) else Float.POSITIVE_INFINITY
val timeSize = fittedFontSize(preferredTime, CLOCK_TIME_MIN_SP, budget) { size ->
measurer.measure(
text = timeText,
style = TextStyle(
fontFamily = family,
fontSize = size.sp,
fontWeight = weight,
letterSpacing = (baseSpacing * size / preferredTime).sp,
),
maxLines = 1,
softWrap = false,
).size.width.toFloat()
}
A few details here matter more than they look.
The budget is in pixels, and so is the answer. constraints.maxWidth is in pixels, and TextLayoutResult.size.width is in pixels too, so the comparison doesn't need a density conversion. The font size is in sp, which the measurer turns into pixels using the current density and the system font scale. A user with large system text gets a clock that starts larger and starts shrinking sooner, which is the right trade.
Four pixels of slack. The budget subtracts 4 px from the available width. The code doesn't say why; we read it as a margin against rounding, but we haven't tested that.
An unbounded width means "don't shrink". If the parent doesn't bound the width, the budget becomes positive infinity, and the fitting function returns the preferred size without measuring anything.
Measure the style you'll draw. The measurer gets the same family, weight, size and letter spacing that the visible Text uses. The family comes from LocalTextStyle, so it follows the font the user picked in settings. ReClaim offers ten families, from Monospace to Cursive to Lora. Their widths at the same size are very different, which is why a hard-coded size per style was never going to work.
The letter spacing scales with the font size. The Minimal clock style uses 2 sp of spacing at the preferred size. At half the size it gets 1 sp. If the spacing stayed fixed while the glyphs shrank, a small Minimal clock would look oddly loose, and its measured width would shrink more slowly than expected. The drawn Text uses the same expression:
Text(
text = timeText,
color = clockColor,
fontSize = timeSize.sp,
fontWeight = weight,
fontFamily = family,
letterSpacing = (baseSpacing * timeSize / preferredTime).sp,
maxLines = 1,
softWrap = false,
overflow = TextOverflow.Ellipsis,
)
One honest gap: the measured TextStyle is built from four properties, while the Material Text merges its arguments into LocalTextStyle. Anything else in that style that changes width, such as font feature settings, would be drawn but not measured. Our theme doesn't set any of those today, so the two should agree, but nothing enforces it.
The date line does this more simply. It copies the theme's titleMedium (or titleSmall in compact mode) with only the font size and line height changed, and passes that same style to both the measurer and the Text. That's the safer pattern, and the time line could probably use it too.
3. The search itself
The fitting logic lives in its own file with no Compose imports:
/** Smallest time size that still reads as a clock when the row is crowded. */
internal const val CLOCK_TIME_MIN_SP = 20f
/** Smallest date size. Below this the line ellipsizes instead of shrinking further. */
internal const val CLOCK_DATE_MIN_SP = 11f
/**
* Largest size in `[min, preferred]` whose measured width fits [maxWidthPx].
* An unbounded or empty width keeps [preferred]. When even [min] is too wide, [min] is the floor.
*/
internal fun fittedFontSize(
preferred: Float,
min: Float,
maxWidthPx: Float,
widthAt: (Float) -> Float,
): Float {
if (preferred <= min) return min
if (maxWidthPx <= 0f || !maxWidthPx.isFinite()) return preferred
if (widthAt(preferred) <= maxWidthPx) return preferred
if (widthAt(min) > maxWidthPx) return min
var lo = min
var hi = preferred
repeat(12) {
val mid = (lo + hi) / 2f
if (widthAt(mid) <= maxWidthPx) lo = mid else hi = mid
}
return lo
}
The early returns handle the common cases cheaply. If the preferred size fits, which it does whenever the clock has the row to itself, there's one measurement and no search. If even the floor doesn't fit, there are two measurements, and the function returns the floor.
Only between those two cases does the loop run. Twelve halvings of the time range (64 − 20 = 44 sp) narrow it to about 0.01 sp, which is far below anything you could see. The compact clock starts at 52 sp, so its range is 32 sp and the final step is smaller still.
There's a property here worth calling out. lo starts at min, which was just measured and fits. After that, lo only ever moves to a mid that was also measured and fits. So the returned size is always one that actually fit, even if text width isn't perfectly monotonic in font size. Font hinting and pixel rounding can make it slightly bumpy. A bump could cost us the largest fitting size, but it can't give us a size that overflows. The floor case is the only exception, and that's deliberate.
Why pass a lambda? widthAt: (Float) -> Float keeps Android out of the function, so it can be tested on the JVM with fake widths:
@Test fun shrinksToTheLargestSizeThatFits() {
val fitted = fittedFontSize(64f, 10f, 200f) { size -> size * 10f }
assertTrue(fitted * 10f <= 200f)
assertTrue(fitted > 19f)
}
@Test fun floorWhenNothingFits() {
assertEquals(CLOCK_TIME_MIN_SP, fittedFontSize(64f, CLOCK_TIME_MIN_SP, 10f) { 100f }, 0.01f)
}
The test file has four cases: preferred fits, unbounded width, shrink, and floor. It doesn't test the Compose side, meaning real fonts, real density, or the rail layout.
4. Floors, and what happens below them
The two floors are 20 sp for the time and 11 sp for the date. The KDoc on the date floor says what happens past it: "Below this the line ellipsizes instead of shrinking further." Both Texts keep maxLines = 1, softWrap = false and TextOverflow.Ellipsis, so the old behavior is still there as a safety net. It just kicks in much later.
We think a floor is the right call. A 9 sp clock between two habit marks technically fits, but nobody can read it at a glance, and that's the whole job. Past a certain point the row is too crowded, and an ellipsis says so more honestly than unreadable text.
5. What it costs
In the worst case the search measures each line 14 times: once at the preferred size, once at the floor, and twelve times in the loop. With two lines, that's up to 28 text layouts each time the clock composes.
The TextMeasurer docs are clear that its cache doesn't help much with this: "Layout-affecting changes like text, font size, or constraints calculate a new layout." Every step of the search uses a new font size, so every step is a fresh layout.
That's acceptable for us: the text changes once a minute, the constraints change when widgets are toggled or the phone rotates, and a five-character string is cheap to lay out. We haven't profiled it on a device, so that's a judgment, not a measurement. For long or fast-changing text, you'd want to cache the result per width.
6. Side effects we found while reading it
The size can change at 10:00. The 12-hour pattern is h:mm, so "9:59" has three digits and "10:00" has four. In a crowded row, the clock can get visibly smaller at ten o'clock and grow again at one. Proportional digits can cause small changes on other minutes too, because "1:11" is narrower than "8:48" in many fonts. We haven't watched this happen on a phone yet; it follows from measuring the actual text. One fix would be to measure a fixed worst-case string, such as the widest digits for the current format, and size the clock once per width instead of once per minute.
The date's size can change daily. The full date pattern is EEEE, MMMM d. "Wednesday, September 30" is much longer than "Friday, May 1", so in a tight row the date can shift size from day to day.
The date pattern fixes the order. DateTimeFormatter.ofPattern(..., Locale.getDefault()) translates the day and month names but keeps our order. Java's ofLocalizedDate "Returns a locale specific date format for the ISO chronology," which would follow the user's locale instead. That's a separate fix from fitting.
The time doesn't follow ReClaim's font-size setting. The date's base style comes from our typography, which applies the user's Small, Medium, Large or Extra Large scale. The time's preferred size is hard-coded at 52 or 64 sp, so that setting only affects the date. System font scale still applies to both, because it lives in the density.
7. The tick, briefly
The clock re-reads the time on each minute boundary:
LaunchedEffect(Unit) {
while (true) {
now = LocalDateTime.now()
delay(60_000L - System.currentTimeMillis() % 60_000L)
}
}
We covered the catch with this pattern in our post on Home-screen tasks: delay most likely runs on a clock that stops in deep sleep, so the first tick after the screen wakes can be late. For the clock, the worst case is about a minute of stale time. The fix we'd reach for is the same as there: re-read the time on resume, and while Home is visible, register for Intent.ACTION_TIME_TICK, which the docs describe as "Sent every minute" and note "You cannot receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver()." Fitting just reruns whenever now changes.
Tapping the clock calls a small wrapper around the system Clock app:
/** Opens the system Clock app (alarms view), falling back to its main screen. */
fun openClock(context: Context) {
val showAlarms = Intent(AlarmClock.ACTION_SHOW_ALARMS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
runCatching { context.startActivity(showAlarms) }
}
The KDoc promises a fallback that the body doesn't have. If no app handles ACTION_SHOW_ALARMS, the runCatching swallows the error and the tap does nothing. That's a one-line fix we haven't made yet.
8. Why not TextAutoSize?
Compose now has a built-in answer. TextAutoSize is described in the reference as an "Interface used by Text composables to override text size to automatically grow or shrink text to fill the layout bounds," with TextAutoSize.StepBased as the ready-made version. It arrived in the Compose Foundation 1.8 line, which went stable on April 23, 2025.
Our project pins the Compose BOM at 2024.12.01, which maps to Foundation 1.7.6, so the API isn't available to us without a BOM upgrade. Hence our own 30-line function. After an upgrade, StepBased could likely replace most of it, though we'd check how it handles our floor and the proportional letter spacing first.
Takeaways
-
Find the width first.
BoxWithConstraintsplusTextMeasurerlets you choose a size from the real space instead of guessing. -
Measure exactly what you draw. Reuse one
TextStylefor both if you can. Scale anything size-relative, like letter spacing, along with the font. - Make the search return a measured fit. Keep the lower bound on sizes you've verified, and non-monotonic widths can't make you overflow.
- Keep a floor. Below a readable size, an ellipsis is more honest than tiny text.
- Live text means live sizes. If the text changes every minute, so can its size.
-
Check your BOM.
TextAutoSizemay already cover your case.
If you'd like the product side of what belongs on a Home screen, our guide to designing a minimal Android home screen covers it from the user's end, and our comparison of minimalist launchers for Android looks at how other launchers approach a quiet home screen.
This post was drafted with AI assistance and reviewed by the ReClaim team.
Top comments (0)