Skip to main content

Crate oxframe_2d

Crate oxframe_2d 

Source
Expand description

2D scene graph of oxframe.

Status: oxframe is under very active development. The API is not stable yet and may change from version to version. Pin the exact version in your Cargo.toml and check the changelog before upgrading.

Scene code creates nodes with builders (Rect::new().width(100.0)) and adds them with Node::add (view.add(..)), which returns a Copy handle whose zero-argument methods of the same names return Signals:

ⓘ
let r = view.add(Rect::new().size(200.0).x(-300.0));
r.x().to(300.0, 1.0).await;

Renderers consume a flat DrawItem list produced by SceneGraph::draw_list, so every backend draws exactly the same thing.

Re-exports§

pub use builder::CameraBuilder;
pub use builder::CircleBuilder;
pub use builder::CodeBuilder;
pub use builder::GridBuilder;
pub use builder::GroupBuilder;
pub use builder::ImgBuilder;
pub use builder::LayoutBuilder;
pub use builder::LineBuilder;
pub use builder::NodeBuilder;
pub use builder::PathBuilder;
pub use builder::PolygonBuilder;
pub use builder::RectBuilder;
pub use builder::StarBuilder;
pub use builder::TxtBuilder;
pub use graph::Direction;
pub use graph::InspectNode;
pub use graph::Justify;
pub use graph::LayoutAlign;
pub use graph::NodeId;
pub use graph::SceneGraph;
pub use theme::Corner;
pub use theme::Ink;
pub use theme::Ink::Accent;
pub use theme::Ink::Background;
pub use theme::Ink::Danger;
pub use theme::Ink::Muted;
pub use theme::Ink::OnAccent;
pub use theme::Ink::Success;
pub use theme::Ink::Surface;
pub use theme::Ink::Text;
pub use theme::Ink::Warning;
pub use theme::IntoPaint;
pub use theme::Len;
pub use theme::Motion;
pub use theme::Pace;
pub use theme::Pace::Fast;
pub use theme::Pace::Normal;
pub use theme::Pace::Slow;
pub use theme::Scale;
pub use theme::ShadowSpec;
pub use theme::Step;
pub use theme::Step::Lg;
pub use theme::Step::Md;
pub use theme::Step::Sm;
pub use theme::Step::Xl;
pub use theme::Step::Xs;
pub use theme::Theme;
pub use theme::TypeRole;
pub use theme::TypeScale;
pub use theme::TypeStyle;

Structs§

