Skip to main content

Crate frus_core

Crate frus_core 

Source
Expand description

frus-core — the fundamental types shared by the whole framework.

This crate holds no logic: only data types (geometry, colour) with no dependency on rendering or on any platform. It is the common foundation for frus-gpu, frus-layout and the rest, which keeps those layers from duplicating types or coupling to one another.

Re-exports§

pub use animation::Animatable;
pub use animation::Animation;
pub use animation::AnimationController;
pub use animation::BouncingScrollSimulation;
pub use animation::ClampedSimulation;
pub use animation::ClampingScrollSimulation;
pub use animation::Curve;
pub use animation::Curved;
pub use animation::FrictionSimulation;
pub use animation::Lerp;
pub use animation::PolynomialFit;
pub use animation::Simulation;
pub use animation::SpringDescription;
pub use animation::SpringSimulation;
pub use animation::Status;
pub use animation::Tolerance;
pub use animation::Tween;
pub use animation::TweenSequence;
pub use animation::Velocity;
pub use animation::VelocityEstimate;
pub use animation::VelocityStrategy;
pub use animation::VelocityTracker;
pub use animation::BOUNCING_DRAG;
pub use animation::BOUNCING_FLING_WEIGHTS;
pub use animation::CLAMPING_FRICTION;
pub use animation::DESKTOP_FLING_WEIGHTS;
pub use animation::MAX_SPRING_TRANSFER_VELOCITY;
pub use platform::debug_default_target_platform_override;
pub use platform::default_target_platform;
pub use platform::set_debug_default_target_platform_override;
pub use platform::Platform;
pub use platform::TargetPlatform;
pub use platform::IS_WEB;

Modules§

animation
Animation: the physics and kinematics layer shared by the whole framework, with no dependency on rendering or on any platform.

Structs§

