Rename Drawable::boxed to into_element and make containers generic
Multi-element are now generic over any drawable child, which can be converted into an element. Co-Authored-By: Nathan Sobo <nathan@zed.dev> Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
4d433663bd
commit
03619dfa55
80 changed files with 1132 additions and 1434 deletions
|
@ -5,7 +5,7 @@ use serde::Deserialize;
|
|||
use collections::HashMap;
|
||||
use gpui::{
|
||||
actions,
|
||||
elements::{ChildView, Container, Empty, MouseEventHandler, ParentElement, Side, Stack},
|
||||
elements::{ChildView, Empty, MouseEventHandler, ParentElement, Side, Stack},
|
||||
geometry::vector::Vector2F,
|
||||
impl_internal_actions,
|
||||
platform::{CursorStyle, MouseButton},
|
||||
|
@ -348,7 +348,8 @@ impl Dock {
|
|||
|
||||
enum DockResizeHandle {}
|
||||
|
||||
let resizable = Container::new(ChildView::new(&self.pane, cx).boxed())
|
||||
let resizable = ChildView::new(&self.pane, cx)
|
||||
.contained()
|
||||
.with_style(panel_style)
|
||||
.with_resize_handle::<DockResizeHandle>(
|
||||
resize_side as usize,
|
||||
|
@ -367,26 +368,21 @@ impl Dock {
|
|||
});
|
||||
|
||||
if anchor == DockAnchor::Right {
|
||||
resizable
|
||||
.constrained()
|
||||
.dynamically(|constraint, _, cx| {
|
||||
SizeConstraint::new(
|
||||
Vector2F::new(20., constraint.min.y()),
|
||||
Vector2F::new(cx.window_size().x() * 0.8, constraint.max.y()),
|
||||
)
|
||||
})
|
||||
.boxed()
|
||||
resizable.constrained().dynamically(|constraint, _, cx| {
|
||||
SizeConstraint::new(
|
||||
Vector2F::new(20., constraint.min.y()),
|
||||
Vector2F::new(cx.window_size().x() * 0.8, constraint.max.y()),
|
||||
)
|
||||
})
|
||||
} else {
|
||||
resizable
|
||||
.constrained()
|
||||
.dynamically(|constraint, _, cx| {
|
||||
SizeConstraint::new(
|
||||
Vector2F::new(constraint.min.x(), 50.),
|
||||
Vector2F::new(constraint.max.x(), cx.window_size().y() * 0.8),
|
||||
)
|
||||
})
|
||||
.boxed()
|
||||
resizable.constrained().dynamically(|constraint, _, cx| {
|
||||
SizeConstraint::new(
|
||||
Vector2F::new(constraint.min.x(), 50.),
|
||||
Vector2F::new(constraint.max.x(), cx.window_size().y() * 0.8),
|
||||
)
|
||||
})
|
||||
}
|
||||
.into_element()
|
||||
}
|
||||
DockAnchor::Expanded => {
|
||||
enum ExpandedDockWash {}
|
||||
|
@ -398,27 +394,24 @@ impl Dock {
|
|||
Empty::new()
|
||||
.contained()
|
||||
.with_background_color(style.wash_color)
|
||||
.boxed()
|
||||
})
|
||||
.capture_all()
|
||||
.on_down(MouseButton::Left, |_, _, cx| {
|
||||
cx.dispatch_action(HideDock);
|
||||
})
|
||||
.with_cursor_style(CursorStyle::Arrow)
|
||||
.boxed(),
|
||||
.with_cursor_style(CursorStyle::Arrow),
|
||||
)
|
||||
.with_child(
|
||||
MouseEventHandler::<ExpandedDockPane, _>::new(0, cx, |_state, cx| {
|
||||
ChildView::new(&self.pane, cx).boxed()
|
||||
ChildView::new(&self.pane, cx)
|
||||
})
|
||||
// Make sure all events directly under the dock pane
|
||||
// are captured
|
||||
.capture_all()
|
||||
.contained()
|
||||
.with_style(style.maximized)
|
||||
.boxed(),
|
||||
.with_style(style.maximized),
|
||||
)
|
||||
.boxed()
|
||||
.into_element()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ impl View for ToggleDockButton {
|
|||
let workspace = self.workspace.upgrade(cx);
|
||||
|
||||
if workspace.is_none() {
|
||||
return Empty::new().boxed();
|
||||
return Empty::new().into_element();
|
||||
}
|
||||
|
||||
let workspace = workspace.unwrap();
|
||||
|
@ -64,7 +64,6 @@ impl View for ToggleDockButton {
|
|||
.with_height(style.icon_size)
|
||||
.contained()
|
||||
.with_style(style.container)
|
||||
.boxed()
|
||||
}
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
|
@ -98,7 +97,7 @@ impl View for ToggleDockButton {
|
|||
cx,
|
||||
)
|
||||
}
|
||||
.boxed()
|
||||
.into_element()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -930,7 +930,7 @@ pub(crate) mod test {
|
|||
}
|
||||
|
||||
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
|
||||
Empty::new().boxed()
|
||||
Empty::new().into_element()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -949,7 +949,7 @@ pub(crate) mod test {
|
|||
_: &AppContext,
|
||||
) -> Element<V> {
|
||||
self.tab_detail.set(detail);
|
||||
Empty::new().boxed()
|
||||
Empty::new().into_element()
|
||||
}
|
||||
|
||||
fn for_each_project_item(
|
||||
|
|
|
@ -255,8 +255,7 @@ pub mod simple_message_notification {
|
|||
.aligned()
|
||||
.top()
|
||||
.left()
|
||||
.flex(1., true)
|
||||
.boxed(),
|
||||
.flex(1., true),
|
||||
)
|
||||
.with_child(
|
||||
MouseEventHandler::<Cancel, _>::new(0, cx, |state, _| {
|
||||
|
@ -271,7 +270,6 @@ pub mod simple_message_notification {
|
|||
.constrained()
|
||||
.with_width(style.button_width)
|
||||
.with_height(style.button_width)
|
||||
.boxed()
|
||||
})
|
||||
.with_padding(Padding::uniform(5.))
|
||||
.on_click(MouseButton::Left, move |_, _, cx| {
|
||||
|
@ -285,23 +283,18 @@ pub mod simple_message_notification {
|
|||
)
|
||||
.aligned()
|
||||
.top()
|
||||
.flex_float()
|
||||
.boxed(),
|
||||
)
|
||||
.boxed(),
|
||||
.flex_float(),
|
||||
),
|
||||
)
|
||||
.with_children({
|
||||
let style = theme.action_message.style_for(state, false);
|
||||
if let Some(click_message) = click_message {
|
||||
Some(
|
||||
Flex::row()
|
||||
.with_child(
|
||||
Text::new(click_message, style.text.clone())
|
||||
.contained()
|
||||
.with_style(style.container)
|
||||
.boxed(),
|
||||
)
|
||||
.boxed(),
|
||||
Flex::row().with_child(
|
||||
Text::new(click_message, style.text.clone())
|
||||
.contained()
|
||||
.with_style(style.container),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
|
@ -309,7 +302,6 @@ pub mod simple_message_notification {
|
|||
.into_iter()
|
||||
})
|
||||
.contained()
|
||||
.boxed()
|
||||
})
|
||||
// Since we're not using a proper overlay, we have to capture these extra events
|
||||
.on_down(MouseButton::Left, |_, _, _| {})
|
||||
|
@ -325,7 +317,7 @@ pub mod simple_message_notification {
|
|||
} else {
|
||||
CursorStyle::Arrow
|
||||
})
|
||||
.boxed()
|
||||
.into_element()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1383,7 +1383,7 @@ impl Pane {
|
|||
row.add_child({
|
||||
enum TabDragReceiver {}
|
||||
let mut receiver =
|
||||
dragged_item_receiver::<TabDragReceiver, _>(ix, ix, true, None, cx, {
|
||||
dragged_item_receiver::<TabDragReceiver, _, _>(ix, ix, true, None, cx, {
|
||||
let item = item.clone();
|
||||
let pane = pane.clone();
|
||||
let detail = detail.clone();
|
||||
|
@ -1437,7 +1437,7 @@ impl Pane {
|
|||
);
|
||||
|
||||
if let Some(tab_tooltip_text) = tab_tooltip_text {
|
||||
return mouse_event_handler
|
||||
mouse_event_handler
|
||||
.with_tooltip::<Self>(
|
||||
ix,
|
||||
tab_tooltip_text,
|
||||
|
@ -1445,10 +1445,10 @@ impl Pane {
|
|||
tooltip_theme,
|
||||
cx,
|
||||
)
|
||||
.boxed();
|
||||
.into_element()
|
||||
} else {
|
||||
mouse_event_handler.into_element()
|
||||
}
|
||||
|
||||
mouse_event_handler.boxed()
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1456,31 +1456,29 @@ impl Pane {
|
|||
receiver = receiver.with_cursor_style(CursorStyle::PointingHand);
|
||||
}
|
||||
|
||||
receiver
|
||||
.as_draggable(
|
||||
DraggedItem {
|
||||
item,
|
||||
pane: pane.clone(),
|
||||
},
|
||||
{
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
receiver.as_draggable(
|
||||
DraggedItem {
|
||||
item,
|
||||
pane: pane.clone(),
|
||||
},
|
||||
{
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
|
||||
let detail = detail.clone();
|
||||
move |dragged_item: &DraggedItem, cx: &mut ViewContext<Workspace>| {
|
||||
let tab_style = &theme.workspace.tab_bar.dragged_tab;
|
||||
Self::render_dragged_tab(
|
||||
&dragged_item.item,
|
||||
dragged_item.pane.clone(),
|
||||
false,
|
||||
detail,
|
||||
false,
|
||||
&tab_style,
|
||||
cx,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
.boxed()
|
||||
let detail = detail.clone();
|
||||
move |dragged_item: &DraggedItem, cx: &mut ViewContext<Workspace>| {
|
||||
let tab_style = &theme.workspace.tab_bar.dragged_tab;
|
||||
Self::render_dragged_tab(
|
||||
&dragged_item.item,
|
||||
dragged_item.pane.clone(),
|
||||
false,
|
||||
detail,
|
||||
false,
|
||||
&tab_style,
|
||||
cx,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1490,15 +1488,14 @@ impl Pane {
|
|||
let filler_style = theme.workspace.tab_bar.tab_style(pane_active, false);
|
||||
enum Filler {}
|
||||
row.add_child(
|
||||
dragged_item_receiver::<Filler, _>(0, filler_index, true, None, cx, |_, _| {
|
||||
dragged_item_receiver::<Filler, _, _>(0, filler_index, true, None, cx, |_, _| {
|
||||
Empty::new()
|
||||
.contained()
|
||||
.with_style(filler_style.container)
|
||||
.with_border(filler_style.container.border)
|
||||
.boxed()
|
||||
})
|
||||
.flex(1., true)
|
||||
.named("filler"),
|
||||
.into_named_element("filler"),
|
||||
);
|
||||
|
||||
row
|
||||
|
@ -1582,91 +1579,76 @@ impl Pane {
|
|||
}
|
||||
|
||||
Flex::row()
|
||||
.with_child(
|
||||
Align::new({
|
||||
let diameter = 7.0;
|
||||
let icon_color = if item.has_conflict(cx) {
|
||||
Some(tab_style.icon_conflict)
|
||||
} else if item.is_dirty(cx) {
|
||||
Some(tab_style.icon_dirty)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
.with_child({
|
||||
let diameter = 7.0;
|
||||
let icon_color = if item.has_conflict(cx) {
|
||||
Some(tab_style.icon_conflict)
|
||||
} else if item.is_dirty(cx) {
|
||||
Some(tab_style.icon_dirty)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
ConstrainedBox::new(
|
||||
Canvas::new(move |scene, bounds, _, _, _| {
|
||||
if let Some(color) = icon_color {
|
||||
let square = RectF::new(bounds.origin(), vec2f(diameter, diameter));
|
||||
scene.push_quad(Quad {
|
||||
bounds: square,
|
||||
background: Some(color),
|
||||
border: Default::default(),
|
||||
corner_radius: diameter / 2.,
|
||||
});
|
||||
}
|
||||
})
|
||||
.boxed(),
|
||||
)
|
||||
.with_width(diameter)
|
||||
.with_height(diameter)
|
||||
.boxed()
|
||||
Canvas::new(move |scene, bounds, _, _, _| {
|
||||
if let Some(color) = icon_color {
|
||||
let square = RectF::new(bounds.origin(), vec2f(diameter, diameter));
|
||||
scene.push_quad(Quad {
|
||||
bounds: square,
|
||||
background: Some(color),
|
||||
border: Default::default(),
|
||||
corner_radius: diameter / 2.,
|
||||
});
|
||||
}
|
||||
})
|
||||
.boxed(),
|
||||
)
|
||||
.constrained()
|
||||
.with_width(diameter)
|
||||
.with_height(diameter)
|
||||
.aligned()
|
||||
})
|
||||
.with_child(title.aligned().contained().with_style(ContainerStyle {
|
||||
margin: Margin {
|
||||
left: tab_style.spacing,
|
||||
right: tab_style.spacing,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}))
|
||||
.with_child(
|
||||
Container::new(Align::new(title).boxed())
|
||||
.with_style(ContainerStyle {
|
||||
margin: Margin {
|
||||
left: tab_style.spacing,
|
||||
right: tab_style.spacing,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
if hovered {
|
||||
let item_id = item.id();
|
||||
enum TabCloseButton {}
|
||||
let icon = Svg::new("icons/x_mark_8.svg");
|
||||
MouseEventHandler::<TabCloseButton, _>::new(item_id, cx, |mouse_state, _| {
|
||||
if mouse_state.hovered() {
|
||||
icon.with_color(tab_style.icon_close_active)
|
||||
} else {
|
||||
icon.with_color(tab_style.icon_close)
|
||||
}
|
||||
})
|
||||
.boxed(),
|
||||
)
|
||||
.with_child(
|
||||
Align::new(
|
||||
ConstrainedBox::new(if hovered {
|
||||
let item_id = item.id();
|
||||
enum TabCloseButton {}
|
||||
let icon = Svg::new("icons/x_mark_8.svg");
|
||||
MouseEventHandler::<TabCloseButton, _>::new(
|
||||
item_id,
|
||||
cx,
|
||||
|mouse_state, _| {
|
||||
if mouse_state.hovered() {
|
||||
icon.with_color(tab_style.icon_close_active).boxed()
|
||||
} else {
|
||||
icon.with_color(tab_style.icon_close).boxed()
|
||||
}
|
||||
},
|
||||
)
|
||||
.with_padding(Padding::uniform(4.))
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, {
|
||||
let pane = pane.clone();
|
||||
move |_, _, cx| {
|
||||
cx.dispatch_action(CloseItemById {
|
||||
item_id,
|
||||
pane: pane.clone(),
|
||||
})
|
||||
}
|
||||
})
|
||||
.named("close-tab-icon")
|
||||
} else {
|
||||
Empty::new().boxed()
|
||||
.with_padding(Padding::uniform(4.))
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, {
|
||||
let pane = pane.clone();
|
||||
move |_, _, cx| {
|
||||
cx.dispatch_action(CloseItemById {
|
||||
item_id,
|
||||
pane: pane.clone(),
|
||||
})
|
||||
}
|
||||
})
|
||||
.with_width(tab_style.close_icon_width)
|
||||
.boxed(),
|
||||
)
|
||||
.boxed(),
|
||||
.into_named_element("close-tab-icon")
|
||||
.constrained()
|
||||
} else {
|
||||
Empty::new().constrained()
|
||||
}
|
||||
.with_width(tab_style.close_icon_width)
|
||||
.aligned(),
|
||||
)
|
||||
.contained()
|
||||
.with_style(container)
|
||||
.constrained()
|
||||
.with_height(tab_style.height)
|
||||
.boxed()
|
||||
.into_element()
|
||||
}
|
||||
|
||||
fn render_tab_bar_buttons(
|
||||
|
@ -1719,7 +1701,7 @@ impl Pane {
|
|||
.contained()
|
||||
.with_style(theme.workspace.tab_bar.pane_button_container)
|
||||
.flex(1., false)
|
||||
.boxed()
|
||||
.into_element()
|
||||
}
|
||||
|
||||
fn render_blank_pane(&mut self, theme: &Theme, _cx: &mut ViewContext<Self>) -> Element<Self> {
|
||||
|
@ -1727,7 +1709,7 @@ impl Pane {
|
|||
Empty::new()
|
||||
.contained()
|
||||
.with_background_color(background)
|
||||
.boxed()
|
||||
.into_element()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1743,113 +1725,106 @@ impl View for Pane {
|
|||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
|
||||
enum MouseNavigationHandler {}
|
||||
|
||||
Stack::new()
|
||||
.with_child(
|
||||
MouseEventHandler::<MouseNavigationHandler, _>::new(0, cx, |_, cx| {
|
||||
let active_item_index = self.active_item_index;
|
||||
MouseEventHandler::<MouseNavigationHandler, _>::new(0, cx, |_, cx| {
|
||||
let active_item_index = self.active_item_index;
|
||||
|
||||
if let Some(active_item) = self.active_item() {
|
||||
Flex::column()
|
||||
.with_child({
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
|
||||
let mut stack = Stack::new();
|
||||
|
||||
enum TabBarEventHandler {}
|
||||
stack.add_child(
|
||||
MouseEventHandler::<TabBarEventHandler, _>::new(
|
||||
0,
|
||||
cx,
|
||||
|_, _| {
|
||||
Empty::new()
|
||||
.contained()
|
||||
.with_style(theme.workspace.tab_bar.container)
|
||||
.boxed()
|
||||
},
|
||||
)
|
||||
.on_down(MouseButton::Left, move |_, _, cx| {
|
||||
cx.dispatch_action(ActivateItem(active_item_index));
|
||||
})
|
||||
.boxed(),
|
||||
);
|
||||
|
||||
let mut tab_row = Flex::row()
|
||||
.with_child(self.render_tabs(cx).flex(1., true).named("tabs"));
|
||||
|
||||
if self.is_active {
|
||||
tab_row.add_child(self.render_tab_bar_buttons(&theme, cx))
|
||||
}
|
||||
|
||||
stack.add_child(tab_row.boxed());
|
||||
stack
|
||||
.constrained()
|
||||
.with_height(theme.workspace.tab_bar.height)
|
||||
.flex(1., false)
|
||||
.named("tab bar")
|
||||
})
|
||||
.with_child({
|
||||
enum PaneContentTabDropTarget {}
|
||||
dragged_item_receiver::<PaneContentTabDropTarget, _>(
|
||||
0,
|
||||
self.active_item_index + 1,
|
||||
false,
|
||||
if self.docked.is_some() {
|
||||
None
|
||||
} else {
|
||||
Some(100.)
|
||||
},
|
||||
cx,
|
||||
{
|
||||
let toolbar = self.toolbar.clone();
|
||||
let toolbar_hidden = toolbar.read(cx).hidden();
|
||||
move |_, cx| {
|
||||
Flex::column()
|
||||
.with_children((!toolbar_hidden).then(|| {
|
||||
ChildView::new(&toolbar, cx).expanded().boxed()
|
||||
}))
|
||||
.with_child(
|
||||
ChildView::new(active_item.as_any(), cx)
|
||||
.flex(1., true)
|
||||
.boxed(),
|
||||
)
|
||||
.boxed()
|
||||
}
|
||||
},
|
||||
)
|
||||
.flex(1., true)
|
||||
.boxed()
|
||||
})
|
||||
.with_child(ChildView::new(&self.tab_context_menu, cx).boxed())
|
||||
.boxed()
|
||||
} else {
|
||||
enum EmptyPane {}
|
||||
if let Some(active_item) = self.active_item() {
|
||||
Flex::column()
|
||||
.with_child({
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
|
||||
dragged_item_receiver::<EmptyPane, _>(0, 0, false, None, cx, |_, cx| {
|
||||
self.render_blank_pane(&theme, cx)
|
||||
})
|
||||
.on_down(MouseButton::Left, |_, _, cx| {
|
||||
cx.focus_parent_view();
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
let mut stack = Stack::new();
|
||||
|
||||
enum TabBarEventHandler {}
|
||||
stack.add_child(
|
||||
MouseEventHandler::<TabBarEventHandler, _>::new(0, cx, |_, _| {
|
||||
Empty::new()
|
||||
.contained()
|
||||
.with_style(theme.workspace.tab_bar.container)
|
||||
})
|
||||
.on_down(
|
||||
MouseButton::Left,
|
||||
move |_, _, cx| {
|
||||
cx.dispatch_action(ActivateItem(active_item_index));
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
let mut tab_row = Flex::row().with_child(
|
||||
self.render_tabs(cx)
|
||||
.flex(1., true)
|
||||
.into_named_element("tabs"),
|
||||
);
|
||||
|
||||
if self.is_active {
|
||||
tab_row.add_child(self.render_tab_bar_buttons(&theme, cx))
|
||||
}
|
||||
|
||||
stack.add_child(tab_row);
|
||||
stack
|
||||
.constrained()
|
||||
.with_height(theme.workspace.tab_bar.height)
|
||||
.flex(1., false)
|
||||
.into_named_element("tab bar")
|
||||
})
|
||||
.with_child({
|
||||
enum PaneContentTabDropTarget {}
|
||||
dragged_item_receiver::<PaneContentTabDropTarget, _, _>(
|
||||
0,
|
||||
self.active_item_index + 1,
|
||||
false,
|
||||
if self.docked.is_some() {
|
||||
None
|
||||
} else {
|
||||
Some(100.)
|
||||
},
|
||||
cx,
|
||||
{
|
||||
let toolbar = self.toolbar.clone();
|
||||
let toolbar_hidden = toolbar.read(cx).hidden();
|
||||
move |_, cx| {
|
||||
Flex::column()
|
||||
.with_children(
|
||||
(!toolbar_hidden)
|
||||
.then(|| ChildView::new(&toolbar, cx).expanded()),
|
||||
)
|
||||
.with_child(
|
||||
ChildView::new(active_item.as_any(), cx).flex(1., true),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
.flex(1., true)
|
||||
})
|
||||
.with_child(ChildView::new(&self.tab_context_menu, cx))
|
||||
.into_element()
|
||||
} else {
|
||||
enum EmptyPane {}
|
||||
let theme = cx.global::<Settings>().theme.clone();
|
||||
|
||||
dragged_item_receiver::<EmptyPane, _, _>(0, 0, false, None, cx, |_, cx| {
|
||||
self.render_blank_pane(&theme, cx)
|
||||
})
|
||||
.on_down(
|
||||
MouseButton::Navigate(NavigationDirection::Back),
|
||||
move |_, _, cx| {
|
||||
let pane = cx.weak_handle();
|
||||
cx.dispatch_action(GoBack { pane: Some(pane) });
|
||||
},
|
||||
)
|
||||
.on_down(MouseButton::Navigate(NavigationDirection::Forward), {
|
||||
move |_, _, cx| {
|
||||
let pane = cx.weak_handle();
|
||||
cx.dispatch_action(GoForward { pane: Some(pane) })
|
||||
}
|
||||
.on_down(MouseButton::Left, |_, _, cx| {
|
||||
cx.focus_parent_view();
|
||||
})
|
||||
.boxed(),
|
||||
)
|
||||
.named("pane")
|
||||
.into_element()
|
||||
}
|
||||
})
|
||||
.on_down(
|
||||
MouseButton::Navigate(NavigationDirection::Back),
|
||||
move |_, _, cx| {
|
||||
let pane = cx.weak_handle();
|
||||
cx.dispatch_action(GoBack { pane: Some(pane) });
|
||||
},
|
||||
)
|
||||
.on_down(MouseButton::Navigate(NavigationDirection::Forward), {
|
||||
move |_, _, cx| {
|
||||
let pane = cx.weak_handle();
|
||||
cx.dispatch_action(GoForward { pane: Some(pane) })
|
||||
}
|
||||
})
|
||||
.into_named_element("pane")
|
||||
}
|
||||
|
||||
fn focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||
|
@ -1917,19 +1892,17 @@ fn render_tab_bar_button<A: Action + Clone>(
|
|||
.constrained()
|
||||
.with_width(style.button_width)
|
||||
.with_height(style.button_width)
|
||||
.boxed()
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, move |_, _, cx| {
|
||||
cx.dispatch_action(action.clone());
|
||||
})
|
||||
.boxed(),
|
||||
}),
|
||||
)
|
||||
.with_children(
|
||||
context_menu.map(|menu| ChildView::new(&menu, cx).aligned().bottom().right().boxed()),
|
||||
context_menu.map(|menu| ChildView::new(&menu, cx).aligned().bottom().right()),
|
||||
)
|
||||
.flex(1., false)
|
||||
.boxed()
|
||||
.into_named_element("tab bar button")
|
||||
}
|
||||
|
||||
impl ItemNavHistory {
|
||||
|
|
|
@ -5,8 +5,7 @@ use gpui::{
|
|||
geometry::{rect::RectF, vector::Vector2F},
|
||||
platform::MouseButton,
|
||||
scene::MouseUp,
|
||||
AppContext, Drawable, Element, EventContext, MouseState, Quad, View, ViewContext,
|
||||
WeakViewHandle,
|
||||
AppContext, Drawable, EventContext, MouseState, Quad, View, ViewContext, WeakViewHandle,
|
||||
};
|
||||
use project::ProjectEntryId;
|
||||
use settings::Settings;
|
||||
|
@ -18,7 +17,7 @@ use crate::{
|
|||
|
||||
use super::DraggedItem;
|
||||
|
||||
pub fn dragged_item_receiver<Tag, F>(
|
||||
pub fn dragged_item_receiver<Tag, D, F>(
|
||||
region_id: usize,
|
||||
drop_index: usize,
|
||||
allow_same_pane: bool,
|
||||
|
@ -28,7 +27,8 @@ pub fn dragged_item_receiver<Tag, F>(
|
|||
) -> MouseEventHandler<Tag, Pane>
|
||||
where
|
||||
Tag: 'static,
|
||||
F: FnOnce(&mut MouseState, &mut ViewContext<Pane>) -> Element<Pane>,
|
||||
D: Drawable<Pane>,
|
||||
F: FnOnce(&mut MouseState, &mut ViewContext<Pane>) -> D,
|
||||
{
|
||||
MouseEventHandler::<Tag, _>::above(region_id, cx, |state, cx| {
|
||||
// Observing hovered will cause a render when the mouse enters regardless
|
||||
|
@ -69,9 +69,7 @@ where
|
|||
});
|
||||
}
|
||||
})
|
||||
.boxed()
|
||||
}))
|
||||
.boxed()
|
||||
})
|
||||
.on_up(MouseButton::Left, {
|
||||
move |event, _, cx| {
|
||||
|
|
|
@ -165,7 +165,7 @@ impl Member {
|
|||
Border::default()
|
||||
};
|
||||
|
||||
let prompt = if let Some((_, leader)) = leader {
|
||||
let leader_status_box = if let Some((_, leader)) = leader {
|
||||
match leader.location {
|
||||
ParticipantLocation::SharedProject {
|
||||
project_id: leader_project_id,
|
||||
|
@ -195,7 +195,6 @@ impl Member {
|
|||
.with_style(
|
||||
theme.workspace.external_location_message.container,
|
||||
)
|
||||
.boxed()
|
||||
},
|
||||
)
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
|
@ -208,7 +207,7 @@ impl Member {
|
|||
.aligned()
|
||||
.bottom()
|
||||
.right()
|
||||
.boxed(),
|
||||
.into_element(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -225,7 +224,7 @@ impl Member {
|
|||
.aligned()
|
||||
.bottom()
|
||||
.right()
|
||||
.boxed(),
|
||||
.into_element(),
|
||||
),
|
||||
ParticipantLocation::External => Some(
|
||||
Label::new(
|
||||
|
@ -240,7 +239,7 @@ impl Member {
|
|||
.aligned()
|
||||
.bottom()
|
||||
.right()
|
||||
.boxed(),
|
||||
.into_element(),
|
||||
),
|
||||
}
|
||||
} else {
|
||||
|
@ -248,14 +247,9 @@ impl Member {
|
|||
};
|
||||
|
||||
Stack::new()
|
||||
.with_child(
|
||||
ChildView::new(pane, cx)
|
||||
.contained()
|
||||
.with_border(border)
|
||||
.boxed(),
|
||||
)
|
||||
.with_children(prompt)
|
||||
.boxed()
|
||||
.with_child(ChildView::new(pane, cx).contained().with_border(border))
|
||||
.with_children(leader_status_box)
|
||||
.into_element()
|
||||
}
|
||||
Member::Axis(axis) => axis.render(
|
||||
project,
|
||||
|
@ -388,12 +382,12 @@ impl PaneAxis {
|
|||
Axis::Vertical => border.bottom = true,
|
||||
Axis::Horizontal => border.right = true,
|
||||
}
|
||||
member = Container::new(member).with_border(border).boxed();
|
||||
member = member.contained().with_border(border).into_element();
|
||||
}
|
||||
|
||||
FlexItem::new(member).flex(flex, true).boxed()
|
||||
FlexItem::new(member).flex(flex, true)
|
||||
}))
|
||||
.boxed()
|
||||
.into_element()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -89,10 +89,9 @@ impl View for SharedScreen {
|
|||
})
|
||||
.contained()
|
||||
.with_style(cx.global::<Settings>().theme.shared_screen)
|
||||
.boxed()
|
||||
})
|
||||
.on_down(MouseButton::Left, |_, _, cx| cx.focus_parent_view())
|
||||
.boxed()
|
||||
.into_element()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,18 +119,16 @@ impl Item for SharedScreen {
|
|||
.with_width(style.type_icon_width)
|
||||
.aligned()
|
||||
.contained()
|
||||
.with_margin_right(style.spacing)
|
||||
.boxed(),
|
||||
.with_margin_right(style.spacing),
|
||||
)
|
||||
.with_child(
|
||||
Label::new(
|
||||
format!("{}'s screen", self.user.github_login),
|
||||
style.label.clone(),
|
||||
)
|
||||
.aligned()
|
||||
.boxed(),
|
||||
.aligned(),
|
||||
)
|
||||
.boxed()
|
||||
.into_element()
|
||||
}
|
||||
|
||||
fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) {
|
||||
|
|
|
@ -202,9 +202,9 @@ impl View for Sidebar {
|
|||
style.initial_size,
|
||||
cx,
|
||||
)
|
||||
.boxed()
|
||||
.into_element()
|
||||
} else {
|
||||
Empty::new().boxed()
|
||||
Empty::new().into_element()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ impl View for SidebarButtons {
|
|||
let is_active = is_open && ix == active_ix;
|
||||
let style = item_style.style_for(state, is_active);
|
||||
Stack::new()
|
||||
.with_child(Svg::new(icon_path).with_color(style.icon_color).boxed())
|
||||
.with_child(Svg::new(icon_path).with_color(style.icon_color))
|
||||
.with_children(if !is_active && item_view.should_show_badge(cx) {
|
||||
Some(
|
||||
Empty::new()
|
||||
|
@ -267,8 +267,7 @@ impl View for SidebarButtons {
|
|||
.with_style(badge_style)
|
||||
.aligned()
|
||||
.bottom()
|
||||
.right()
|
||||
.boxed(),
|
||||
.right(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
|
@ -278,7 +277,6 @@ impl View for SidebarButtons {
|
|||
.with_height(style.icon_size)
|
||||
.contained()
|
||||
.with_style(style.container)
|
||||
.boxed()
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, {
|
||||
|
@ -292,12 +290,11 @@ impl View for SidebarButtons {
|
|||
tooltip_style.clone(),
|
||||
cx,
|
||||
)
|
||||
.boxed()
|
||||
},
|
||||
))
|
||||
.contained()
|
||||
.with_style(group_style)
|
||||
.boxed()
|
||||
.into_element()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,9 +56,8 @@ impl View for StatusBar {
|
|||
.aligned()
|
||||
.contained()
|
||||
.with_margin_right(theme.item_spacing)
|
||||
.boxed()
|
||||
}))
|
||||
.boxed(),
|
||||
.into_element(),
|
||||
|
||||
right: Flex::row()
|
||||
.with_children(self.right_items.iter().rev().map(|i| {
|
||||
|
@ -66,15 +65,14 @@ impl View for StatusBar {
|
|||
.aligned()
|
||||
.contained()
|
||||
.with_margin_left(theme.item_spacing)
|
||||
.boxed()
|
||||
}))
|
||||
.boxed(),
|
||||
.into_element(),
|
||||
}
|
||||
.contained()
|
||||
.with_style(theme.container)
|
||||
.constrained()
|
||||
.with_height(theme.height)
|
||||
.boxed()
|
||||
.into_element()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,9 +77,9 @@ impl View for Toolbar {
|
|||
.contained()
|
||||
.with_margin_right(spacing);
|
||||
if let Some((flex, expanded)) = flex {
|
||||
primary_left_items.push(left_item.flex(flex, expanded).boxed());
|
||||
primary_left_items.push(left_item.flex(flex, expanded).into_element());
|
||||
} else {
|
||||
primary_left_items.push(left_item.boxed());
|
||||
primary_left_items.push(left_item.into_element());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,9 +90,9 @@ impl View for Toolbar {
|
|||
.with_margin_left(spacing)
|
||||
.flex_float();
|
||||
if let Some((flex, expanded)) = flex {
|
||||
primary_right_items.push(right_item.flex(flex, expanded).boxed());
|
||||
primary_right_items.push(right_item.flex(flex, expanded).into_element());
|
||||
} else {
|
||||
primary_right_items.push(right_item.boxed());
|
||||
primary_right_items.push(right_item.into_element());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ impl View for Toolbar {
|
|||
ChildView::new(item.as_any(), cx)
|
||||
.constrained()
|
||||
.with_height(theme.height)
|
||||
.boxed(),
|
||||
.into_element(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -151,13 +151,12 @@ impl View for Toolbar {
|
|||
.with_children(primary_left_items)
|
||||
.with_children(primary_right_items)
|
||||
.constrained()
|
||||
.with_height(height)
|
||||
.boxed(),
|
||||
.with_height(height),
|
||||
)
|
||||
.with_children(secondary_item)
|
||||
.contained()
|
||||
.with_style(container_style)
|
||||
.boxed()
|
||||
.into_named_element("toolbar")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,7 +189,6 @@ fn nav_button<A: Action + Clone>(
|
|||
.with_width(style.button_width)
|
||||
.with_height(style.button_width)
|
||||
.aligned()
|
||||
.boxed()
|
||||
})
|
||||
.with_cursor_style(if enabled {
|
||||
CursorStyle::PointingHand
|
||||
|
@ -209,7 +207,7 @@ fn nav_button<A: Action + Clone>(
|
|||
)
|
||||
.contained()
|
||||
.with_margin_right(spacing)
|
||||
.boxed()
|
||||
.into_named_element("nav button")
|
||||
}
|
||||
|
||||
impl Toolbar {
|
||||
|
|
|
@ -2088,29 +2088,24 @@ impl Workspace {
|
|||
};
|
||||
|
||||
enum TitleBar {}
|
||||
ConstrainedBox::new(
|
||||
MouseEventHandler::<TitleBar, _>::new(0, cx, |_, cx| {
|
||||
Container::new(
|
||||
Stack::new()
|
||||
.with_children(
|
||||
self.titlebar_item
|
||||
.as_ref()
|
||||
.map(|item| ChildView::new(item, cx).boxed()),
|
||||
)
|
||||
.boxed(),
|
||||
MouseEventHandler::<TitleBar, _>::new(0, cx, |_, cx| {
|
||||
Stack::new()
|
||||
.with_children(
|
||||
self.titlebar_item
|
||||
.as_ref()
|
||||
.map(|item| ChildView::new(item, cx)),
|
||||
)
|
||||
.contained()
|
||||
.with_style(container_theme)
|
||||
.boxed()
|
||||
})
|
||||
.on_click(MouseButton::Left, |event, _, cx| {
|
||||
if event.click_count == 2 {
|
||||
cx.zoom_window();
|
||||
}
|
||||
})
|
||||
.boxed(),
|
||||
)
|
||||
})
|
||||
.on_click(MouseButton::Left, |event, _, cx| {
|
||||
if event.click_count == 2 {
|
||||
cx.zoom_window();
|
||||
}
|
||||
})
|
||||
.constrained()
|
||||
.with_height(theme.workspace.titlebar.height)
|
||||
.named("titlebar")
|
||||
.into_named_element("titlebar")
|
||||
}
|
||||
|
||||
fn active_item_path_changed(&mut self, cx: &mut ViewContext<Self>) {
|
||||
|
@ -2191,11 +2186,10 @@ impl Workspace {
|
|||
.aligned()
|
||||
.contained()
|
||||
.with_style(theme.workspace.disconnected_overlay.container)
|
||||
.boxed()
|
||||
})
|
||||
.with_cursor_style(CursorStyle::Arrow)
|
||||
.capture_all()
|
||||
.boxed(),
|
||||
.into_named_element("disconnected overlay"),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
|
@ -2216,7 +2210,6 @@ impl Workspace {
|
|||
ChildView::new(notification.as_any(), cx)
|
||||
.contained()
|
||||
.with_style(theme.notification)
|
||||
.boxed()
|
||||
}))
|
||||
.constrained()
|
||||
.with_width(theme.notifications.width)
|
||||
|
@ -2225,7 +2218,7 @@ impl Workspace {
|
|||
.aligned()
|
||||
.bottom()
|
||||
.right()
|
||||
.boxed(),
|
||||
.into_element(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -2857,8 +2850,7 @@ impl View for Workspace {
|
|||
constraint.max.y(),
|
||||
),
|
||||
)
|
||||
})
|
||||
.boxed(),
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
|
@ -2876,18 +2868,15 @@ impl View for Workspace {
|
|||
self.active_pane(),
|
||||
cx,
|
||||
))
|
||||
.flex(1., true)
|
||||
.boxed(),
|
||||
.flex(1., true),
|
||||
)
|
||||
.with_children(self.dock.render(
|
||||
&theme,
|
||||
DockAnchor::Bottom,
|
||||
cx,
|
||||
))
|
||||
.boxed(),
|
||||
)),
|
||||
)
|
||||
.flex(1., true)
|
||||
.boxed(),
|
||||
.flex(1., true),
|
||||
)
|
||||
.with_children(self.dock.render(&theme, DockAnchor::Right, cx))
|
||||
.with_children(
|
||||
|
@ -2903,49 +2892,38 @@ impl View for Workspace {
|
|||
constraint.max.y(),
|
||||
),
|
||||
)
|
||||
})
|
||||
.boxed(),
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
)
|
||||
.boxed()
|
||||
})
|
||||
.with_child(
|
||||
Overlay::new(
|
||||
Stack::new()
|
||||
.with_children(self.dock.render(
|
||||
&theme,
|
||||
DockAnchor::Expanded,
|
||||
cx,
|
||||
))
|
||||
.with_children(self.modal.as_ref().map(|modal| {
|
||||
ChildView::new(modal, cx)
|
||||
.contained()
|
||||
.with_style(theme.workspace.modal)
|
||||
.aligned()
|
||||
.top()
|
||||
.boxed()
|
||||
}))
|
||||
.with_children(
|
||||
self.render_notifications(&theme.workspace, cx),
|
||||
)
|
||||
.boxed(),
|
||||
)
|
||||
.boxed(),
|
||||
)
|
||||
.flex(1.0, true)
|
||||
.boxed(),
|
||||
.with_child(Overlay::new(
|
||||
Stack::new()
|
||||
.with_children(self.dock.render(
|
||||
&theme,
|
||||
DockAnchor::Expanded,
|
||||
cx,
|
||||
))
|
||||
.with_children(self.modal.as_ref().map(|modal| {
|
||||
ChildView::new(modal, cx)
|
||||
.contained()
|
||||
.with_style(theme.workspace.modal)
|
||||
.aligned()
|
||||
.top()
|
||||
}))
|
||||
.with_children(self.render_notifications(&theme.workspace, cx)),
|
||||
))
|
||||
.flex(1.0, true),
|
||||
)
|
||||
.with_child(ChildView::new(&self.status_bar, cx).boxed())
|
||||
.with_child(ChildView::new(&self.status_bar, cx))
|
||||
.contained()
|
||||
.with_background_color(theme.workspace.background)
|
||||
.boxed(),
|
||||
.with_background_color(theme.workspace.background),
|
||||
)
|
||||
.with_children(DragAndDrop::render(cx))
|
||||
.with_children(self.render_disconnected_overlay(cx))
|
||||
.named("workspace")
|
||||
.into_named_element("workspace")
|
||||
}
|
||||
|
||||
fn focus_in(&mut self, view: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue