Components
An explainer is a handful of blocks. Each one takes its color and type from the theme, places
itself, and answers enter, next and exit. The player is the
gallery example; the still under each block is the moment that block is on screen.
Loading live preview…
Source of components — edit in the playground
//! A short explainer built only from components.
//! The scene body stays under 40 lines: the blocks already know the theme,
//! the safe area and how to appear.
use oxframe::prelude::*;
#[oxframe::scene]
pub async fn explainer(view: View) {
let title = view.add(TitleCard::new("Binary search").subtitle("O(log n)"));
title.enter().await;
title.next().await;
title.exit().await;
let chapter = view.add(ChapterMarker::new("1 Search"));
chapter.enter().await;
chapter.next().await;
chapter.exit().await;
let steps = view.add(BulletList::new(["Take the middle", "Compare", "Drop half"]));
steps.enter().await;
for _ in 0..steps.len() {
steps.next().await;
}
steps.exit().await;
let code = view.add(CodeExplainer::new("lo + (hi - lo) / 2").step(1, 1, "the middle"));
code.enter().await;
code.next().await;
code.exit().await;
let flow = view.add(FlowDiagram::new().edge("Client", "API").edge("API", "DB"));
flow.enter().await;
for _ in 0..flow.len() {
flow.next().await;
}
flow.exit().await;
let card = view.add(Rect::new().size(280.0).fill(Surface).opacity(0.0));
let call = view.add(Callout::new(card).text("the middle"));
all((card.fade_in(), call.enter())).await;
call.next().await;
all((card.fade_out(), call.exit())).await;
let lower = view.add(LowerThird::new("Ada").role("walks the half"));
lower.enter().await;
lower.next().await;
lower.exit().await;
let end = view.add(EndCard::new("That's the search").note("Repeat from the top"));
end.enter().await;
end.next().await;
end.exit().await;
}
pub fn project() -> Project {
Project::new("components")
.aspects([Aspect::Landscape, Aspect::Portrait, Aspect::Square])
.scene(explainer())
}Title card
let title = view.add(TitleCard::new("Binary search").subtitle("O(log n)"));
title.enter().await;
title.next().await;
title.exit().await; enter fades the card and the title in. next reveals the subtitle.
TitleCard::logo() puts the oxframe logo before the title, sized to it: TitleCard::new("oxframe").logo(). Logo::new().height(48) is the logo alone,
a node like any other.
Chapter marker
let chapter = view.add(ChapterMarker::new("1 Search"));
chapter.enter().await; A label pinned to the top safe area, including on a vertical frame.
Bullet list
let steps = view.add(BulletList::new(["Take the middle", "Compare", "Drop half"]));
steps.enter().await;
for _ in 0..steps.len() { steps.next().await; } enter shows the stack. Each next reveals one row.
Code explainer
let code = view.add(
CodeExplainer::new("lo + (hi - lo) / 2").step(1, 1, "the middle"),
);
code.enter().await;
code.next().await; enter shows the source. Each next focuses the next line range (1-based, inclusive)
and sets the caption. A light theme uses a light code theme.
Flow diagram
let flow = view.add(FlowDiagram::new().edge("Client", "API").edge("API", "DB"));
flow.enter().await;
for _ in 0..flow.len() { flow.next().await; } You name the links. The diagram lays the nodes out in layers, left to right. .down() stacks the layers. next highlights the next node.
Callout
let card = view.add(Rect::new().size(280.0).fill(Surface));
let call = view.add(Callout::new(card).text("the middle"));
call.enter().await;
call.next().await; The caption sits above the target. enter draws the arrow, next shows the words.
Lower third
let lower = view.add(LowerThird::new("Ada").role("walks the half"));
lower.enter().await;
lower.next().await; Pinned to the bottom safe area. next reveals the role.
End card
let end = view.add(EndCard::new("That's the search").note("Repeat from the top"));
end.enter().await;
end.next().await;
end.exit().await; Same rhythm as a title card. The note waits for next.
Made by Oxframe
let end = view.add(EndCard::new("").made_by().note("oxframe.dev"));
end.enter().await;
end.next().await; EndCard::made_by() shows “made by”, the oxframe logo and “Oxframe” in place of the
title. MadeBy::new().font_size(40) is the same line on its own, to put under other
content; enter fades it in. EndCard::rich takes styled runs for the
title, as Txt::rich does.
Every component goes wherever a node does, so you can place other nodes around it: caption.next_to(&end_card, Side::Bottom).
The gallery example components is a full explainer in under 40 lines. Project::aspects makes oxframe check look at 16:9, 9:16 and 1:1.