use std::rc::Rc;
use gpui::{App, ElementId, IntoElement, SharedString, Window};
mod layout;
mod render;
mod types;
pub use types::{BreadcrumbItem, BreadcrumbsColors};
use types::{BreadcrumbSelect, SeparatorFactory};
#[derive(IntoElement)]
pub struct Breadcrumbs {
pub(super) id: ElementId,
pub(super) items: Vec<BreadcrumbItem>,
pub(super) accessible_label: SharedString,
pub(super) overflow_label: SharedString,
pub(super) on_select: Option<BreadcrumbSelect>,
pub(super) max_items: Option<usize>,
pub(super) separator: Option<SeparatorFactory>,
pub(super) colors: BreadcrumbsColors,
}
impl Breadcrumbs {
pub fn new(id: impl Into<ElementId>, items: impl IntoIterator<Item = BreadcrumbItem>) -> Self {
Self {
id: id.into(),
items: items.into_iter().collect(),
accessible_label: "Breadcrumb".into(),
overflow_label: "More breadcrumbs".into(),
on_select: None,
max_items: None,
separator: None,
colors: BreadcrumbsColors::default(),
}
}
pub fn accessible_label(mut self, label: impl Into<SharedString>) -> Self {
self.accessible_label = label.into();
self
}
pub fn overflow_label(mut self, label: impl Into<SharedString>) -> Self {
self.overflow_label = label.into();
self
}
pub fn on_select(
mut self,
handler: impl Fn(SharedString, &mut Window, &mut App) + 'static,
) -> Self {
self.on_select = Some(Rc::new(handler));
self
}
pub fn max_items(mut self, count: usize) -> Self {
self.max_items = Some(count.max(2));
self
}
pub fn separator<E: IntoElement>(mut self, separator: impl Fn() -> E + 'static) -> Self {
self.separator = Some(Rc::new(move || separator().into_any_element()));
self
}
pub fn colors(mut self, colors: BreadcrumbsColors) -> Self {
self.colors = colors;
self
}
}