Camera
Handle to a Camera node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
CameraBuilder
A camera: everything added to it is seen through it, so animating its x/y (the point it looks at), zoom and rotation pans, zooms and turns the view. Nodes added to the view itself stay on screen (titles, captions, a HUD).
Circle
Handle to a Circle node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
CircleBuilder
Builder for a Circle node: set the initial values, then pass it to add.
Code
Handle to a Code node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
CodeBuilder
Builder for a Code node: set the initial values, then pass it to add.
CodeTheme
Colors of a code theme.
Color
sRGB color with straight (non-premultiplied) alpha, components in 0..=1.
DrawItem
One thing to paint, in local coordinates of transform. Paints already include the node’s opacity (unless the node draws into a layer).
Gradient
A gradient in the node’s local coordinates (origin at the node center).
Grid
Handle to a Grid node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
GridBuilder
Builder for a Grid node: set the initial values, then pass it to add.
Group
Handle to a Group node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
GroupBuilder
Builder for a Group node: set the initial values, then pass it to add.
Img
Handle to a Img node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
ImgBuilder
Builder for a Img node: set the initial values, then pass it to add.
InspectNode
A node as oxframe inspect and the visual linter see it.
Layer
Everything drawn until the matching Primitive::PopLayer is rendered into its own buffer, filtered, clipped and composited as a whole.
Layout
Handle to a Layout node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
LayoutBuilder
Places children in a row or column. Children’s x/y become offsets from their layout position.
Line
Handle to a Line node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
LineBuilder
Builder for a Line node: set the initial values, then pass it to add.
Motion
Durations in seconds and the eases for entering, leaving and emphasis.
Node
Untyped node handle with the properties every node has.
NodeId
Index of a node in its SceneGraph. Assigned in creation order, so it is deterministic too.
Path
Handle to a Path node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
PathBuilder
Builder for a Path node: set the initial values, then pass it to add.
Polygon
Handle to a Polygon node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
PolygonBuilder
Builder for a Polygon node: set the initial values, then pass it to add.
RasterImage
Decoded raster image: sRGB RGBA8, straight alpha.
Rect
Handle to a Rect node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
RectBuilder
Builder for a Rect node: set the initial values, then pass it to add.
RichSpan
A run of text with its own look; unset fields use the node’s style.
SafeArea
The rectangle to_edge keeps inside, in scene coordinates (origin at the center, y down).
Scale
Five pixel sizes, smallest to largest.
SceneGraph
Arena of nodes for one scene run. Node 0 is the view (root).
Shadow
Drop shadow of a layer.
ShadowSpec
A drop shadow.
Signal
A reactive value.
Star
Handle to a Star node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
StarBuilder
Builder for a Star node: set the initial values, then pass it to add.
StrokeStyle
How an outline is drawn.
Theme
Colors, type, space, radii, shadows and motion for one look.
Txt
Handle to a Txt node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
TxtBuilder
Builder for a Txt node: set the initial values, then pass it to add.
TypeScale
Display, headings, body, caption and code.
TypeStyle
One text role: size in pixels, weight 100..=900, line height as a multiple.
VectorImage
SVG converted to filled/stroked paths (gradients become their first stop color in v1).
VectorShape
One painted path of a VectorImage.
View
Root of a scene. Origin is the center of the frame, y points down.

Enums§

BlendMode
How a node’s layer is composited onto what is below it.
Direction
Main axis of a Layout.
Edge
An edge of a node or of the safe area.
GradientKind
Shape of a Gradient.
ImageSource
Decoded image data for an Img node.
Ink
A color role. Use it wherever a Color is accepted: .fill(Accent).
Justify
Main-axis distribution of children; only matters with a fixed size.
Lang
Language for syntax highlighting.
LayoutAlign
Cross-axis alignment of children in a Layout.
LineCap
Shape of the ends of open outlines.
LineJoin
Shape of outline corners.
Pace
How long a motion token lasts: .to(1.0, Normal).
Paint
What a shape is filled or stroked with.
Place
How a node is placed. Resolved every frame; not set by scene code directly.
Primitive
A drawing operation in a DrawItem.
Side
Which side of a neighbor Node::next_to uses.
Span
A length in pixels, or a percentage of the frame (or of a sized parent).
Step
A step on the space, radius and shadow scales: .padding(Md), .radius(Lg).
TextAlign
Horizontal alignment of lines.
TypeRole
Which type role .display(), .h1() and the others select.

Constants§

MONO
Built-in monospace family (JetBrains Mono).
SANS
Built-in sans-serif family (Inter).
SLIDE_DISTANCE
How far Node::slide_in starts from the node’s place, in pixels.

Traits§

Corner
A corner radius: pixels, or a Step on the radius scale.
IntoPaint
Something that can be used as a color: a Color or an Ink.
Len
A padding, gap or margin: pixels, or a Step on the space scale.
NodeBuilder
Describes a node before it is added to the scene.
Percent
A number that can be a percentage. pct(80) and pct(80.0) are the same.

Functions§

enter_theme
Installs theme for the duration of f.
pct
80 percent of the frame, or of the parent when it has a fixed size.
span
Shorthand for RichSpan::new.
trim
The part of path between fractions start and end of its total length (0 ≤ start ≤ end ≤ 1), as used by the start/end signals.