Take a target view when marking an element as draggable
This commit is contained in:
parent
b0cbd13e7a
commit
5b40641fde
12 changed files with 86 additions and 36 deletions
|
@ -54,12 +54,12 @@ pub trait Item: View {
|
|||
fn tab_description<'a>(&'a self, _: usize, _: &'a AppContext) -> Option<Cow<str>> {
|
||||
None
|
||||
}
|
||||
fn tab_content(
|
||||
fn tab_content<V: View>(
|
||||
&self,
|
||||
detail: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
cx: &AppContext,
|
||||
) -> Element<Pane>;
|
||||
) -> Element<V>;
|
||||
fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project::Item)) {}
|
||||
fn is_singleton(&self, _cx: &AppContext) -> bool {
|
||||
false
|
||||
|
@ -181,6 +181,12 @@ pub trait ItemHandle: 'static + fmt::Debug {
|
|||
style: &theme::Tab,
|
||||
cx: &AppContext,
|
||||
) -> Element<Pane>;
|
||||
fn dragged_tab_content(
|
||||
&self,
|
||||
detail: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
cx: &AppContext,
|
||||
) -> Element<Workspace>;
|
||||
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
|
||||
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>;
|
||||
fn project_item_model_ids(&self, cx: &AppContext) -> SmallVec<[usize; 3]>;
|
||||
|
@ -281,6 +287,15 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
|||
self.read(cx).tab_content(detail, style, cx)
|
||||
}
|
||||
|
||||
fn dragged_tab_content(
|
||||
&self,
|
||||
detail: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
cx: &AppContext,
|
||||
) -> Element<Workspace> {
|
||||
self.read(cx).tab_content(detail, style, cx)
|
||||
}
|
||||
|
||||
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath> {
|
||||
let this = self.read(cx);
|
||||
let mut result = None;
|
||||
|
@ -927,12 +942,12 @@ pub(crate) mod test {
|
|||
})
|
||||
}
|
||||
|
||||
fn tab_content(
|
||||
fn tab_content<V: View>(
|
||||
&self,
|
||||
detail: Option<usize>,
|
||||
_: &theme::Tab,
|
||||
_: &AppContext,
|
||||
) -> Element<Pane> {
|
||||
) -> Element<V> {
|
||||
self.tab_detail.set(detail);
|
||||
Empty::new().boxed()
|
||||
}
|
||||
|
|
|
@ -1401,7 +1401,7 @@ impl Pane {
|
|||
enum Tab {}
|
||||
let mouse_event_handler =
|
||||
MouseEventHandler::<Tab, Pane>::new(ix, cx, |_, cx| {
|
||||
Self::render_tab::<Pane>(
|
||||
Self::render_tab(
|
||||
&item,
|
||||
pane.clone(),
|
||||
ix == 0,
|
||||
|
@ -1466,9 +1466,9 @@ impl Pane {
|
|||
let theme = cx.global::<Settings>().theme.clone();
|
||||
|
||||
let detail = detail.clone();
|
||||
move |dragged_item: &DraggedItem, cx: &mut ViewContext<Pane>| {
|
||||
move |dragged_item: &DraggedItem, cx: &mut ViewContext<Workspace>| {
|
||||
let tab_style = &theme.workspace.tab_bar.dragged_tab;
|
||||
Self::render_tab::<Pane>(
|
||||
Self::render_dragged_tab(
|
||||
&dragged_item.item,
|
||||
dragged_item.pane.clone(),
|
||||
false,
|
||||
|
@ -1541,7 +1541,7 @@ impl Pane {
|
|||
tab_details
|
||||
}
|
||||
|
||||
fn render_tab<V: View>(
|
||||
fn render_tab(
|
||||
item: &Box<dyn ItemHandle>,
|
||||
pane: WeakViewHandle<Pane>,
|
||||
first: bool,
|
||||
|
@ -1551,6 +1551,31 @@ impl Pane {
|
|||
cx: &mut ViewContext<Self>,
|
||||
) -> Element<Self> {
|
||||
let title = item.tab_content(detail, &tab_style, cx);
|
||||
Self::render_tab_with_title(title, item, pane, first, hovered, tab_style, cx)
|
||||
}
|
||||
|
||||
fn render_dragged_tab(
|
||||
item: &Box<dyn ItemHandle>,
|
||||
pane: WeakViewHandle<Pane>,
|
||||
first: bool,
|
||||
detail: Option<usize>,
|
||||
hovered: bool,
|
||||
tab_style: &theme::Tab,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) -> Element<Workspace> {
|
||||
let title = item.dragged_tab_content(detail, &tab_style, cx);
|
||||
Self::render_tab_with_title(title, item, pane, first, hovered, tab_style, cx)
|
||||
}
|
||||
|
||||
fn render_tab_with_title<T: View>(
|
||||
title: Element<T>,
|
||||
item: &Box<dyn ItemHandle>,
|
||||
pane: WeakViewHandle<Pane>,
|
||||
first: bool,
|
||||
hovered: bool,
|
||||
tab_style: &theme::Tab,
|
||||
cx: &mut ViewContext<T>,
|
||||
) -> Element<T> {
|
||||
let mut container = tab_style.container.clone();
|
||||
if first {
|
||||
container.border.left = false;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
item::{Item, ItemEvent},
|
||||
ItemNavHistory, Pane, WorkspaceId,
|
||||
ItemNavHistory, WorkspaceId,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use call::participant::{Frame, RemoteVideoTrack};
|
||||
|
@ -106,12 +106,12 @@ impl Item for SharedScreen {
|
|||
}
|
||||
}
|
||||
|
||||
fn tab_content(
|
||||
fn tab_content<V: View>(
|
||||
&self,
|
||||
_: Option<usize>,
|
||||
style: &theme::Tab,
|
||||
_: &AppContext,
|
||||
) -> gpui::Element<Pane> {
|
||||
) -> gpui::Element<V> {
|
||||
Flex::row()
|
||||
.with_child(
|
||||
Svg::new("icons/disable_screen_sharing_12.svg")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue