This commit is contained in:
Nathan Sobo 2023-04-11 18:21:56 -06:00
parent 3de8fe0f87
commit e115baa60c
94 changed files with 1477 additions and 1310 deletions

View file

@ -9,8 +9,7 @@ use gpui::{
geometry::vector::Vector2F,
impl_internal_actions,
platform::{CursorStyle, MouseButton},
AppContext, Border, Element, ElementBox, RenderContext, SizeConstraint, ViewContext,
ViewHandle,
AppContext, Border, Element, ElementBox, SizeConstraint, ViewContext, ViewHandle,
};
use settings::{DockAnchor, Settings};
use theme::Theme;
@ -315,7 +314,7 @@ impl Dock {
&self,
theme: &Theme,
anchor: DockAnchor,
cx: &mut RenderContext<Workspace>,
cx: &mut ViewContext<Workspace>,
) -> Option<ElementBox> {
let style = &theme.workspace.dock;

View file

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

View file

@ -740,8 +740,8 @@ pub(crate) mod test {
use super::{Item, ItemEvent};
use crate::{sidebar::SidebarItem, ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
use gpui::{
elements::Empty, AppContext, Element, ElementBox, Entity, ModelHandle, RenderContext, Task,
View, ViewContext, ViewHandle, WeakViewHandle,
elements::Empty, AppContext, Element, ElementBox, Entity, ModelHandle, Task, View,
ViewContext, ViewHandle, WeakViewHandle,
};
use project::{Project, ProjectEntryId, ProjectPath, WorktreeId};
use smallvec::SmallVec;
@ -899,7 +899,7 @@ pub(crate) mod test {
"TestItem"
}
fn render(&mut self, _: &mut RenderContext<Self>) -> ElementBox {
fn render(&mut self, _: &mut ViewContext<Self>) -> ElementBox {
Empty::new().boxed()
}
}

View file

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

View file

@ -24,8 +24,7 @@ use gpui::{
keymap_matcher::KeymapContext,
platform::{CursorStyle, MouseButton, NavigationDirection, PromptLevel},
Action, AnyViewHandle, AnyWeakViewHandle, AppContext, AsyncAppContext, Entity, EventContext,
ModelHandle, MouseRegion, Quad, RenderContext, Task, View, ViewContext, ViewHandle,
WeakViewHandle,
ModelHandle, MouseRegion, Quad, Task, View, ViewContext, ViewHandle, WeakViewHandle,
};
use project::{Project, ProjectEntryId, ProjectPath};
use serde::Deserialize;
@ -1221,7 +1220,7 @@ impl Pane {
});
}
fn render_tabs(&mut self, cx: &mut RenderContext<Self>) -> impl Element {
fn render_tabs(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
let theme = cx.global::<Settings>().theme.clone();
let pane = cx.handle();
@ -1302,7 +1301,7 @@ impl Pane {
let theme = cx.global::<Settings>().theme.clone();
let detail = detail.clone();
move |dragged_item, cx: &mut RenderContext<Workspace>| {
move |dragged_item, cx: &mut ViewContext<Workspace>| {
let tab_style = &theme.workspace.tab_bar.dragged_tab;
Self::render_tab(
&dragged_item.item,
@ -1384,7 +1383,7 @@ impl Pane {
detail: Option<usize>,
hovered: bool,
tab_style: &theme::Tab,
cx: &mut RenderContext<V>,
cx: &mut ViewContext<V>,
) -> ElementBox {
let title = item.tab_content(detail, &tab_style, cx);
let mut container = tab_style.container.clone();
@ -1408,7 +1407,7 @@ impl Pane {
Canvas::new(move |bounds, _, cx| {
if let Some(color) = icon_color {
let square = RectF::new(bounds.origin(), vec2f(diameter, diameter));
cx.scene.push_quad(Quad {
scene.push_quad(Quad {
bounds: square,
background: Some(color),
border: Default::default(),
@ -1476,11 +1475,7 @@ impl Pane {
.boxed()
}
fn render_tab_bar_buttons(
&mut self,
theme: &Theme,
cx: &mut RenderContext<Self>,
) -> ElementBox {
fn render_tab_bar_buttons(&mut self, theme: &Theme, cx: &mut ViewContext<Self>) -> ElementBox {
Flex::row()
// New menu
.with_child(render_tab_bar_button(
@ -1529,7 +1524,7 @@ impl Pane {
.boxed()
}
fn render_blank_pane(&mut self, theme: &Theme, _cx: &mut RenderContext<Self>) -> ElementBox {
fn render_blank_pane(&mut self, theme: &Theme, _cx: &mut ViewContext<Self>) -> ElementBox {
let background = theme.workspace.background;
Empty::new()
.contained()
@ -1547,7 +1542,7 @@ impl View for Pane {
"Pane"
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
let this = cx.handle();
enum MouseNavigationHandler {}
@ -1705,7 +1700,7 @@ impl View for Pane {
fn render_tab_bar_button<A: Action + Clone>(
index: usize,
icon: &'static str,
cx: &mut RenderContext<Pane>,
cx: &mut ViewContext<Pane>,
action: A,
context_menu: Option<ViewHandle<ContextMenu>>,
) -> ElementBox {
@ -1853,7 +1848,7 @@ impl PaneBackdrop {
}
}
impl Element for PaneBackdrop {
impl Element<Pane> for PaneBackdrop {
type LayoutState = ();
type PaintState = ();
@ -1861,31 +1856,34 @@ impl Element for PaneBackdrop {
fn layout(
&mut self,
constraint: gpui::SizeConstraint,
cx: &mut gpui::LayoutContext,
view: &mut Pane,
cx: &mut ViewContext<Pane>,
) -> (Vector2F, Self::LayoutState) {
let size = self.child.layout(constraint, cx);
let size = self.child.layout(constraint, view, cx);
(size, ())
}
fn paint(
&mut self,
scene: &mut gpui::SceneBuilder,
bounds: RectF,
visible_bounds: RectF,
_: &mut Self::LayoutState,
cx: &mut gpui::PaintContext,
view: &mut Pane,
cx: &mut ViewContext<Pane>,
) -> Self::PaintState {
let background = cx.global::<Settings>().theme.editor.background;
let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default();
cx.scene.push_quad(gpui::Quad {
scene.push_quad(gpui::Quad {
bounds: RectF::new(bounds.origin(), bounds.size()),
background: Some(background),
..Default::default()
});
let child_view_id = self.child_view;
cx.scene.push_mouse_region(
scene.push_mouse_region(
MouseRegion::new::<Self>(child_view_id, 0, visible_bounds).on_down(
gpui::platform::MouseButton::Left,
move |_, cx| {
@ -1895,8 +1893,9 @@ impl Element for PaneBackdrop {
),
);
cx.paint_layer(Some(bounds), |cx| {
self.child.paint(bounds.origin(), visible_bounds, cx)
scene.paint_layer(Some(bounds), |scene| {
self.child
.paint(scene, bounds.origin(), visible_bounds, view, cx)
})
}
@ -1907,9 +1906,10 @@ impl Element for PaneBackdrop {
_visible_bounds: RectF,
_layout: &Self::LayoutState,
_paint: &Self::PaintState,
cx: &gpui::MeasurementContext,
view: &V,
cx: &gpui::ViewContext<V>,
) -> Option<RectF> {
self.child.rect_for_text_range(range_utf16, cx)
self.child.rect_for_text_range(range_utf16, view, cx)
}
fn debug(
@ -1917,12 +1917,13 @@ impl Element for PaneBackdrop {
_bounds: RectF,
_layout: &Self::LayoutState,
_paint: &Self::PaintState,
cx: &gpui::DebugContext,
view: &V,
cx: &gpui::ViewContext<V>,
) -> serde_json::Value {
gpui::json::json!({
"type": "Pane Back Drop",
"view": self.child_view,
"child": self.child.debug(cx),
"child": self.child.debug(view, cx),
})
}
}

View file

@ -5,7 +5,7 @@ use gpui::{
geometry::{rect::RectF, vector::Vector2F},
platform::MouseButton,
scene::MouseUp,
AppContext, Element, ElementBox, EventContext, MouseState, Quad, RenderContext, WeakViewHandle,
AppContext, Element, ElementBox, EventContext, MouseState, Quad, ViewContext, WeakViewHandle,
};
use project::ProjectEntryId;
use settings::Settings;
@ -22,14 +22,14 @@ pub fn dragged_item_receiver<Tag, F>(
drop_index: usize,
allow_same_pane: bool,
split_margin: Option<f32>,
cx: &mut RenderContext<Pane>,
cx: &mut ViewContext<Pane>,
render_child: F,
) -> MouseEventHandler<Tag>
where
Tag: 'static,
F: FnOnce(&mut MouseState, &mut RenderContext<Pane>) -> ElementBox,
F: FnOnce(&mut MouseState, &mut ViewContext<Pane>) -> ElementBox,
{
MouseEventHandler::<Tag>::above(region_id, cx, |state, cx| {
MouseEventHandler::<Tag>::above(region_id, cx, |state, _, cx| {
// Observing hovered will cause a render when the mouse enters regardless
// of if mouse position was accessed before
let drag_position = if state.hovered() {
@ -59,7 +59,7 @@ where
.unwrap_or(bounds);
cx.paint_stacking_context(None, None, |cx| {
cx.scene.push_quad(Quad {
scene.push_quad(Quad {
bounds: overlay_region,
background: Some(overlay_color(cx)),
border: Default::default(),
@ -102,7 +102,7 @@ pub fn handle_dropped_item(
index: usize,
allow_same_pane: bool,
split_margin: Option<f32>,
cx: &mut EventContext,
cx: &mut ViewContext<Self>,
) {
enum Action {
Move(WeakViewHandle<Pane>, usize),
@ -110,11 +110,11 @@ pub fn handle_dropped_item(
}
let drag_and_drop = cx.global::<DragAndDrop<Workspace>>();
let action = if let Some((_, dragged_item)) =
drag_and_drop.currently_dragged::<DraggedItem>(cx.window_id)
drag_and_drop.currently_dragged::<DraggedItem>(cx.window_id())
{
Action::Move(dragged_item.pane.clone(), dragged_item.item.id())
} else if let Some((_, project_entry)) =
drag_and_drop.currently_dragged::<ProjectEntryId>(cx.window_id)
drag_and_drop.currently_dragged::<ProjectEntryId>(cx.window_id())
{
Action::Open(*project_entry)
} else {

View file

@ -5,7 +5,7 @@ use gpui::{
elements::*,
geometry::{rect::RectF, vector::Vector2F},
platform::{CursorStyle, MouseButton},
Axis, Border, ModelHandle, RenderContext, ViewHandle,
Axis, Border, ModelHandle, ViewContext, ViewHandle,
};
use project::Project;
use serde::Deserialize;
@ -70,7 +70,7 @@ impl PaneGroup {
follower_states: &FollowerStatesByLeader,
active_call: Option<&ModelHandle<ActiveCall>>,
active_pane: &ViewHandle<Pane>,
cx: &mut RenderContext<Workspace>,
cx: &mut ViewContext<Workspace>,
) -> ElementBox {
self.root.render(
project,
@ -131,7 +131,7 @@ impl Member {
follower_states: &FollowerStatesByLeader,
active_call: Option<&ModelHandle<ActiveCall>>,
active_pane: &ViewHandle<Pane>,
cx: &mut RenderContext<Workspace>,
cx: &mut ViewContext<Workspace>,
) -> ElementBox {
enum FollowIntoExternalProject {}
@ -366,7 +366,7 @@ impl PaneAxis {
follower_state: &FollowerStatesByLeader,
active_call: Option<&ModelHandle<ActiveCall>>,
active_pane: &ViewHandle<Pane>,
cx: &mut RenderContext<Workspace>,
cx: &mut ViewContext<Workspace>,
) -> ElementBox {
let last_member_ix = self.members.len() - 1;
Flex::new(self.axis)

View file

@ -9,7 +9,7 @@ use gpui::{
elements::*,
geometry::{rect::RectF, vector::vec2f},
platform::MouseButton,
AppContext, Entity, RenderContext, Task, View, ViewContext,
AppContext, Entity, Task, View, ViewContext,
};
use settings::Settings;
use smallvec::SmallVec;
@ -64,7 +64,7 @@ impl View for SharedScreen {
"SharedScreen"
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
enum Focus {}
let frame = self.frame.clone();
@ -76,7 +76,7 @@ impl View for SharedScreen {
vec2f(frame.width() as f32, frame.height() as f32),
);
let origin = bounds.origin() + (bounds.size() / 2.) - size / 2.;
cx.scene.push_surface(gpui::platform::mac::Surface {
scene.push_surface(gpui::platform::mac::Surface {
bounds: RectF::new(origin, size),
image_buffer: frame.image(),
});

View file

@ -1,7 +1,7 @@
use crate::StatusItemView;
use gpui::{
elements::*, impl_actions, platform::CursorStyle, platform::MouseButton, AnyViewHandle,
AppContext, Entity, RenderContext, Subscription, View, ViewContext, ViewHandle,
AppContext, Entity, Subscription, View, ViewContext, ViewHandle,
};
use serde::Deserialize;
use settings::Settings;
@ -188,7 +188,7 @@ impl View for Sidebar {
"Sidebar"
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
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 RenderContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
let theme = &cx.global::<Settings>().theme;
let tooltip_style = theme.tooltip.clone();
let theme = &theme.workspace.status_bar.sidebar_buttons;

View file

@ -9,7 +9,7 @@ use gpui::{
},
json::{json, ToJson},
AnyViewHandle, AppContext, DebugContext, ElementBox, Entity, LayoutContext, MeasurementContext,
PaintContext, RenderContext, SizeConstraint, Subscription, View, ViewContext, ViewHandle,
PaintContext, SceneBuilder, SizeConstraint, Subscription, View, ViewContext, ViewHandle,
};
use settings::Settings;
@ -42,7 +42,7 @@ impl View for StatusBar {
"StatusBar"
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
let theme = &cx.global::<Settings>().theme.workspace.status_bar;
StatusBarElement {
@ -143,44 +143,49 @@ struct StatusBarElement {
right: ElementBox,
}
impl Element for StatusBarElement {
impl<V: View> Element<V> for StatusBarElement {
type LayoutState = ();
type PaintState = ();
fn layout(
&mut self,
mut constraint: SizeConstraint,
cx: &mut LayoutContext,
view: &mut V,
cx: &mut ViewContext<V>,
) -> (Vector2F, Self::LayoutState) {
let max_width = constraint.max.x();
constraint.min = vec2f(0., constraint.min.y());
let right_size = self.right.layout(constraint, cx);
let right_size = self.right.layout(constraint, view, cx);
let constraint = SizeConstraint::new(
vec2f(0., constraint.min.y()),
vec2f(max_width - right_size.x(), constraint.max.y()),
);
self.left.layout(constraint, cx);
self.left.layout(constraint, view, cx);
(vec2f(max_width, right_size.y()), ())
}
fn paint(
&mut self,
scene: &mut SceneBuilder,
bounds: RectF,
visible_bounds: RectF,
_: &mut Self::LayoutState,
cx: &mut PaintContext,
view: &mut V,
cx: &mut ViewContext<V>,
) -> Self::PaintState {
let origin_y = bounds.upper_right().y();
let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default();
let left_origin = vec2f(bounds.lower_left().x(), origin_y);
self.left.paint(left_origin, visible_bounds, cx);
self.left
.paint(scene, left_origin, visible_bounds, view, cx);
let right_origin = vec2f(bounds.upper_right().x() - self.right.size().x(), origin_y);
self.right.paint(right_origin, visible_bounds, cx);
self.right
.paint(scene, right_origin, visible_bounds, view, cx);
}
fn rect_for_text_range(

View file

@ -1,7 +1,7 @@
use crate::{ItemHandle, Pane};
use gpui::{
elements::*, platform::CursorStyle, platform::MouseButton, Action, AnyViewHandle, AppContext,
Entity, RenderContext, View, ViewContext, ElementBox, ViewHandle, WeakViewHandle,
ElementBox, Entity, View, ViewContext, ViewHandle, WeakViewHandle,
};
use settings::Settings;
@ -59,7 +59,7 @@ impl View for Toolbar {
"Toolbar"
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
let theme = &cx.global::<Settings>().theme.workspace.toolbar;
let mut primary_left_items = Vec::new();
@ -168,7 +168,7 @@ fn nav_button<A: Action + Clone>(
action: A,
tooltip_action: A,
action_name: &str,
cx: &mut RenderContext<Toolbar>,
cx: &mut ViewContext<Toolbar>,
) -> ElementBox {
MouseEventHandler::<A>::new(0, cx, |state, _| {
let style = if enabled {

View file

@ -45,8 +45,7 @@ use gpui::{
WindowOptions,
},
Action, AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, Entity, ModelContext,
ModelHandle, RenderContext, SizeConstraint, Subscription, Task, View, ViewContext, ViewHandle,
WeakViewHandle,
ModelHandle, SizeConstraint, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle,
};
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem};
use language::LanguageRegistry;
@ -2054,10 +2053,10 @@ impl Workspace {
self.leader_state.followers.contains(&peer_id)
}
fn render_titlebar(&self, theme: &Theme, cx: &mut RenderContext<Self>) -> ElementBox {
fn render_titlebar(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> ElementBox {
// 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(cx.window_id());
let is_fullscreen = cx.window_is_fullscreen();
let container_theme = if is_fullscreen {
let mut container_theme = theme.workspace.titlebar.container;
container_theme.padding.left = container_theme.padding.right;
@ -2154,7 +2153,7 @@ impl Workspace {
}
}
fn render_disconnected_overlay(&self, cx: &mut RenderContext<Workspace>) -> Option<ElementBox> {
fn render_disconnected_overlay(&self, cx: &mut ViewContext<Workspace>) -> Option<ElementBox> {
if self.project.read(cx).is_read_only() {
enum DisconnectedOverlay {}
Some(
@ -2810,7 +2809,7 @@ impl View for Workspace {
"Workspace"
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
fn render(&mut self, cx: &mut ViewContext<Self>) -> ElementBox {
let theme = cx.global::<Settings>().theme.clone();
Stack::new()
.with_child(