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 video::VideoInfo;
pub use video::VideoSource;
pub use video::set_video_opener;
pub use builder::CameraBuilder;
pub use builder::CircleBuilder;
pub use builder::CodeBuilder;
pub use builder::CustomBuilder;
pub use builder::EffectBuilder;
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::ParticlesBuilder;
pub use builder::PathBuilder;
pub use builder::PolygonBuilder;
pub use builder::RectBuilder;
pub use builder::ShaderBuilder;
pub use builder::StarBuilder;
pub use builder::TxtBuilder;
pub use builder::VideoBuilder;
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 graph::add_site;
pub use node_api::Draw;
pub use post::Input;
pub use post::Shade;
pub use post::ShadeOp;
pub use post::apply as apply_shade;
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;

Modules§

node_api
Nodes of your own: a struct that draws itself with a DrawCtx.
post
Pixel shaders that read what was drawn: the frame before a node, or the node’s own layer.
video
A video clip as a node.

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.
CodeText
The source of a Code node.
CodeTheme
Colors of a code theme.
CodeTween
Diff tween returned by CodeText::to, Code::insert, Code::remove and Code::replace.
Color
sRGB color with straight (non-premultiplied) alpha, components in 0..=1.
Custom
Handle to geometry drawn by a closure. Derefs to Node.
CustomBuilder
Builder for a Custom node.
DrawCtx
What a crate::Custom node draws into. Coordinates are the node’s own: the origin is the node center, positive x is right, positive y is down.
DrawItem
One thing to paint, in local coordinates of transform. Paints already include the node’s opacity (unless the node draws into a layer).
DrawRng
A generator from DrawCtx::rng.
Effect
Handle to a node’s shader effect, from Node::effect.
EffectBuilder
A shader effect for Node::effect.
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.
Icon
Handle to an icon. Derefs to Node; color and stroke_width animate every path of it.
IconBuilder
Builder for an Icon: icon!("lucide:server").size(64.0).color(Accent).
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.
Particles
Handle to a Particles node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
ParticlesBuilder
Builder for a Particles node.
Pass
One pass in topological order: contents before the composite that uses them.
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.
Pen
A shape just added to a DrawCtx, waiting for a fill or a stroke.
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).
Shader
Handle to a WGSL shader. Derefs to Node.
ShaderBuilder
Builder for a Shader node.
ShaderDiag
A WGSL problem found while painting.
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.
Svg
Handle to a Svg node in the scene: cheap to copy, its methods return the node’s properties as Signals. Derefs to Node.
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.
Video
Handle to a video clip. Derefs to Node.
VideoBuilder
Builder for a Video node.
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.
IconStyle
How an icon is painted: Lucide and Tabler outlines are strokes, filled variants and brand logos are fills.
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.
PassKind
What a pass draws.
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§

add_site
Runs f so that the nodes it adds report the caller’s file and line in check and inspect.
current_theme
Theme of the scene that is running, or the dark theme outside one. The theme of the scene that is running, or Theme::dark outside one.
draft_shaders
Paints shader nodes at half resolution until dropped.
enter_theme
Installs theme for the duration of f.
layer_fingerprint
Identity of a layer slice, including its PushLayer at start through the matching PopLayer. Used to reuse a layer whose vectors did not change.
lens_drops
The lens_drops preset: water drops on the lens that magnify and flip what was drawn before this node, inside its box.
pass_graph
Passes for items, in the order they must run.
pct
80 percent of the frame, or of the parent when it has a fixed size.
ripple
Rings that push a node’s colors out from its center, like a drop on water. The node’s outline stays, so a flat fill shows no rings: use it on text, a gradient, an image or water. Put it on a node with Node::effect.
set_shader_budget_ms
Milliseconds a shader raster may take before shader_slow.
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.
waves
The waves preset: a crest of foam over deep water.