settings_ui: Dynamic navbar filtering (#39494)
Closes #ISSUE Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -10,7 +10,7 @@ pub struct Disclosure {
|
||||
is_open: bool,
|
||||
selected: bool,
|
||||
disabled: bool,
|
||||
on_toggle: Option<Arc<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>>,
|
||||
on_toggle_expanded: Option<Arc<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>>,
|
||||
cursor_style: CursorStyle,
|
||||
opened_icon: IconName,
|
||||
closed_icon: IconName,
|
||||
@@ -24,7 +24,7 @@ impl Disclosure {
|
||||
is_open,
|
||||
selected: false,
|
||||
disabled: false,
|
||||
on_toggle: None,
|
||||
on_toggle_expanded: None,
|
||||
cursor_style: CursorStyle::PointingHand,
|
||||
opened_icon: IconName::ChevronDown,
|
||||
closed_icon: IconName::ChevronRight,
|
||||
@@ -32,11 +32,11 @@ impl Disclosure {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_toggle(
|
||||
pub fn on_toggle_expanded(
|
||||
mut self,
|
||||
handler: impl Into<Option<Arc<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>>>,
|
||||
) -> Self {
|
||||
self.on_toggle = handler.into();
|
||||
self.on_toggle_expanded = handler.into();
|
||||
self
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ impl Toggleable for Disclosure {
|
||||
|
||||
impl Clickable for Disclosure {
|
||||
fn on_click(mut self, handler: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static) -> Self {
|
||||
self.on_toggle = Some(Arc::new(handler));
|
||||
self.on_toggle_expanded = Some(Arc::new(handler));
|
||||
self
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ impl RenderOnce for Disclosure {
|
||||
.when_some(self.visible_on_hover.clone(), |this, group_name| {
|
||||
this.visible_on_hover(group_name)
|
||||
})
|
||||
.when_some(self.on_toggle, move |this, on_toggle| {
|
||||
.when_some(self.on_toggle_expanded, move |this, on_toggle| {
|
||||
this.on_click(move |event, window, cx| on_toggle(event, window, cx))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -107,7 +107,8 @@ impl RenderOnce for ListHeader {
|
||||
h_flex()
|
||||
.gap(DynamicSpacing::Base04.rems(cx))
|
||||
.children(self.toggle.map(|is_open| {
|
||||
Disclosure::new("toggle", is_open).on_toggle(self.on_toggle.clone())
|
||||
Disclosure::new("toggle", is_open)
|
||||
.on_toggle_expanded(self.on_toggle.clone())
|
||||
}))
|
||||
.child(
|
||||
div()
|
||||
|
||||
@@ -308,7 +308,10 @@ impl RenderOnce for ListItem {
|
||||
.when(is_open && !self.always_show_disclosure_icon, |this| {
|
||||
this.visible_on_hover("")
|
||||
})
|
||||
.child(Disclosure::new("toggle", is_open).on_toggle(self.on_toggle))
|
||||
.child(
|
||||
Disclosure::new("toggle", is_open)
|
||||
.on_toggle_expanded(self.on_toggle),
|
||||
)
|
||||
}))
|
||||
.child(
|
||||
h_flex()
|
||||
|
||||
@@ -9,7 +9,7 @@ pub struct TreeViewItem {
|
||||
id: ElementId,
|
||||
group_name: Option<SharedString>,
|
||||
label: SharedString,
|
||||
toggle: bool,
|
||||
expanded: bool,
|
||||
selected: bool,
|
||||
disabled: bool,
|
||||
focused: bool,
|
||||
@@ -28,7 +28,7 @@ impl TreeViewItem {
|
||||
id: id.into(),
|
||||
group_name: None,
|
||||
label: label.into(),
|
||||
toggle: false,
|
||||
expanded: false,
|
||||
selected: false,
|
||||
disabled: false,
|
||||
focused: false,
|
||||
@@ -73,8 +73,8 @@ impl TreeViewItem {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn toggle(mut self, toggle: bool) -> Self {
|
||||
self.toggle = toggle;
|
||||
pub fn expanded(mut self, toggle: bool) -> Self {
|
||||
self.expanded = toggle;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -161,10 +161,12 @@ impl RenderOnce for TreeViewItem {
|
||||
})
|
||||
.hover(|s| s.bg(cx.theme().colors().element_hover))
|
||||
.child(
|
||||
Disclosure::new("toggle", self.toggle)
|
||||
Disclosure::new("toggle", self.expanded)
|
||||
.when_some(
|
||||
self.on_toggle.clone(),
|
||||
|disclosure, on_toggle| disclosure.on_toggle(on_toggle),
|
||||
|disclosure, on_toggle| {
|
||||
disclosure.on_toggle_expanded(on_toggle)
|
||||
},
|
||||
)
|
||||
.opened_icon(IconName::ChevronDown)
|
||||
.closed_icon(IconName::ChevronRight),
|
||||
|
||||
Reference in New Issue
Block a user