Affine
A 2D affine transform (a 2×3 matrix). A point (x, y) becomes (a·x + c·y + e, b·x + d·y + f): a 2×2 linear part [[a, c], [b, d]] (scale, rotation, shear) plus a translation (e, f).
Alignment
Where to place a child inside its containing box: two continuous fractions in [-1, 1]. x = -1 hugs the left, 0 centres, +1 hugs the right; y = -1 is the top, +1 the bottom. Being continuous, it interpolates (crate::Lerp): a Tween<Alignment> slides a child from one anchor to another. The nine usual anchors are provided as constants (Alignment::CENTER, Alignment::TOP_LEFT, and so on).
AlignmentDirectional
A directional anchor: the horizontal axis is expressed start → end rather than left → right. x_start = -1 hugs the start edge (left in LTR, right in RTL), +1 the end edge. Resolved into a physical Alignment at render time from the reading direction — the anchor follows the text without the caller ever testing which way it runs.
Backdrop
A filter over what has already been painted underneath a layer: the frosted glass a sheet, a bar or a dialog sits on.
Border
A box’s border, side by side — the reference’s Border (box_border.dart:431): each of the four sides its own colour and width.
BorderDirectional
A box’s border, by the line’s start and end — the reference’s BorderDirectional (box_border.dart:799): the start side is the left in a left-to-right script and the right in a right-to-left one.
BorderRadius
Corner radii, per corner (logical px). From<f32> covers the uniform case: anywhere a radius is expected, a plain 10.0 still works.
BorderRadiusDirectional
A corner radius named by the reading direction rather than by the wall (border_radius.dart:621).
BorderSide
One edge of a shape: what colour it is drawn in and how thick it is (border_side.dart).
BoxDecoration
The complete decoration of a box — the reference’s BoxDecoration (box_decoration.dart:81).
BoxShadow
A soft drop shadow.
Color
An RGBA colour. Components lie in [0.0, 1.0].
Colors
The named colours of the material palette, as plain Color constants.
DecorationImage
A picture painted as a box’s background — the reference’s DecorationImage.
FittedSizes
The two sizes a fit settles on — the reference’s FittedSizes.
Hct
A colour in HCT: CAM16 hue (degrees), CAM16 chroma, and L* tone.
ImageData
An image’s pixels: 8-bit RGBA, sRGB, row by row from the top-left corner (width * height * 4 bytes). Immutable once built.
ImagePiece
One part of a picture drawn somewhere: where, and which part, in 0..1 of the picture (a negative width walks it backwards, which is how a picture is mirrored).
Insets
Insets — padding or margin — per side, in logical pixels.
InsetsDirectional
Directional insets: start/end instead of left/right. In LTR, start is the left; in RTL it is the right. Resolved into concrete Insets at layout time.
LayerFilter
Everything a layer applies to its own pixels at compositing time. All three are optional and independent; LayerFilter::is_none is the fast path the renderer takes when nothing is asked for, which is nearly always.
LayerTransform
The transform applied to a layer (Primitive::Layer) at compositing time: an arbitrary Affine (translation, per-axis scale, rotation, or any composition of them) in screen pixels. The layer is first rendered flat into a texture, as with group opacity, then composited transformed — so a single pass transforms a whole subtree (rects, text, images) without touching any individual primitive’s shaders.
LinearGradient
A gradient along a line, from begin to end (gradient.dart’s LinearGradient). Unset, from the centre of the left side to the centre of the right.
MaterialColor
A colour ramp: one hue in numbered steps, from the palest (50) to the darkest (900), plus the primary step the family is named after.
Path
A vector path: a sequence of PathVerb. Built in builder style (chainable), and consumed at render time.
Platform
Facts about the machine the application runs on, fixed for the life of the process. Unlike TargetPlatform, nothing overrides them.
Point
A 2D point.
RadialGradient
A gradient round a centre (gradient.dart’s RadialGradient): the first colour at center, the last on the circle radius round it. With a focal point, the first colour is on the circle focal_radius round that point instead, and the gradient runs between the two circles.
Rect
An axis-aligned rectangle, in logical pixels.
ResolvedTextStyle
A TextStyle with every question answered: what to measure with, and what to draw.
Scene
A 2D scene: the declarative description of what to draw.
SemanticsProperties
A widget’s resolved semantic annotation, for accessibility.
ShaderMask
A colour blended over a subtree — the ShaderMask widget’s payload.
Size
A 2D size (width × height).
Stroke
An outline (the line a path is drawn with): colour, width, in pixels, and how its ends are drawn.
SweepGradient
A gradient turning round a centre (gradient.dart’s SweepGradient): from start_angle to end_angle, in radians clockwise from the right.
TextBlock
The box a block of text is laid out in: how wide it is, whether the text wraps at that width, and where the lines sit inside it. See Scene::text_block.
TextDecoration
A text’s decoration lines, which combine with one another. They have no effect on measurement: the text’s geometry does not change, and the lines are drawn by the backend from the baseline metrics.
TextRun
A text run ready to render: a fragment plus its typographic attributes and colour, all resolved — nothing left to inherit.
TextScaleGuard
Puts back the scale that was in force before install_text_scale, when dropped — including while a panic unwinds, so one bad frame cannot leave a stale scale installed for every frame after it.
TextSpan
A rich-text tree: each node carries a fragment of text, partial style overrides — whatever is unspecified inherits from the parent, so a .bold() child keeps its parent’s size — and children of its own.
TextStyle
The typographic attributes of a single line of text — every field optional.
TonalPalette
A tonal palette: one hue and chroma spread across the tone scale. tone(90) is very light, tone(10) very dark, and both read as one colour.
WindowInsets
The window insets, split by nature: padding is the area permanently taken by the system (status and navigation bars, the notch — all static), while view_insets is the area covered by transient UI, chiefly the soft keyboard. Avoiding the keyboard means keeping content clear of WindowInsets::safe.

Enums§

