gpui-component/crates/ui/src/dock/panel.rs
Jason Lee c5c8e46ac7
New Dock (#172)
https://github.com/user-attachments/assets/c8c55faa-8f17-4fa2-9f62-5fdd598087ef

- [x] Move to insert panel to tabs middle.
- [x] Zoom panel
- [x] Tab popup menu (Close Panel, Split, Zoom in/Zoom out)
- [x] TabBar scrollable
- [ ] TabBar nav history
2024-08-23 18:01:29 +08:00

53 lines
1.3 KiB
Rust

use gpui::{AnyView, EventEmitter, FocusableView, SharedString, View, WindowContext};
use rust_i18n::t;
use super::PanelEvent;
pub trait Panel: EventEmitter<PanelEvent> + FocusableView {
/// The title of the panel, default is `None`.
fn title(&self, _cx: &WindowContext) -> SharedString {
t!("Dock.Unnamed").into()
}
/// Whether the panel can be closed, default is `true`.
fn closeable(&self, _cx: &WindowContext) -> bool {
true
}
}
pub trait PanelView: 'static + Send + Sync {
/// The title of the panel, default is `None`.
fn title(&self, _cx: &WindowContext) -> SharedString {
t!("Dock.Unnamed").into()
}
fn view(&self) -> AnyView;
}
impl<T: Panel> PanelView for View<T> {
fn title(&self, cx: &WindowContext) -> SharedString {
self.read(cx).title(cx)
}
fn view(&self) -> AnyView {
self.clone().into()
}
}
impl From<&dyn PanelView> for AnyView {
fn from(handle: &dyn PanelView) -> Self {
handle.view()
}
}
impl<T: Panel> From<&dyn PanelView> for View<T> {
fn from(value: &dyn PanelView) -> Self {
value.view().downcast::<T>().unwrap()
}
}
impl PartialEq for dyn PanelView {
fn eq(&self, other: &Self) -> bool {
self.view() == other.view()
}
}