update dock
This commit is contained in:
+18
-96
@@ -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)]
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
pub enum DockPlacement {
|
pub enum DockPlacement {
|
||||||
#[serde(rename = "center")]
|
#[serde(rename = "center")]
|
||||||
@@ -37,7 +43,8 @@ pub enum DockPlacement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
match self {
|
||||||
Self::Left | Self::Right => Axis::Horizontal,
|
Self::Left | Self::Right => Axis::Horizontal,
|
||||||
Self::Bottom => Axis::Vertical,
|
Self::Bottom => Axis::Vertical,
|
||||||
@@ -48,24 +55,16 @@ impl DockPlacement {
|
|||||||
pub fn is_left(&self) -> bool {
|
pub fn is_left(&self) -> bool {
|
||||||
matches!(self, Self::Left)
|
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.
|
/// This is unlike Panel, it can't be move or add any other panel.
|
||||||
pub struct Dock {
|
pub struct Dock {
|
||||||
pub(super) placement: DockPlacement,
|
pub(super) placement: DockPlacement,
|
||||||
dock_area: WeakEntity<DockArea>,
|
dock_area: WeakEntity<DockArea>,
|
||||||
pub(crate) panel: DockItem,
|
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) size: Pixels,
|
||||||
pub(super) open: bool,
|
pub(super) open: bool,
|
||||||
/// Whether the Dock is collapsible, default: true
|
/// Whether the Dock is collapsible, default: true
|
||||||
@@ -117,22 +116,6 @@ impl Dock {
|
|||||||
Self::new(dock_area, DockPlacement::Left, window, cx)
|
Self::new(dock_area, DockPlacement::Left, window, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bottom(
|
|
||||||
dock_area: WeakEntity<DockArea>,
|
|
||||||
window: &mut Window,
|
|
||||||
cx: &mut Context<Self>,
|
|
||||||
) -> Self {
|
|
||||||
Self::new(dock_area, DockPlacement::Bottom, window, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn right(
|
|
||||||
dock_area: WeakEntity<DockArea>,
|
|
||||||
window: &mut Window,
|
|
||||||
cx: &mut Context<Self>,
|
|
||||||
) -> Self {
|
|
||||||
Self::new(dock_area, DockPlacement::Right, window, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Update the Dock to be collapsible or not.
|
/// Update the Dock to be collapsible or not.
|
||||||
///
|
///
|
||||||
/// And if the Dock is not collapsible, it will be open.
|
/// 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 { .. } => {
|
DockItem::Panel { .. } => {
|
||||||
// Not supported
|
// Not supported
|
||||||
}
|
}
|
||||||
@@ -275,8 +248,7 @@ impl Dock {
|
|||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
self.panel
|
self.panel.add_panel(panel, &self.dock_area, window, cx);
|
||||||
.add_panel(panel, &self.dock_area, None, window, cx);
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,52 +300,10 @@ impl Dock {
|
|||||||
.expect("DockArea is missing")
|
.expect("DockArea is missing")
|
||||||
.read(cx);
|
.read(cx);
|
||||||
let area_bounds = dock_area.bounds;
|
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
|
let size = mouse_position.x - area_bounds.left();
|
||||||
if let Some(left_dock) = &dock_area.left_dock
|
let max_size = (area_bounds.size.width - PANEL_MIN_SIZE).max(PANEL_MIN_SIZE);
|
||||||
&& left_dock.entity_id() != cx.entity().entity_id()
|
self.size = size.clamp(PANEL_MIN_SIZE, max_size);
|
||||||
{
|
|
||||||
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!(),
|
|
||||||
}
|
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
@@ -394,7 +324,7 @@ impl Dock {
|
|||||||
|
|
||||||
impl Render for Dock {
|
impl Render for Dock {
|
||||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl gpui::IntoElement {
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl gpui::IntoElement {
|
||||||
if !self.open && !self.placement.is_bottom() {
|
if !self.open {
|
||||||
return div();
|
return div();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,21 +333,13 @@ impl Render for Dock {
|
|||||||
div()
|
div()
|
||||||
.relative()
|
.relative()
|
||||||
.overflow_hidden()
|
.overflow_hidden()
|
||||||
.map(|this| match self.placement {
|
.h_flex()
|
||||||
DockPlacement::Left | DockPlacement::Right => this.h_flex().h_full().w(self.size),
|
.h_full()
|
||||||
DockPlacement::Bottom => this.w_full().h(self.size),
|
.w(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.))
|
|
||||||
})
|
|
||||||
.map(|this| match &self.panel {
|
.map(|this| match &self.panel {
|
||||||
DockItem::Split { view, .. } => this.child(view.clone()),
|
DockItem::Split { view, .. } => this.child(view.clone()),
|
||||||
DockItem::Tabs { view, .. } => this.child(view.clone()),
|
DockItem::Tabs { view, .. } => this.child(view.clone()),
|
||||||
DockItem::Panel { view, .. } => this.child(view.clone().view().cached(cache_style)),
|
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(self.render_resize_handle(window, cx))
|
||||||
.child(DockElement {
|
.child(DockElement {
|
||||||
|
|||||||
@@ -169,7 +169,10 @@
|
|||||||
],
|
],
|
||||||
"info": {
|
"info": {
|
||||||
"stack": {
|
"stack": {
|
||||||
"sizes": [704.0, 263.0],
|
"sizes": [
|
||||||
|
704.0,
|
||||||
|
263.0
|
||||||
|
],
|
||||||
"axis": 1
|
"axis": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,64 +201,5 @@
|
|||||||
"size": 350.0,
|
"size": 350.0,
|
||||||
"open": true,
|
"open": true,
|
||||||
"resizeable": 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+106
-372
@@ -5,7 +5,6 @@ mod resize_handle;
|
|||||||
mod stack_panel;
|
mod stack_panel;
|
||||||
mod state;
|
mod state;
|
||||||
mod tab_panel;
|
mod tab_panel;
|
||||||
mod tiles;
|
|
||||||
mod window_controls;
|
mod window_controls;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -23,7 +22,6 @@ pub use panel::*;
|
|||||||
pub use stack_panel::*;
|
pub use stack_panel::*;
|
||||||
pub use state::*;
|
pub use state::*;
|
||||||
pub use tab_panel::*;
|
pub use tab_panel::*;
|
||||||
pub use tiles::*;
|
|
||||||
|
|
||||||
/// Initialize the dock, registering the [`PanelRegistry`] global.
|
/// 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<dyn std::any::Any + Send + Sync>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AnyDrag {
|
||||||
|
pub fn new<T: 'static + Send + Sync>(value: T) -> Self {
|
||||||
|
Self {
|
||||||
|
value: Arc::new(value),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub enum DockEvent {
|
pub enum DockEvent {
|
||||||
/// The layout of the dock has changed, subscribers this to save the layout.
|
/// 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.
|
/// Where a host-owned drag landed, and how much the container can say about it.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum DropTarget {
|
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
|
/// 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
|
/// coordinates, so the container reports the panel and the edge it resolved
|
||||||
/// from the cursor instead.
|
/// from the cursor instead.
|
||||||
@@ -95,10 +103,6 @@ pub struct DockArea {
|
|||||||
center: DockItem,
|
center: DockItem,
|
||||||
/// The left dock of the dock_area.
|
/// The left dock of the dock_area.
|
||||||
left_dock: Option<Entity<Dock>>,
|
left_dock: Option<Entity<Dock>>,
|
||||||
/// The bottom dock of the dock_area.
|
|
||||||
bottom_dock: Option<Entity<Dock>>,
|
|
||||||
/// The right dock of the dock_area.
|
|
||||||
right_dock: Option<Entity<Dock>>,
|
|
||||||
|
|
||||||
/// The entity_id of the [`TabPanel`](TabPanel) where each toggle button should be displayed,
|
/// The entity_id of the [`TabPanel`](TabPanel) where each toggle button should be displayed,
|
||||||
toggle_button_panels: Edges<Option<EntityId>>,
|
toggle_button_panels: Edges<Option<EntityId>>,
|
||||||
@@ -144,13 +148,6 @@ pub enum DockItem {
|
|||||||
size: Option<Pixels>,
|
size: Option<Pixels>,
|
||||||
view: Arc<dyn PanelView>,
|
view: Arc<dyn PanelView>,
|
||||||
},
|
},
|
||||||
/// Tiles layout
|
|
||||||
Tiles {
|
|
||||||
/// Self size, only used for build split panels
|
|
||||||
size: Option<Pixels>,
|
|
||||||
items: Vec<TileItem>,
|
|
||||||
view: Entity<Tiles>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for DockItem {
|
impl std::fmt::Debug for DockItem {
|
||||||
@@ -172,7 +169,6 @@ impl std::fmt::Debug for DockItem {
|
|||||||
.field("active_ix", active_ix)
|
.field("active_ix", active_ix)
|
||||||
.finish(),
|
.finish(),
|
||||||
DockItem::Panel { .. } => f.debug_struct("Panel").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::Split { size, .. } => *size,
|
||||||
Self::Tabs { size, .. } => *size,
|
Self::Tabs { size, .. } => *size,
|
||||||
Self::Panel { size, .. } => *size,
|
Self::Panel { size, .. } => *size,
|
||||||
Self::Tiles { size, .. } => *size,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +189,6 @@ impl DockItem {
|
|||||||
match self {
|
match self {
|
||||||
Self::Split { ref mut size, .. } => *size = new_size,
|
Self::Split { ref mut size, .. } => *size = new_size,
|
||||||
Self::Tabs { 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::Panel { ref mut size, .. } => *size = new_size,
|
||||||
}
|
}
|
||||||
self
|
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<DockItem>,
|
|
||||||
metas: Vec<impl Into<TileMeta> + Copy>,
|
|
||||||
dock_area: &WeakEntity<DockArea>,
|
|
||||||
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.
|
/// 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.
|
/// 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 {
|
match self {
|
||||||
Self::Split { view, .. } => Arc::new(view.clone()),
|
Self::Split { view, .. } => Arc::new(view.clone()),
|
||||||
Self::Tabs { view, .. } => Arc::new(view.clone()),
|
Self::Tabs { view, .. } => Arc::new(view.clone()),
|
||||||
Self::Tiles { view, .. } => Arc::new(view.clone()),
|
|
||||||
Self::Panel { view, .. } => view.clone(),
|
Self::Panel { view, .. } => view.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -440,13 +379,6 @@ impl DockItem {
|
|||||||
if let Ok(tabs) = view.clone().downcast::<TabPanel>() {
|
if let Ok(tabs) = view.clone().downcast::<TabPanel>() {
|
||||||
return tabs.read(cx).panels.iter().all(|panel| is_empty(panel, cx));
|
return tabs.read(cx).panels.iter().all(|panel| is_empty(panel, cx));
|
||||||
}
|
}
|
||||||
if let Ok(tiles) = view.downcast::<Tiles>() {
|
|
||||||
return tiles
|
|
||||||
.read(cx)
|
|
||||||
.panels()
|
|
||||||
.iter()
|
|
||||||
.all(|item| is_empty(&item.panel, cx));
|
|
||||||
}
|
|
||||||
|
|
||||||
!panel.visible(cx)
|
!panel.visible(cx)
|
||||||
}
|
}
|
||||||
@@ -462,15 +394,6 @@ impl DockItem {
|
|||||||
}
|
}
|
||||||
Self::Tabs { items, .. } => items.iter().find(|item| *item == &panel).cloned(),
|
Self::Tabs { items, .. } => items.iter().find(|item| *item == &panel).cloned(),
|
||||||
Self::Panel { view, .. } => Some(view.clone()),
|
Self::Panel { view, .. } => Some(view.clone()),
|
||||||
Self::Tiles { items, .. } => items.iter().find_map(|item| {
|
|
||||||
// `==` on `Arc<dyn PanelView>` 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,
|
&mut self,
|
||||||
panel: Arc<dyn PanelView>,
|
panel: Arc<dyn PanelView>,
|
||||||
dock_area: &WeakEntity<DockArea>,
|
dock_area: &WeakEntity<DockArea>,
|
||||||
bounds: Option<Bounds<Pixels>>,
|
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) {
|
) {
|
||||||
@@ -508,21 +430,6 @@ impl DockItem {
|
|||||||
stack_panel.add_panel(new_item.view(), None, dock_area.clone(), window, cx);
|
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 { .. } => {}
|
Self::Panel { .. } => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -544,11 +451,6 @@ impl DockItem {
|
|||||||
split.remove_panel(panel, window, cx);
|
split.remove_panel(panel, window, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
DockItem::Tiles { view, .. } => {
|
|
||||||
view.update(cx, |tiles, cx| {
|
|
||||||
tiles.remove(panel, window, cx);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
DockItem::Panel { .. } => {}
|
DockItem::Panel { .. } => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -566,7 +468,6 @@ impl DockItem {
|
|||||||
item.set_collapsed(collapsed, window, cx);
|
item.set_collapsed(collapsed, window, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DockItem::Tiles { .. } => {}
|
|
||||||
DockItem::Panel { view, .. } => view.set_active(!collapsed, window, cx),
|
DockItem::Panel { view, .. } => view.set_active(!collapsed, window, cx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -576,17 +477,6 @@ impl DockItem {
|
|||||||
match self {
|
match self {
|
||||||
DockItem::Tabs { view, .. } => Some(view.clone()),
|
DockItem::Tabs { view, .. } => Some(view.clone()),
|
||||||
DockItem::Split { view, .. } => view.read(cx).left_top_tab_panel(true, cx),
|
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<Entity<TabPanel>> {
|
|
||||||
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,
|
DockItem::Panel { .. } => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -615,8 +505,6 @@ impl DockArea {
|
|||||||
bounds: Bounds::default(),
|
bounds: Bounds::default(),
|
||||||
center: dock_item,
|
center: dock_item,
|
||||||
left_dock: None,
|
left_dock: None,
|
||||||
right_dock: None,
|
|
||||||
bottom_dock: None,
|
|
||||||
zoom_view: None,
|
zoom_view: None,
|
||||||
toggle_button_panels: Edges::default(),
|
toggle_button_panels: Edges::default(),
|
||||||
toggle_button_visible: true,
|
toggle_button_visible: true,
|
||||||
@@ -635,22 +523,6 @@ impl DockArea {
|
|||||||
self.bounds
|
self.bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Subscribe to the tiles item drag item drop event
|
|
||||||
fn subscribe_tiles_item_drop(
|
|
||||||
&mut self,
|
|
||||||
tile_panel: &Entity<Tiles>,
|
|
||||||
_: &mut Window,
|
|
||||||
cx: &mut Context<Self>,
|
|
||||||
) {
|
|
||||||
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.
|
/// Set the panel style of the dock area.
|
||||||
pub fn panel_style(mut self, style: PanelStyle) -> Self {
|
pub fn panel_style(mut self, style: PanelStyle) -> Self {
|
||||||
self.panel_style = style;
|
self.panel_style = style;
|
||||||
@@ -681,31 +553,11 @@ impl DockArea {
|
|||||||
self.left_dock.as_ref()
|
self.left_dock.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the bottom dock item.
|
|
||||||
pub fn bottom_dock(&self) -> Option<&Entity<Dock>> {
|
|
||||||
self.bottom_dock.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the right dock item.
|
|
||||||
pub fn right_dock(&self) -> Option<&Entity<Dock>> {
|
|
||||||
self.right_dock.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Remove the left dock.
|
/// Remove the left dock.
|
||||||
pub fn remove_left_dock(&mut self, _: &mut Window, _: &mut Context<Self>) {
|
pub fn remove_left_dock(&mut self, _: &mut Window, _: &mut Context<Self>) {
|
||||||
self.left_dock = None;
|
self.left_dock = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove the bottom dock.
|
|
||||||
pub fn remove_bottom_dock(&mut self, _: &mut Window, _: &mut Context<Self>) {
|
|
||||||
self.bottom_dock = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Remove the right dock.
|
|
||||||
pub fn remove_right_dock(&mut self, _: &mut Window, _: &mut Context<Self>) {
|
|
||||||
self.right_dock = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The the DockItem as the center of the dock area.
|
/// The the DockItem as the center of the dock area.
|
||||||
///
|
///
|
||||||
/// This is used to render at the Center of the DockArea.
|
/// 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);
|
self.update_toggle_button_tab_panels(window, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_bottom_dock(
|
|
||||||
&mut self,
|
|
||||||
panel: DockItem,
|
|
||||||
size: Option<Pixels>,
|
|
||||||
open: bool,
|
|
||||||
window: &mut Window,
|
|
||||||
cx: &mut Context<Self>,
|
|
||||||
) {
|
|
||||||
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<Pixels>,
|
|
||||||
open: bool,
|
|
||||||
window: &mut Window,
|
|
||||||
cx: &mut Context<Self>,
|
|
||||||
) {
|
|
||||||
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.
|
/// 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) {
|
pub fn set_locked(&mut self, locked: bool, _window: &mut Window, _cx: &mut App) {
|
||||||
self.locked = locked;
|
self.locked = locked;
|
||||||
@@ -797,9 +605,7 @@ impl DockArea {
|
|||||||
pub fn has_dock(&self, placement: DockPlacement) -> bool {
|
pub fn has_dock(&self, placement: DockPlacement) -> bool {
|
||||||
match placement {
|
match placement {
|
||||||
DockPlacement::Left => self.left_dock.is_some(),
|
DockPlacement::Left => self.left_dock.is_some(),
|
||||||
DockPlacement::Bottom => self.bottom_dock.is_some(),
|
DockPlacement::Center | DockPlacement::Right | DockPlacement::Bottom => false,
|
||||||
DockPlacement::Right => self.right_dock.is_some(),
|
|
||||||
DockPlacement::Center => false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,23 +617,13 @@ impl DockArea {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|dock| dock.read(cx).is_open())
|
.map(|dock| dock.read(cx).is_open())
|
||||||
.unwrap_or(false),
|
.unwrap_or(false),
|
||||||
DockPlacement::Bottom => self
|
DockPlacement::Center | DockPlacement::Right | DockPlacement::Bottom => false,
|
||||||
.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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the dock at the given placement to be open or closed.
|
/// 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(
|
pub fn set_dock_collapsible(
|
||||||
&mut self,
|
&mut self,
|
||||||
collapsible_edges: Edges<bool>,
|
collapsible_edges: Edges<bool>,
|
||||||
@@ -839,18 +635,6 @@ impl DockArea {
|
|||||||
dock.set_collapsible(collapsible_edges.left, window, cx);
|
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.
|
/// Determine if the dock at the given placement is collapsible.
|
||||||
@@ -861,17 +645,7 @@ impl DockArea {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|dock| dock.read(cx).collapsible)
|
.map(|dock| dock.read(cx).collapsible)
|
||||||
.unwrap_or(false),
|
.unwrap_or(false),
|
||||||
DockPlacement::Bottom => self
|
DockPlacement::Center | DockPlacement::Right | DockPlacement::Bottom => false,
|
||||||
.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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -882,14 +656,9 @@ impl DockArea {
|
|||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
let dock = match placement {
|
if let DockPlacement::Left = placement
|
||||||
DockPlacement::Left => &self.left_dock,
|
&& let Some(dock) = self.left_dock.as_ref()
|
||||||
DockPlacement::Bottom => &self.bottom_dock,
|
{
|
||||||
DockPlacement::Right => &self.right_dock,
|
|
||||||
DockPlacement::Center => return,
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(dock) = dock {
|
|
||||||
dock.update(cx, |view, cx| {
|
dock.update(cx, |view, cx| {
|
||||||
view.toggle_open(window, cx);
|
view.toggle_open(window, cx);
|
||||||
})
|
})
|
||||||
@@ -902,11 +671,17 @@ impl DockArea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Add a panel item to the dock area at the given placement.
|
/// 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(
|
pub fn add_panel(
|
||||||
&mut self,
|
&mut self,
|
||||||
panel: Arc<dyn PanelView>,
|
panel: Arc<dyn PanelView>,
|
||||||
placement: DockPlacement,
|
placement: DockPlacement,
|
||||||
bounds: Option<Bounds<Pixels>>,
|
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
@@ -925,39 +700,69 @@ impl DockArea {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DockPlacement::Bottom => {
|
DockPlacement::Right | DockPlacement::Bottom => {
|
||||||
if let Some(dock) = self.bottom_dock.as_ref() {
|
self.add_panel_to_center_side(panel, placement, window, cx);
|
||||||
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::Center => {
|
DockPlacement::Center => {
|
||||||
self.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<dyn PanelView>,
|
||||||
|
placement: DockPlacement,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
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.
|
/// Remove panel from the DockArea at the given placement.
|
||||||
pub fn remove_panel(
|
pub fn remove_panel(
|
||||||
&mut self,
|
&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 => {
|
DockPlacement::Center => {
|
||||||
self.center.remove_panel(panel, window, cx);
|
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();
|
cx.notify();
|
||||||
}
|
}
|
||||||
@@ -1004,8 +799,6 @@ impl DockArea {
|
|||||||
) {
|
) {
|
||||||
self.remove_panel(panel.clone(), DockPlacement::Center, window, cx);
|
self.remove_panel(panel.clone(), DockPlacement::Center, window, cx);
|
||||||
self.remove_panel(panel.clone(), DockPlacement::Left, 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.
|
/// 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));
|
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.center = state.center.to_item(weak_self, window, cx);
|
||||||
self.update_toggle_button_tab_panels(window, cx);
|
self.update_toggle_button_tab_panels(window, cx);
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -1048,21 +833,11 @@ impl DockArea {
|
|||||||
.left_dock
|
.left_dock
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|dock| DockState::new(dock.clone(), cx));
|
.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 {
|
DockAreaState {
|
||||||
version: self.version,
|
version: self.version,
|
||||||
center,
|
center,
|
||||||
left_dock,
|
left_dock,
|
||||||
right_dock,
|
|
||||||
bottom_dock,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1094,9 +869,6 @@ impl DockArea {
|
|||||||
DockItem::Tabs { .. } => {
|
DockItem::Tabs { .. } => {
|
||||||
// We subscribe to the tab panel event in StackPanel's insert_panel
|
// 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 { .. } => {
|
DockItem::Panel { .. } => {
|
||||||
// Not supported
|
// Not supported
|
||||||
}
|
}
|
||||||
@@ -1171,30 +943,16 @@ impl DockArea {
|
|||||||
match &self.center {
|
match &self.center {
|
||||||
DockItem::Split { view, .. } => view.clone().into_any_element(),
|
DockItem::Split { view, .. } => view.clone().into_any_element(),
|
||||||
DockItem::Tabs { 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(),
|
DockItem::Panel { view, .. } => view.clone().view().into_any_element(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_toggle_button_tab_panels(&mut self, _: &mut Window, cx: &mut Context<Self>) {
|
pub fn update_toggle_button_tab_panels(&mut self, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
// Left toggle button
|
// The left dock's toggle button lives in the center's top-left tab panel.
|
||||||
self.toggle_button_panels.left = self
|
self.toggle_button_panels.left = self
|
||||||
.center
|
.center
|
||||||
.left_top_tab_panel(cx)
|
.left_top_tab_panel(cx)
|
||||||
.map(|view| view.entity_id());
|
.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<DockEvent> for DockArea {}
|
impl EventEmitter<DockEvent> for DockArea {}
|
||||||
@@ -1212,48 +970,24 @@ impl Render for DockArea {
|
|||||||
if let Some(zoom_view) = self.zoom_view.clone() {
|
if let Some(zoom_view) = self.zoom_view.clone() {
|
||||||
this.child(zoom_view)
|
this.child(zoom_view)
|
||||||
} else {
|
} else {
|
||||||
match &self.center {
|
// render dock
|
||||||
DockItem::Tiles { view, .. } => {
|
this.child(
|
||||||
// render tiles
|
div()
|
||||||
this.child(view.clone())
|
.flex()
|
||||||
}
|
.flex_row()
|
||||||
_ => {
|
.h_full()
|
||||||
// render dock
|
// Left dock
|
||||||
this.child(
|
.when_some(self.left_dock.clone(), |this, dock| {
|
||||||
|
this.child(div().flex().flex_none().child(dock))
|
||||||
|
})
|
||||||
|
// Center
|
||||||
|
.child(
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex_1()
|
||||||
.flex_row()
|
.overflow_hidden()
|
||||||
.h_full()
|
.child(self.render_items(window, cx)),
|
||||||
// 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))
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ use gpui::{
|
|||||||
Window,
|
Window,
|
||||||
};
|
};
|
||||||
use gpui_component::{
|
use gpui_component::{
|
||||||
ActiveTheme, AxisExt as _, Placement, ResizablePanelEvent, ResizablePanelGroup, ResizableState,
|
ActiveTheme, Placement, ResizablePanelEvent, ResizablePanelGroup, ResizableState, h_flex,
|
||||||
h_flex, resizable_panel,
|
resizable_panel,
|
||||||
};
|
};
|
||||||
use smallvec::SmallVec;
|
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<Entity<TabPanel>> {
|
|
||||||
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::<TabPanel>() {
|
|
||||||
Some(tab_panel)
|
|
||||||
} else if let Ok(stack_panel) = view.view().downcast::<StackPanel>() {
|
|
||||||
stack_panel.read(cx).right_top_tab_panel(false, cx)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Remove all panels from the stack.
|
/// Remove all panels from the stack.
|
||||||
pub(super) fn remove_all_panels(&mut self, _: &mut Window, cx: &mut Context<Self>) {
|
pub(super) fn remove_all_panels(&mut self, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
self.panels.clear();
|
self.panels.clear();
|
||||||
|
|||||||
@@ -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 itertools::Itertools as _;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@@ -15,10 +15,6 @@ pub struct DockAreaState {
|
|||||||
pub center: PanelState,
|
pub center: PanelState,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub left_dock: Option<DockState>,
|
pub left_dock: Option<DockState>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub right_dock: Option<DockState>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub bottom_dock: Option<DockState>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to serialize and deserialize the Dock
|
/// Used to serialize and deserialize the Dock
|
||||||
@@ -72,30 +68,6 @@ pub struct PanelState {
|
|||||||
pub info: PanelInfo,
|
pub info: PanelInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
|
|
||||||
pub struct TileMeta {
|
|
||||||
pub bounds: Bounds<Pixels>,
|
|
||||||
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<Bounds<Pixels>> for TileMeta {
|
|
||||||
fn from(bounds: Bounds<Pixels>) -> Self {
|
|
||||||
Self { bounds, z_index: 0 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum PanelInfo {
|
pub enum PanelInfo {
|
||||||
#[serde(rename = "stack")]
|
#[serde(rename = "stack")]
|
||||||
@@ -107,8 +79,6 @@ pub enum PanelInfo {
|
|||||||
Tabs { active_index: usize },
|
Tabs { active_index: usize },
|
||||||
#[serde(rename = "panel")]
|
#[serde(rename = "panel")]
|
||||||
Panel(serde_json::Value),
|
Panel(serde_json::Value),
|
||||||
#[serde(rename = "tiles")]
|
|
||||||
Tiles { metas: Vec<TileMeta> },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PanelInfo {
|
impl PanelInfo {
|
||||||
@@ -127,10 +97,6 @@ impl PanelInfo {
|
|||||||
Self::Panel(info)
|
Self::Panel(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tiles(metas: Vec<TileMeta>) -> Self {
|
|
||||||
Self::Tiles { metas }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn axis(&self) -> Option<Axis> {
|
pub fn axis(&self) -> Option<Axis> {
|
||||||
match self {
|
match self {
|
||||||
Self::Stack { axis, .. } => Some(if *axis == 0 {
|
Self::Stack { axis, .. } => Some(if *axis == 0 {
|
||||||
@@ -232,7 +198,6 @@ impl PanelState {
|
|||||||
);
|
);
|
||||||
DockItem::tabs(vec![view.into()], &dock_area, window, cx)
|
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.panel_name, "TabPanel");
|
||||||
assert_eq!(left_dock.panel.children.len(), 1);
|
assert_eq!(left_dock.panel.children.len(), 1);
|
||||||
assert_eq!(left_dock.panel.children[0].panel_name, "StoryContainer");
|
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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+99
-168
@@ -152,8 +152,6 @@ pub struct TabPanel {
|
|||||||
will_split_placement: Option<Placement>,
|
will_split_placement: Option<Placement>,
|
||||||
drop_placeholder_animation: Option<DropPlaceholderAnimation>,
|
drop_placeholder_animation: Option<DropPlaceholderAnimation>,
|
||||||
drop_placeholder_animation_name: SharedString,
|
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
|
/// Bounds of the title bar row (the wrapper around the tab bar), in
|
||||||
/// window coordinates. Measured via `on_prepaint` to position the
|
/// window coordinates. Measured via `on_prepaint` to position the
|
||||||
@@ -183,9 +181,8 @@ impl Panel for TabPanel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. When is the final panel in the dock, it will not able to close.
|
// The final panel in the dock is not closable.
|
||||||
// 2. When is in the Tiles, it will always able to close (by active panel state).
|
if !self.draggable(cx) {
|
||||||
if !self.draggable(cx) && !self.in_tiles {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,18 +311,12 @@ impl TabPanel {
|
|||||||
zoomed: false,
|
zoomed: false,
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
closable: true,
|
closable: true,
|
||||||
in_tiles: false,
|
|
||||||
title_bar_bounds: None,
|
title_bar_bounds: None,
|
||||||
title_bar_strip_bounds: None,
|
title_bar_strip_bounds: None,
|
||||||
title_bar_suffix_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<StackPanel>) {
|
pub(super) fn set_parent(&mut self, view: WeakEntity<StackPanel>) {
|
||||||
self.stack_panel = Some(view);
|
self.stack_panel = Some(view);
|
||||||
}
|
}
|
||||||
@@ -717,6 +708,11 @@ impl TabPanel {
|
|||||||
_: &mut Window,
|
_: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Option<Button> {
|
) -> Option<Button> {
|
||||||
|
// Only the left dock can be toggled.
|
||||||
|
if placement != DockPlacement::Left {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
if self.zoomed {
|
if self.zoomed {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -733,47 +729,15 @@ impl TabPanel {
|
|||||||
let toggle_button_panels = dock_area.toggle_button_panels;
|
let toggle_button_panels = dock_area.toggle_button_panels;
|
||||||
|
|
||||||
// Check if current TabPanel's entity_id matches the one stored in DockArea for this placement
|
// Check if current TabPanel's entity_id matches the one stored in DockArea for this placement
|
||||||
if !match placement {
|
if dock_area.left_dock.is_none() || toggle_button_panels.left != Some(view_entity_id) {
|
||||||
DockPlacement::Left => {
|
|
||||||
dock_area.left_dock.is_some() && toggle_button_panels.left == Some(view_entity_id)
|
|
||||||
}
|
|
||||||
DockPlacement::Right => {
|
|
||||||
dock_area.right_dock.is_some() && toggle_button_panels.right == Some(view_entity_id)
|
|
||||||
}
|
|
||||||
DockPlacement::Bottom => {
|
|
||||||
dock_area.bottom_dock.is_some()
|
|
||||||
&& toggle_button_panels.bottom == Some(view_entity_id)
|
|
||||||
}
|
|
||||||
DockPlacement::Center => unreachable!(),
|
|
||||||
} {
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_open = dock_area.is_dock_open(placement, cx);
|
let is_open = dock_area.is_dock_open(placement, cx);
|
||||||
|
let icon = if is_open {
|
||||||
let icon = match placement {
|
IconName::PanelLeft
|
||||||
DockPlacement::Left => {
|
} else {
|
||||||
if is_open {
|
IconName::PanelLeftOpen
|
||||||
IconName::PanelLeft
|
|
||||||
} else {
|
|
||||||
IconName::PanelLeftOpen
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DockPlacement::Right => {
|
|
||||||
if is_open {
|
|
||||||
IconName::PanelRight
|
|
||||||
} else {
|
|
||||||
IconName::PanelRightOpen
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DockPlacement::Bottom => {
|
|
||||||
if is_open {
|
|
||||||
IconName::PanelBottom
|
|
||||||
} else {
|
|
||||||
IconName::PanelBottomOpen
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DockPlacement::Center => unreachable!(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
@@ -810,11 +774,7 @@ impl TabPanel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let left_dock_button = self.render_dock_toggle_button(DockPlacement::Left, window, cx);
|
let left_dock_button = self.render_dock_toggle_button(DockPlacement::Left, window, cx);
|
||||||
let bottom_dock_button = self.render_dock_toggle_button(DockPlacement::Bottom, window, cx);
|
let has_extend_dock_button = left_dock_button.is_some();
|
||||||
let right_dock_button = self.render_dock_toggle_button(DockPlacement::Right, window, cx);
|
|
||||||
let has_extend_dock_button = left_dock_button.is_some() || bottom_dock_button.is_some();
|
|
||||||
|
|
||||||
let is_bottom_dock = bottom_dock_button.is_some();
|
|
||||||
|
|
||||||
// macOS: the traffic lights overlay the window's top-left corner. The
|
// macOS: the traffic lights overlay the window's top-left corner. The
|
||||||
// left dock (sidebar) normally clears them; when it is closed or
|
// left dock (sidebar) normally clears them; when it is closed or
|
||||||
@@ -849,7 +809,6 @@ impl TabPanel {
|
|||||||
.pr_2()
|
.pr_2()
|
||||||
.when(left_dock_button.is_some(), |this| this.pl_2())
|
.when(left_dock_button.is_some(), |this| this.pl_2())
|
||||||
.when(needs_traffic_light_padding, |this| this.pl(px(80.)))
|
.when(needs_traffic_light_padding, |this| this.pl(px(80.)))
|
||||||
.when(right_dock_button.is_some(), |this| this.pr_2())
|
|
||||||
.when_some(title_style, |this, theme| {
|
.when_some(title_style, |this, theme| {
|
||||||
this.bg(theme.background).text_color(theme.foreground)
|
this.bg(theme.background).text_color(theme.foreground)
|
||||||
})
|
})
|
||||||
@@ -859,8 +818,7 @@ impl TabPanel {
|
|||||||
.flex_shrink_0()
|
.flex_shrink_0()
|
||||||
.mr_1()
|
.mr_1()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.children(left_dock_button)
|
.children(left_dock_button),
|
||||||
.children(bottom_dock_button),
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
@@ -889,8 +847,7 @@ impl TabPanel {
|
|||||||
.flex_shrink_0()
|
.flex_shrink_0()
|
||||||
.ml_1()
|
.ml_1()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(self.render_toolbar(state, window, cx))
|
.child(self.render_toolbar(state, window, cx)),
|
||||||
.children(right_dock_button),
|
|
||||||
),
|
),
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
@@ -973,17 +930,13 @@ impl TabPanel {
|
|||||||
.top_0()
|
.top_0()
|
||||||
// Right -1 for avoid border overlap with the first tab
|
// Right -1 for avoid border overlap with the first tab
|
||||||
.right(-px(1.))
|
.right(-px(1.))
|
||||||
.border_r_1()
|
|
||||||
.border_b_1()
|
|
||||||
.h_full()
|
.h_full()
|
||||||
.border_color(cx.theme().border)
|
|
||||||
.bg(cx.theme().tokens.tab_bar)
|
.bg(cx.theme().tokens.tab_bar)
|
||||||
.px_2()
|
.px_2()
|
||||||
.when(needs_traffic_light_padding, |this| {
|
.when(needs_traffic_light_padding, |this| {
|
||||||
this.pl(px(80.))
|
this.pl(px(80.))
|
||||||
})
|
})
|
||||||
.children(left_dock_button)
|
.children(left_dock_button),
|
||||||
.children(bottom_dock_button),
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -1017,21 +970,8 @@ impl TabPanel {
|
|||||||
})
|
})
|
||||||
.selected(active)
|
.selected(active)
|
||||||
.on_click(cx.listener({
|
.on_click(cx.listener({
|
||||||
let is_collapsed = self.collapsed;
|
|
||||||
let dock_area = self.dock_area.clone();
|
|
||||||
move |view, _, window, cx| {
|
move |view, _, window, cx| {
|
||||||
view.set_active_ix(ix, window, cx);
|
view.set_active_ix(ix, window, cx);
|
||||||
|
|
||||||
// Open dock if clicked on the collapsed bottom dock
|
|
||||||
if is_bottom_dock && is_collapsed {
|
|
||||||
_ = dock_area.update(cx, |dock_area, cx| {
|
|
||||||
dock_area.toggle_dock(
|
|
||||||
DockPlacement::Bottom,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.when(!droppable, |this| {
|
.when(!droppable, |this| {
|
||||||
@@ -1060,23 +1000,18 @@ impl TabPanel {
|
|||||||
this.on_drop(drag, Some(ix), true, window, cx)
|
this.on_drop(drag, Some(ix), true, window, cx)
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
.when(
|
.drag_over::<AnyDrag>(|this, _, _, cx| {
|
||||||
!self.in_tiles,
|
this.rounded_l_none()
|
||||||
|this| {
|
.border_l_2()
|
||||||
this.drag_over::<AnyDrag>(|this, _, _, cx| {
|
.border_r_0()
|
||||||
this.rounded_l_none()
|
.border_color(cx.theme().drag_border)
|
||||||
.border_l_2()
|
})
|
||||||
.border_r_0()
|
.on_drop(cx.listener(
|
||||||
.border_color(cx.theme().drag_border)
|
|this, item: &AnyDrag, _, cx| {
|
||||||
})
|
this.will_split_placement = None;
|
||||||
.on_drop(cx.listener(
|
this.emit_drag_drop(item, None, cx);
|
||||||
|this, item: &AnyDrag, _, cx| {
|
|
||||||
this.will_split_placement = None;
|
|
||||||
this.emit_drag_drop(item, None, cx);
|
|
||||||
},
|
|
||||||
))
|
|
||||||
},
|
},
|
||||||
)
|
))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
@@ -1120,19 +1055,14 @@ impl TabPanel {
|
|||||||
this.on_drop(drag, ix, false, window, cx)
|
this.on_drop(drag, ix, false, window, cx)
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
.when(
|
.drag_over::<AnyDrag>(|this, _, _, cx| {
|
||||||
!self.in_tiles,
|
this.bg(cx.theme().tokens.drop_target)
|
||||||
|this| {
|
})
|
||||||
this.drag_over::<AnyDrag>(|this, _, _, cx| {
|
.on_drop(
|
||||||
this.bg(cx.theme().tokens.drop_target)
|
cx.listener(|this, item: &AnyDrag, _, cx| {
|
||||||
})
|
this.will_split_placement = None;
|
||||||
.on_drop(cx.listener(
|
this.emit_drag_drop(item, None, cx);
|
||||||
|this, item: &AnyDrag, _, cx| {
|
}),
|
||||||
this.will_split_placement = None;
|
|
||||||
this.emit_drag_drop(item, None, cx);
|
|
||||||
},
|
|
||||||
))
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -1142,10 +1072,7 @@ impl TabPanel {
|
|||||||
.items_center()
|
.items_center()
|
||||||
.top_0()
|
.top_0()
|
||||||
.right_0()
|
.right_0()
|
||||||
.border_l_1()
|
|
||||||
.border_b_1()
|
|
||||||
.h_full()
|
.h_full()
|
||||||
.border_color(cx.theme().border)
|
|
||||||
.bg(cx.theme().tokens.tab_bar)
|
.bg(cx.theme().tokens.tab_bar)
|
||||||
.px_2()
|
.px_2()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
@@ -1165,8 +1092,7 @@ impl TabPanel {
|
|||||||
self.active_panel(cx)
|
self.active_panel(cx)
|
||||||
.and_then(|panel| panel.title_suffix(window, cx)),
|
.and_then(|panel| panel.title_suffix(window, cx)),
|
||||||
)
|
)
|
||||||
.child(self.render_toolbar(state, window, cx))
|
.child(self.render_toolbar(state, window, cx)),
|
||||||
.when_some(right_dock_button, |this, btn| this.child(btn)),
|
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -1214,9 +1140,7 @@ impl TabPanel {
|
|||||||
)
|
)
|
||||||
.when(state.droppable, |this| {
|
.when(state.droppable, |this| {
|
||||||
this.on_drag_move(cx.listener(Self::on_panel_drag_move))
|
this.on_drag_move(cx.listener(Self::on_panel_drag_move))
|
||||||
.when(!self.in_tiles, |this| {
|
.on_drag_move(cx.listener(Self::on_item_drag_move))
|
||||||
this.on_drag_move(cx.listener(Self::on_item_drag_move))
|
|
||||||
})
|
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.invisible()
|
.invisible()
|
||||||
@@ -1233,13 +1157,11 @@ impl TabPanel {
|
|||||||
.on_drop(cx.listener(|this, drag: &DragPanel, window, cx| {
|
.on_drop(cx.listener(|this, drag: &DragPanel, window, cx| {
|
||||||
this.on_drop(drag, None, true, window, cx)
|
this.on_drop(drag, None, true, window, cx)
|
||||||
}))
|
}))
|
||||||
.when(!self.in_tiles, |this| {
|
.group_drag_over::<AnyDrag>("", |this| this.visible())
|
||||||
this.group_drag_over::<AnyDrag>("", |this| this.visible())
|
.on_drop(cx.listener(|this, item: &AnyDrag, _, cx| {
|
||||||
.on_drop(cx.listener(|this, item: &AnyDrag, _, cx| {
|
let placement = this.will_split_placement.take();
|
||||||
let placement = this.will_split_placement.take();
|
this.emit_drag_drop(item, placement, cx);
|
||||||
this.emit_drag_drop(item, placement, cx);
|
}))
|
||||||
}))
|
|
||||||
})
|
|
||||||
.when_some(placeholder, |this, animation| {
|
.when_some(placeholder, |this, animation| {
|
||||||
let from = animation.from.origin - animation.to.origin;
|
let from = animation.from.origin - animation.to.origin;
|
||||||
this.child(
|
this.child(
|
||||||
@@ -1601,9 +1523,8 @@ impl TabPanel {
|
|||||||
self.remove_panel(panel, window, cx);
|
self.remove_panel(panel, window, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove self from the parent DockArea.
|
// Remove self from the parent DockArea when the last panel is closed.
|
||||||
// This is ensure to remove from Tiles
|
if self.panels.is_empty() {
|
||||||
if self.panels.is_empty() && self.in_tiles {
|
|
||||||
let tab_panel = Arc::new(cx.entity());
|
let tab_panel = Arc::new(cx.entity());
|
||||||
window.defer(cx, {
|
window.defer(cx, {
|
||||||
let dock_area = self.dock_area.clone();
|
let dock_area = self.dock_area.clone();
|
||||||
@@ -1681,12 +1602,12 @@ mod tests {
|
|||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
use gpui::{TestAppContext, VisualTestContext, WindowHandle, WindowOptions, size};
|
use gpui::{Axis, TestAppContext, VisualTestContext, WindowHandle, WindowOptions, size};
|
||||||
use gpui_component::tab::{Tab, TabBar};
|
use gpui_component::tab::{Tab, TabBar};
|
||||||
use gpui_component::{Root, Theme, v_flex};
|
use gpui_component::{Root, Theme, v_flex};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{DockItem, TileMeta};
|
use crate::DockItem;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn drop_placeholder_bounds_cover_each_target_placement() {
|
fn drop_placeholder_bounds_cover_each_target_placement() {
|
||||||
@@ -2018,49 +1939,6 @@ mod tests {
|
|||||||
assert!(cx.read(|cx| fixture.dock_area.read(cx).is_center_empty(cx)));
|
assert!(cx.read(|cx| fixture.dock_area.read(cx).is_center_empty(cx)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A `TabPanel` inside `Tiles` has no parent `StackPanel` to remove itself
|
|
||||||
/// from, so emptying it leaves the tile behind and the walk has to recurse.
|
|
||||||
#[gpui::test]
|
|
||||||
fn center_holding_only_empty_tiles_is_empty(cx: &mut TestAppContext) {
|
|
||||||
let fixture = setup(cx);
|
|
||||||
let mut cx = VisualTestContext::from_window(fixture.window.into(), cx);
|
|
||||||
|
|
||||||
let (tabs, tab_panel, panels) = build_tabs(&fixture, &["A"], None, &mut cx);
|
|
||||||
let weak_dock_area = fixture.dock_area.downgrade();
|
|
||||||
cx.update(|window, cx| {
|
|
||||||
let tiles = DockItem::tiles(
|
|
||||||
vec![tabs],
|
|
||||||
vec![TileMeta::default()],
|
|
||||||
&weak_dock_area,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
fixture
|
|
||||||
.dock_area
|
|
||||||
.update(cx, |area, cx| area.set_center(tiles, window, cx))
|
|
||||||
});
|
|
||||||
cx.run_until_parked();
|
|
||||||
assert!(!cx.read(|cx| fixture.dock_area.read(cx).is_center_empty(cx)));
|
|
||||||
|
|
||||||
for panel in panels {
|
|
||||||
cx.update(|window, cx| {
|
|
||||||
tab_panel.update(cx, |tab_panel, cx| {
|
|
||||||
tab_panel.remove_panel(Arc::new(panel.clone()), window, cx)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
cx.run_until_parked();
|
|
||||||
|
|
||||||
let tiles = cx.read(|cx| {
|
|
||||||
let DockItem::Tiles { view, .. } = fixture.dock_area.read(cx).center() else {
|
|
||||||
unreachable!("the centre is a Tiles item");
|
|
||||||
};
|
|
||||||
view.read(cx).panels().len()
|
|
||||||
});
|
|
||||||
assert_eq!(tiles, 1, "the emptied TabPanel is still listed as a tile");
|
|
||||||
assert!(cx.read(|cx| fixture.dock_area.read(cx).is_center_empty(cx)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
fn single_panel_group_receives_initial_active(cx: &mut TestAppContext) {
|
fn single_panel_group_receives_initial_active(cx: &mut TestAppContext) {
|
||||||
let fixture = setup(cx);
|
let fixture = setup(cx);
|
||||||
@@ -2287,6 +2165,59 @@ mod tests {
|
|||||||
assert_eq!(drain(&fixture.log), [("A", false)]);
|
assert_eq!(drain(&fixture.log), [("A", false)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adding a panel to the right of the center splits it horizontally;
|
||||||
|
/// a later bottom add wraps the split in a vertical one.
|
||||||
|
#[gpui::test]
|
||||||
|
fn add_panel_splits_the_center(cx: &mut TestAppContext) {
|
||||||
|
let fixture = setup(cx);
|
||||||
|
let mut cx = VisualTestContext::from_window(fixture.window.into(), cx);
|
||||||
|
|
||||||
|
let (item_a, _, _) = build_tabs(&fixture, &["A"], None, &mut cx);
|
||||||
|
let (_item_b, _, panels_b) = build_tabs(&fixture, &["B"], None, &mut cx);
|
||||||
|
let (_item_c, _, panels_c) = build_tabs(&fixture, &["C"], None, &mut cx);
|
||||||
|
|
||||||
|
cx.update(|window, cx| {
|
||||||
|
fixture.dock_area.update(cx, |dock_area, cx| {
|
||||||
|
dock_area.set_center(item_a, window, cx);
|
||||||
|
dock_area.add_panel(
|
||||||
|
Arc::new(panels_b[0].clone()),
|
||||||
|
DockPlacement::Right,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
let (axis, len) = cx.read(|cx| match fixture.dock_area.read(cx).center() {
|
||||||
|
DockItem::Split { axis, items, .. } => (*axis, items.len()),
|
||||||
|
other => panic!("center must be a horizontal split, got {other:?}"),
|
||||||
|
});
|
||||||
|
assert_eq!(axis, Axis::Horizontal);
|
||||||
|
assert_eq!(len, 2, "the right panel must be appended to the split");
|
||||||
|
|
||||||
|
cx.update(|window, cx| {
|
||||||
|
fixture.dock_area.update(cx, |dock_area, cx| {
|
||||||
|
dock_area.add_panel(
|
||||||
|
Arc::new(panels_c[0].clone()),
|
||||||
|
DockPlacement::Bottom,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.read(|cx| match fixture.dock_area.read(cx).center() {
|
||||||
|
DockItem::Split {
|
||||||
|
axis, items, sizes, ..
|
||||||
|
} => {
|
||||||
|
assert_eq!(*axis, Axis::Vertical);
|
||||||
|
assert_eq!(items.len(), 2);
|
||||||
|
assert_eq!(sizes.len(), 2);
|
||||||
|
}
|
||||||
|
other => panic!("center must be wrapped in a vertical split, got {other:?}"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct ProbeFlags {
|
struct ProbeFlags {
|
||||||
empty_down: AtomicBool,
|
empty_down: AtomicBool,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -133,8 +133,6 @@ impl RenderOnce for ControlIcon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render the window control buttons, or an empty placeholder on macOS (the
|
|
||||||
/// traffic lights are drawn natively).
|
|
||||||
pub(crate) fn window_controls(window: &mut Window, cx: &mut App) -> impl IntoElement {
|
pub(crate) fn window_controls(window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||||
if cfg!(target_os = "macos") || cfg!(target_family = "wasm") {
|
if cfg!(target_os = "macos") || cfg!(target_family = "wasm") {
|
||||||
return div().id("window-controls");
|
return div().id("window-controls");
|
||||||
|
|||||||
@@ -651,7 +651,7 @@ impl RepoDetailView {
|
|||||||
cx.new(|cx| CommitDiffView::new(worktree, repo_name, commit_id.into(), window, cx));
|
cx.new(|cx| CommitDiffView::new(worktree, repo_name, commit_id.into(), window, cx));
|
||||||
|
|
||||||
dock_area.update(cx, |dock_area, cx| {
|
dock_area.update(cx, |dock_area, cx| {
|
||||||
dock_area.add_panel(Arc::new(panel), DockPlacement::Center, None, window, cx);
|
dock_area.add_panel(Arc::new(panel), DockPlacement::Center, window, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -665,7 +665,7 @@ impl RepoDetailView {
|
|||||||
cx.new(|cx| IssuesView::new(self.store.clone(), self.display_name(cx), window, cx));
|
cx.new(|cx| IssuesView::new(self.store.clone(), self.display_name(cx), window, cx));
|
||||||
|
|
||||||
dock_area.update(cx, |dock_area, cx| {
|
dock_area.update(cx, |dock_area, cx| {
|
||||||
dock_area.add_panel(Arc::new(panel), DockPlacement::Center, None, window, cx);
|
dock_area.add_panel(Arc::new(panel), DockPlacement::Center, window, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,7 +679,7 @@ impl RepoDetailView {
|
|||||||
.new(|cx| PullRequestsView::new(self.store.clone(), self.display_name(cx), window, cx));
|
.new(|cx| PullRequestsView::new(self.store.clone(), self.display_name(cx), window, cx));
|
||||||
|
|
||||||
dock_area.update(cx, |dock_area, cx| {
|
dock_area.update(cx, |dock_area, cx| {
|
||||||
dock_area.add_panel(Arc::new(panel), DockPlacement::Center, None, window, cx);
|
dock_area.add_panel(Arc::new(panel), DockPlacement::Center, window, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ impl RepoListView {
|
|||||||
|
|
||||||
if let Some(dock_area) = dock_area.upgrade() {
|
if let Some(dock_area) = dock_area.upgrade() {
|
||||||
dock_area.update(cx, |dock_area, cx| {
|
dock_area.update(cx, |dock_area, cx| {
|
||||||
dock_area.add_panel(Arc::new(detail), DockPlacement::Center, None, window, cx);
|
dock_area.add_panel(Arc::new(detail), DockPlacement::Center, window, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ impl SidebarPanel {
|
|||||||
self.explore = Some(panel.downgrade());
|
self.explore = Some(panel.downgrade());
|
||||||
|
|
||||||
let _ = self.dock_area.update(cx, |dock_area, cx| {
|
let _ = self.dock_area.update(cx, |dock_area, cx| {
|
||||||
dock_area.add_panel(Arc::new(panel), DockPlacement::Center, None, window, cx);
|
dock_area.add_panel(Arc::new(panel), DockPlacement::Center, window, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user