Expand description
§Cranpose UI Graphics
cranpose-ui-graphics provides geometry, units, colors, brushes, paths and
render-effect data. Widget authors use these values to describe visual
content. Renderer authors consume the same values to produce pixels.
Application code can import common types through
cranpose::prelude.
§Define geometry and color
use cranpose_ui_graphics::{Color, Dp, Point, Rect, Size};
let padding = Dp(16.0);
let bounds = Rect::from_origin_size(Point::new(8.0, 12.0), Size::new(120.0, 48.0));
let accent = Color::from_rgb_u8(40, 110, 220);The feature set is empty. Dp, Sp and Px remain distinct units;
Density converts logical values to the device grid. See the
Density API,
the graphics API
and the crate source.
Re-exports§
pub use transform::ProjectiveTransform;pub use transform::WindowCoordinates;pub use alpha_mask::*;pub use liquid_glass::*;pub use render_effect::*;pub use unit::*;
Modules§
- accessibility
- Host-provided accessibility preferences shared by animation and rendering.
- alpha_
mask - Alpha-mask helpers for graphics-layer effects.
- framework_
shaders - WGSL sources for the framework’s rendering pipelines.
- layer_
transform - liquid_
glass - LiquidGlass effect: a refractive glass material rendered via RuntimeShader.
- prelude
- render_
effect - Render effects that can be applied to graphics layers.
- transform
- Projective geometry shared by layout coordinates and renderers.
- unit
- Length units:
Dp,Sp,Px, and theDensitythat converts between them.
Structs§
- ArcGeometry
- A resolved circular band between two radii, limited to an angular sweep.
- ArcRecord
Args - The arc as the app drew it, the arguments of
CommandRecorder::push_arc. - Brush
Record - A gradient brush of a recording, addressed by
ShapeRecord::brush. - Color
- Command
Recorder - Mutable command data owned exclusively while a draw scope records it.
Publishing with
Self::finishshares the completed shape data without copying it. - Command
Recording - A completed draw command with shared shape data, ordered segments and
non-shape primitives. Bounds and content metadata are recorded while drawing;
the complete fingerprint is computed when a cache first requests it.
Use
CommandRecorderto build a command andSelf::into_recorderto edit it. - Corner
Radii - Custom
Pointer Icon - An application-drawn pointer shape: a bitmap plus the hotspot, the pixel inside the image that sits exactly on the pointer’s position.
- Dash
Path Effect - Dashes along a stroke: on for the first interval, off for the second,
and so on, starting
phaseinto the pattern. Compose’sPathEffect.dashPathEffect(intervals, phase). Up toDashPathEffect::MAX_INTERVALSintervals; a pattern with an odd count or a non-positive sum draws the stroke whole, as Skia does. - DpOffset
- Density-independent offset for shadows.
- Draw
Scope Default - Draw
Text Style - Everything
crate::DrawScopeneeds to measure and draw a run of text. - Edge
Insets - Padding values for each edge of a rectangle.
- Font
Weight - Font weight (100-900)
- FxHasher
- Non-cryptographic hasher for in-memory frame-to-frame change detection.
- Gradient
Stop Record - One gradient stop in the layout the shader reads.
- Graphics
Layer - Image
Bitmap - Immutable image data used by UI primitives and render backends.
- Line
Frame - Where a pixel sits relative to a
LineGeometry: its midpoint, the unit direction from start to end, and half its length. - Line
Geometry - A stroked straight segment: its two ends, half its width and its cap,
in the units it is drawn in.
crate::DrawPrimitive::Linelowers to it, and the GPU and CPU renderers take their coverage from the same frame. - Line
Height Style - How a line of text sits inside the height it was given, and what a paragraph gives back at its edges.
- Path
- A path built from lines and curves: Compose’s
Path. - Path
Contour - One contour of a
Path: its flattened points and whether it closes back to its first. - Point
- Record
Segment - A run of consecutive entries of one lane that a single draw can take: shapes sharing a blend mode and a brush class, or a run of other primitives.
- Record
Tables - The POD half of a recording: what the GPU reads, shared with the
renderer behind an
Arcso a packet carries it without a copy. - Recording
Summary - What a recording contains, answered once while recording so no consumer rescans it.
- Rect
- Rounded
Corner Shape - Shadow
- Static shadow configuration.
- Shadow
Scope - Pixel-space shadow scope used by block-based APIs.
- Shape
Record - One complete recorded shape in the draw command’s local space.
Every value the app passed is kept verbatim, so the record
materialises back into the exact
DrawPrimitivethe call described, and the derived arc values the fragment stage needs sit beside them. - Shape
Record Body - Shape properties independent of an arc’s angles, in instance-buffer layout.
- Shape
Record Curve - Corner radii and arc-angle properties, in instance-buffer layout.
- Shape
Recorder - The POD half of a recording as it is written: the shape records with
their brush and stop tables and coalesced segments, and the bounds
those records reach. Plain data throughout, so a scene carries one
across threads;
CommandRecordingwraps it with the other lane. - Shape
Records - Recorded shapes stored in parallel columns, ready for GPU upload.
- Size
- Stroke
- Describes how an outline is stroked.
- Text
Measurement - What a string occupies once laid out — the answer
DrawScope::measure_textgives, and exactly the boxdraw_textfills. - Text
Primitive - A run of text, positioned and ready to rasterize.
- Transform
Origin - Trapezoid
- One vertical slice of a filled path: the area between a top and a bottom
edge, each straight, over the columns from
lefttoright. - Vector
Path - A parsed SVG path: subpaths flattened to polylines, ready to fill.
Enums§
- Blend
Mode - Blend mode used for draw primitives.
- Brush
- Color
Filter - Simple image color filter model.
- Compositing
Strategy - Cursor
Icon - Describes the appearance of the (usually mouse) cursor icon.
- Draw
Primitive - Draw
Style - How
crate::DrawScope::draw_pathpaints a path: Compose’sFillandStrokedraw styles, the stroke dashed when it carries a path effect. - Font
Style - Font style (normal, italic, oblique)
- Gradient
Blur Direction - Axis and direction used to interpolate the blur radius.
- Image
Bitmap Error - Errors returned while constructing an
ImageBitmap. - Image
Pixel Format - Storage format of an immutable bitmap.
- Image
Sampling - Texture sampling mode for image primitives.
- Layer
Shape - Line
Height Alignment - Where the leading — the difference between a line’s box and the font’s own ascent-plus-descent extent — is spent.
- Line
Height Mode - What a requested line height means when the font does not fit inside it.
- Line
Height Trim - Which edges of a text block give their leading back.
- Path
Fill Rule - Fill rule for
VectorPathrasterization. - Pointer
Icon - The pointer’s appearance over a region of the UI.
- Pointer
Icon Error - Errors returned while constructing a
CustomPointerIcon. - Record
Lane - Which lane a segment’s entries live in.
- Recorded
- What
ShapeRecorder::push_primitivedid with a primitive. - Shadow
Primitive - Stroke
Cap - Shape of the two ends of an open stroked path (an arc, today).
- Stroke
Join - Shape produced where two stroked segments meet at a corner.
- SvgPath
Error - Errors produced while parsing SVG path data.
- Text
Align - Horizontal placement of the text block inside the box it is drawn in.
- Text
Vertical Align - Vertical placement of the text block inside the box it is drawn in.
Constants§
- ARC_
BAND_ MIN_ INNER_ RADIUS - A band whose inner radius is within the strip’s margin of the centre is a disc: its strip would be the whole disc’s quad and more.
- ARC_
BAND_ MIN_ RADIUS - Bands narrower than this radius draw as their quad: the pixels a band would save cost less than its vertices.
- ARC_
BUCKETS - How many segment-count buckets band-drawn arcs fall into: one per
power-of-two segment count of
ARC_BUCKET_SEGMENTS. - ARC_
BUCKET_ SEGMENTS - The strip segments a bucket’s arcs are drawn with.
- ARC_
RING_ RADII - The outer radius, in the command’s units, above which a full ring moves
to the next of
ARC_RING_SEGMENTS. - ARC_
RING_ SEGMENTS - The segments a full ring takes with an outer radius up to each of
ARC_RING_RADII, and above the last: the angular step a band at that radius keeps whatever its sweep, so its chords overshoot the circle by the same few pixels and a short arc takes only the segments its sweep needs. - BAND_
ANGULAR_ PAD - The radians a band’s strip extends past each end of its sweep beyond
the angle the ring’s padded half-width subtends at its padded inner
radius, which covers every cap and the margin; float slack only.
band_positionpads by the same amount. - BAND_
MARGIN - The device pixels a band’s quad or strip, and a line’s quad, extend past
the shape on each side: the half pixel the fragment stage anti-aliases
plus a sixteenth pixel for rasterization rounding.
band_positioninshape.wgslpads by the same amount. - BAND_
MAX_ STEP - The widest angle one segment of a band’s strip spans. Past a quarter turn a strip’s outer polygon is larger than the square around the band’s padded disc, so a band whose padded sweep needs wider segments than its class has, which only a render scale below the recording’s can make, draws that square instead.
- BAND_
MIN_ SEGMENTS - The fewest strip segments a band draws with. A short band’s strip and a rectangular shape both use four vertices in the same segment class.
- BAND_
VERTEX_ PIXELS - What one strip vertex costs against fill, in pixels of the command’s units. A tiling GPU writes every vertex’s varyings, sixteen vectors here, to memory before it shades a pixel, and reads the record the vertex came from; a pixel reads and writes a few bytes and runs the distance field once. A band of many segments over few pixels is dearer than the quad it replaces.
- BRUSH_
KIND_ LINEAR - The brush kinds of
BrushRecord::kind. - BRUSH_
KIND_ RADIAL - See
BRUSH_KIND_LINEAR. - BRUSH_
KIND_ SWEEP - See
BRUSH_KIND_LINEAR. - BUILTIN_
RUNTIME_ SHADER_ SOURCES - The framework’s own runtime shader sources. A renderer rebuilds the
pipelines its last launch drew the first screen with from these, matched
by
crate::runtime_shader_source_hash, before the app builds them. - FRAGMENT_
KIND_ ARC - FRAGMENT_
KIND_ FILL - The fragment program’s shape kinds: a filled rect or round rect, a stroked one, an arc band, a line segment and a slice of a path fill.
- FRAGMENT_
KIND_ LINE - FRAGMENT_
KIND_ STROKE - FRAGMENT_
KIND_ TRAPEZOID - GRADIENT_
BLUR_ LEVELS - The blur levels’ shares of the wide radius: the renderer blurs the capture by each, and the shader blends the sharp source and the levels around the radius each fragment asks for.
- GRADIENT_
BLUR_ WGSL - WGSL implementation of a per-fragment Gaussian-style blur kernel.
- MAX_
POINTER_ ICON_ SIZE - The largest custom pointer icon a platform is asked to draw, in pixels.
- OCCLUDER_
MIN_ AREA - The least interior, in square logical pixels, that a solid fill lays down ahead of the paint: a card or a background, not a chip, a glyph- sized dot or a circle, whose interior is empty.
- QUAD_
INDICES - The indices one quad’s two triangles take.
- QUAD_
VERTICES - The vertices of one quad: its four corners, which its two triangles share through the strip index pattern.
- RECORD_
KIND_ ARC - The kind bits of
ShapeRecord::flags: an arc band or annular sector. - RECORD_
KIND_ LINE - The kind bits of
ShapeRecord::flags: a stroked straight segment, or a slice of a path fill, whose cap bits areTRAPEZOID_CAP. - RECORD_
KIND_ RECT - The kind bits of
ShapeRecord::flags: a plain rect. - RECORD_
KIND_ ROUND_ RECT - The kind bits of
ShapeRecord::flags: a rounded rect. - TAU
- Full turn in radians.
- TRAPEZOID_
CAP - The cap bits of a line record that is a slice of a path fill: no stroke cap takes them. Its join bits hold which of its sides are open.
Traits§
- Draw
Scope - Draw
Text Measurer - Font-backed measurement, injected into a
crate::DrawScopeDefaultby the UI layer. - Render
Hash
Functions§
- align_
text_ block - Resolves the top-left corner a text block of
measurementgets when it is aligned insiderect. - arc_
band - Resolves the
(inner, outer, cap)band described by acrate::DrawPrimitive::Arc. - arc_
trig - The trig the GPU derives for a band from its normalized start and sweep:
the mid-angle sine and cosine and the half-sweep sine and cosine, with the
full circle’s sentinel. Arc records leave their
radiizero for the GPU to fill; the renderer’s CPU mirrors of the band geometry call this. - band_
bucket - The bucket of
ARC_BUCKET_SEGMENTSa strip ofsegmentsdraws from. - band_
class_ segments - The strip segments every record of band class
classis drawn at. - band_
padded_ range - Where a band’s strip starts and the padded sweep it covers, for a band of
centre-line radius
midand padded half-widthring_halfoverstartandsweep, in one unit: the angular pad is bounded above (atan(x) is at most x), so no transcendental per band, and a sweep the pad closes is the full circle. The vertex stage takes it in device pixels, where theBAND_MARGINthe half-width includes is measured. - band_
pays - Whether an arc’s band strip costs less than
rect, the quad it would otherwise draw; seeShapeRecord::is_banded. - estimate_
text_ measurement - Font-free estimate used when no
DrawTextMeasureris installed. - expand_
rect rectgrown bymarginon every side.- for_
each_ stroke_ line - Hands
linethe segments a stroke draws for the polyline throughpoints, closed back to its first point whenclosed. An open polyline’s two ends take the stroke’s cap; every corner takes the cap closest to the stroke’s join, round for round and bevel joins, square for a miter, which is exact at a right angle. A segment whose two ends want the same cap draws with it; one whose ends differ draws butt ends, grown by half the width at a square end, and a dot of the stroke at a round one. - gradient_
blur_ effect - Build a spatially varying blur effect.
- inflate_
rect - Grows
rectbyamounton every side, clamping to a non-negative size. - normalized_
band - The band a primitive’s arc arguments describe, normalised as the fragment stage draws it.
- primitive_
coverage_ rect - The rect a primitive’s pixels can reach, or
Nonewhen it has none of its own (a content marker or a shadow). - request_
shader_ warm_ ups - Asks every renderer to compile the pipelines of
warm_upson its background compiler, before a frame needs them. - shader_
warm_ ups_ after - The warm-ups requested after the first
seen, in the order they were requested: a renderer passes how many it has already queued. - strip_
index_ pattern - The index pattern of one record’s strip of
segmentsquads over itsstrip_vertices: vertex2bsits at boundarybon the inner radius and2b + 1on the outer, and quadjis the triangles(2j, 2j + 1, 2j + 2)and(2j + 2, 2j + 1, 2j + 3). A quad-drawn record is the pattern’s first quad over the rect’s corners: vertex2x + yis corner(x, y). - strip_
indices - The indices a strip of
segmentsquads draws with. - strip_
vertices - The vertices a strip of
segmentsquads shares: an inner and an outer vertex at each of itssegments + 1boundaries.
Type Aliases§
- FxBuild
Hasher std::hash::BuildHasherforFxHasher, forHashMap/HashSeton the per-frame path.