use std::{cell::Cell, rc::Rc};
use gpui::{
App, AppContext as _, Context, Entity, EventEmitter, FocusHandle, Focusable, IntoElement,
Pixels, Render, Styled as _, Window, div,
};
use gpui_base::dock::PanelEvent;
use crate::{ElementExt as _, dock::Panel};
pub(crate) struct MeasuredProbe {
focus_handle: FocusHandle,
height: Rc<Cell<Pixels>>,
}
impl MeasuredProbe {
pub(crate) fn new(height: Rc<Cell<Pixels>>, cx: &mut App) -> Entity<Self> {
cx.new(|cx| Self {
focus_handle: cx.focus_handle(),
height,
})
}
}
impl gpui_base::dock::Panel for MeasuredProbe {
fn panel_name(&self) -> &'static str {
"MeasuredProbe"
}
}
impl Panel for MeasuredProbe {}
impl EventEmitter<PanelEvent> for MeasuredProbe {}
impl Focusable for MeasuredProbe {
fn focus_handle(&self, _: &App) -> FocusHandle {
self.focus_handle.clone()
}
}
impl Render for MeasuredProbe {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
let height = self.height.clone();
div()
.size_full()
.on_prepaint(move |bounds, _, _| height.set(bounds.size.height))
}
}
pub(crate) struct SizedProbe {
focus_handle: FocusHandle,
size: Rc<Cell<gpui::Size<Pixels>>>,
}
impl SizedProbe {
pub(crate) fn new(size: Rc<Cell<gpui::Size<Pixels>>>, cx: &mut App) -> Entity<Self> {
cx.new(|cx| Self {
focus_handle: cx.focus_handle(),
size,
})
}
}
impl gpui_base::dock::Panel for SizedProbe {
fn panel_name(&self) -> &'static str {
"SizedProbe"
}
}
impl Panel for SizedProbe {}
impl EventEmitter<PanelEvent> for SizedProbe {}
impl Focusable for SizedProbe {
fn focus_handle(&self, _: &App) -> FocusHandle {
self.focus_handle.clone()
}
}
impl Render for SizedProbe {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
let size = self.size.clone();
div()
.size_full()
.on_prepaint(move |bounds, _, _| size.set(bounds.size))
}
}
pub(crate) struct HideableProbe {
focus_handle: FocusHandle,
visible: bool,
height: Rc<Cell<Pixels>>,
}
impl HideableProbe {
pub(crate) fn new(height: Rc<Cell<Pixels>>, cx: &mut App) -> Entity<Self> {
cx.new(|cx| Self {
focus_handle: cx.focus_handle(),
visible: true,
height,
})
}
pub(crate) fn set_visible(&mut self, visible: bool, cx: &mut Context<Self>) {
self.visible = visible;
cx.notify();
}
}
impl gpui_base::dock::Panel for HideableProbe {
fn panel_name(&self) -> &'static str {
"HideableProbe"
}
fn visible(&self, _: &App) -> bool {
self.visible
}
}
impl Panel for HideableProbe {}
impl EventEmitter<PanelEvent> for HideableProbe {}
impl Focusable for HideableProbe {
fn focus_handle(&self, _: &App) -> FocusHandle {
self.focus_handle.clone()
}
}
impl Render for HideableProbe {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
let height = self.height.clone();
div()
.size_full()
.on_prepaint(move |bounds, _, _| height.set(bounds.size.height))
}
}