diff --git a/crates/dock/src/dock.rs b/crates/dock/src/dock.rs index 87ca560..1813149 100644 --- a/crates/dock/src/dock.rs +++ b/crates/dock/src/dock.rs @@ -24,6 +24,12 @@ impl Render for ResizePanel { } } +/// Where to place a panel. +/// +/// The [`DockArea`] has a fixed left dock and a center area. `Left` targets +/// the left dock; `Center` adds a tab to the center; `Right` and `Bottom` +/// split the center so the new panel lands on the given side of the existing +/// center content. #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] pub enum DockPlacement { #[serde(rename = "center")] @@ -37,7 +43,8 @@ pub enum DockPlacement { } impl DockPlacement { - fn axis(&self) -> Axis { + /// The split axis used when the placement splits the center area. + pub(crate) fn axis(&self) -> Axis { match self { Self::Left | Self::Right => Axis::Horizontal, Self::Bottom => Axis::Vertical, @@ -48,24 +55,16 @@ impl DockPlacement { pub fn is_left(&self) -> bool { matches!(self, Self::Left) } - - pub fn is_bottom(&self) -> bool { - matches!(self, Self::Bottom) - } - - pub fn is_right(&self) -> bool { - matches!(self, Self::Right) - } } -/// The Dock is a fixed container that places at left, bottom, right of the Windows. +/// The Dock is a fixed container that places at the left side of the window. /// /// This is unlike Panel, it can't be move or add any other panel. pub struct Dock { pub(super) placement: DockPlacement, dock_area: WeakEntity, pub(crate) panel: DockItem, - /// The size is means the width or height of the Dock, if the placement is left or right, the size is width, otherwise the size is height. + /// The width of the dock. pub(super) size: Pixels, pub(super) open: bool, /// Whether the Dock is collapsible, default: true @@ -117,22 +116,6 @@ impl Dock { Self::new(dock_area, DockPlacement::Left, window, cx) } - pub fn bottom( - dock_area: WeakEntity, - window: &mut Window, - cx: &mut Context, - ) -> Self { - Self::new(dock_area, DockPlacement::Bottom, window, cx) - } - - pub fn right( - dock_area: WeakEntity, - window: &mut Window, - cx: &mut Context, - ) -> Self { - Self::new(dock_area, DockPlacement::Right, window, cx) - } - /// Update the Dock to be collapsible or not. /// /// And if the Dock is not collapsible, it will be open. @@ -212,16 +195,6 @@ impl Dock { } }); } - DockItem::Tiles { view, .. } => { - window.defer(cx, { - let view = view.clone(); - move |window, cx| { - _ = dock_area.update(cx, |this, cx| { - this.subscribe_panel(&view, window, cx); - }); - } - }); - } DockItem::Panel { .. } => { // Not supported } @@ -275,8 +248,7 @@ impl Dock { window: &mut Window, cx: &mut Context, ) { - self.panel - .add_panel(panel, &self.dock_area, None, window, cx); + self.panel.add_panel(panel, &self.dock_area, window, cx); cx.notify(); } @@ -328,52 +300,10 @@ impl Dock { .expect("DockArea is missing") .read(cx); let area_bounds = dock_area.bounds; - let mut left_dock_size = px(0.0); - let mut right_dock_size = px(0.0); - // Get the size of the left dock if it's open and not the current dock - if let Some(left_dock) = &dock_area.left_dock - && left_dock.entity_id() != cx.entity().entity_id() - { - let left_dock_read = left_dock.read(cx); - if left_dock_read.is_open() { - left_dock_size = left_dock_read.size; - } - } - - // Get the size of the right dock if it's open and not the current dock - if let Some(right_dock) = &dock_area.right_dock - && right_dock.entity_id() != cx.entity().entity_id() - { - let right_dock_read = right_dock.read(cx); - if right_dock_read.is_open() { - right_dock_size = right_dock_read.size; - } - } - - let size = match self.placement { - DockPlacement::Left => mouse_position.x - area_bounds.left(), - DockPlacement::Right => area_bounds.right() - mouse_position.x, - DockPlacement::Bottom => area_bounds.bottom() - mouse_position.y, - DockPlacement::Center => unreachable!(), - }; - match self.placement { - DockPlacement::Left => { - let max_size = - (area_bounds.size.width - PANEL_MIN_SIZE - right_dock_size).max(PANEL_MIN_SIZE); - self.size = size.clamp(PANEL_MIN_SIZE, max_size); - } - DockPlacement::Right => { - let max_size = - (area_bounds.size.width - PANEL_MIN_SIZE - left_dock_size).max(PANEL_MIN_SIZE); - self.size = size.clamp(PANEL_MIN_SIZE, max_size); - } - DockPlacement::Bottom => { - let max_size = (area_bounds.size.height - PANEL_MIN_SIZE).max(PANEL_MIN_SIZE); - self.size = size.clamp(PANEL_MIN_SIZE, max_size); - } - DockPlacement::Center => unreachable!(), - } + let size = mouse_position.x - area_bounds.left(); + let max_size = (area_bounds.size.width - PANEL_MIN_SIZE).max(PANEL_MIN_SIZE); + self.size = size.clamp(PANEL_MIN_SIZE, max_size); cx.notify(); } @@ -394,7 +324,7 @@ impl Dock { impl Render for Dock { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl gpui::IntoElement { - if !self.open && !self.placement.is_bottom() { + if !self.open { return div(); } @@ -403,21 +333,13 @@ impl Render for Dock { div() .relative() .overflow_hidden() - .map(|this| match self.placement { - DockPlacement::Left | DockPlacement::Right => this.h_flex().h_full().w(self.size), - DockPlacement::Bottom => this.w_full().h(self.size), - DockPlacement::Center => unreachable!(), - }) - // Bottom Dock should keep the title bar, then user can click the Toggle button - .when(!self.open && self.placement.is_bottom(), |this| { - this.h(px(29.)) - }) + .h_flex() + .h_full() + .w(self.size) .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().cached(cache_style)), - // Not support to render Tiles and Tile into Dock - DockItem::Tiles { .. } => this, }) .child(self.render_resize_handle(window, cx)) .child(DockElement { diff --git a/crates/dock/src/fixtures/layout.json b/crates/dock/src/fixtures/layout.json index 13b7a76..d1ceb41 100644 --- a/crates/dock/src/fixtures/layout.json +++ b/crates/dock/src/fixtures/layout.json @@ -169,7 +169,10 @@ ], "info": { "stack": { - "sizes": [704.0, 263.0], + "sizes": [ + 704.0, + 263.0 + ], "axis": 1 } } @@ -198,64 +201,5 @@ "size": 350.0, "open": true, "resizeable": true - }, - "right_dock": { - "panel": { - "panel_name": "TabPanel", - "children": [ - { - "panel_name": "StoryContainer", - "children": [], - "info": { - "panel": { - "story_klass": "ImageStory" - } - } - } - ], - "info": { - "tabs": { - "active_index": 0 - } - } - }, - "placement": "right", - "size": 320.0, - "open": true, - "resizeable": true - }, - "bottom_dock": { - "panel": { - "panel_name": "TabPanel", - "children": [ - { - "panel_name": "StoryContainer", - "children": [], - "info": { - "panel": { - "story_klass": "TextStory" - } - } - }, - { - "panel_name": "StoryContainer", - "children": [], - "info": { - "panel": { - "story_klass": "IconStory" - } - } - } - ], - "info": { - "tabs": { - "active_index": 0 - } - } - }, - "placement": "bottom", - "size": 200.0, - "open": true, - "resizeable": true } -} +} \ No newline at end of file diff --git a/crates/dock/src/lib.rs b/crates/dock/src/lib.rs index a902e39..1d5a461 100644 --- a/crates/dock/src/lib.rs +++ b/crates/dock/src/lib.rs @@ -5,7 +5,6 @@ mod resize_handle; mod stack_panel; mod state; mod tab_panel; -mod tiles; mod window_controls; use std::sync::Arc; @@ -23,7 +22,6 @@ pub use panel::*; pub use stack_panel::*; pub use state::*; pub use tab_panel::*; -pub use tiles::*; /// Initialize the dock, registering the [`PanelRegistry`] global. /// @@ -54,6 +52,20 @@ pub(crate) fn t(key: &'static str) -> &'static str { } } +/// A host-owned drag item, dragged into the dock by the application. +#[derive(Clone, Debug)] +pub struct AnyDrag { + pub value: Arc, +} + +impl AnyDrag { + pub fn new(value: T) -> Self { + Self { + value: Arc::new(value), + } + } +} + pub enum DockEvent { /// The layout of the dock has changed, subscribers this to save the layout. /// @@ -68,10 +80,6 @@ pub enum DockEvent { /// Where a host-owned drag landed, and how much the container can say about it. #[derive(Clone, Debug)] pub enum DropTarget { - /// Dropped on a [`Tiles`] canvas, where the landing position is just the - /// cursor position and the host can read it directly. - Canvas, - /// Dropped on a [`TabPanel`] in a split layout. A split layout has no free /// coordinates, so the container reports the panel and the edge it resolved /// from the cursor instead. @@ -95,10 +103,6 @@ pub struct DockArea { center: DockItem, /// The left dock of the dock_area. left_dock: Option>, - /// The bottom dock of the dock_area. - bottom_dock: Option>, - /// The right dock of the dock_area. - right_dock: Option>, /// The entity_id of the [`TabPanel`](TabPanel) where each toggle button should be displayed, toggle_button_panels: Edges>, @@ -144,13 +148,6 @@ pub enum DockItem { size: Option, view: Arc, }, - /// Tiles layout - Tiles { - /// Self size, only used for build split panels - size: Option, - items: Vec, - view: Entity, - }, } impl std::fmt::Debug for DockItem { @@ -172,7 +169,6 @@ impl std::fmt::Debug for DockItem { .field("active_ix", active_ix) .finish(), DockItem::Panel { .. } => f.debug_struct("Panel").finish(), - DockItem::Tiles { .. } => f.debug_struct("Tiles").finish(), } } } @@ -184,7 +180,6 @@ impl DockItem { Self::Split { size, .. } => *size, Self::Tabs { size, .. } => *size, Self::Panel { size, .. } => *size, - Self::Tiles { size, .. } => *size, } } @@ -194,7 +189,6 @@ impl DockItem { match self { Self::Split { ref mut size, .. } => *size = new_size, Self::Tabs { ref mut size, .. } => *size = new_size, - Self::Tiles { ref mut size, .. } => *size = new_size, Self::Panel { ref mut size, .. } => *size = new_size, } self @@ -303,60 +297,6 @@ impl DockItem { } } - /// Create DockItem with tiles layout - /// - /// This items and metas should have the same length. - pub fn tiles( - items: Vec, - metas: Vec + Copy>, - dock_area: &WeakEntity, - window: &mut Window, - cx: &mut App, - ) -> Self { - assert!(items.len() == metas.len()); - - let tile_panel = cx.new(|cx| { - let mut tiles = Tiles::new(window, cx); - for (ix, item) in items.clone().into_iter().enumerate() { - match item { - DockItem::Tabs { view, .. } => { - let meta: TileMeta = metas[ix].into(); - let tile_item = - TileItem::new(Arc::new(view), meta.bounds).z_index(meta.z_index); - tiles.add_item(tile_item, dock_area, window, cx); - } - DockItem::Panel { view, .. } => { - let meta: TileMeta = metas[ix].into(); - let tile_item = - TileItem::new(view.clone(), meta.bounds).z_index(meta.z_index); - tiles.add_item(tile_item, dock_area, window, cx); - } - _ => { - // Ignore non-tabs items - } - } - } - tiles - }); - - window.defer(cx, { - let tile_panel = tile_panel.clone(); - let dock_area = dock_area.clone(); - move |window, cx| { - _ = dock_area.update(cx, |this, cx| { - this.subscribe_panel(&tile_panel, window, cx); - this.subscribe_tiles_item_drop(&tile_panel, window, cx); - }); - } - }); - - Self::Tiles { - size: None, - items: tile_panel.read(cx).panels.clone(), - view: tile_panel, - } - } - /// Create DockItem with tabs layout, items are displayed as tabs. /// /// The `active_ix` is the index of the active tab, if `None` the first tab is active. @@ -412,7 +352,6 @@ impl DockItem { match self { Self::Split { view, .. } => Arc::new(view.clone()), Self::Tabs { view, .. } => Arc::new(view.clone()), - Self::Tiles { view, .. } => Arc::new(view.clone()), Self::Panel { view, .. } => view.clone(), } } @@ -440,13 +379,6 @@ impl DockItem { if let Ok(tabs) = view.clone().downcast::() { return tabs.read(cx).panels.iter().all(|panel| is_empty(panel, cx)); } - if let Ok(tiles) = view.downcast::() { - return tiles - .read(cx) - .panels() - .iter() - .all(|item| is_empty(&item.panel, cx)); - } !panel.visible(cx) } @@ -462,15 +394,6 @@ impl DockItem { } Self::Tabs { items, .. } => items.iter().find(|item| *item == &panel).cloned(), Self::Panel { view, .. } => Some(view.clone()), - Self::Tiles { items, .. } => items.iter().find_map(|item| { - // `==` on `Arc` moves the captured `panel` - // inside the closure; `eq` borrows both sides. - if item.panel.eq(&panel) { - Some(item.panel.clone()) - } else { - None - } - }), } } @@ -479,7 +402,6 @@ impl DockItem { &mut self, panel: Arc, dock_area: &WeakEntity, - bounds: Option>, window: &mut Window, cx: &mut App, ) { @@ -508,21 +430,6 @@ impl DockItem { stack_panel.add_panel(new_item.view(), None, dock_area.clone(), window, cx); }); } - Self::Tiles { view, items, .. } => { - let tile_item = TileItem::new( - Arc::new(cx.new(|cx| { - let mut tab_panel = TabPanel::new(None, dock_area.clone(), window, cx); - tab_panel.add_panel(panel.clone(), window, cx); - tab_panel - })), - bounds.unwrap_or_else(|| TileMeta::default().bounds), - ); - - items.push(tile_item.clone()); - view.update(cx, |tiles, cx| { - tiles.add_item(tile_item, dock_area, window, cx); - }); - } Self::Panel { .. } => {} } } @@ -544,11 +451,6 @@ impl DockItem { split.remove_panel(panel, window, cx); }); } - DockItem::Tiles { view, .. } => { - view.update(cx, |tiles, cx| { - tiles.remove(panel, window, cx); - }); - } DockItem::Panel { .. } => {} } } @@ -566,7 +468,6 @@ impl DockItem { item.set_collapsed(collapsed, window, cx); } } - DockItem::Tiles { .. } => {} DockItem::Panel { view, .. } => view.set_active(!collapsed, window, cx), } } @@ -576,17 +477,6 @@ impl DockItem { match self { DockItem::Tabs { view, .. } => Some(view.clone()), DockItem::Split { view, .. } => view.read(cx).left_top_tab_panel(true, cx), - DockItem::Tiles { .. } => None, - DockItem::Panel { .. } => None, - } - } - - /// Recursively traverses to find the right-most and top-most TabPanel. - pub(crate) fn right_top_tab_panel(&self, cx: &App) -> Option> { - match self { - DockItem::Tabs { view, .. } => Some(view.clone()), - DockItem::Split { view, .. } => view.read(cx).right_top_tab_panel(true, cx), - DockItem::Tiles { .. } => None, DockItem::Panel { .. } => None, } } @@ -615,8 +505,6 @@ impl DockArea { bounds: Bounds::default(), center: dock_item, left_dock: None, - right_dock: None, - bottom_dock: None, zoom_view: None, toggle_button_panels: Edges::default(), toggle_button_visible: true, @@ -635,22 +523,6 @@ impl DockArea { self.bounds } - /// Subscribe to the tiles item drag item drop event - fn subscribe_tiles_item_drop( - &mut self, - tile_panel: &Entity, - _: &mut Window, - cx: &mut Context, - ) { - self._subscriptions - .push(cx.subscribe(tile_panel, move |_, _, evt: &DragDrop, cx| { - cx.emit(DockEvent::DragDrop { - item: evt.0.clone(), - target: DropTarget::Canvas, - }); - })); - } - /// Set the panel style of the dock area. pub fn panel_style(mut self, style: PanelStyle) -> Self { self.panel_style = style; @@ -681,31 +553,11 @@ impl DockArea { self.left_dock.as_ref() } - /// Return the bottom dock item. - pub fn bottom_dock(&self) -> Option<&Entity> { - self.bottom_dock.as_ref() - } - - /// Return the right dock item. - pub fn right_dock(&self) -> Option<&Entity> { - self.right_dock.as_ref() - } - /// Remove the left dock. pub fn remove_left_dock(&mut self, _: &mut Window, _: &mut Context) { self.left_dock = None; } - /// Remove the bottom dock. - pub fn remove_bottom_dock(&mut self, _: &mut Window, _: &mut Context) { - self.bottom_dock = None; - } - - /// Remove the right dock. - pub fn remove_right_dock(&mut self, _: &mut Window, _: &mut Context) { - self.right_dock = None; - } - /// The the DockItem as the center of the dock area. /// /// This is used to render at the Center of the DockArea. @@ -738,50 +590,6 @@ impl DockArea { self.update_toggle_button_tab_panels(window, cx); } - pub fn set_bottom_dock( - &mut self, - panel: DockItem, - size: Option, - open: bool, - window: &mut Window, - cx: &mut Context, - ) { - self.subscribe_item(&panel, window, cx); - let weak_self = cx.entity().downgrade(); - self.bottom_dock = Some(cx.new(|cx| { - let mut dock = Dock::bottom(weak_self.clone(), window, cx); - if let Some(size) = size { - dock.set_size(size, window, cx); - } - dock.set_panel(panel, window, cx); - dock.set_open(open, window, cx); - dock - })); - self.update_toggle_button_tab_panels(window, cx); - } - - pub fn set_right_dock( - &mut self, - panel: DockItem, - size: Option, - open: bool, - window: &mut Window, - cx: &mut Context, - ) { - self.subscribe_item(&panel, window, cx); - let weak_self = cx.entity().downgrade(); - self.right_dock = Some(cx.new(|cx| { - let mut dock = Dock::right(weak_self.clone(), window, cx); - if let Some(size) = size { - dock.set_size(size, window, cx); - } - dock.set_panel(panel, window, cx); - dock.set_open(open, window, cx); - dock - })); - self.update_toggle_button_tab_panels(window, cx); - } - /// Set locked state of the dock area, if locked, the dock area cannot be split or move, but allows to resize panels. pub fn set_locked(&mut self, locked: bool, _window: &mut Window, _cx: &mut App) { self.locked = locked; @@ -797,9 +605,7 @@ impl DockArea { pub fn has_dock(&self, placement: DockPlacement) -> bool { match placement { DockPlacement::Left => self.left_dock.is_some(), - DockPlacement::Bottom => self.bottom_dock.is_some(), - DockPlacement::Right => self.right_dock.is_some(), - DockPlacement::Center => false, + DockPlacement::Center | DockPlacement::Right | DockPlacement::Bottom => false, } } @@ -811,23 +617,13 @@ impl DockArea { .as_ref() .map(|dock| dock.read(cx).is_open()) .unwrap_or(false), - DockPlacement::Bottom => self - .bottom_dock - .as_ref() - .map(|dock| dock.read(cx).is_open()) - .unwrap_or(false), - DockPlacement::Right => self - .right_dock - .as_ref() - .map(|dock| dock.read(cx).is_open()) - .unwrap_or(false), - DockPlacement::Center => false, + DockPlacement::Center | DockPlacement::Right | DockPlacement::Bottom => false, } } /// Set the dock at the given placement to be open or closed. /// - /// Only the left, bottom, right dock can be toggled. + /// Only the left dock can be toggled. pub fn set_dock_collapsible( &mut self, collapsible_edges: Edges, @@ -839,18 +635,6 @@ impl DockArea { dock.set_collapsible(collapsible_edges.left, window, cx); }); } - - if let Some(bottom_dock) = self.bottom_dock.as_ref() { - bottom_dock.update(cx, |dock, cx| { - dock.set_collapsible(collapsible_edges.bottom, window, cx); - }); - } - - if let Some(right_dock) = self.right_dock.as_ref() { - right_dock.update(cx, |dock, cx| { - dock.set_collapsible(collapsible_edges.right, window, cx); - }); - } } /// Determine if the dock at the given placement is collapsible. @@ -861,17 +645,7 @@ impl DockArea { .as_ref() .map(|dock| dock.read(cx).collapsible) .unwrap_or(false), - DockPlacement::Bottom => self - .bottom_dock - .as_ref() - .map(|dock| dock.read(cx).collapsible) - .unwrap_or(false), - DockPlacement::Right => self - .right_dock - .as_ref() - .map(|dock| dock.read(cx).collapsible) - .unwrap_or(false), - DockPlacement::Center => false, + DockPlacement::Center | DockPlacement::Right | DockPlacement::Bottom => false, } } @@ -882,14 +656,9 @@ impl DockArea { window: &mut Window, cx: &mut Context, ) { - let dock = match placement { - DockPlacement::Left => &self.left_dock, - DockPlacement::Bottom => &self.bottom_dock, - DockPlacement::Right => &self.right_dock, - DockPlacement::Center => return, - }; - - if let Some(dock) = dock { + if let DockPlacement::Left = placement + && let Some(dock) = self.left_dock.as_ref() + { dock.update(cx, |view, cx| { view.toggle_open(window, cx); }) @@ -902,11 +671,17 @@ impl DockArea { } /// Add a panel item to the dock area at the given placement. + /// + /// - [`DockPlacement::Left`] adds the panel to the left dock (creating it + /// if needed). + /// - [`DockPlacement::Center`] adds the panel as a tab in the center. + /// - [`DockPlacement::Right`] and [`DockPlacement::Bottom`] split the + /// center so the panel lands on the given side of the existing center + /// content. pub fn add_panel( &mut self, panel: Arc, placement: DockPlacement, - bounds: Option>, window: &mut Window, cx: &mut Context, ) { @@ -925,39 +700,69 @@ impl DockArea { ); } } - DockPlacement::Bottom => { - if let Some(dock) = self.bottom_dock.as_ref() { - dock.update(cx, |dock, cx| dock.add_panel(panel, window, cx)) - } else { - self.set_bottom_dock( - DockItem::tabs(vec![panel], &weak_self, window, cx), - None, - true, - window, - cx, - ); - } - } - DockPlacement::Right => { - if let Some(dock) = self.right_dock.as_ref() { - dock.update(cx, |dock, cx| dock.add_panel(panel, window, cx)) - } else { - self.set_right_dock( - DockItem::tabs(vec![panel], &weak_self, window, cx), - None, - true, - window, - cx, - ); - } + DockPlacement::Right | DockPlacement::Bottom => { + self.add_panel_to_center_side(panel, placement, window, cx); } DockPlacement::Center => { self.center - .add_panel(panel, &cx.entity().downgrade(), bounds, window, cx); + .add_panel(panel, &cx.entity().downgrade(), window, cx); } } } + /// Split the center so the new panel lands on the given side of the + /// existing center content (right of it for [`DockPlacement::Right`], + /// below it for [`DockPlacement::Bottom`]). + /// + /// The existing center keeps its place. Repeating adds with the same axis + /// appends further tab groups to the split; a different axis wraps the + /// current center in a new split. An empty center is added to directly. + fn add_panel_to_center_side( + &mut self, + panel: Arc, + placement: DockPlacement, + window: &mut Window, + cx: &mut Context, + ) { + debug_assert!(matches!( + placement, + DockPlacement::Right | DockPlacement::Bottom + )); + + let weak_self = cx.entity().downgrade(); + + if self.center.is_empty(cx) { + self.center.add_panel(panel, &weak_self, window, cx); + } else if let DockItem::Split { + axis, + size: _, + items, + sizes, + view, + } = &mut self.center + && *axis == placement.axis() + { + // The center is already split along this axis: append a new tab group. + let new_item = DockItem::tabs(vec![panel], &weak_self, window, cx); + items.push(new_item.clone()); + sizes.push(None); + view.update(cx, |stack, cx| { + stack.add_panel(new_item.view(), None, weak_self.clone(), window, cx); + }); + } else { + // Wrap the existing center in a new split. + let existing = self.center.clone(); + let new_item = DockItem::tabs(vec![panel], &weak_self, window, cx); + let items = vec![existing, new_item]; + let sizes = vec![None; items.len()]; + self.center = + DockItem::split_with_sizes(placement.axis(), items, sizes, &weak_self, window, cx); + } + + self.update_toggle_button_tab_panels(window, cx); + cx.notify(); + } + /// Remove panel from the DockArea at the given placement. pub fn remove_panel( &mut self, @@ -974,23 +779,13 @@ impl DockArea { }); } } - DockPlacement::Right => { - if let Some(dock) = self.right_dock.as_mut() { - dock.update(cx, |dock, cx| { - dock.remove_panel(panel, window, cx); - }); - } - } - DockPlacement::Bottom => { - if let Some(dock) = self.bottom_dock.as_mut() { - dock.update(cx, |dock, cx| { - dock.remove_panel(panel, window, cx); - }); - } - } DockPlacement::Center => { self.center.remove_panel(panel, window, cx); } + DockPlacement::Right | DockPlacement::Bottom => { + // The panel lives in the center; splits are part of it. + self.center.remove_panel(panel, window, cx); + } } cx.notify(); } @@ -1004,8 +799,6 @@ impl DockArea { ) { self.remove_panel(panel.clone(), DockPlacement::Center, window, cx); self.remove_panel(panel.clone(), DockPlacement::Left, window, cx); - self.remove_panel(panel.clone(), DockPlacement::Right, window, cx); - self.remove_panel(panel.clone(), DockPlacement::Bottom, window, cx); } /// Load the state of the DockArea from the DockAreaState. @@ -1024,14 +817,6 @@ impl DockArea { self.left_dock = Some(left_dock_state.to_dock(weak_self.clone(), window, cx)); } - if let Some(right_dock_state) = state.right_dock { - self.right_dock = Some(right_dock_state.to_dock(weak_self.clone(), window, cx)); - } - - if let Some(bottom_dock_state) = state.bottom_dock { - self.bottom_dock = Some(bottom_dock_state.to_dock(weak_self.clone(), window, cx)); - } - self.center = state.center.to_item(weak_self, window, cx); self.update_toggle_button_tab_panels(window, cx); Ok(()) @@ -1048,21 +833,11 @@ impl DockArea { .left_dock .as_ref() .map(|dock| DockState::new(dock.clone(), cx)); - let right_dock = self - .right_dock - .as_ref() - .map(|dock| DockState::new(dock.clone(), cx)); - let bottom_dock = self - .bottom_dock - .as_ref() - .map(|dock| DockState::new(dock.clone(), cx)); DockAreaState { version: self.version, center, left_dock, - right_dock, - bottom_dock, } } @@ -1094,9 +869,6 @@ impl DockArea { DockItem::Tabs { .. } => { // We subscribe to the tab panel event in StackPanel's insert_panel } - DockItem::Tiles { .. } => { - // We subscribe to the tab panel event in Tiles's [`add_item`](Tiles::add_item) - } DockItem::Panel { .. } => { // Not supported } @@ -1171,30 +943,16 @@ impl DockArea { match &self.center { DockItem::Split { view, .. } => view.clone().into_any_element(), DockItem::Tabs { view, .. } => view.clone().into_any_element(), - DockItem::Tiles { view, .. } => view.clone().into_any_element(), DockItem::Panel { view, .. } => view.clone().view().into_any_element(), } } pub fn update_toggle_button_tab_panels(&mut self, _: &mut Window, cx: &mut Context) { - // Left toggle button + // The left dock's toggle button lives in the center's top-left tab panel. self.toggle_button_panels.left = self .center .left_top_tab_panel(cx) .map(|view| view.entity_id()); - - // Right toggle button - self.toggle_button_panels.right = self - .center - .right_top_tab_panel(cx) - .map(|view| view.entity_id()); - - // Bottom toggle button - self.toggle_button_panels.bottom = self - .bottom_dock - .as_ref() - .and_then(|dock| dock.read(cx).panel.left_top_tab_panel(cx)) - .map(|view| view.entity_id()); } } impl EventEmitter for DockArea {} @@ -1212,48 +970,24 @@ impl Render for DockArea { if let Some(zoom_view) = self.zoom_view.clone() { this.child(zoom_view) } else { - match &self.center { - DockItem::Tiles { view, .. } => { - // render tiles - this.child(view.clone()) - } - _ => { - // render dock - this.child( + // render dock + this.child( + div() + .flex() + .flex_row() + .h_full() + // Left dock + .when_some(self.left_dock.clone(), |this, dock| { + this.child(div().flex().flex_none().child(dock)) + }) + // Center + .child( div() - .flex() - .flex_row() - .h_full() - // Left dock - .when_some(self.left_dock.clone(), |this, dock| { - this.child(div().flex().flex_none().child(dock)) - }) - // Center - .child( - div() - .flex() - .flex_1() - .flex_col() - .overflow_hidden() - // Top center - .child( - div() - .flex_1() - .overflow_hidden() - .child(self.render_items(window, cx)), - ) - // Bottom Dock - .when_some(self.bottom_dock.clone(), |this, dock| { - this.child(dock) - }), - ) - // Right Dock - .when_some(self.right_dock.clone(), |this, dock| { - this.child(div().flex().flex_none().child(dock)) - }), - ) - } - } + .flex_1() + .overflow_hidden() + .child(self.render_items(window, cx)), + ), + ) } }) } diff --git a/crates/dock/src/stack_panel.rs b/crates/dock/src/stack_panel.rs index 5d64a55..de47643 100644 --- a/crates/dock/src/stack_panel.rs +++ b/crates/dock/src/stack_panel.rs @@ -6,8 +6,8 @@ use gpui::{ Window, }; use gpui_component::{ - ActiveTheme, AxisExt as _, Placement, ResizablePanelEvent, ResizablePanelGroup, ResizableState, - h_flex, resizable_panel, + ActiveTheme, Placement, ResizablePanelEvent, ResizablePanelGroup, ResizableState, h_flex, + resizable_panel, }; use smallvec::SmallVec; @@ -354,38 +354,6 @@ impl StackPanel { } } - /// Find the first top right in the stack. - pub(super) fn right_top_tab_panel( - &self, - check_parent: bool, - cx: &App, - ) -> Option> { - if check_parent - && let Some(parent) = self.parent.as_ref().and_then(|parent| parent.upgrade()) - && let Some(panel) = parent.read(cx).right_top_tab_panel(true, cx) - { - return Some(panel); - } - - let panel = if self.axis.is_vertical() { - self.panels.first() - } else { - self.panels.last() - }; - - if let Some(view) = panel { - if let Ok(tab_panel) = view.view().downcast::() { - Some(tab_panel) - } else if let Ok(stack_panel) = view.view().downcast::() { - stack_panel.read(cx).right_top_tab_panel(false, cx) - } else { - None - } - } else { - None - } - } - /// Remove all panels from the stack. pub(super) fn remove_all_panels(&mut self, _: &mut Window, cx: &mut Context) { self.panels.clear(); diff --git a/crates/dock/src/state.rs b/crates/dock/src/state.rs index acfc406..389bd3c 100644 --- a/crates/dock/src/state.rs +++ b/crates/dock/src/state.rs @@ -1,4 +1,4 @@ -use gpui::{App, AppContext, Axis, Bounds, Entity, Pixels, WeakEntity, Window, point, px, size}; +use gpui::{App, AppContext, Axis, Entity, Pixels, WeakEntity, Window}; use itertools::Itertools as _; use serde::{Deserialize, Serialize}; @@ -15,10 +15,6 @@ pub struct DockAreaState { pub center: PanelState, #[serde(skip_serializing_if = "Option::is_none")] pub left_dock: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub right_dock: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub bottom_dock: Option, } /// Used to serialize and deserialize the Dock @@ -72,30 +68,6 @@ pub struct PanelState { pub info: PanelInfo, } -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] -pub struct TileMeta { - pub bounds: Bounds, - pub z_index: usize, -} - -impl Default for TileMeta { - fn default() -> Self { - Self { - bounds: Bounds { - origin: point(px(10.), px(10.)), - size: size(px(200.), px(200.)), - }, - z_index: 0, - } - } -} - -impl From> for TileMeta { - fn from(bounds: Bounds) -> Self { - Self { bounds, z_index: 0 } - } -} - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum PanelInfo { #[serde(rename = "stack")] @@ -107,8 +79,6 @@ pub enum PanelInfo { Tabs { active_index: usize }, #[serde(rename = "panel")] Panel(serde_json::Value), - #[serde(rename = "tiles")] - Tiles { metas: Vec }, } impl PanelInfo { @@ -127,10 +97,6 @@ impl PanelInfo { Self::Panel(info) } - pub fn tiles(metas: Vec) -> Self { - Self::Tiles { metas } - } - pub fn axis(&self) -> Option { match self { Self::Stack { axis, .. } => Some(if *axis == 0 { @@ -232,7 +198,6 @@ impl PanelState { ); DockItem::tabs(vec![view.into()], &dock_area, window, cx) } - PanelInfo::Tiles { metas } => DockItem::tiles(items, metas, &dock_area, window, cx), } } } @@ -264,19 +229,5 @@ mod tests { assert_eq!(left_dock.panel.panel_name, "TabPanel"); assert_eq!(left_dock.panel.children.len(), 1); assert_eq!(left_dock.panel.children[0].panel_name, "StoryContainer"); - - let bottom_dock = state.bottom_dock.unwrap(); - assert!(bottom_dock.open); - assert_eq!(bottom_dock.size, px(200.0)); - assert_eq!(bottom_dock.panel.panel_name, "TabPanel"); - assert_eq!(bottom_dock.panel.children.len(), 2); - assert_eq!(bottom_dock.panel.children[0].panel_name, "StoryContainer"); - - let right_dock = state.right_dock.unwrap(); - assert!(right_dock.open); - assert_eq!(right_dock.size, px(320.0)); - assert_eq!(right_dock.panel.panel_name, "TabPanel"); - assert_eq!(right_dock.panel.children.len(), 1); - assert_eq!(right_dock.panel.children[0].panel_name, "StoryContainer"); } } diff --git a/crates/dock/src/tab_panel.rs b/crates/dock/src/tab_panel.rs index 32d4dbb..a2caa6a 100644 --- a/crates/dock/src/tab_panel.rs +++ b/crates/dock/src/tab_panel.rs @@ -152,8 +152,6 @@ pub struct TabPanel { will_split_placement: Option, drop_placeholder_animation: Option, drop_placeholder_animation_name: SharedString, - /// Is TabPanel used in Tiles. - in_tiles: bool, /// Bounds of the title bar row (the wrapper around the tab bar), in /// window coordinates. Measured via `on_prepaint` to position the @@ -183,9 +181,8 @@ impl Panel for TabPanel { return false; } - // 1. When is the final panel in the dock, it will not able to close. - // 2. When is in the Tiles, it will always able to close (by active panel state). - if !self.draggable(cx) && !self.in_tiles { + // The final panel in the dock is not closable. + if !self.draggable(cx) { return false; } @@ -314,18 +311,12 @@ impl TabPanel { zoomed: false, collapsed: false, closable: true, - in_tiles: false, title_bar_bounds: None, title_bar_strip_bounds: None, title_bar_suffix_bounds: None, } } - /// Mark the TabPanel as being used in Tiles. - pub(super) fn set_in_tiles(&mut self, in_tiles: bool) { - self.in_tiles = in_tiles; - } - pub(super) fn set_parent(&mut self, view: WeakEntity) { self.stack_panel = Some(view); } @@ -717,6 +708,11 @@ impl TabPanel { _: &mut Window, cx: &mut Context, ) -> Option