Nucleus
Windows

HiDPI and text rendering

How Nucleus windows follow each monitor's scale factor, and how ClearType text works on Windows.

View as Markdown

Every Nucleus window tracks the scale factor of the display it sits on and re-renders when that factor changes. Keep your layout in Dp: Modifier.size(48.dp) covers 48 device pixels at 1.0 and 96 at 2.0.

Read the current density

@Composable
fun ShowDensity() {
    val density = LocalDensity.current
    Text("Scale: ${density.density}x · font scale: ${density.fontScale}")
}

LocalDensity updates when you move the window to another display, plug in a monitor, or change the system scale. Outside composition, read TaoWindow.scaleFactor, or each display's TaoMonitor.scaleFactor:

val scales = TaoMonitors.all().associate { it.name to it.scaleFactor }

On Linux, scale factors are integers. On a fractional Wayland output (125 %, 150 %), Nucleus renders at the integer scale and the compositor scales the result.

Render ClearType text on Windows

Changed in 3.0

Opaque windows on Windows now draw text with LCD (ClearType) antialiasing instead of grayscale. See Migrate from 2.x.

You write no code for it. It works under HotSpot, ProGuard and GraalVM Native Image, and needs the Nucleus Gradle plugin's nucleus.application { } setup. Text stays grayscale on popups, NativeView overlays, Mica and Acrylic backdrops, transparent = true windows, and when ClearType is off in Windows.

Turn LCD text off

Keep grayscale text at run time:

build.gradle.kts
nucleus.application {
    jvmArgs("-Dnucleus.text.lcd=false")
}

Or skip the build-time patch, which also makes the runtime property a no-op:

gradle.properties
nucleus.text.lcd.patch=false

Notes

  • Hold window sizes in Dp, never in pixels, so they survive a scale change.
  • On Windows, popups and DecoratedDialog take the DPI and work area of the monitor they open on, even when it differs from the owner's.

API reference

SymbolDescription
LocalDensity.currentCompose density of the window the composable renders in.
TaoWindow.scaleFactorCurrent scale factor of the window's monitor.
TaoMonitors.all() / TaoMonitor.scaleFactorEvery attached display and its scale factor.
-Dnucleus.text.lcd=falseRuntime: keep grayscale text on Windows.
-Pnucleus.text.lcd.patch=falseBuild: skip the LCD patch of ui-text-desktop.

What's next

Was this page helpful?
Edit on GitHub

Last updated on