use aetna_core::prelude::*;
use aetna_core::{UiState, layout};
fn scroll_list_fixture() -> El {
let rows: Vec<El> = (0..20)
.map(|i| {
row([
badge(format!("#{i}")).info(),
text(format!("Notification {i}")).bold(),
spacer(),
text(format!("{}m ago", i + 1)).muted(),
])
.gap(tokens::SPACE_SM)
.height(Size::Fixed(44.0))
.padding(Sides::xy(tokens::SPACE_MD, tokens::SPACE_SM))
})
.collect();
let list = scroll(rows)
.key("notifications")
.height(Size::Fixed(420.0))
.padding(tokens::SPACE_SM);
column([
h2("Notifications"),
text("Roll the wheel inside the panel to scroll. The content is taller than the viewport.")
.muted(),
list,
])
.gap(tokens::SPACE_LG)
.padding(tokens::SPACE_XL)
}
fn main() -> std::io::Result<()> {
let mut root = scroll_list_fixture();
layout::assign_ids(&mut root);
let scroll_id = find_id(&root, "notifications").expect("scroll node id");
let mut ui_state = UiState::new();
ui_state.set_scroll_offset(scroll_id, 220.0);
let viewport = Rect::new(0.0, 0.0, 720.0, 600.0);
let bundle = render_bundle_with(
&mut root,
&mut ui_state,
viewport,
Some("crates/aetna-core/src"),
);
let out_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("out");
let written = write_bundle(&bundle, &out_dir, "scroll_list")?;
for p in &written {
println!("wrote {}", p.display());
}
if !bundle.lint.findings.is_empty() {
eprintln!("\nlint findings ({}):", bundle.lint.findings.len());
eprint!("{}", bundle.lint.text());
}
Ok(())
}
fn find_id(node: &El, key: &str) -> Option<String> {
if node.key.as_deref() == Some(key) {
return Some(node.computed_id.clone());
}
node.children.iter().find_map(|c| find_id(c, key))
}