Style Unit
Flor's layout system uses Unit and Length types to represent size units. All units are converted to pixel values before being passed to layout engine.
Unit
Unit is unit type marker, used to mark which unit system a number belongs to.
Default value is Unit::Px.
Px (Pixel)
Pixel is absolute unit, no conversion. Layout engine directly uses pixel value.
Pt (Point)
Point is printing unit, uses window DPI for conversion:
Under standard 96 DPI, 1pt = 1.333px, 12pt = 16px.
Rem (Root em)
Rem is unit relative to root element font size. Flor uses window configured rem_px as conversion base:
Default rem_px = 16.0, i.e. 1rem = 16px.
Vw (Viewport Width)
Vw is unit relative to viewport width:
Viewport width equals window client area width. 50vw means half of viewport width.
Vh (Viewport Height)
Vh is unit relative to viewport height:
Viewport height equals window client area height. 50vh means half of viewport height.
Length
Length is length type with number, binding number and unit together.
Example:
UnitMetrics
UnitMetrics stores window-level unit conversion parameters, each window maintains one instance.
Default Values
Update Timing
These values are initialized when window is created, and updated at following times:
- When window size changes, update
viewport_widthandviewport_height - When DPI changes, update
dpi_xanddpi_y - When user modifies
WindowOption::rem_px, updaterem_px
Unit Conversion Formula
Usage Suggestions
- Px: For precise sizes, like border width, icon size
- Rem: For font size, spacing, convenient for responsive design
- Pt: For printing related scenarios, or when need to stay consistent with CSS pt
- Vw / Vh: For viewport related layout, like fullscreen container, center positioning

