use std::panic::Location;
use crate::tokens;
use crate::tree::*;
#[track_caller]
pub fn page<I, E>(children: I) -> El
where
I: IntoIterator<Item = E>,
E: Into<El>,
{
let loc = Location::caller();
stack([column(children)
.at_loc(loc)
.gap(tokens::SPACE_4)
.align(Align::Stretch)
.padding(tokens::SPACE_4)
.fill_size()])
.at_loc(loc)
.fill_size()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::widgets::toolbar::{toolbar, toolbar_title};
#[test]
fn page_bakes_padding_and_overlay_root() {
let p = page([toolbar([toolbar_title("Documents")])]);
assert_eq!(p.axis, Axis::Overlay);
assert_eq!(p.width, Size::Fill(1.0));
assert_eq!(p.height, Size::Fill(1.0));
assert_eq!(p.children.len(), 1);
let content = &p.children[0];
assert_eq!(content.axis, Axis::Column);
assert_eq!(content.padding, Sides::all(tokens::SPACE_4));
assert_eq!(content.gap, tokens::SPACE_4);
assert_eq!(content.align, Align::Stretch);
assert!(content.fill.is_none());
}
#[test]
fn page_root_is_lint_clean_and_tooltip_capable() {
let mut root = page([
toolbar([toolbar_title("Library")]),
crate::text("cell").key("cell").tooltip("a tooltip"),
]);
let bundle =
crate::bundle::artifact::render_bundle(&mut root, Rect::new(0.0, 0.0, 640.0, 480.0));
assert!(
bundle.lint.findings.is_empty(),
"page() root must lint clean:\n{}",
bundle.lint.text()
);
}
}