Skip to main content

Module density

Module density 

Source
Expand description

Physical-size-stable sizing across the Kobo fleet.

Kobo’s fb_var_screeninfo reports 0mm for the panel’s physical size on most models, so ppi cannot be derived from millimetres reliably. Instead it is looked up from the panel resolution (the same approach KOReader takes).

dp(n) returns n design units expressed at the reference density, scaled to the current panel so a control keeps the same real-world size on a 212ppi Nia and a 300ppi Sage alike. The existing UI was tuned on a 300ppi panel, so wrapping a former raw-pixel literal in dp() leaves 300ppi devices untouched and only rescales the rest.

Constants§

REF_PPI
Reference density: dp(n) == n at 300ppi, the most common modern Kobo panel.

Functions§

dp
Physical-size-stable pixels: n design units at the reference 300ppi, scaled to the current panel.
dp_at
Explicit-ppi variant of dp: the pure, testable core that does not read the global PPI latch. Call this when the panel density is known locally (e.g. inside a layout computation that already received ppi as a param).
dpf
Float variant for font sizes and sub-pixel geometry.
init_ppi
Latch the panel density once at startup. Call from setup after the framebuffer resolution is known.
ppi
ppi_for
Resolve ppi from a panel resolution. Orientation-agnostic (sorts the pair), so it works whether the framebuffer reports portrait or landscape.