use std::panic::Location;
use crate::cursor::Cursor;
use crate::tokens;
use crate::tree::*;
use crate::widgets::text::text;
#[track_caller]
pub fn breadcrumb<I, E>(children: I) -> El
where
I: IntoIterator<Item = E>,
E: Into<El>,
{
row(children)
.at_loc(Location::caller())
.width(Size::Hug)
.height(Size::Hug)
.gap(tokens::SPACE_2)
.align(Align::Center)
}
#[track_caller]
pub fn breadcrumb_list<I, E>(children: I) -> El
where
I: IntoIterator<Item = E>,
E: Into<El>,
{
row(children)
.at_loc(Location::caller())
.width(Size::Hug)
.height(Size::Hug)
.gap(tokens::SPACE_2)
.align(Align::Center)
}
#[track_caller]
pub fn breadcrumb_item(child: impl Into<El>) -> El {
row([child.into()])
.at_loc(Location::caller())
.width(Size::Hug)
.height(Size::Hug)
.align(Align::Center)
}
#[track_caller]
pub fn breadcrumb_link(label: impl Into<String>) -> El {
text(label)
.at_loc(Location::caller())
.small()
.muted()
.ellipsis()
.cursor(Cursor::Pointer)
.width(Size::Hug)
}
#[track_caller]
pub fn breadcrumb_page(label: impl Into<String>) -> El {
text(label)
.at_loc(Location::caller())
.small()
.semibold()
.ellipsis()
.width(Size::Hug)
}
#[track_caller]
pub fn breadcrumb_separator() -> El {
text("/")
.at_loc(Location::caller())
.small()
.muted()
.width(Size::Hug)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn breadcrumb_list_centers_inline_items() {
let crumbs = breadcrumb_list([
breadcrumb_item(breadcrumb_link("Projects")),
breadcrumb_separator(),
breadcrumb_item(breadcrumb_page("Aetna")),
]);
assert_eq!(crumbs.axis, Axis::Row);
assert_eq!(crumbs.align, Align::Center);
assert_eq!(crumbs.gap, tokens::SPACE_2);
assert_eq!(crumbs.children.len(), 3);
}
#[test]
fn breadcrumb_link_and_page_have_distinct_treatments() {
let link = breadcrumb_link("Projects");
let page = breadcrumb_page("Aetna");
assert_eq!(link.text_color, Some(tokens::MUTED_FOREGROUND));
assert_eq!(link.cursor, Some(Cursor::Pointer));
assert_eq!(page.font_weight, FontWeight::Semibold);
}
}