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: SharedString,
20 pub(super) overflow_label: 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: "Breadcrumb".into(),
34 overflow_label: "More breadcrumbs".into(),
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 {
44 self.accessible_label = label.into();
45 self
46 }
47
48 pub fn overflow_label(mut self, label: impl Into<SharedString>) -> Self {
50 self.overflow_label = label.into();
51 self
52 }
53
54 pub fn on_select(
57 mut self,
58 handler: impl Fn(SharedString, &mut Window, &mut App) + 'static,
59 ) -> Self {
60 self.on_select = Some(Rc::new(handler));
61 self
62 }
63
64 pub fn max_items(mut self, count: usize) -> Self {
67 self.max_items = Some(count.max(2));
68 self
69 }
70
71 pub fn separator<E: IntoElement>(mut self, separator: impl Fn() -> E + 'static) -> Self {
74 self.separator = Some(Rc::new(move || separator().into_any_element()));
75 self
76 }
77
78 pub fn colors(mut self, colors: BreadcrumbsColors) -> Self {
80 self.colors = colors;
81 self
82 }
83}