HiDPI and text rendering
How Nucleus windows follow each monitor's scale factor, and how ClearType text works on Windows.
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:
nucleus.application {
jvmArgs("-Dnucleus.text.lcd=false")
}Or skip the build-time patch, which also makes the runtime property a no-op:
nucleus.text.lcd.patch=falseNotes
- Hold window sizes in
Dp, never in pixels, so they survive a scale change. - On Windows, popups and
DecoratedDialogtake the DPI and work area of the monitor they open on, even when it differs from the owner's.
API reference
| Symbol | Description |
|---|---|
LocalDensity.current | Compose density of the window the composable renders in. |
TaoWindow.scaleFactor | Current scale factor of the window's monitor. |
TaoMonitors.all() / TaoMonitor.scaleFactor | Every attached display and its scale factor. |
-Dnucleus.text.lcd=false | Runtime: keep grayscale text on Windows. |
-Pnucleus.text.lcd.patch=false | Build: skip the LCD patch of ui-text-desktop. |
What's next
- Windows: the window you render your UI into.
- Window state: sizes, screens, and placement.
- Linux and Wayland: session detection and Wayland behavior.
Last updated on