Expand description
Units and geometry, typed as GPUI’s gpui::geometry: a length is
Points (GPUI’s Pixels), Rems, a Percentage (a fraction:
0.5 is 50%) or one of the lengths styles give
(AbsoluteLength, DefiniteLength, Length); an angle is
Radians; shapes are generic over their unit (Point, Size,
Bounds, Edges, Corners). Public API takes and returns these,
never a bare f32 for a length, an angle or a fraction (held by the
unit_types test; docs/dev/geometry.md).
NSH lays out in points; DevicePixels and ScaledPixels exist
only where a platform draws or reports pixels. Conversions happen at
the boundaries: taffy here (taffy.rs, the one place), the platforms
where they hand values to their toolkits, nsh-js where it decodes JS
numbers.
The units are #[repr(transparent)] newtypes and the shapes
#[repr(C)] structs of them: zero cost on hot paths. Deviations from
GPUI are deliberate and listed in docs/dev/geometry.md (points rather
than pixels, f32’s comparisons rather than a total order, a public
.0, CSS angle constructors).
Structs§
- Bounds
- A rectangle: its top left corner (
origin) and itssize. A view’s frame is its bounds relative to its parent. - Corners
- A value for each corner of a box: radii.
- Device
Pixels - Physical pixels of a display: what a platform’s bitmaps, swap chains
and pointer events in pixels count. NSH’s own values are
Points; conversions happen at the platform boundary, with the surface’s scale factor. - Edges
- A value for each edge of a box: insets, paddings, borders.
- Percentage
- A fraction of a whole:
0.5is 50%,1.0all of it. NSH keeps CSS percentages as fractions everywhere (styles, gradients, transform origins). Values outside0..=1are taken (a gradient stop at 150%, a-50%translation). - Point
- A point:
xto the right,ydown, from the origin of what it is relative to. - Points
- A length in points, the unit NSH lays out in (GPUI’s
Pixels): the platform’s density-independent unit (iOS / macOS points, Android dp, CSSpxon the web, DIPs on Windows). Style strings’pxand bare numbers are points. Device pixels areDevicePixels/ScaledPixels, met only where a platform draws or reports them. - Radians
- An angle in radians. Which way it turns and where 0 points is the
API’s that takes it (CSS: 0 points up, clockwise).
deg,turnandgradmake one from CSS’s other angle units. - Rems
- A length in rems: multiples of a root font size (16 points in style
strings,
REM_SIZE). - Scaled
Pixels - Points scaled to device pixels without rounding: a fractional device
position, as a platform draws at (
Points::scale). - Size
- A width and a height.
Enums§
- Absolute
Length - A length known without layout: points, or rems of a root font size.
- Axis
- A direction in two dimensions (
"vertical"or"horizontal"in JS: a prop that names one, a split’s or a resizable group’s). - Definite
Length - A length that is not
auto: absolute, or a fraction of a reference length (the parent’s size for a box, the gradient line for a color stop). - Length
- A length a style gives a box: definite, or
auto(sized by layout).
Constants§
- REM_
SIZE - The points of one rem in NSH’s style strings and Tailwind’s default theme (CSS’s 16px).
Traits§
- Along
- A two-dimensional value read or changed along one
Axis. - Half
- A value that can be halved (the center of a
Bounds). - IsZero
- A value that can be zero.
Functions§
- auto
auto: sized by layout.- bounds
- Bounds at
originofsize. - deg
degreesdegrees, in radians (CSSdeg).- grad
gradiansgradians, in radians: 400 to a turn (CSSgrad).- percentage
valueas a fraction of a whole (percentage(0.5)is 50%).- point
- A point at
x,y. - px
pointspoints. The name is GPUI’s and CSS’s: a CSSpxis a point.- radians
valueradians.- relative
fractionof the reference length, the parent’s size for a box (relative(0.5)is 50%).- rems
remsrems.- size
- A size of
width×height. - turn
turnswhole turns, in radians (CSSturn).