Start work on dragging tabs
This commit is contained in:
parent
5f5b86ee24
commit
a4a501603e
3 changed files with 48 additions and 51 deletions
|
@ -29,7 +29,7 @@ pub struct GroupStyle {
|
||||||
pub style: Box<StyleRefinement>,
|
pub style: Box<StyleRefinement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait InteractiveElement: Sized + Element {
|
pub trait InteractiveElement: Sized {
|
||||||
fn interactivity(&mut self) -> &mut Interactivity;
|
fn interactivity(&mut self) -> &mut Interactivity;
|
||||||
|
|
||||||
fn group(mut self, group: impl Into<SharedString>) -> Self {
|
fn group(mut self, group: impl Into<SharedString>) -> Self {
|
||||||
|
@ -436,7 +436,6 @@ pub trait StatefulInteractiveElement: InteractiveElement {
|
||||||
"calling tooltip more than once on the same element is not supported"
|
"calling tooltip more than once on the same element is not supported"
|
||||||
);
|
);
|
||||||
self.interactivity().tooltip_builder = Some(Rc::new(build_tooltip));
|
self.interactivity().tooltip_builder = Some(Rc::new(build_tooltip));
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
use std::cmp::Ordering;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use gpui::{AnyElement, AnyView, ClickEvent, IntoElement, MouseButton};
|
|
||||||
use smallvec::SmallVec;
|
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
use gpui::{AnyElement, IntoElement, Stateful};
|
||||||
|
use smallvec::SmallVec;
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
/// The position of a [`Tab`] within a list of tabs.
|
/// The position of a [`Tab`] within a list of tabs.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
|
@ -29,12 +26,10 @@ pub enum TabCloseSide {
|
||||||
|
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct Tab {
|
pub struct Tab {
|
||||||
id: ElementId,
|
div: Stateful<Div>,
|
||||||
selected: bool,
|
selected: bool,
|
||||||
position: TabPosition,
|
position: TabPosition,
|
||||||
close_side: TabCloseSide,
|
close_side: TabCloseSide,
|
||||||
on_click: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
|
||||||
tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView + 'static>>,
|
|
||||||
start_slot: Option<AnyElement>,
|
start_slot: Option<AnyElement>,
|
||||||
end_slot: Option<AnyElement>,
|
end_slot: Option<AnyElement>,
|
||||||
children: SmallVec<[AnyElement; 2]>,
|
children: SmallVec<[AnyElement; 2]>,
|
||||||
|
@ -43,12 +38,10 @@ pub struct Tab {
|
||||||
impl Tab {
|
impl Tab {
|
||||||
pub fn new(id: impl Into<ElementId>) -> Self {
|
pub fn new(id: impl Into<ElementId>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: id.into(),
|
div: div().id(id),
|
||||||
selected: false,
|
selected: false,
|
||||||
position: TabPosition::First,
|
position: TabPosition::First,
|
||||||
close_side: TabCloseSide::End,
|
close_side: TabCloseSide::End,
|
||||||
on_click: None,
|
|
||||||
tooltip: None,
|
|
||||||
start_slot: None,
|
start_slot: None,
|
||||||
end_slot: None,
|
end_slot: None,
|
||||||
children: SmallVec::new(),
|
children: SmallVec::new(),
|
||||||
|
@ -65,16 +58,6 @@ impl Tab {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_click(mut self, handler: impl Fn(&ClickEvent, &mut WindowContext) + 'static) -> Self {
|
|
||||||
self.on_click = Some(Rc::new(handler));
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn tooltip(mut self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self {
|
|
||||||
self.tooltip = Some(Box::new(tooltip));
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn start_slot<E: IntoElement>(mut self, element: impl Into<Option<E>>) -> Self {
|
pub fn start_slot<E: IntoElement>(mut self, element: impl Into<Option<E>>) -> Self {
|
||||||
self.start_slot = element.into().map(IntoElement::into_any_element);
|
self.start_slot = element.into().map(IntoElement::into_any_element);
|
||||||
self
|
self
|
||||||
|
@ -86,6 +69,14 @@ impl Tab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl InteractiveElement for Tab {
|
||||||
|
fn interactivity(&mut self) -> &mut gpui::Interactivity {
|
||||||
|
self.div.interactivity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StatefulInteractiveElement for Tab {}
|
||||||
|
|
||||||
impl Selectable for Tab {
|
impl Selectable for Tab {
|
||||||
fn selected(mut self, selected: bool) -> Self {
|
fn selected(mut self, selected: bool) -> Self {
|
||||||
self.selected = selected;
|
self.selected = selected;
|
||||||
|
@ -100,7 +91,7 @@ impl ParentElement for Tab {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderOnce for Tab {
|
impl RenderOnce for Tab {
|
||||||
type Rendered = Div;
|
type Rendered = Stateful<Div>;
|
||||||
|
|
||||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||||
const HEIGHT_IN_REMS: f32 = 30. / 16.;
|
const HEIGHT_IN_REMS: f32 = 30. / 16.;
|
||||||
|
@ -120,7 +111,7 @@ impl RenderOnce for Tab {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
div()
|
self.div
|
||||||
.h(rems(HEIGHT_IN_REMS))
|
.h(rems(HEIGHT_IN_REMS))
|
||||||
.bg(tab_bg)
|
.bg(tab_bg)
|
||||||
.border_color(cx.theme().colors().border)
|
.border_color(cx.theme().colors().border)
|
||||||
|
@ -146,7 +137,6 @@ impl RenderOnce for Tab {
|
||||||
.child(
|
.child(
|
||||||
h_stack()
|
h_stack()
|
||||||
.group("")
|
.group("")
|
||||||
.id(self.id)
|
|
||||||
.relative()
|
.relative()
|
||||||
.h_full()
|
.h_full()
|
||||||
.px_5()
|
.px_5()
|
||||||
|
@ -154,18 +144,6 @@ impl RenderOnce for Tab {
|
||||||
.text_color(text_color)
|
.text_color(text_color)
|
||||||
// .hover(|style| style.bg(tab_hover_bg))
|
// .hover(|style| style.bg(tab_hover_bg))
|
||||||
// .active(|style| style.bg(tab_active_bg))
|
// .active(|style| style.bg(tab_active_bg))
|
||||||
.when_some(self.on_click, |tab, on_click| {
|
|
||||||
tab.cursor_pointer().on_click(move |event, cx| {
|
|
||||||
// HACK: GPUI currently fires `on_click` with any mouse button,
|
|
||||||
// but we only care about the left button.
|
|
||||||
if event.down.button == MouseButton::Left {
|
|
||||||
(on_click)(event, cx)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.when_some(self.tooltip, |tab, tooltip| {
|
|
||||||
tab.tooltip(move |cx| tooltip(cx))
|
|
||||||
})
|
|
||||||
.child(
|
.child(
|
||||||
h_stack()
|
h_stack()
|
||||||
.w_3()
|
.w_3()
|
||||||
|
|
|
@ -7,10 +7,10 @@ use crate::{
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use collections::{HashMap, HashSet, VecDeque};
|
use collections::{HashMap, HashSet, VecDeque};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, impl_actions, overlay, prelude::*, Action, AnchorCorner, AnyWeakView, AppContext,
|
actions, impl_actions, overlay, prelude::*, Action, AnchorCorner, AnyDrag, AnyWeakView,
|
||||||
AsyncWindowContext, DismissEvent, Div, EntityId, EventEmitter, FocusHandle, Focusable,
|
AppContext, AsyncWindowContext, DismissEvent, Div, EntityId, EventEmitter, FocusHandle,
|
||||||
FocusableView, Model, MouseButton, NavigationDirection, Pixels, Point, PromptLevel, Render,
|
Focusable, FocusableView, Model, MouseButton, NavigationDirection, Pixels, Point, PromptLevel,
|
||||||
Subscription, Task, View, ViewContext, VisualContext, WeakView, WindowContext,
|
Render, Subscription, Task, View, ViewContext, VisualContext, WeakView, WindowContext,
|
||||||
};
|
};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use project::{Project, ProjectEntryId, ProjectPath};
|
use project::{Project, ProjectEntryId, ProjectPath};
|
||||||
|
@ -25,6 +25,7 @@ use std::{
|
||||||
Arc,
|
Arc,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use theme::ThemeSettings;
|
||||||
|
|
||||||
use ui::{
|
use ui::{
|
||||||
h_stack, prelude::*, right_click_menu, ButtonSize, Color, Icon, IconButton, IconSize,
|
h_stack, prelude::*, right_click_menu, ButtonSize, Color, Icon, IconButton, IconSize,
|
||||||
|
@ -231,6 +232,13 @@ pub struct NavigationEntry {
|
||||||
pub timestamp: usize,
|
pub timestamp: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct DraggedTab {
|
||||||
|
pub pane: View<Pane>,
|
||||||
|
pub ix: usize,
|
||||||
|
pub detail: usize,
|
||||||
|
pub is_active: bool,
|
||||||
|
}
|
||||||
|
|
||||||
// pub struct DraggedItem {
|
// pub struct DraggedItem {
|
||||||
// pub handle: Box<dyn ItemHandle>,
|
// pub handle: Box<dyn ItemHandle>,
|
||||||
// pub pane: WeakView<Pane>,
|
// pub pane: WeakView<Pane>,
|
||||||
|
@ -1501,7 +1509,17 @@ impl Pane {
|
||||||
.on_click(cx.listener(move |pane: &mut Self, event, cx| {
|
.on_click(cx.listener(move |pane: &mut Self, event, cx| {
|
||||||
pane.activate_item(ix, true, true, cx)
|
pane.activate_item(ix, true, true, cx)
|
||||||
}))
|
}))
|
||||||
// .on_drag(move |pane, cx| pane.render_tab(ix, item.boxed_clone(), detail, cx))
|
.on_drag({
|
||||||
|
let pane = cx.view().clone();
|
||||||
|
move |cx| {
|
||||||
|
cx.build_view(|cx| DraggedTab {
|
||||||
|
pane: pane.clone(),
|
||||||
|
detail,
|
||||||
|
is_active,
|
||||||
|
ix,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
// .drag_over::<DraggedTab>(|d| d.bg(cx.theme().colors().element_drop_target))
|
// .drag_over::<DraggedTab>(|d| d.bg(cx.theme().colors().element_drop_target))
|
||||||
// .on_drop(|_view, state: View<DraggedTab>, cx| {
|
// .on_drop(|_view, state: View<DraggedTab>, cx| {
|
||||||
// eprintln!("{:?}", state.read(cx));
|
// eprintln!("{:?}", state.read(cx));
|
||||||
|
@ -3131,15 +3149,17 @@ fn dirty_message_for(buffer_path: Option<ProjectPath>) -> String {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
struct DraggedTab {
|
|
||||||
title: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Render for DraggedTab {
|
impl Render for DraggedTab {
|
||||||
type Element = Div;
|
type Element = <Tab as RenderOnce>::Rendered;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
div().w_8().h_4().bg(gpui::red())
|
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
|
||||||
|
let item = &self.pane.read(cx).items[self.ix];
|
||||||
|
let label = item.tab_content(Some(self.detail), false, cx);
|
||||||
|
Tab::new("")
|
||||||
|
.selected(self.is_active)
|
||||||
|
.child(label)
|
||||||
|
.render(cx)
|
||||||
|
.font(ui_font)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue