Render editor fold indicators using Disclosure
s (#13008)
This PR updates the spots where we render the fold indicators in editors to use the `Disclosure` component instead of re-implementing similar UI. This makes this UI more consistent across Zed. Release Notes: - N/A
This commit is contained in:
parent
af8e7af265
commit
1a40e98413
3 changed files with 35 additions and 32 deletions
|
@ -8,6 +8,7 @@ use crate::{prelude::*, Color, IconButton, IconButtonShape, IconName, IconSize};
|
|||
pub struct Disclosure {
|
||||
id: ElementId,
|
||||
is_open: bool,
|
||||
selected: bool,
|
||||
on_toggle: Option<Arc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
}
|
||||
|
||||
|
@ -16,6 +17,7 @@ impl Disclosure {
|
|||
Self {
|
||||
id: id.into(),
|
||||
is_open,
|
||||
selected: false,
|
||||
on_toggle: None,
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +31,20 @@ impl Disclosure {
|
|||
}
|
||||
}
|
||||
|
||||
impl Selectable for Disclosure {
|
||||
fn selected(mut self, selected: bool) -> Self {
|
||||
self.selected = selected;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Clickable for Disclosure {
|
||||
fn on_click(mut self, handler: impl Fn(&ClickEvent, &mut WindowContext) + 'static) -> Self {
|
||||
self.on_toggle = Some(Arc::new(handler));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for Disclosure {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
IconButton::new(
|
||||
|
@ -41,6 +57,7 @@ impl RenderOnce for Disclosure {
|
|||
.shape(IconButtonShape::Square)
|
||||
.icon_color(Color::Muted)
|
||||
.icon_size(IconSize::Small)
|
||||
.selected(self.selected)
|
||||
.when_some(self.on_toggle, move |this, on_toggle| {
|
||||
this.on_click(move |event, cx| on_toggle(event, cx))
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue