From 07a8e70d1ac7b80bcc8f4f4fa0549d2f5b1c6deb Mon Sep 17 00:00:00 2001
From: reya <123083837+reyamir@users.noreply.github.com>
Date: Thu, 5 Dec 2024 10:12:08 +0700
Subject: [PATCH] dock: Add DockItem::panel (#464)
**Description**:
Improve the flexibility of `DockArea`, sometime user won't need a
`TabPanel`, just display some message or UI elements. Curren implement
only allow use Tab or Split. So this PR will add `Plain` to `DockItem`,
user can put anything which implement `PanelView` trait.
**Usage**:
```rust
let left_panels = DockItem::panel(Arc::new(<- PanelView ->));
_ = dock_area.update(cx, |view, cx| {
view.set_version(DOCK_AREA.version, cx);
view.set_left_dock(left_panels, Some(px(260.)), true, cx);
view.set_center(dock_item, cx);
view.set_dock_collapsible(
Edges {
left: false,
..Default::default()
},
cx,
);
});
```
**Screenshot**
---
crates/ui/src/dock/dock.rs | 4 ++++
crates/ui/src/dock/mod.rs | 19 +++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/crates/ui/src/dock/dock.rs b/crates/ui/src/dock/dock.rs
index 41bf3941..274dfc92 100644
--- a/crates/ui/src/dock/dock.rs
+++ b/crates/ui/src/dock/dock.rs
@@ -188,6 +188,9 @@ impl Dock {
}
});
}
+ DockItem::Panel { .. } => {
+ // Not supported
+ }
}
}
@@ -367,6 +370,7 @@ impl Render for Dock {
.map(|this| match &self.panel {
DockItem::Split { view, .. } => this.child(view.clone()),
DockItem::Tabs { view, .. } => this.child(view.clone()),
+ DockItem::Panel { view, .. } => this.child(view.clone().view()),
})
.child(self.render_resize_handle(cx))
.child(DockElement {
diff --git a/crates/ui/src/dock/mod.rs b/crates/ui/src/dock/mod.rs
index 4f6c13b0..672cceea 100644
--- a/crates/ui/src/dock/mod.rs
+++ b/crates/ui/src/dock/mod.rs
@@ -68,17 +68,21 @@ pub struct DockArea {
/// DockItem is a tree structure that represents the layout of the dock.
#[derive(Clone)]
pub enum DockItem {
+ /// Split layout
Split {
axis: gpui::Axis,
items: Vec,
sizes: Vec