Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Merge remote-tracking branch 'origin/main' into paint-context

Nathan Sobodb96fb130775
diff --cc crates/gpui/src/app.rs
index fd22dc466e2,8682e6c9dd6..2a9d9f47687
--- a/crates/gpui/src/app.rs
+++ b/crates/gpui/src/app.rs
@@@ -3485,72 -3485,6 +3506,94 @@@ impl<V: View> BorrowWindowContext for L
}
}
+pub struct PaintContext<'a, 'b, 'c, V: View> {
+ view_context: &'c mut ViewContext<'a, 'b, V>,
+ text_style_stack: Vec<Arc<TextStyle>>,
+}
+
+impl<'a, 'b, 'c, V: View> PaintContext<'a, 'b, 'c, V> {
+ pub fn new(view_context: &'c mut ViewContext<'a, 'b, V>) -> Self {
+ Self {
+ view_context,
+ text_style_stack: Vec::new(),
+ }
+ }
+
+ pub fn text_style(&self) -> Arc<TextStyle> {
+ self.text_style_stack
+ .last()
+ .cloned()
+ .unwrap_or(Default::default())
+ }
+
+ pub fn with_text_style<S, F, T>(&mut self, style: S, f: F) -> T
+ where
+ S: Into<Arc<TextStyle>>,
+ F: FnOnce(&mut Self) -> T,
+ {
+ self.text_style_stack.push(style.into());
+ let result = f(self);
+ self.text_style_stack.pop();
+ result
+ }
+}
+
+impl<'a, 'b, 'c, V: View> Deref for PaintContext<'a, 'b, 'c, V> {
+ type Target = ViewContext<'a, 'b, V>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.view_context
+ }
+}
+
+impl<V: View> DerefMut for PaintContext<'_, '_, '_, V> {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.view_context
+ }
+}
+
+impl<V: View> BorrowAppContext for PaintContext<'_, '_, '_, V> {
+ fn read_with<T, F: FnOnce(&AppContext) -> T>(&self, f: F) -> T {
+ BorrowAppContext::read_with(&*self.view_context, f)
+ }
+
+ fn update<T, F: FnOnce(&mut AppContext) -> T>(&mut self, f: F) -> T {
+ BorrowAppContext::update(&mut *self.view_context, f)
+ }
+}
+
+impl<V: View> BorrowWindowContext for PaintContext<'_, '_, '_, V> {
- fn read_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
- BorrowWindowContext::read_with(&*self.view_context, window_id, f)
++ type Result<T> = T;
++
++ fn read_window<T, F>(&self, window: AnyWindowHandle, f: F) -> Self::Result<T>
++ where
++ F: FnOnce(&WindowContext) -> T,
++ {
++ BorrowWindowContext::read_window(self.view_context, window, f)
+ }
+
- fn update<T, F: FnOnce(&mut WindowContext) -> T>(&mut self, window_id: usize, f: F) -> T {
- BorrowWindowContext::update(&mut *self.view_context, window_id, f)
++ fn read_window_optional<T, F>(&self, window: AnyWindowHandle, f: F) -> Option<T>
++ where
++ F: FnOnce(&WindowContext) -> Option<T>,
++ {
++ BorrowWindowContext::read_window_optional(self.view_context, window, f)
++ }
++
++ fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Self::Result<T>
++ where
++ F: FnOnce(&mut WindowContext) -> T,
++ {
++ BorrowWindowContext::update_window(self.view_context, window, f)
++ }
++
++ fn update_window_optional<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Option<T>
++ where
++ F: FnOnce(&mut WindowContext) -> Option<T>,
++ {
++ BorrowWindowContext::update_window_optional(self.view_context, window, f)
+ }
+}
+
pub struct EventContext<'a, 'b, 'c, V: View> {
view_context: &'c mut ViewContext<'a, 'b, V>,
pub(crate) handled: bool,
diff --cc crates/gpui/src/app/window.rs
index c6ab7c6ebb2,1012d7e77ec..51eb3b8fa61
--- a/crates/gpui/src/app/window.rs
+++ b/crates/gpui/src/app/window.rs
@@@ -13,9 -13,9 +13,10 @@@ use crate::
},
text_layout::TextLayoutCache,
util::post_inc,
- Action, AnyView, AnyViewHandle, AppContext, BorrowAppContext, BorrowWindowContext, Effect,
- Element, Entity, Handle, LayoutContext, MouseRegion, MouseRegionId, PaintContext, SceneBuilder,
- Subscription, View, ViewContext, ViewHandle, WindowInvalidation,
+ Action, AnyView, AnyViewHandle, AnyWindowHandle, AppContext, BorrowAppContext,
+ BorrowWindowContext, Effect, Element, Entity, Handle, LayoutContext, MouseRegion,
- MouseRegionId, SceneBuilder, Subscription, View, ViewContext, ViewHandle, WindowInvalidation,
++ MouseRegionId, PaintContext, SceneBuilder, Subscription, View, ViewContext, ViewHandle,
++ WindowInvalidation,
};
use anyhow::{anyhow, bail, Result};
use collections::{HashMap, HashSet};
diff --cc crates/workspace/src/pane_group.rs
index 4a90d92b350,3d7032c1487..dfda5092ca6
--- a/crates/workspace/src/pane_group.rs
+++ b/crates/workspace/src/pane_group.rs
@@@ -593,8 -593,9 +593,9 @@@ mod element
},
json::{self, ToJson},
platform::{CursorStyle, MouseButton},
- AnyElement, Axis, CursorRegion, Element, LayoutContext, MouseRegion, PaintContext,
- RectFExt, SceneBuilder, SizeConstraint, Vector2FExt, ViewContext,
+ scene::MouseDrag,
+ AnyElement, Axis, CursorRegion, Element, EventContext, LayoutContext, MouseRegion,
- RectFExt, SceneBuilder, SizeConstraint, Vector2FExt, ViewContext,
++ PaintContext, RectFExt, SceneBuilder, SizeConstraint, Vector2FExt, ViewContext,
};
use crate::{