Render editor fold indicators using Disclosures (#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:
Marshall Bowers 2024-06-13 16:05:47 -04:00 committed by GitHub
parent af8e7af265
commit 1a40e98413
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 32 deletions

View file

@ -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))
})