diff --git a/crates/breadcrumbs/src/breadcrumbs.rs b/crates/breadcrumbs/src/breadcrumbs.rs index ecb5d8adaf..e53261d7a0 100644 --- a/crates/breadcrumbs/src/breadcrumbs.rs +++ b/crates/breadcrumbs/src/breadcrumbs.rs @@ -41,7 +41,7 @@ impl View for Breadcrumbs { "Breadcrumbs" } - fn render(&mut self, cx: &mut ViewContext) -> ElementBox { + fn render(&mut self, cx: &mut ViewContext) -> ElementBox { let active_item = match &self.active_item { Some(active_item) => active_item, None => return Empty::new().boxed(), diff --git a/crates/collab_ui/src/face_pile.rs b/crates/collab_ui/src/face_pile.rs index 9269a32fdb..f813cd34a9 100644 --- a/crates/collab_ui/src/face_pile.rs +++ b/crates/collab_ui/src/face_pile.rs @@ -7,7 +7,8 @@ use gpui::{ }, json::ToJson, serde_json::{self, json}, - Axis, DebugContext, Element, ElementBox, MeasurementContext, PaintContext, + Axis, DebugContext, Element, ElementBox, MeasurementContext, PaintContext, SceneBuilder, + ViewContext, }; pub(crate) struct FacePile { @@ -24,14 +25,15 @@ impl FacePile { } } -impl Element for FacePile { +impl Element for FacePile { type LayoutState = (); type PaintState = (); fn layout( &mut self, constraint: gpui::SizeConstraint, - cx: &mut gpui::LayoutContext, + view: &mut Self, + cx: &mut ViewContext, ) -> (Vector2F, Self::LayoutState) { debug_assert!(constraint.max_along(Axis::Horizontal) == f32::INFINITY); @@ -46,10 +48,12 @@ impl Element for FacePile { fn paint( &mut self, + scene: &mut SceneBuilder, bounds: RectF, visible_bounds: RectF, _layout: &mut Self::LayoutState, - cx: &mut PaintContext, + view: &mut Self, + cx: &mut ViewContext, ) -> Self::PaintState { let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default(); @@ -59,7 +63,7 @@ impl Element for FacePile { for face in self.faces.iter_mut().rev() { let size = face.size(); origin_x -= size.x(); - cx.paint_layer(None, |cx| { + scene.paint_layer(None, |scene| { face.paint(scene, vec2f(origin_x, origin_y), visible_bounds, view, cx); }); origin_x += self.overlap; @@ -94,8 +98,8 @@ impl Element for FacePile { } } -impl Extend for FacePile { - fn extend>(&mut self, children: T) { +impl Extend> for FacePile { + fn extend>>(&mut self, children: T) { self.faces.extend(children); } } diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 9b7445559f..fdf75ad69d 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -1176,9 +1176,7 @@ mod tests { } fn editor_blocks(editor: &ViewHandle, cx: &mut AppContext) -> Vec<(u32, String)> { - let mut presenter = cx.build_window(editor.id(), 0., Default::default()); - let mut cx = presenter.build_layout_context(Default::default(), false, cx); - cx.render(editor, |editor, cx| { + editor.update(cx, |editor, cx| { let snapshot = editor.snapshot(cx); snapshot .blocks_in_range(0..snapshot.max_point().row()) diff --git a/crates/feedback/src/deploy_feedback_button.rs b/crates/feedback/src/deploy_feedback_button.rs index a41abe6584..05985fc2c3 100644 --- a/crates/feedback/src/deploy_feedback_button.rs +++ b/crates/feedback/src/deploy_feedback_button.rs @@ -32,7 +32,7 @@ impl View for DeployFeedbackButton { let theme = cx.global::().theme.clone(); Stack::new() .with_child( - MouseEventHandler::::new(0, cx, |state, _| { + MouseEventHandler::::new(0, cx, |state, _| { let style = &theme .workspace .status_bar @@ -53,12 +53,12 @@ impl View for DeployFeedbackButton { .boxed() }) .with_cursor_style(CursorStyle::PointingHand) - .on_click(MouseButton::Left, move |_, cx| { + .on_click(MouseButton::Left, move |_, _, cx| { if !active { cx.dispatch_action(GiveFeedback) } }) - .with_tooltip::( + .with_tooltip::( 0, "Send Feedback".into(), Some(Box::new(GiveFeedback)), diff --git a/crates/feedback/src/feedback_info_text.rs b/crates/feedback/src/feedback_info_text.rs index 78eb6864b4..fbe97e86cc 100644 --- a/crates/feedback/src/feedback_info_text.rs +++ b/crates/feedback/src/feedback_info_text.rs @@ -43,7 +43,7 @@ impl View for FeedbackInfoText { .boxed(), ) .with_child( - MouseEventHandler::::new(0, cx, |state, _| { + MouseEventHandler::::new(0, cx, |state, _| { let contained_text = if state.hovered() { &theme.feedback.link_text_hover } else { @@ -58,7 +58,7 @@ impl View for FeedbackInfoText { .boxed() }) .with_cursor_style(CursorStyle::PointingHand) - .on_click(MouseButton::Left, |_, cx| { + .on_click(MouseButton::Left, |_, _, cx| { cx.dispatch_action(OpenZedCommunityRepo) }) .boxed(), diff --git a/crates/feedback/src/submit_feedback_button.rs b/crates/feedback/src/submit_feedback_button.rs index 562a0e76ed..21cf9666fb 100644 --- a/crates/feedback/src/submit_feedback_button.rs +++ b/crates/feedback/src/submit_feedback_button.rs @@ -32,7 +32,7 @@ impl View for SubmitFeedbackButton { fn render(&mut self, cx: &mut ViewContext) -> ElementBox { let theme = cx.global::().theme.clone(); enum SubmitFeedbackButton {} - MouseEventHandler::::new(0, cx, |state, _| { + MouseEventHandler::::new(0, cx, |state, _| { let style = theme.feedback.submit_button.style_for(state, false); Label::new("Submit as Markdown", style.text.clone()) .contained() @@ -40,13 +40,13 @@ impl View for SubmitFeedbackButton { .boxed() }) .with_cursor_style(CursorStyle::PointingHand) - .on_click(MouseButton::Left, |_, cx| { + .on_click(MouseButton::Left, |_, _, cx| { cx.dispatch_action(SubmitFeedback) }) .aligned() .contained() .with_margin_left(theme.feedback.button_margin) - .with_tooltip::( + .with_tooltip::( 0, "cmd-s".into(), Some(Box::new(SubmitFeedback)), diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 0a16042126..4caef6fa64 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -3823,6 +3823,94 @@ impl UpdateView for ViewContext<'_, '_, '_, V> { } } +pub struct EventContext<'a, 'b, 'c, 'd, V: View> { + view_context: &'d mut ViewContext<'a, 'b, 'c, V>, + pub(crate) handled: bool, +} + +impl<'a, 'b, 'c, 'd, V: View> EventContext<'a, 'b, 'c, 'd, V> { + pub(crate) fn new(view_context: &'d mut ViewContext<'a, 'b, 'c, V>) -> Self { + EventContext { + view_context, + handled: true, + } + } + + pub fn propagate_event(&mut self) { + self.handled = false; + } +} + +impl<'a, 'b, 'c, 'd, V: View> Deref for EventContext<'a, 'b, 'c, 'd, V> { + type Target = ViewContext<'a, 'b, 'c, V>; + + fn deref(&self) -> &Self::Target { + &self.view_context + } +} + +impl DerefMut for EventContext<'_, '_, '_, '_, V> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.view_context + } +} + +impl UpdateModel for EventContext<'_, '_, '_, '_, V> { + fn update_model( + &mut self, + handle: &ModelHandle, + update: &mut dyn FnMut(&mut T, &mut ModelContext) -> O, + ) -> O { + self.view_context.update_model(handle, update) + } +} + +impl ReadView for EventContext<'_, '_, '_, '_, V> { + fn read_view(&self, handle: &crate::ViewHandle) -> &W { + self.view_context.read_view(handle) + } +} + +impl UpdateView for EventContext<'_, '_, '_, '_, V> { + fn update_view( + &mut self, + handle: &ViewHandle, + update: &mut dyn FnMut(&mut T, &mut ViewContext) -> S, + ) -> S + where + T: View, + { + self.view_context.update_view(handle, update) + } +} + +impl UpgradeModelHandle for EventContext<'_, '_, '_, '_, V> { + fn upgrade_model_handle( + &self, + handle: &WeakModelHandle, + ) -> Option> { + self.view_context.upgrade_model_handle(handle) + } + + fn model_handle_is_upgradable(&self, handle: &WeakModelHandle) -> bool { + self.view_context.model_handle_is_upgradable(handle) + } + + fn upgrade_any_model_handle(&self, handle: &AnyWeakModelHandle) -> Option { + self.view_context.upgrade_any_model_handle(handle) + } +} + +impl UpgradeViewHandle for EventContext<'_, '_, '_, '_, V> { + fn upgrade_view_handle(&self, handle: &WeakViewHandle) -> Option> { + self.view_context.upgrade_view_handle(handle) + } + + fn upgrade_any_view_handle(&self, handle: &AnyWeakViewHandle) -> Option { + self.view_context.upgrade_any_view_handle(handle) + } +} + pub(crate) enum Reference<'a, T> { Immutable(&'a T), Mutable(&'a mut T), diff --git a/crates/gpui/src/elements/mouse_event_handler.rs b/crates/gpui/src/elements/mouse_event_handler.rs index c2c53b8b15..dc82648ef4 100644 --- a/crates/gpui/src/elements/mouse_event_handler.rs +++ b/crates/gpui/src/elements/mouse_event_handler.rs @@ -7,10 +7,11 @@ use crate::{ platform::CursorStyle, platform::MouseButton, scene::{ - CursorRegion, EventContext, HandlerSet, MouseClick, MouseDown, MouseDownOut, MouseDrag, - MouseHover, MouseMove, MouseMoveOut, MouseScrollWheel, MouseUp, MouseUpOut, + CursorRegion, HandlerSet, MouseClick, MouseDown, MouseDownOut, MouseDrag, MouseHover, + MouseMove, MouseMoveOut, MouseScrollWheel, MouseUp, MouseUpOut, }, - Element, ElementBox, MouseRegion, MouseState, SceneBuilder, SizeConstraint, View, ViewContext, + Element, ElementBox, EventContext, MouseRegion, MouseState, SceneBuilder, SizeConstraint, View, + ViewContext, }; use serde_json::json; use std::{marker::PhantomData, ops::Range}; diff --git a/crates/gpui/src/gpui.rs b/crates/gpui/src/gpui.rs index 5e7ee19b5b..147e71b0ce 100644 --- a/crates/gpui/src/gpui.rs +++ b/crates/gpui/src/gpui.rs @@ -15,9 +15,7 @@ pub use clipboard::ClipboardItem; pub mod fonts; pub mod geometry; pub mod scene; -pub use scene::{ - Border, CursorRegion, EventContext, MouseRegion, MouseRegionId, Quad, Scene, SceneBuilder, -}; +pub use scene::{Border, CursorRegion, MouseRegion, MouseRegionId, Quad, Scene, SceneBuilder}; pub mod text_layout; pub use text_layout::TextLayoutCache; mod util; diff --git a/crates/gpui/src/scene/mouse_region.rs b/crates/gpui/src/scene/mouse_region.rs index 601634329c..258583124f 100644 --- a/crates/gpui/src/scene/mouse_region.rs +++ b/crates/gpui/src/scene/mouse_region.rs @@ -1,22 +1,14 @@ +use crate::{platform::MouseButton, window::WindowContext, EventContext, View, ViewContext}; +use collections::HashMap; +use pathfinder_geometry::rect::RectF; +use smallvec::SmallVec; use std::{ any::{Any, TypeId}, fmt::Debug, mem::Discriminant, - ops::{Deref, DerefMut}, rc::Rc, }; -use collections::HashMap; - -use pathfinder_geometry::rect::RectF; -use smallvec::SmallVec; - -use crate::{ - platform::MouseButton, window::WindowContext, AnyModelHandle, AnyViewHandle, - AnyWeakModelHandle, AnyWeakViewHandle, Entity, ModelHandle, ReadView, UpgradeModelHandle, - UpgradeViewHandle, View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle, -}; - use super::{ mouse_event::{ MouseClick, MouseDown, MouseDownOut, MouseDrag, MouseEvent, MouseHover, MouseMove, MouseUp, @@ -206,71 +198,6 @@ impl MouseRegionId { } } -pub struct EventContext<'a, 'b, 'c, 'd, V: View> { - view_context: &'d mut ViewContext<'a, 'b, 'c, V>, - handled: bool, -} - -impl<'a, 'b, 'c, 'd, V: View> EventContext<'a, 'b, 'c, 'd, V> { - fn new(view_context: &'d mut ViewContext<'a, 'b, 'c, V>) -> Self { - EventContext { - view_context, - handled: true, - } - } - - pub fn propagate_event(&mut self) { - self.handled = false; - } -} - -impl<'a, 'b, 'c, 'd, V: View> Deref for EventContext<'a, 'b, 'c, 'd, V> { - type Target = ViewContext<'a, 'b, 'c, V>; - - fn deref(&self) -> &Self::Target { - &self.view_context - } -} - -impl DerefMut for EventContext<'_, '_, '_, '_, V> { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.view_context - } -} - -impl ReadView for EventContext<'_, '_, '_, '_, V> { - fn read_view(&self, handle: &crate::ViewHandle) -> &W { - self.view_context.read_view(handle) - } -} - -impl UpgradeModelHandle for EventContext<'_, '_, '_, '_, V> { - fn upgrade_model_handle( - &self, - handle: &WeakModelHandle, - ) -> Option> { - self.view_context.upgrade_model_handle(handle) - } - - fn model_handle_is_upgradable(&self, handle: &WeakModelHandle) -> bool { - self.view_context.model_handle_is_upgradable(handle) - } - - fn upgrade_any_model_handle(&self, handle: &AnyWeakModelHandle) -> Option { - self.view_context.upgrade_any_model_handle(handle) - } -} - -impl UpgradeViewHandle for EventContext<'_, '_, '_, '_, V> { - fn upgrade_view_handle(&self, handle: &WeakViewHandle) -> Option> { - self.view_context.upgrade_view_handle(handle) - } - - fn upgrade_any_view_handle(&self, handle: &AnyWeakViewHandle) -> Option { - self.view_context.upgrade_any_view_handle(handle) - } -} - pub type HandlerCallback = Rc bool>; #[derive(Clone, PartialEq, Eq, Hash)] diff --git a/crates/gpui/src/views/select.rs b/crates/gpui/src/views/select.rs index dba1b8023b..3786a39d6c 100644 --- a/crates/gpui/src/views/select.rs +++ b/crates/gpui/src/views/select.rs @@ -1,8 +1,8 @@ use serde::Deserialize; use crate::{ - actions, elements::*, impl_actions, platform::MouseButton, AppContext, Entity, View, - ViewContext, WeakViewHandle, + actions, elements::*, impl_actions, platform::MouseButton, AppContext, Entity, EventContext, + View, ViewContext, WeakViewHandle, }; pub struct Select { @@ -116,9 +116,10 @@ impl View for Select { .with_style(style.header) .boxed() }) - .on_click(MouseButton::Left, move |_, _, cx| { - cx.dispatch_action(ToggleSelect) - }) + .on_click( + MouseButton::Left, + move |_, _, cx: &mut EventContext| cx.dispatch_action(ToggleSelect), + ) .boxed(), ); if self.is_open { @@ -150,9 +151,12 @@ impl View for Select { ) }, ) - .on_click(MouseButton::Left, move |_, _, cx| { - cx.dispatch_action(SelectItem(ix)) - }) + .on_click( + MouseButton::Left, + move |_, _, cx: &mut EventContext| { + cx.dispatch_action(SelectItem(ix)) + }, + ) .boxed() })) }, diff --git a/crates/language_selector/src/active_buffer_language.rs b/crates/language_selector/src/active_buffer_language.rs index 87499664ae..5689d9a909 100644 --- a/crates/language_selector/src/active_buffer_language.rs +++ b/crates/language_selector/src/active_buffer_language.rs @@ -50,7 +50,7 @@ impl View for ActiveBufferLanguage { "ActiveBufferLanguage" } - fn render(&mut self, cx: &mut ViewContext) -> ElementBox { + fn render(&mut self, cx: &mut ViewContext) -> ElementBox { if let Some(active_language) = self.active_language.as_ref() { let active_language_text = if let Some(active_language_text) = active_language { active_language_text.to_string() @@ -58,7 +58,7 @@ impl View for ActiveBufferLanguage { "Unknown".to_string() }; - MouseEventHandler::::new(0, cx, |state, cx| { + MouseEventHandler::::new(0, cx, |state, cx| { let theme = &cx.global::().theme.workspace.status_bar; let style = theme.active_language.style_for(state, false); Label::new(active_language_text, style.text.clone()) @@ -67,7 +67,9 @@ impl View for ActiveBufferLanguage { .boxed() }) .with_cursor_style(CursorStyle::PointingHand) - .on_click(MouseButton::Left, |_, cx| cx.dispatch_action(crate::Toggle)) + .on_click(MouseButton::Left, |_, _, cx| { + cx.dispatch_action(crate::Toggle) + }) .boxed() } else { Empty::new().boxed() diff --git a/crates/language_selector/src/language_selector.rs b/crates/language_selector/src/language_selector.rs index 3269fafed0..1eb85a1a25 100644 --- a/crates/language_selector/src/language_selector.rs +++ b/crates/language_selector/src/language_selector.rs @@ -120,7 +120,7 @@ impl View for LanguageSelector { "LanguageSelector" } - fn render(&mut self, cx: &mut ViewContext) -> ElementBox { + fn render(&mut self, cx: &mut ViewContext) -> ElementBox { ChildView::new(&self.picker, cx).boxed() } @@ -210,7 +210,7 @@ impl PickerDelegate for LanguageSelector { mouse_state: &mut MouseState, selected: bool, cx: &AppContext, - ) -> ElementBox { + ) -> ElementBox> { let settings = cx.global::(); let theme = &settings.theme; let mat = &self.matches[ix]; diff --git a/crates/outline/src/outline.rs b/crates/outline/src/outline.rs index c7167b0eb4..f4397b6f1a 100644 --- a/crates/outline/src/outline.rs +++ b/crates/outline/src/outline.rs @@ -48,7 +48,7 @@ impl View for OutlineView { "OutlineView" } - fn render(&mut self, cx: &mut ViewContext) -> ElementBox { + fn render(&mut self, cx: &mut ViewContext) -> ElementBox { ChildView::new(&self.picker, cx).boxed() } @@ -238,7 +238,7 @@ impl PickerDelegate for OutlineView { mouse_state: &mut MouseState, selected: bool, cx: &AppContext, - ) -> ElementBox { + ) -> ElementBox> { let settings = cx.global::(); let string_match = &self.matches[ix]; let style = settings.theme.picker.item.style_for(mouse_state, selected); diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 4cd75e94ec..bfaa74a5ed 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -1251,7 +1251,7 @@ impl ProjectPanel { .as_draggable(entry_id, { let row_container_style = theme.dragged_entry.container; - move |_, _, cx: &mut ViewContext| { + move |_, cx: &mut ViewContext| { let theme = cx.global::().theme.clone(); Self::render_entry_visual_element( &details, diff --git a/crates/project_symbols/src/project_symbols.rs b/crates/project_symbols/src/project_symbols.rs index 3586ff7726..6a5c677d8f 100644 --- a/crates/project_symbols/src/project_symbols.rs +++ b/crates/project_symbols/src/project_symbols.rs @@ -48,7 +48,7 @@ impl View for ProjectSymbolsView { "ProjectSymbolsView" } - fn render(&mut self, cx: &mut ViewContext) -> ElementBox { + fn render(&mut self, cx: &mut ViewContext) -> ElementBox { ChildView::new(&self.picker, cx).boxed() } @@ -238,7 +238,7 @@ impl PickerDelegate for ProjectSymbolsView { mouse_state: &mut MouseState, selected: bool, cx: &AppContext, - ) -> ElementBox { + ) -> ElementBox> { let string_match = &self.matches[ix]; let settings = cx.global::(); let style = &settings.theme.picker.item; diff --git a/crates/recent_projects/src/highlighted_workspace_location.rs b/crates/recent_projects/src/highlighted_workspace_location.rs index a71a7dd2d7..6a7064e35b 100644 --- a/crates/recent_projects/src/highlighted_workspace_location.rs +++ b/crates/recent_projects/src/highlighted_workspace_location.rs @@ -3,7 +3,7 @@ use std::path::Path; use fuzzy::StringMatch; use gpui::{ elements::{Label, LabelStyle}, - Element, ElementBox, + Element, ElementBox, View, }; use workspace::WorkspaceLocation; @@ -42,7 +42,7 @@ impl HighlightedText { } } - pub fn render(self, style: impl Into) -> ElementBox { + pub fn render(self, style: impl Into) -> ElementBox { Label::new(self.text, style) .with_highlights(self.highlight_positions) .boxed() diff --git a/crates/recent_projects/src/recent_projects.rs b/crates/recent_projects/src/recent_projects.rs index ed45b778dd..6e75babae5 100644 --- a/crates/recent_projects/src/recent_projects.rs +++ b/crates/recent_projects/src/recent_projects.rs @@ -101,7 +101,7 @@ impl View for RecentProjectsView { "RecentProjectsView" } - fn render(&mut self, cx: &mut ViewContext) -> ElementBox { + fn render(&mut self, cx: &mut ViewContext) -> ElementBox { ChildView::new(&self.picker, cx).boxed() } @@ -183,7 +183,7 @@ impl PickerDelegate for RecentProjectsView { mouse_state: &mut gpui::MouseState, selected: bool, cx: &gpui::AppContext, - ) -> ElementBox { + ) -> ElementBox> { let settings = cx.global::(); let string_match = &self.matches[ix]; let style = settings.theme.picker.item.style_for(mouse_state, selected); diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index 6506536842..3ce926409b 100644 --- a/crates/terminal_view/src/terminal_element.rs +++ b/crates/terminal_view/src/terminal_element.rs @@ -410,7 +410,7 @@ impl TerminalElement { ), ) // Update drag selections - .on_drag(MouseButton::Left, move |event, _, cx| { + .on_drag(MouseButton::Left, move |event, _: &mut TerminalView, cx| { if cx.is_parent_view_focused() { if let Some(conn_handle) = connection.upgrade(cx) { conn_handle.update(cx, |terminal, cx| { @@ -432,7 +432,7 @@ impl TerminalElement { ), ) // Context menu - .on_click(MouseButton::Right, move |e, _, cx| { + .on_click(MouseButton::Right, move |e, _: &mut TerminalView, cx| { let mouse_mode = if let Some(conn_handle) = connection.upgrade(cx) { conn_handle.update(cx, |terminal, _cx| terminal.mouse_mode(e.shift)) } else { @@ -445,7 +445,7 @@ impl TerminalElement { }); } }) - .on_move(move |event, _, cx| { + .on_move(move |event, _: &mut TerminalView, cx| { if cx.is_parent_view_focused() { if let Some(conn_handle) = connection.upgrade(cx) { conn_handle.update(cx, |terminal, cx| { @@ -455,7 +455,7 @@ impl TerminalElement { } } }) - .on_scroll(move |event, _, cx| { + .on_scroll(move |event, _: &mut TerminalView, cx| { if let Some(conn_handle) = connection.upgrade(cx) { conn_handle.update(cx, |terminal, cx| { terminal.scroll_wheel(event, origin); @@ -598,27 +598,25 @@ impl Element for TerminalElement { }); let view_handle = self.view.clone(); - let hyperlink_tooltip = last_hovered_hyperlink.and_then(|(uri, _, id)| { - // last_mouse.and_then(|_last_mouse| { - view_handle.upgrade(cx).map(|handle| { - let mut tooltip = cx.render(&handle, |_, cx| { - Overlay::new( - Empty::new() - .contained() - .constrained() - .with_width(dimensions.width()) - .with_height(dimensions.height()) - .with_tooltip::(id, uri, None, tooltip_style, cx) - .boxed(), - ) - .with_position_mode(gpui::elements::OverlayPositionMode::Local) - .boxed() - }); + let hyperlink_tooltip = last_hovered_hyperlink.map(|(uri, _, id)| { + let mut tooltip = Overlay::new( + Empty::new() + .contained() + .constrained() + .with_width(dimensions.width()) + .with_height(dimensions.height()) + .with_tooltip::(id, uri, None, tooltip_style, cx) + .boxed(), + ) + .with_position_mode(gpui::elements::OverlayPositionMode::Local) + .boxed(); - tooltip.layout(SizeConstraint::new(Vector2F::zero(), cx.window_size), cx); - tooltip - }) - // }) + tooltip.layout( + SizeConstraint::new(Vector2F::zero(), cx.window_size()), + view, + cx, + ); + tooltip }); let TerminalContent { @@ -647,7 +645,7 @@ impl Element for TerminalElement { cells, &text_style, &terminal_theme, - cx.text_layout_cache, + cx.text_layout_cache(), cx.font_cache(), last_hovered_hyperlink .as_ref() @@ -669,7 +667,7 @@ impl Element for TerminalElement { terminal_theme.foreground }; - cx.text_layout_cache.layout_str( + cx.text_layout_cache().layout_str( &str_trxt, text_style.font_size, &[( @@ -744,11 +742,11 @@ impl Element for TerminalElement { // Elements are ephemeral, only at paint time do we know what could be clicked by a mouse self.attach_mouse_handlers( + scene, origin, self.view.id(), visible_bounds, layout.mode, - view, cx, ); diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 6a68bfc7dd..5be91c9351 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -396,7 +396,7 @@ impl View for TerminalView { Stack::new() .with_child( TerminalElement::new( - cx.handle(), + cx.handle().downgrade(), terminal_handle, focused, self.should_show_cursor(focused, cx), diff --git a/crates/theme/src/ui.rs b/crates/theme/src/ui.rs index 093b990d7b..c1b420d5ac 100644 --- a/crates/theme/src/ui.rs +++ b/crates/theme/src/ui.rs @@ -175,7 +175,7 @@ pub fn keystroke_label_for( pub type ButtonStyle = Interactive; -pub fn cta_button( +pub fn cta_button( label: L, action: A, max_width: f32, @@ -183,12 +183,11 @@ pub fn cta_button( cx: &mut ViewContext, ) -> ElementBox where - Tag: 'static, L: Into>, A: 'static + Action + Clone, V: View, { - cta_button_with_click::(label, max_width, style, cx, move |_, _, cx| { + cta_button_with_click::(label, max_width, style, cx, move |_, _, cx| { cx.dispatch_action(action.clone()) }) .boxed() diff --git a/crates/vim/src/normal.rs b/crates/vim/src/normal.rs index ad55c87576..3147fb6cf9 100644 --- a/crates/vim/src/normal.rs +++ b/crates/vim/src/normal.rs @@ -251,7 +251,7 @@ fn paste(_: &mut Workspace, _: &Paste, cx: &mut ViewContext) { vim.update_active_editor(cx, |editor, cx| { editor.transact(cx, |editor, cx| { editor.set_clip_at_line_ends(false, cx); - if let Some(item) = cx.as_mut().read_from_clipboard() { + if let Some(item) = cx.read_from_clipboard() { let mut clipboard_text = Cow::Borrowed(item.text()); if let Some(mut clipboard_selections) = item.metadata::>() diff --git a/crates/vim/src/visual.rs b/crates/vim/src/visual.rs index cd4f956df1..1e8d02e063 100644 --- a/crates/vim/src/visual.rs +++ b/crates/vim/src/visual.rs @@ -209,7 +209,7 @@ pub fn paste(_: &mut Workspace, _: &VisualPaste, cx: &mut ViewContext Vim::update(cx, |vim, cx| { vim.update_active_editor(cx, |editor, cx| { editor.transact(cx, |editor, cx| { - if let Some(item) = cx.as_mut().read_from_clipboard() { + if let Some(item) = cx.read_from_clipboard() { copy_selections_content(editor, editor.selections.line_mode, cx); let mut clipboard_text = Cow::Borrowed(item.text()); if let Some(mut clipboard_selections) = diff --git a/crates/welcome/src/base_keymap_picker.rs b/crates/welcome/src/base_keymap_picker.rs index be516ed038..9ce36c49be 100644 --- a/crates/welcome/src/base_keymap_picker.rs +++ b/crates/welcome/src/base_keymap_picker.rs @@ -161,7 +161,7 @@ impl PickerDelegate for BaseKeymapSelector { mouse_state: &mut gpui::MouseState, selected: bool, cx: &gpui::AppContext, - ) -> gpui::ElementBox { + ) -> gpui::ElementBox> { let theme = &cx.global::().theme; let keymap_match = &self.matches[ix]; let style = theme.picker.item.style_for(mouse_state, selected); diff --git a/crates/welcome/src/welcome.rs b/crates/welcome/src/welcome.rs index 3505884fb2..fc726db912 100644 --- a/crates/welcome/src/welcome.rs +++ b/crates/welcome/src/welcome.rs @@ -10,7 +10,7 @@ use gpui::{ use settings::{settings_file::SettingsFile, Settings}; use workspace::{ - item::Item, open_new, sidebar::SidebarSide, AppState, PaneBackdrop, Welcome, Workspace, + item::Item, open_new, sidebar::SidebarSide, AppState, Pane, PaneBackdrop, Welcome, Workspace, WorkspaceId, }; @@ -55,7 +55,7 @@ impl View for WelcomePage { "WelcomePage" } - fn render(&mut self, cx: &mut gpui::ViewContext) -> ElementBox { + fn render(&mut self, cx: &mut gpui::ViewContext) -> ElementBox { let self_handle = cx.handle(); let settings = cx.global::(); let theme = settings.theme.clone(); @@ -203,7 +203,7 @@ impl Item for WelcomePage { _detail: Option, style: &theme::Tab, _cx: &gpui::AppContext, - ) -> gpui::ElementBox { + ) -> ElementBox { Flex::row() .with_child( Label::new("Welcome to Zed!", style.label.clone()) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 9f67991f5e..2b12316a25 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1851,13 +1851,13 @@ impl NavHistory { } } -pub struct PaneBackdrop { +pub struct PaneBackdrop { child_view: usize, - child: ElementBox, + child: ElementBox, } -impl PaneBackdrop { - pub fn new(pane_item_view: usize, child: ElementBox) -> Self { +impl PaneBackdrop { + pub fn new(pane_item_view: usize, child: ElementBox) -> Self { PaneBackdrop { child, child_view: pane_item_view, @@ -1865,7 +1865,7 @@ impl PaneBackdrop { } } -impl Element for PaneBackdrop { +impl Element for PaneBackdrop { type LayoutState = (); type PaintState = (); @@ -1873,8 +1873,8 @@ impl Element for PaneBackdrop { fn layout( &mut self, constraint: gpui::SizeConstraint, - view: &mut Pane, - cx: &mut ViewContext, + view: &mut V, + cx: &mut ViewContext, ) -> (Vector2F, Self::LayoutState) { let size = self.child.layout(constraint, view, cx); (size, ()) @@ -1886,8 +1886,8 @@ impl Element for PaneBackdrop { bounds: RectF, visible_bounds: RectF, _: &mut Self::LayoutState, - view: &mut Pane, - cx: &mut ViewContext, + view: &mut V, + cx: &mut ViewContext, ) -> Self::PaintState { let background = cx.global::().theme.editor.background; @@ -1903,7 +1903,7 @@ impl Element for PaneBackdrop { scene.push_mouse_region( MouseRegion::new::(child_view_id, 0, visible_bounds).on_down( gpui::platform::MouseButton::Left, - move |_, _: &mut Pane, cx| { + move |_, _: &mut V, cx| { let window_id = cx.window_id(); cx.app_context().focus(window_id, Some(child_view_id)) }, @@ -1923,8 +1923,8 @@ impl Element for PaneBackdrop { _visible_bounds: RectF, _layout: &Self::LayoutState, _paint: &Self::PaintState, - view: &Pane, - cx: &gpui::ViewContext, + view: &V, + cx: &gpui::ViewContext, ) -> Option { self.child.rect_for_text_range(range_utf16, view, cx) } @@ -1934,8 +1934,8 @@ impl Element for PaneBackdrop { _bounds: RectF, _layout: &Self::LayoutState, _paint: &Self::PaintState, - view: &Pane, - cx: &gpui::ViewContext, + view: &V, + cx: &gpui::ViewContext, ) -> serde_json::Value { gpui::json::json!({ "type": "Pane Back Drop",