Units
This demo covers the Tripous CSS unit helper functions. They are intentionally small helpers used by layout and visual code when a value may arrive as a number, a pixel string, a percent string, or another CSS length value.
A plain number is treated as pixels. A string without an explicit suffix also defaults to pixels.
The helpers do not calculate real browser measurements for relative units such as em
or %; they only split and normalize the textual CSS value.
Unit constants
tp.UnitMap contains the CSS unit suffix strings used by the helper
functions, such as px, %, em, and
pt.
Extract unit and number
tp.ExtractUnit() returns the suffix and tp.ExtractNumber()
returns the numeric part. Missing units default to pixels.
Check common units
tp.IsPixel(), tp.IsEm(), and tp.IsPercent()
answer simple unit questions without forcing caller code to parse the string.
Normalize to pixels
tp.px() creates a pixel CSS value from a number or from the numeric
part of a CSS length string.