use gpui_kit::{AnyElement, App, IntoElement, RenderOnce, Window, base::Selectable};
#[derive(IntoElement)]
pub(crate) struct OpenSlot {
build: Box<dyn FnOnce(bool) -> AnyElement>,
open: bool,
pinned: bool,
}
impl OpenSlot {
pub(crate) fn built(build: impl FnOnce(bool) -> AnyElement + 'static) -> Self {
Self {
build: Box::new(build),
open: false,
pinned: false,
}
}
pub(crate) fn fixed(element: AnyElement, open: bool) -> Self {
Self {
build: Box::new(move |_| element),
open,
pinned: true,
}
}
}
impl Selectable for OpenSlot {
fn selected(self, _: bool) -> Self {
self
}
fn is_selected(&self) -> bool {
false
}
fn open(mut self, open: bool) -> Self {
if !self.pinned {
self.open = open;
}
self
}
fn is_open(&self) -> bool {
self.open
}
}
impl RenderOnce for OpenSlot {
fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement {
(self.build)(self.open)
}
}