gpui_material_components/navigation/
breadcrumbs.rs1use std::rc::Rc;
2
3use gpui::{App, ElementId, IntoElement, SharedString, Window};
4
5mod layout;
6mod render;
7mod types;
8
9pub use types::{BreadcrumbItem, BreadcrumbsColors};
10
11use types::{BreadcrumbSelect, SeparatorFactory};
12
13#[derive(IntoElement)]
16pub struct Breadcrumbs {
17 pub(super) id: ElementId,
18 pub(super) items: Vec<BreadcrumbItem>,
19 pub(super) accessible_label: Option<SharedString>,
20 pub(super) overflow_label: Option<SharedString>,
21 pub(super) on_select: Option<BreadcrumbSelect>,
22 pub(super) max_items: Option<usize>,
23 pub(super) separator: Option<SeparatorFactory>,
24 pub(super) colors: BreadcrumbsColors,
25}
26
27impl Breadcrumbs {
28 pub fn new(id: impl Into<ElementId>, items: impl IntoIterator<Item = BreadcrumbItem>) -> Self {
30 Self {
31 id: id.into(),
32 items: items.into_iter().collect(),
33 accessible_label: None,
34 overflow_label: None,
35 on_select: None,
36 max_items: None,
37 separator: None,
38 colors: BreadcrumbsColors::default(),
39 }
40 }
41
42 pub fn accessible_label(mut self, label: impl Into<SharedString>) -> Self {
45 self.accessible_label = Some(label.into());
46 self
47 }
48
49 pub fn overflow_label(mut self, label: impl Into<SharedString>) -> Self {
52 self.overflow_label = Some(label.into());
53 self
54 }
55
56 pub fn on_select(
59 mut self,
60 handler: impl Fn(SharedString, &mut Window, &mut App) + 'static,
61 ) -> Self {
62 self.on_select = Some(Rc::new(handler));
63 self
64 }
65
66 pub fn max_items(mut self, count: usize) -> Self {
69 self.max_items = Some(count.max(2));
70 self
71 }
72
73 pub fn separator<E: IntoElement>(mut self, separator: impl Fn() -> E + 'static) -> Self {
76 self.separator = Some(Rc::new(move || separator().into_any_element()));
77 self
78 }
79
80 pub fn colors(mut self, colors: BreadcrumbsColors) -> Self {
82 self.colors = colors;
83 self
84 }
85}