AlignmentGeometry
A resolvable anchor — either physical (Alignment) or directional (AlignmentDirectional). A widget accepts either one, through Into, and resolves it against the reading direction at render time.
BlendMode
How a source colour is combined with the destination underneath it.
BlurStyle
Which side of a shape a blur keeps (milestone 645), the reference’s BlurStyle.
BoxBorder
A box’s border, by its physical sides or by the line’s start and end.
BoxFit
How an image is fitted into its destination box — the same set of modes as the CSS object-fit property.
BoxShape
The shape a box decoration paints — the reference’s BoxShape (box_border.dart:26).
ClipShape
The clip shape of a Primitive::Layer, inscribed in its clip rectangle. Compositing multiplies the layer’s alpha by the shape’s coverage, with antialiased edges. This is the building block of the ClipRRect, ClipOval and ClipPath widgets.
ColorFilter
A function applied to every pixel of a subtree, independently of its neighbours: greyscale, a tint, a contrast curve.
Fetched
What is known about an image that has to be fetched before it can be shown.
FontFamily
A font family, as a style names it.
FontWeight
Font weight — a useful subset, mapped onto the CSS/OpenType weights.
FractionalMask
A MaskShader written in fractions of the box it covers — (0, 0) the top-left corner, (1, 1) the bottom-right.
Gradient
Any of the three.
ImageFilter
A filter that treats the subtree as an image, so a pixel’s result depends on its neighbours: a blur, a spread, a shrink.
ImageRepeat
How a picture fills the room its fit leaves: once, or repeated across, down, or both — the reference’s ImageRepeat.
InsetsGeometry
Insets that are either physical (Insets) or directional (InsetsDirectional). A widget accepts either one — or one number for all four sides — through Into, and resolves it against the reading direction at layout time.
MaskShader
The colour a ShaderMask blends over its subtree, as a two-stop fade.
Orientation
Display orientation, derived from the width-to-height ratio.
PathGradient
How a path’s fill fades: along a line, or outwards from a centre.
PathVerb
A single drawing command.
Primitive
A drawing primitive.
Role
An element’s semantic role (a subset aligned on AccessKit/ARIA roles: what a screen reader announces).
ShapeBorder
What shape a box is (shape_border.dart), and the edge around it.
SizeClass
A display-width band.
StrokeCap
How an open line ends — the reference’s StrokeCap (milestone 630).
TargetPlatform
The platforms whose conventions a widget can follow.
TextAlign
How the lines of a piece of text are aligned inside the box it was given.
TextDirection
The reading direction of text and layout. An ambient context: in RTL, rows, alignment and directional insets all flip horizontally.
TextOverflow
What becomes of text that does not fit the box it was given.
TileMode
What a gradient does past its ends (dart:ui’s TileMode).
Toggled
The checked state of a toggleable control (checkbox, switch, radio).

Constants§

DEFAULT_IMAGE_CACHE_BYTES
The default ceiling on decoded network images held in memory: the reference’s own figure.
DEFAULT_LINE_HEIGHT
The line height a style that says nothing gets, as a multiple of the font size.
DEFAULT_TEXT_SIZE
The font size a text ends up at when nothing anywhere in the chain named one.
IS_WEB
Whether this binary runs in a browser. A constant: a build is for the web or not.
MAX_IMAGE_TILES
The most tiles one repeated picture draws. A one-pixel pattern repeated over a large box would otherwise be millions of draws; past this, the rest of the box stays empty.

Functions§

apply_box_fit
Fits input into output by fit — the reference’s applyBoxFit.
cached
Resolves bytes to pixels once, returning the same handle on every later call.
debug_default_target_platform_override
The override of default_target_platform, if one is set.
default_target_platform
The platform whose conventions an application follows unless its theme says otherwise: the debug override if one is set, else the browser’s operating system on the web, else the platform the binary was built for.
fetched
What is known about the image at url, starting the fetch if this is the first ask.
fits
The rule for anything that measures itself: report a whole number of pixels, rounded up.
forget_cached_images
Empties the store. For tests that want a decode to happen again; an application has no reason to call it, since the entries are one per embedded asset and bounded by how many the binary carries.
forget_fetched_images
Forgets every fetched image and every remembered failure. For tests; see forget_cached_images.
image_cache_budget
The ceiling currently in force.
image_cache_bytes
The decoded bytes the store is currently holding.
images_in_flight
How many images are in flight right now.
install_text_scale
Installs the reader’s font-size setting until the returned guard is dropped.
paint_elevation
Paints the shadows of a surface elevation high, with corners radius, behind rect: BoxShadow::for_elevation’s three, each as BoxDecoration paints one. Nothing at a height of nought or in a colour with no opacity (milestone 606).
set_debug_default_target_platform_override
Makes default_target_platform report platform, or, with None, what it would report on its own: for trying another platform’s behaviour during development, and for tests. It is process-wide, so a test that sets it resets it before it returns.
set_image_cache_budget
Sets the ceiling on decoded network images held in memory, in bytes.
set_image_fetcher
Names the thing that gets bytes over the network.
surface_tint_opacity
How strongly a Material 3 surface is tinted at a given elevation.
text_scale
The reader’s font-size setting in force on this thread, or 1.0 outside any with_text_scale.
tile
Tiles t past the gradient’s ends (dart:ui’s TileMode): None where nothing is drawn.
with_text_scale
Runs f with the reader’s font-size setting in force, restoring whatever was there before — including while a panic unwinds, so one bad frame cannot leave a stale scale installed for every frame after it.

Type Aliases§

ImageFetcher
Hands the bytes at url to the callback, once, from wherever suits the platform.
ImageHandle
A shared image handle: cheap to clone (reference counted), and stored as-is inside a crate::Primitive::Image.