dock: Implement core panel addition logic for tiling layout (#644)

This commit is contained in:
ihavecoke 2025-02-20 21:20:59 +08:00 committed by GitHub
parent 06f9178ec4
commit 03d5f83a83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 5 deletions

View file

@ -446,7 +446,7 @@ impl StoryWorkspace {
};
self.dock_area.update(cx, |dock_area, cx| {
dock_area.add_panel(panel, action.0, window, cx);
dock_area.add_panel(panel, action.0, None, window, cx);
});
}

View file

@ -271,7 +271,8 @@ impl Dock {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.panel.add_panel(panel, &self.dock_area, window, cx);
self.panel
.add_panel(panel, &self.dock_area, None, window, cx);
cx.notify();
}

View file

@ -314,6 +314,7 @@ impl DockItem {
&mut self,
panel: Arc<dyn PanelView>,
dock_area: &WeakEntity<DockArea>,
bounds: Option<Bounds<Pixels>>,
window: &mut Window,
cx: &mut App,
) {
@ -342,7 +343,13 @@ impl DockItem {
stack_panel.add_panel(new_item.view(), None, dock_area.clone(), window, cx);
});
}
Self::Tiles { .. } => {}
Self::Tiles { view, .. } => {
view.update(cx, |tiles, cx| {
let bounds = bounds.unwrap_or_else(|| TileMeta::default().bounds);
tiles.add_item(TileItem::new(panel.clone(), bounds), dock_area, window, cx);
cx.notify();
});
}
Self::Panel { .. } => {}
}
}
@ -422,6 +429,11 @@ impl DockArea {
this
}
/// Return the bounds of the dock area.
pub fn bounds(&self) -> Bounds<Pixels> {
self.bounds
}
/// Subscribe to the tiles item drag item drop event
fn subscribe_tiles_item_drop(
&mut self,
@ -649,6 +661,7 @@ impl DockArea {
&mut self,
panel: Arc<dyn PanelView>,
placement: DockPlacement,
bounds: Option<Bounds<Pixels>>,
window: &mut Window,
cx: &mut Context<Self>,
) {
@ -695,7 +708,7 @@ impl DockArea {
}
DockPlacement::Center => {
self.items
.add_panel(panel, &cx.entity().downgrade(), window, cx);
.add_panel(panel, &cx.entity().downgrade(), bounds, window, cx);
}
}
}

View file

@ -62,7 +62,7 @@ pub use styled::*;
pub use time::*;
pub use title_bar::*;
pub use virtual_list::{h_virtual_list, v_virtual_list, VirtualList};
pub use window_border::{window_border, WindowBorder};
pub use window_border::{window_border, window_paddings, WindowBorder};
pub use colors::*;
pub use icon::*;