Skip to main content

inline_runs/
inline_runs.rs

1//! inline_runs — exercises the attributed-text path.
2//!
3//! One paragraph composed of styled inline runs (regular + bold +
4//! italic + colored + monospace) plus a hard break, all flowing through
5//! cosmic-text's rich-text shaping. Wrapping decisions cross run
6//! boundaries — the same way a `<p>` containing `<strong>`, `<em>`,
7//! `<code>`, and `<br>` would behave in HTML.
8//!
9//! Inspect `out/inline_runs.tree.txt` to see the Inlines container with
10//! its child Text/HardBreak runs, and `out/inline_runs.draw_ops.txt`
11//! to see the single `Attr ... runs=N` line that draw_ops emits — one
12//! attributed text op per paragraph, with all the styling baked in.
13//!
14//! Run: `cargo run -p aetna-core --example inline_runs`
15
16use aetna_core::prelude::*;
17
18fn fixture() -> El {
19    column([
20        h2("Inline runs"),
21        text_runs([
22            text("Aetna's attributed-text path lets you compose runs with "),
23            text("bold").bold(),
24            text(", "),
25            text("italic").italic(),
26            text(", "),
27            text("colored").color(tokens::DESTRUCTIVE),
28            text(", and "),
29            text("inline code").code(),
30            text(" segments inside one wrapping paragraph."),
31            hard_break(),
32            text("Hard breaks act like ").muted(),
33            text("<br>").code(),
34            text(" — they end the current line without breaking out of the run.").muted(),
35        ])
36        .wrap_text()
37        .width(Size::Fill(1.0))
38        .height(Size::Hug),
39        paragraph(
40            "All of the above flows through one cosmic-text rich-text shape — \
41             wrapping decisions cross run boundaries the way real prose wraps.",
42        )
43        .muted(),
44    ])
45    .gap(tokens::SPACE_4)
46    .padding(tokens::SPACE_7)
47    .width(Size::Fixed(640.0))
48}
49
50fn main() -> std::io::Result<()> {
51    let mut root = fixture();
52
53    let viewport = Rect::new(0.0, 0.0, 640.0, 360.0);
54    let bundle = render_bundle(&mut root, viewport);
55
56    let out_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("out");
57    let written = write_bundle(&bundle, &out_dir, "inline_runs")?;
58    for p in &written {
59        println!("wrote {}", p.display());
60    }
61
62    if !bundle.lint.findings.is_empty() {
63        eprintln!("\nlint findings ({}):", bundle.lint.findings.len());
64        eprint!("{}", bundle.lint.text());
65    }
66
67    Ok(())
68}