This commit is contained in:
Nathan Sobo 2023-04-11 18:48:00 -06:00
parent e115baa60c
commit e6cc132b19
14 changed files with 119 additions and 83 deletions

View file

@ -315,7 +315,7 @@ impl Dock {
theme: &Theme,
anchor: DockAnchor,
cx: &mut ViewContext<Workspace>,
) -> Option<ElementBox> {
) -> Option<ElementBox<Self>> {
let style = &theme.workspace.dock;
self.position

View file

@ -34,7 +34,7 @@ impl View for ToggleDockButton {
"Dock Toggle"
}
fn render(&mut self, cx: &mut gpui::ViewContext<'_, Self>) -> ElementBox {
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> ElementBox<Self> {
let workspace = self.workspace.upgrade(cx);
if workspace.is_none() {

View file

@ -47,8 +47,12 @@ pub trait Item: View {
fn tab_description<'a>(&'a self, _: usize, _: &'a AppContext) -> Option<Cow<'a, str>> {
None
}
fn tab_content(&self, detail: Option<usize>, style: &theme::Tab, cx: &AppContext)
-> ElementBox;
fn tab_content(
&self,
detail: Option<usize>,
style: &theme::Tab,
cx: &AppContext,
) -> ElementBox<Self>;
fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project::Item)) {}
fn is_singleton(&self, _cx: &AppContext) -> bool {
false
@ -130,7 +134,7 @@ pub trait Item: View {
ToolbarItemLocation::Hidden
}
fn breadcrumbs(&self, _theme: &Theme, _cx: &AppContext) -> Option<Vec<ElementBox>> {
fn breadcrumbs(&self, _theme: &Theme, _cx: &AppContext) -> Option<Vec<ElementBox<Self>>> {
None
}
@ -163,8 +167,12 @@ pub trait ItemHandle: 'static + fmt::Debug {
handler: Box<dyn Fn(ItemEvent, &mut AppContext)>,
) -> gpui::Subscription;
fn tab_description<'a>(&self, detail: usize, cx: &'a AppContext) -> Option<Cow<'a, str>>;
fn tab_content(&self, detail: Option<usize>, style: &theme::Tab, cx: &AppContext)
-> ElementBox;
fn tab_content(
&self,
detail: Option<usize>,
style: &theme::Tab,
cx: &AppContext,
) -> ElementBox<Pane>;
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]>;
@ -213,7 +221,7 @@ pub trait ItemHandle: 'static + fmt::Debug {
) -> gpui::Subscription;
fn to_searchable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>>;
fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation;
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<ElementBox>>;
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<ElementBox<Pane>>>;
fn serialized_item_kind(&self) -> Option<&'static str>;
fn show_toolbar(&self, cx: &AppContext) -> bool;
}
@ -257,7 +265,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
detail: Option<usize>,
style: &theme::Tab,
cx: &AppContext,
) -> ElementBox {
) -> ElementBox<Pane> {
self.read(cx).tab_content(detail, style, cx)
}
@ -583,7 +591,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
self.read(cx).breadcrumb_location()
}
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<ElementBox>> {
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<ElementBox<Self>>> {
self.read(cx).breadcrumbs(theme, cx)
}
@ -899,7 +907,7 @@ pub(crate) mod test {
"TestItem"
}
fn render(&mut self, _: &mut ViewContext<Self>) -> ElementBox {
fn render(&mut self, _: &mut ViewContext<Self>) -> ElementBox<Self> {
Empty::new().boxed()
}
}
@ -912,7 +920,12 @@ pub(crate) mod test {
})
}
fn tab_content(&self, detail: Option<usize>, _: &theme::Tab, _: &AppContext) -> ElementBox {
fn tab_content(
&self,
detail: Option<usize>,
_: &theme::Tab,
_: &AppContext,
) -> ElementBox<Self> {
self.tab_detail.set(detail);
Empty::new().boxed()
}

View file

@ -229,7 +229,7 @@ pub mod simple_message_notification {
"MessageNotification"
}
fn render(&mut self, cx: &mut gpui::ViewContext<'_, Self>) -> gpui::ElementBox {
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> gpui::ElementBox<Self> {
let theme = cx.global::<Settings>().theme.clone();
let theme = &theme.simple_message_notification;

View file

@ -1383,8 +1383,8 @@ impl Pane {
detail: Option<usize>,
hovered: bool,
tab_style: &theme::Tab,
cx: &mut ViewContext<V>,
) -> ElementBox {
cx: &mut ViewContext<Self>,
) -> ElementBox<Self> {
let title = item.tab_content(detail, &tab_style, cx);
let mut container = tab_style.container.clone();
if first {
@ -1404,7 +1404,7 @@ impl Pane {
};
ConstrainedBox::new(
Canvas::new(move |bounds, _, cx| {
Canvas::new(move |scene, bounds, _, cx| {
if let Some(color) = icon_color {
let square = RectF::new(bounds.origin(), vec2f(diameter, diameter));
scene.push_quad(Quad {
@ -1475,7 +1475,11 @@ impl Pane {
.boxed()
}
fn render_tab_bar_buttons(&mut self, theme: &Theme, cx: &mut ViewContext<Self>) -> ElementBox {
fn render_tab_bar_buttons(
&mut self,
theme: &Theme,
cx: &mut ViewContext<Self>,
) -> ElementBox<Self> {
Flex::row()
// New menu
.with_child(render_tab_bar_button(
@ -1524,7 +1528,11 @@ impl Pane {
.boxed()
}
fn render_blank_pane(&mut self, theme: &Theme, _cx: &mut ViewContext<Self>) -> ElementBox {
fn render_blank_pane(
&mut self,
theme: &Theme,
_cx: &mut ViewContext<Self>,
) -> ElementBox<Self> {
let background = theme.workspace.background;
Empty::new()
.contained()
@ -1542,7 +1550,7 @@ impl View for Pane {
"Pane"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox<Self> {
let this = cx.handle();
enum MouseNavigationHandler {}
@ -1703,7 +1711,7 @@ fn render_tab_bar_button<A: Action + Clone>(
cx: &mut ViewContext<Pane>,
action: A,
context_menu: Option<ViewHandle<ContextMenu>>,
) -> ElementBox {
) -> ElementBox<Pane> {
enum TabBarButton {}
Stack::new()
@ -1837,10 +1845,11 @@ impl NavHistory {
pub struct PaneBackdrop {
child_view: usize,
child: ElementBox,
child: ElementBox<Pane>,
}
impl PaneBackdrop {
pub fn new(pane_item_view: usize, child: ElementBox) -> Self {
pub fn new(pane_item_view: usize, child: ElementBox<Pane>) -> Self {
PaneBackdrop {
child,
child_view: pane_item_view,
@ -1906,8 +1915,8 @@ impl Element<Pane> for PaneBackdrop {
_visible_bounds: RectF,
_layout: &Self::LayoutState,
_paint: &Self::PaintState,
view: &V,
cx: &gpui::ViewContext<V>,
view: &Pane,
cx: &gpui::ViewContext<Pane>,
) -> Option<RectF> {
self.child.rect_for_text_range(range_utf16, view, cx)
}
@ -1917,8 +1926,8 @@ impl Element<Pane> for PaneBackdrop {
_bounds: RectF,
_layout: &Self::LayoutState,
_paint: &Self::PaintState,
view: &V,
cx: &gpui::ViewContext<V>,
view: &Pane,
cx: &gpui::ViewContext<Pane>,
) -> serde_json::Value {
gpui::json::json!({
"type": "Pane Back Drop",

View file

@ -5,7 +5,7 @@ use gpui::{
geometry::{rect::RectF, vector::Vector2F},
platform::MouseButton,
scene::MouseUp,
AppContext, Element, ElementBox, EventContext, MouseState, Quad, ViewContext, WeakViewHandle,
AppContext, Element, ElementBox, MouseState, Quad, ViewContext, WeakViewHandle,
};
use project::ProjectEntryId;
use settings::Settings;
@ -24,10 +24,10 @@ pub fn dragged_item_receiver<Tag, F>(
split_margin: Option<f32>,
cx: &mut ViewContext<Pane>,
render_child: F,
) -> MouseEventHandler<Tag>
) -> MouseEventHandler<Tag, Pane>
where
Tag: 'static,
F: FnOnce(&mut MouseState, &mut ViewContext<Pane>) -> ElementBox,
F: FnOnce(&mut MouseState, &mut ViewContext<Pane>) -> ElementBox<Pane>,
{
MouseEventHandler::<Tag>::above(region_id, cx, |state, _, cx| {
// Observing hovered will cause a render when the mouse enters regardless
@ -48,7 +48,7 @@ where
Stack::new()
.with_child(render_child(state, cx))
.with_children(drag_position.map(|drag_position| {
Canvas::new(move |bounds, _, cx| {
Canvas::new(move |scene, bounds, _, cx| {
if bounds.contains_point(drag_position) {
let overlay_region = split_margin
.and_then(|split_margin| {
@ -58,7 +58,7 @@ where
.map(|(dir, margin)| dir.along_edge(bounds, margin))
.unwrap_or(bounds);
cx.paint_stacking_context(None, None, |cx| {
scene.paint_stacking_context(None, None, |cx| {
scene.push_quad(Quad {
bounds: overlay_region,
background: Some(overlay_color(cx)),
@ -102,7 +102,7 @@ pub fn handle_dropped_item(
index: usize,
allow_same_pane: bool,
split_margin: Option<f32>,
cx: &mut ViewContext<Self>,
cx: &mut ViewContext<Pane>,
) {
enum Action {
Move(WeakViewHandle<Pane>, usize),

View file

@ -71,7 +71,7 @@ impl PaneGroup {
active_call: Option<&ModelHandle<ActiveCall>>,
active_pane: &ViewHandle<Pane>,
cx: &mut ViewContext<Workspace>,
) -> ElementBox {
) -> ElementBox<Workspace> {
self.root.render(
project,
theme,
@ -132,7 +132,7 @@ impl Member {
active_call: Option<&ModelHandle<ActiveCall>>,
active_pane: &ViewHandle<Pane>,
cx: &mut ViewContext<Workspace>,
) -> ElementBox {
) -> ElementBox<Workspace> {
enum FollowIntoExternalProject {}
match self {
@ -367,7 +367,7 @@ impl PaneAxis {
active_call: Option<&ModelHandle<ActiveCall>>,
active_pane: &ViewHandle<Pane>,
cx: &mut ViewContext<Workspace>,
) -> ElementBox {
) -> ElementBox<Workspace> {
let last_member_ix = self.members.len() - 1;
Flex::new(self.axis)
.with_children(self.members.iter().enumerate().map(|(ix, member)| {

View file

@ -64,12 +64,12 @@ impl View for SharedScreen {
"SharedScreen"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox<Self> {
enum Focus {}
let frame = self.frame.clone();
MouseEventHandler::<Focus>::new(0, cx, |_, cx| {
Canvas::new(move |bounds, _, cx| {
Canvas::new(move |scene, bounds, _, cx| {
if let Some(frame) = frame.clone() {
let size = constrain_size_preserving_aspect_ratio(
bounds.size(),
@ -103,7 +103,7 @@ impl Item for SharedScreen {
_: Option<usize>,
style: &theme::Tab,
_: &AppContext,
) -> gpui::ElementBox {
) -> gpui::ElementBox<Self> {
Flex::row()
.with_child(
Svg::new("icons/disable_screen_sharing_12.svg")

View file

@ -188,7 +188,7 @@ impl View for Sidebar {
"Sidebar"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox<Self> {
if let Some(active_item) = self.active_item() {
enum ResizeHandleTag {}
let style = &cx.global::<Settings>().theme.workspace.sidebar;
@ -225,7 +225,7 @@ impl View for SidebarButtons {
"SidebarToggleButton"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox<Self> {
let theme = &cx.global::<Settings>().theme;
let tooltip_style = theme.tooltip.clone();
let theme = &theme.workspace.status_bar.sidebar_buttons;

View file

@ -8,8 +8,8 @@ use gpui::{
vector::{vec2f, Vector2F},
},
json::{json, ToJson},
AnyViewHandle, AppContext, DebugContext, ElementBox, Entity, LayoutContext, MeasurementContext,
PaintContext, SceneBuilder, SizeConstraint, Subscription, View, ViewContext, ViewHandle,
AnyViewHandle, AppContext, ElementBox, Entity, SceneBuilder, SizeConstraint, Subscription,
View, ViewContext, ViewHandle,
};
use settings::Settings;
@ -42,7 +42,7 @@ impl View for StatusBar {
"StatusBar"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox<Self> {
let theme = &cx.global::<Settings>().theme.workspace.status_bar;
StatusBarElement {
@ -139,19 +139,19 @@ impl From<&dyn StatusItemViewHandle> for AnyViewHandle {
}
struct StatusBarElement {
left: ElementBox,
right: ElementBox,
left: ElementBox<StatusBar>,
right: ElementBox<StatusBar>,
}
impl<V: View> Element<V> for StatusBarElement {
impl Element<StatusBar> for StatusBarElement {
type LayoutState = ();
type PaintState = ();
fn layout(
&mut self,
mut constraint: SizeConstraint,
view: &mut V,
cx: &mut ViewContext<V>,
view: &mut StatusBar,
cx: &mut ViewContext<StatusBar>,
) -> (Vector2F, Self::LayoutState) {
let max_width = constraint.max.x();
constraint.min = vec2f(0., constraint.min.y());
@ -173,8 +173,8 @@ impl<V: View> Element<V> for StatusBarElement {
bounds: RectF,
visible_bounds: RectF,
_: &mut Self::LayoutState,
view: &mut V,
cx: &mut ViewContext<V>,
view: &mut StatusBar,
cx: &mut ViewContext<StatusBar>,
) -> Self::PaintState {
let origin_y = bounds.upper_right().y();
let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default();
@ -195,7 +195,8 @@ impl<V: View> Element<V> for StatusBarElement {
_: RectF,
_: &Self::LayoutState,
_: &Self::PaintState,
_: &MeasurementContext,
_: &StatusBar,
_: &ViewContext<StatusBar>,
) -> Option<RectF> {
None
}
@ -205,7 +206,8 @@ impl<V: View> Element<V> for StatusBarElement {
bounds: RectF,
_: &Self::LayoutState,
_: &Self::PaintState,
_: &DebugContext,
_: &StatusBar,
_: &ViewContext<StatusBar>,
) -> serde_json::Value {
json!({
"type": "StatusBarElement",

View file

@ -59,7 +59,7 @@ impl View for Toolbar {
"Toolbar"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox<Self> {
let theme = &cx.global::<Settings>().theme.workspace.toolbar;
let mut primary_left_items = Vec::new();
@ -169,7 +169,7 @@ fn nav_button<A: Action + Clone>(
tooltip_action: A,
action_name: &str,
cx: &mut ViewContext<Toolbar>,
) -> ElementBox {
) -> ElementBox<Toolbar> {
MouseEventHandler::<A>::new(0, cx, |state, _| {
let style = if enabled {
style.style_for(state, false)

View file

@ -2053,7 +2053,7 @@ impl Workspace {
self.leader_state.followers.contains(&peer_id)
}
fn render_titlebar(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> ElementBox {
fn render_titlebar(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> ElementBox<Self> {
// TODO: There should be a better system in place for this
// (https://github.com/zed-industries/zed/issues/1290)
let is_fullscreen = cx.window_is_fullscreen();
@ -2153,7 +2153,10 @@ impl Workspace {
}
}
fn render_disconnected_overlay(&self, cx: &mut ViewContext<Workspace>) -> Option<ElementBox> {
fn render_disconnected_overlay(
&self,
cx: &mut ViewContext<Workspace>,
) -> Option<ElementBox<Workspace>> {
if self.project.read(cx).is_read_only() {
enum DisconnectedOverlay {}
Some(
@ -2181,7 +2184,7 @@ impl Workspace {
&self,
theme: &theme::Workspace,
cx: &AppContext,
) -> Option<ElementBox> {
) -> Option<ElementBox<Workspace>> {
if self.notifications.is_empty() {
None
} else {
@ -2809,7 +2812,7 @@ impl View for Workspace {
"Workspace"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox<Self> {
let theme = cx.global::<Settings>().theme.clone();
Stack::new()
.with_child(