This commit is contained in:
2026-10-22 18:16:41 +07:00
parent bebb4cebbf
commit bd9f4e2861
7 changed files with 42 additions and 26 deletions
+18 -2
View File
@@ -19,6 +19,7 @@ pub struct Nav {
suffix: Option<AnyElement>,
selected: bool,
clickable: bool,
gap: bool,
#[allow(clippy::type_complexity)]
on_click: Option<Rc<dyn Fn(&ClickEvent, &mut Window, &mut App)>>,
}
@@ -38,6 +39,7 @@ impl Nav {
suffix: None,
selected: false,
clickable: false,
gap: true,
on_click: None,
}
}
@@ -48,6 +50,12 @@ impl Nav {
self
}
/// Whether to space the row's contents apart.
pub fn gap(mut self, gap: bool) -> Self {
self.gap = gap;
self
}
/// Sets the element shown before the label, such as an avatar or icon.
pub fn prefix(mut self, prefix: impl IntoElement) -> Self {
self.prefix = Some(prefix.into_any_element());
@@ -107,9 +115,17 @@ impl RenderOnce for Nav {
.h_8()
.w_full()
.px_2()
.gap_2()
.when(self.gap, |this| this.gap_2())
.rounded(cx.theme().radius)
.when_some(self.prefix, |this, prefix| this.child(prefix))
.when_some(self.prefix, |this, prefix| {
this.child(
h_flex()
.w_6()
.flex_shrink_0()
.justify_center()
.child(prefix),
)
})
.child(div().flex_1().min_w_0().truncate().child(self.label))
.when_some(self.suffix, |this, suffix| {
this.child(div().flex_shrink_0().child(suffix))