
This PR adds new `Button` and `IconButton` components built on top of our new button abstractions. Both of these buttons are built from the common `ButtonLike` base, and implement the `ButtonCommon` (name TBD) trait in order to provide a common interface. There are still some visual tweaks that we'll need to make to the new buttons, but those should be straightforward to make after we land this. Release Notes: - N/A
48 lines
1.1 KiB
Rust
48 lines
1.1 KiB
Rust
use std::rc::Rc;
|
|
|
|
use gpui::ClickEvent;
|
|
|
|
use crate::prelude::*;
|
|
use crate::{Color, Icon, IconButton, IconSize};
|
|
|
|
#[derive(IntoElement)]
|
|
pub struct Disclosure {
|
|
is_open: bool,
|
|
on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
|
}
|
|
|
|
impl Disclosure {
|
|
pub fn new(is_open: bool) -> Self {
|
|
Self {
|
|
is_open,
|
|
on_toggle: None,
|
|
}
|
|
}
|
|
|
|
pub fn on_toggle(
|
|
mut self,
|
|
handler: impl Into<Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>>,
|
|
) -> Self {
|
|
self.on_toggle = handler.into();
|
|
self
|
|
}
|
|
}
|
|
|
|
impl RenderOnce for Disclosure {
|
|
type Rendered = IconButton;
|
|
|
|
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
|
|
IconButton::new(
|
|
"toggle",
|
|
match self.is_open {
|
|
true => Icon::ChevronDown,
|
|
false => Icon::ChevronRight,
|
|
},
|
|
)
|
|
.icon_color(Color::Muted)
|
|
.icon_size(IconSize::Small)
|
|
.when_some(self.on_toggle, move |this, on_toggle| {
|
|
this.on_click(move |event, cx| on_toggle(event, cx))
|
|
})
|
|
}
|
|
}
|