Rename context parameters to `cx` in gpui

Max Brunsfeld created

Change summary

gpui/examples/text.rs                    |  20 
gpui/src/app.rs                          | 345 ++++++++++++-------------
gpui/src/elements.rs                     |  58 ++--
gpui/src/elements/align.rs               |  20 
gpui/src/elements/canvas.rs              |   4 
gpui/src/elements/constrained_box.rs     |  20 
gpui/src/elements/container.rs           |  24 
gpui/src/elements/event_handler.rs       |  22 
gpui/src/elements/flex.rs                |  42 +-
gpui/src/elements/label.rs               |  28 +-
gpui/src/elements/line_box.rs            |  30 +-
gpui/src/elements/mouse_event_handler.rs |  36 +-
gpui/src/elements/stack.rs               |  24 
gpui/src/elements/svg.rs                 |   8 
gpui/src/elements/uniform_list.rs        |  36 +-
gpui/src/keymap.rs                       |  36 +-
gpui/src/platform/mac/fonts.rs           |  12 
gpui/src/presenter.rs                    |  96 +++---
gpui/src/text_layout.rs                  |   6 
gpui_macros/src/lib.rs                   |   8 
20 files changed, 434 insertions(+), 441 deletions(-)

Detailed changes

gpui/examples/text.rs 🔗

@@ -10,9 +10,9 @@ use simplelog::SimpleLogger;
 fn main() {
     SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
 
-    gpui::App::new(()).unwrap().run(|ctx| {
-        ctx.platform().activate(true);
-        ctx.add_window(|_| TextView);
+    gpui::App::new(()).unwrap().run(|cx| {
+        cx.platform().activate(true);
+        cx.add_window(|_| TextView);
     });
 }
 
@@ -58,15 +58,15 @@ impl gpui::Element for TextElement {
         &mut self,
         bounds: RectF,
         _: &mut Self::LayoutState,
-        ctx: &mut gpui::PaintContext,
+        cx: &mut gpui::PaintContext,
     ) -> Self::PaintState {
         let font_size = 12.;
-        let family = ctx.font_cache.load_family(&["SF Pro Display"]).unwrap();
-        let normal = ctx
+        let family = cx.font_cache.load_family(&["SF Pro Display"]).unwrap();
+        let normal = cx
             .font_cache
             .select_font(family, &Default::default())
             .unwrap();
-        let bold = ctx
+        let bold = cx
             .font_cache
             .select_font(
                 family,
@@ -78,7 +78,7 @@ impl gpui::Element for TextElement {
             .unwrap();
 
         let text = "Hello world!";
-        let line = ctx.text_layout_cache.layout_str(
+        let line = cx.text_layout_cache.layout_str(
             text,
             font_size,
             &[
@@ -90,12 +90,12 @@ impl gpui::Element for TextElement {
             ],
         );
 
-        ctx.scene.push_quad(Quad {
+        cx.scene.push_quad(Quad {
             bounds: bounds,
             background: Some(ColorU::white()),
             ..Default::default()
         });
-        line.paint(bounds.origin(), bounds, ctx);
+        line.paint(bounds.origin(), bounds, cx);
     }
 
     fn dispatch_event(

gpui/src/app.rs 🔗

@@ -34,16 +34,16 @@ pub trait Entity: 'static + Send + Sync {
 
 pub trait View: Entity {
     fn ui_name() -> &'static str;
-    fn render<'a>(&self, app: &AppContext) -> ElementBox;
-    fn on_focus(&mut self, _ctx: &mut ViewContext<Self>) {}
-    fn on_blur(&mut self, _ctx: &mut ViewContext<Self>) {}
+    fn render<'a>(&self, cx: &AppContext) -> ElementBox;
+    fn on_focus(&mut self, _: &mut ViewContext<Self>) {}
+    fn on_blur(&mut self, _: &mut ViewContext<Self>) {}
     fn keymap_context(&self, _: &AppContext) -> keymap::Context {
         Self::default_keymap_context()
     }
     fn default_keymap_context() -> keymap::Context {
-        let mut ctx = keymap::Context::default();
-        ctx.set.insert(Self::ui_name().into());
-        ctx
+        let mut cx = keymap::Context::default();
+        cx.set.insert(Self::ui_name().into());
+        cx
     }
 }
 
@@ -114,14 +114,14 @@ impl App {
     ) -> T {
         let platform = platform::test::platform();
         let foreground = Rc::new(executor::Foreground::test());
-        let ctx = Rc::new(RefCell::new(MutableAppContext::new(
+        let cx = Rc::new(RefCell::new(MutableAppContext::new(
             foreground,
             Rc::new(platform),
             asset_source,
         )));
-        ctx.borrow_mut().weak_self = Some(Rc::downgrade(&ctx));
-        let mut ctx = ctx.borrow_mut();
-        f(&mut *ctx)
+        cx.borrow_mut().weak_self = Some(Rc::downgrade(&cx));
+        let mut cx = cx.borrow_mut();
+        f(&mut *cx)
     }
 
     pub fn test_async<T, F, A: AssetSource, Fn>(asset_source: A, f: Fn) -> T
@@ -131,7 +131,7 @@ impl App {
     {
         let platform = Rc::new(platform::test::platform());
         let foreground = Rc::new(executor::Foreground::test());
-        let ctx = TestAppContext(
+        let cx = TestAppContext(
             Rc::new(RefCell::new(MutableAppContext::new(
                 foreground.clone(),
                 platform.clone(),
@@ -139,9 +139,9 @@ impl App {
             ))),
             platform,
         );
-        ctx.0.borrow_mut().weak_self = Some(Rc::downgrade(&ctx.0));
+        cx.0.borrow_mut().weak_self = Some(Rc::downgrade(&cx.0));
 
-        let future = f(ctx);
+        let future = f(cx);
         smol::block_on(foreground.run(future))
     }
 
@@ -154,21 +154,20 @@ impl App {
             asset_source,
         ))));
 
-        let ctx = app.0.clone();
+        let cx = app.0.clone();
         platform.on_menu_command(Box::new(move |command, arg| {
-            let mut ctx = ctx.borrow_mut();
-            if let Some(key_window_id) = ctx.platform.key_window_id() {
-                if let Some((presenter, _)) =
-                    ctx.presenters_and_platform_windows.get(&key_window_id)
+            let mut cx = cx.borrow_mut();
+            if let Some(key_window_id) = cx.platform.key_window_id() {
+                if let Some((presenter, _)) = cx.presenters_and_platform_windows.get(&key_window_id)
                 {
                     let presenter = presenter.clone();
-                    let path = presenter.borrow().dispatch_path(ctx.as_ref());
-                    ctx.dispatch_action_any(key_window_id, &path, command, arg.unwrap_or(&()));
+                    let path = presenter.borrow().dispatch_path(cx.as_ref());
+                    cx.dispatch_action_any(key_window_id, &path, command, arg.unwrap_or(&()));
                 } else {
-                    ctx.dispatch_global_action_any(command, arg.unwrap_or(&()));
+                    cx.dispatch_global_action_any(command, arg.unwrap_or(&()));
                 }
             } else {
-                ctx.dispatch_global_action_any(command, arg.unwrap_or(&()));
+                cx.dispatch_global_action_any(command, arg.unwrap_or(&()));
             }
         }));
 
@@ -180,11 +179,11 @@ impl App {
     where
         F: 'static + FnMut(&mut MutableAppContext),
     {
-        let ctx = self.0.clone();
+        let cx = self.0.clone();
         self.0
             .borrow()
             .platform
-            .on_become_active(Box::new(move || callback(&mut *ctx.borrow_mut())));
+            .on_become_active(Box::new(move || callback(&mut *cx.borrow_mut())));
         self
     }
 
@@ -192,11 +191,11 @@ impl App {
     where
         F: 'static + FnMut(&mut MutableAppContext),
     {
-        let ctx = self.0.clone();
+        let cx = self.0.clone();
         self.0
             .borrow()
             .platform
-            .on_resign_active(Box::new(move || callback(&mut *ctx.borrow_mut())));
+            .on_resign_active(Box::new(move || callback(&mut *cx.borrow_mut())));
         self
     }
 
@@ -204,9 +203,9 @@ impl App {
     where
         F: 'static + FnMut(Event, &mut MutableAppContext) -> bool,
     {
-        let ctx = self.0.clone();
+        let cx = self.0.clone();
         self.0.borrow().platform.on_event(Box::new(move |event| {
-            callback(event, &mut *ctx.borrow_mut())
+            callback(event, &mut *cx.borrow_mut())
         }));
         self
     }
@@ -215,12 +214,12 @@ impl App {
     where
         F: 'static + FnMut(Vec<PathBuf>, &mut MutableAppContext),
     {
-        let ctx = self.0.clone();
+        let cx = self.0.clone();
         self.0
             .borrow()
             .platform
             .on_open_files(Box::new(move |paths| {
-                callback(paths, &mut *ctx.borrow_mut())
+                callback(paths, &mut *cx.borrow_mut())
             }));
         self
     }
@@ -231,13 +230,13 @@ impl App {
     {
         let platform = self.0.borrow().platform.clone();
         platform.run(Box::new(move || {
-            let mut ctx = self.0.borrow_mut();
-            on_finish_launching(&mut *ctx);
+            let mut cx = self.0.borrow_mut();
+            on_finish_launching(&mut *cx);
         }))
     }
 
     pub fn font_cache(&self) -> Arc<FontCache> {
-        self.0.borrow().ctx.font_cache.clone()
+        self.0.borrow().cx.font_cache.clone()
     }
 
     fn update<T, F: FnOnce(&mut MutableAppContext) -> T>(&mut self, callback: F) -> T {
@@ -347,7 +346,7 @@ impl TestAppContext {
     }
 
     pub fn font_cache(&self) -> Arc<FontCache> {
-        self.0.borrow().ctx.font_cache.clone()
+        self.0.borrow().cx.font_cache.clone()
     }
 
     pub fn platform(&self) -> Rc<dyn platform::Platform> {
@@ -398,11 +397,11 @@ impl AsyncAppContext {
         T: Entity,
         F: FnOnce(&mut ModelContext<T>) -> T,
     {
-        self.update(|ctx| ctx.add_model(build_model))
+        self.update(|cx| cx.add_model(build_model))
     }
 
     pub fn background_executor(&self) -> Arc<executor::Background> {
-        self.0.borrow().ctx.background.clone()
+        self.0.borrow().cx.background.clone()
     }
 }
 
@@ -426,9 +425,9 @@ impl ReadModelWith for AsyncAppContext {
         handle: &ModelHandle<E>,
         read: F,
     ) -> T {
-        let ctx = self.0.borrow();
-        let ctx = ctx.as_ref();
-        read(handle.read(ctx), ctx)
+        let cx = self.0.borrow();
+        let cx = cx.as_ref();
+        read(handle.read(cx), cx)
     }
 }
 
@@ -452,9 +451,9 @@ impl ReadViewWith for AsyncAppContext {
         V: View,
         F: FnOnce(&V, &AppContext) -> T,
     {
-        let ctx = self.0.borrow();
-        let ctx = ctx.as_ref();
-        read(handle.read(ctx), ctx)
+        let cx = self.0.borrow();
+        let cx = cx.as_ref();
+        read(handle.read(cx), cx)
     }
 }
 
@@ -478,9 +477,9 @@ impl ReadModelWith for TestAppContext {
         handle: &ModelHandle<E>,
         read: F,
     ) -> T {
-        let ctx = self.0.borrow();
-        let ctx = ctx.as_ref();
-        read(handle.read(ctx), ctx)
+        let cx = self.0.borrow();
+        let cx = cx.as_ref();
+        read(handle.read(cx), cx)
     }
 }
 
@@ -504,9 +503,9 @@ impl ReadViewWith for TestAppContext {
         V: View,
         F: FnOnce(&V, &AppContext) -> T,
     {
-        let ctx = self.0.borrow();
-        let ctx = ctx.as_ref();
-        read(handle.read(ctx), ctx)
+        let cx = self.0.borrow();
+        let cx = cx.as_ref();
+        read(handle.read(cx), cx)
     }
 }
 
@@ -519,7 +518,7 @@ pub struct MutableAppContext {
     weak_self: Option<rc::Weak<RefCell<Self>>>,
     platform: Rc<dyn platform::Platform>,
     assets: Arc<AssetCache>,
-    ctx: AppContext,
+    cx: AppContext,
     actions: HashMap<TypeId, HashMap<String, Vec<Box<ActionCallback>>>>,
     global_actions: HashMap<String, Vec<Box<GlobalActionCallback>>>,
     keystroke_matcher: keymap::Matcher,
@@ -548,7 +547,7 @@ impl MutableAppContext {
             weak_self: None,
             platform,
             assets: Arc::new(AssetCache::new(asset_source)),
-            ctx: AppContext {
+            cx: AppContext {
                 models: Default::default(),
                 views: Default::default(),
                 windows: Default::default(),
@@ -584,7 +583,7 @@ impl MutableAppContext {
     }
 
     pub fn font_cache(&self) -> &Arc<FontCache> {
-        &self.ctx.font_cache
+        &self.cx.font_cache
     }
 
     pub fn foreground_executor(&self) -> &Rc<executor::Foreground> {
@@ -592,7 +591,7 @@ impl MutableAppContext {
     }
 
     pub fn background_executor(&self) -> &Arc<executor::Background> {
-        &self.ctx.background
+        &self.cx.background
     }
 
     pub fn on_debug_elements<F>(&mut self, window_id: usize, callback: F)
@@ -606,7 +605,7 @@ impl MutableAppContext {
     pub fn debug_elements(&self, window_id: usize) -> Option<crate::json::Value> {
         self.debug_elements_callbacks
             .get(&window_id)
-            .map(|debug_elements| debug_elements(&self.ctx))
+            .map(|debug_elements| debug_elements(&self.cx))
     }
 
     pub fn add_action<S, V, T, F>(&mut self, name: S, mut handler: F)
@@ -621,20 +620,20 @@ impl MutableAppContext {
         let handler = Box::new(
             move |view: &mut dyn AnyView,
                   arg: &dyn Any,
-                  app: &mut MutableAppContext,
+                  cx: &mut MutableAppContext,
                   window_id: usize,
                   view_id: usize| {
                 match arg.downcast_ref() {
                     Some(arg) => {
-                        let mut ctx = ViewContext::new(app, window_id, view_id);
+                        let mut cx = ViewContext::new(cx, window_id, view_id);
                         handler(
                             view.as_any_mut()
                                 .downcast_mut()
                                 .expect("downcast is type safe"),
                             arg,
-                            &mut ctx,
+                            &mut cx,
                         );
-                        ctx.halt_action_dispatch
+                        cx.halt_action_dispatch
                     }
                     None => {
                         log::error!("Could not downcast argument for action {}", name_clone);
@@ -660,9 +659,9 @@ impl MutableAppContext {
     {
         let name = name.into();
         let name_clone = name.clone();
-        let handler = Box::new(move |arg: &dyn Any, app: &mut MutableAppContext| {
+        let handler = Box::new(move |arg: &dyn Any, cx: &mut MutableAppContext| {
             if let Some(arg) = arg.downcast_ref() {
-                handler(arg, app);
+                handler(arg, cx);
             } else {
                 log::error!("Could not downcast argument for action {}", name_clone);
             }
@@ -672,30 +671,30 @@ impl MutableAppContext {
     }
 
     pub fn window_ids(&self) -> impl Iterator<Item = usize> + '_ {
-        self.ctx.windows.keys().cloned()
+        self.cx.windows.keys().cloned()
     }
 
     pub fn root_view<T: View>(&self, window_id: usize) -> Option<ViewHandle<T>> {
-        self.ctx
+        self.cx
             .windows
             .get(&window_id)
             .and_then(|window| window.root_view.clone().downcast::<T>())
     }
 
     pub fn root_view_id(&self, window_id: usize) -> Option<usize> {
-        self.ctx.root_view_id(window_id)
+        self.cx.root_view_id(window_id)
     }
 
     pub fn focused_view_id(&self, window_id: usize) -> Option<usize> {
-        self.ctx.focused_view_id(window_id)
+        self.cx.focused_view_id(window_id)
     }
 
     pub fn render_view(&self, window_id: usize, view_id: usize) -> Result<ElementBox> {
-        self.ctx.render_view(window_id, view_id)
+        self.cx.render_view(window_id, view_id)
     }
 
     pub fn render_views(&self, window_id: usize) -> HashMap<usize, ElementBox> {
-        self.ctx.render_views(window_id)
+        self.cx.render_views(window_id)
     }
 
     pub fn update<T, F: FnOnce() -> T>(&mut self, callback: F) -> T {
@@ -792,7 +791,7 @@ impl MutableAppContext {
         let mut halted_dispatch = false;
 
         for view_id in path.iter().rev() {
-            if let Some(mut view) = self.ctx.views.remove(&(window_id, *view_id)) {
+            if let Some(mut view) = self.cx.views.remove(&(window_id, *view_id)) {
                 let type_id = view.as_any().type_id();
 
                 if let Some((name, mut handlers)) = self
@@ -813,7 +812,7 @@ impl MutableAppContext {
                         .insert(name, handlers);
                 }
 
-                self.ctx.views.insert((window_id, *view_id), view);
+                self.cx.views.insert((window_id, *view_id), view);
 
                 if halted_dispatch {
                     break;
@@ -857,7 +856,7 @@ impl MutableAppContext {
         let mut context_chain = Vec::new();
         let mut context = keymap::Context::default();
         for view_id in &responder_chain {
-            if let Some(view) = self.ctx.views.get(&(window_id, *view_id)) {
+            if let Some(view) = self.cx.views.get(&(window_id, *view_id)) {
                 context.extend(view.keymap_context(self.as_ref()));
                 context_chain.push(context.clone());
             } else {
@@ -869,10 +868,10 @@ impl MutableAppContext {
         }
 
         let mut pending = false;
-        for (i, ctx) in context_chain.iter().enumerate().rev() {
+        for (i, cx) in context_chain.iter().enumerate().rev() {
             match self
                 .keystroke_matcher
-                .push_keystroke(keystroke.clone(), responder_chain[i], ctx)
+                .push_keystroke(keystroke.clone(), responder_chain[i], cx)
             {
                 MatchResult::None => {}
                 MatchResult::Pending => pending = true,
@@ -899,10 +898,10 @@ impl MutableAppContext {
     {
         self.pending_flushes += 1;
         let model_id = post_inc(&mut self.next_entity_id);
-        let handle = ModelHandle::new(model_id, &self.ctx.ref_counts);
-        let mut ctx = ModelContext::new(self, model_id);
-        let model = build_model(&mut ctx);
-        self.ctx.models.insert(model_id, Box::new(model));
+        let handle = ModelHandle::new(model_id, &self.cx.ref_counts);
+        let mut cx = ModelContext::new(self, model_id);
+        let model = build_model(&mut cx);
+        self.cx.models.insert(model_id, Box::new(model));
         self.flush_effects();
         handle
     }
@@ -916,7 +915,7 @@ impl MutableAppContext {
         let window_id = post_inc(&mut self.next_window_id);
         let root_view = self.add_view(window_id, build_root_view);
 
-        self.ctx.windows.insert(
+        self.cx.windows.insert(
             window_id,
             Window {
                 root_view: root_view.clone().into(),
@@ -925,14 +924,14 @@ impl MutableAppContext {
             },
         );
         self.open_platform_window(window_id);
-        root_view.update(self, |view, ctx| view.on_focus(ctx));
+        root_view.update(self, |view, cx| view.on_focus(cx));
         self.flush_effects();
 
         (window_id, root_view)
     }
 
     pub fn remove_window(&mut self, window_id: usize) {
-        self.ctx.windows.remove(&window_id);
+        self.cx.windows.remove(&window_id);
         self.presenters_and_platform_windows.remove(&window_id);
         self.remove_dropped_entities();
     }
@@ -949,7 +948,7 @@ impl MutableAppContext {
         let text_layout_cache = TextLayoutCache::new(self.platform.fonts());
         let presenter = Rc::new(RefCell::new(Presenter::new(
             window_id,
-            self.ctx.font_cache.clone(),
+            self.cx.font_cache.clone(),
             text_layout_cache,
             self.assets.clone(),
             self,
@@ -959,12 +958,12 @@ impl MutableAppContext {
             let mut app = self.upgrade();
             let presenter = presenter.clone();
             window.on_event(Box::new(move |event| {
-                app.update(|ctx| {
+                app.update(|cx| {
                     if let Event::KeyDown { keystroke, .. } = &event {
-                        if ctx
+                        if cx
                             .dispatch_keystroke(
                                 window_id,
-                                presenter.borrow().dispatch_path(ctx.as_ref()),
+                                presenter.borrow().dispatch_path(cx.as_ref()),
                                 keystroke,
                             )
                             .unwrap()
@@ -973,7 +972,7 @@ impl MutableAppContext {
                         }
                     }
 
-                    presenter.borrow_mut().dispatch_event(event, ctx);
+                    presenter.borrow_mut().dispatch_event(event, cx);
                 })
             }));
         }
@@ -982,11 +981,11 @@ impl MutableAppContext {
             let mut app = self.upgrade();
             let presenter = presenter.clone();
             window.on_resize(Box::new(move |window| {
-                app.update(|ctx| {
+                app.update(|cx| {
                     let scene = presenter.borrow_mut().build_scene(
                         window.size(),
                         window.scale_factor(),
-                        ctx,
+                        cx,
                     );
                     window.present_scene(scene);
                 })
@@ -996,15 +995,15 @@ impl MutableAppContext {
         {
             let mut app = self.upgrade();
             window.on_close(Box::new(move || {
-                app.update(|ctx| ctx.remove_window(window_id));
+                app.update(|cx| cx.remove_window(window_id));
             }));
         }
 
         self.presenters_and_platform_windows
             .insert(window_id, (presenter.clone(), window));
 
-        self.on_debug_elements(window_id, move |ctx| {
-            presenter.borrow().debug_elements(ctx).unwrap()
+        self.on_debug_elements(window_id, move |cx| {
+            presenter.borrow().debug_elements(cx).unwrap()
         });
     }
 
@@ -1013,7 +1012,7 @@ impl MutableAppContext {
         T: View,
         F: FnOnce(&mut ViewContext<T>) -> T,
     {
-        self.add_option_view(window_id, |ctx| Some(build_view(ctx)))
+        self.add_option_view(window_id, |cx| Some(build_view(cx)))
             .unwrap()
     }
 
@@ -1028,11 +1027,11 @@ impl MutableAppContext {
     {
         let view_id = post_inc(&mut self.next_entity_id);
         self.pending_flushes += 1;
-        let handle = ViewHandle::new(window_id, view_id, &self.ctx.ref_counts);
-        let mut ctx = ViewContext::new(self, window_id, view_id);
-        let handle = if let Some(view) = build_view(&mut ctx) {
-            self.ctx.views.insert((window_id, view_id), Box::new(view));
-            if let Some(window) = self.ctx.windows.get_mut(&window_id) {
+        let handle = ViewHandle::new(window_id, view_id, &self.cx.ref_counts);
+        let mut cx = ViewContext::new(self, window_id, view_id);
+        let handle = if let Some(view) = build_view(&mut cx) {
+            self.cx.views.insert((window_id, view_id), Box::new(view));
+            if let Some(window) = self.cx.windows.get_mut(&window_id) {
                 window
                     .invalidation
                     .get_or_insert_with(Default::default)
@@ -1050,13 +1049,13 @@ impl MutableAppContext {
     fn remove_dropped_entities(&mut self) {
         loop {
             let (dropped_models, dropped_views, dropped_values) =
-                self.ctx.ref_counts.lock().take_dropped();
+                self.cx.ref_counts.lock().take_dropped();
             if dropped_models.is_empty() && dropped_views.is_empty() && dropped_values.is_empty() {
                 break;
             }
 
             for model_id in dropped_models {
-                self.ctx.models.remove(&model_id);
+                self.cx.models.remove(&model_id);
                 self.subscriptions.remove(&model_id);
                 self.model_observations.remove(&model_id);
             }
@@ -1064,8 +1063,8 @@ impl MutableAppContext {
             for (window_id, view_id) in dropped_views {
                 self.subscriptions.remove(&view_id);
                 self.model_observations.remove(&view_id);
-                self.ctx.views.remove(&(window_id, view_id));
-                let change_focus_to = self.ctx.windows.get_mut(&window_id).and_then(|window| {
+                self.cx.views.remove(&(window_id, view_id));
+                let change_focus_to = self.cx.windows.get_mut(&window_id).and_then(|window| {
                     window
                         .invalidation
                         .get_or_insert_with(Default::default)
@@ -1083,7 +1082,7 @@ impl MutableAppContext {
                 }
             }
 
-            let mut values = self.ctx.values.write();
+            let mut values = self.cx.values.write();
             for key in dropped_values {
                 values.remove(&key);
             }
@@ -1126,7 +1125,7 @@ impl MutableAppContext {
 
     fn update_windows(&mut self) {
         let mut invalidations = HashMap::new();
-        for (window_id, window) in &mut self.ctx.windows {
+        for (window_id, window) in &mut self.cx.windows {
             if let Some(invalidation) = window.invalidation.take() {
                 invalidations.insert(*window_id, invalidation);
             }
@@ -1153,9 +1152,9 @@ impl MutableAppContext {
             for mut subscription in subscriptions {
                 let alive = match &mut subscription {
                     Subscription::FromModel { model_id, callback } => {
-                        if let Some(mut model) = self.ctx.models.remove(model_id) {
+                        if let Some(mut model) = self.cx.models.remove(model_id) {
                             callback(model.as_any_mut(), payload.as_ref(), self, *model_id);
-                            self.ctx.models.insert(*model_id, model);
+                            self.cx.models.insert(*model_id, model);
                             true
                         } else {
                             false
@@ -1166,7 +1165,7 @@ impl MutableAppContext {
                         view_id,
                         callback,
                     } => {
-                        if let Some(mut view) = self.ctx.views.remove(&(*window_id, *view_id)) {
+                        if let Some(mut view) = self.cx.views.remove(&(*window_id, *view_id)) {
                             callback(
                                 view.as_any_mut(),
                                 payload.as_ref(),
@@ -1174,7 +1173,7 @@ impl MutableAppContext {
                                 *window_id,
                                 *view_id,
                             );
-                            self.ctx.views.insert((*window_id, *view_id), view);
+                            self.cx.views.insert((*window_id, *view_id), view);
                             true
                         } else {
                             false
@@ -1194,13 +1193,13 @@ impl MutableAppContext {
 
     fn notify_model_observers(&mut self, observed_id: usize) {
         if let Some(observations) = self.model_observations.remove(&observed_id) {
-            if self.ctx.models.contains_key(&observed_id) {
+            if self.cx.models.contains_key(&observed_id) {
                 for mut observation in observations {
                     let alive = match &mut observation {
                         ModelObservation::FromModel { model_id, callback } => {
-                            if let Some(mut model) = self.ctx.models.remove(model_id) {
+                            if let Some(mut model) = self.cx.models.remove(model_id) {
                                 callback(model.as_any_mut(), observed_id, self, *model_id);
-                                self.ctx.models.insert(*model_id, model);
+                                self.cx.models.insert(*model_id, model);
                                 true
                             } else {
                                 false
@@ -1211,7 +1210,7 @@ impl MutableAppContext {
                             view_id,
                             callback,
                         } => {
-                            if let Some(mut view) = self.ctx.views.remove(&(*window_id, *view_id)) {
+                            if let Some(mut view) = self.cx.views.remove(&(*window_id, *view_id)) {
                                 callback(
                                     view.as_any_mut(),
                                     observed_id,
@@ -1219,7 +1218,7 @@ impl MutableAppContext {
                                     *window_id,
                                     *view_id,
                                 );
-                                self.ctx.views.insert((*window_id, *view_id), view);
+                                self.cx.views.insert((*window_id, *view_id), view);
                                 true
                             } else {
                                 false
@@ -1239,7 +1238,7 @@ impl MutableAppContext {
     }
 
     fn notify_view_observers(&mut self, window_id: usize, view_id: usize) {
-        if let Some(window) = self.ctx.windows.get_mut(&window_id) {
+        if let Some(window) = self.cx.windows.get_mut(&window_id) {
             window
                 .invalidation
                 .get_or_insert_with(Default::default)
@@ -1248,10 +1247,10 @@ impl MutableAppContext {
         }
 
         if let Some(observations) = self.view_observations.remove(&view_id) {
-            if self.ctx.views.contains_key(&(window_id, view_id)) {
+            if self.cx.views.contains_key(&(window_id, view_id)) {
                 for mut observation in observations {
                     let alive = if let Some(mut view) = self
-                        .ctx
+                        .cx
                         .views
                         .remove(&(observation.window_id, observation.view_id))
                     {
@@ -1263,7 +1262,7 @@ impl MutableAppContext {
                             observation.window_id,
                             observation.view_id,
                         );
-                        self.ctx
+                        self.cx
                             .views
                             .insert((observation.window_id, observation.view_id), view);
                         true
@@ -1284,7 +1283,7 @@ impl MutableAppContext {
 
     fn focus(&mut self, window_id: usize, focused_id: usize) {
         if self
-            .ctx
+            .cx
             .windows
             .get(&window_id)
             .map(|w| w.focused_view_id)
@@ -1295,22 +1294,22 @@ impl MutableAppContext {
 
         self.pending_flushes += 1;
 
-        let blurred_id = self.ctx.windows.get_mut(&window_id).map(|window| {
+        let blurred_id = self.cx.windows.get_mut(&window_id).map(|window| {
             let blurred_id = window.focused_view_id;
             window.focused_view_id = focused_id;
             blurred_id
         });
 
         if let Some(blurred_id) = blurred_id {
-            if let Some(mut blurred_view) = self.ctx.views.remove(&(window_id, blurred_id)) {
+            if let Some(mut blurred_view) = self.cx.views.remove(&(window_id, blurred_id)) {
                 blurred_view.on_blur(self, window_id, blurred_id);
-                self.ctx.views.insert((window_id, blurred_id), blurred_view);
+                self.cx.views.insert((window_id, blurred_id), blurred_view);
             }
         }
 
-        if let Some(mut focused_view) = self.ctx.views.remove(&(window_id, focused_id)) {
+        if let Some(mut focused_view) = self.cx.views.remove(&(window_id, focused_id)) {
             focused_view.on_focus(self, window_id, focused_id);
-            self.ctx.views.insert((window_id, focused_id), focused_view);
+            self.cx.views.insert((window_id, focused_id), focused_view);
         }
 
         self.flush_effects();
@@ -1322,8 +1321,8 @@ impl MutableAppContext {
         Fut: 'static + Future<Output = T>,
         T: 'static,
     {
-        let ctx = AsyncAppContext(self.weak_self.as_ref().unwrap().upgrade().unwrap());
-        self.foreground.spawn(f(ctx))
+        let cx = AsyncAppContext(self.weak_self.as_ref().unwrap().upgrade().unwrap());
+        self.foreground.spawn(f(cx))
     }
 
     pub fn write_to_clipboard(&self, item: ClipboardItem) {
@@ -1337,7 +1336,7 @@ impl MutableAppContext {
 
 impl ReadModel for MutableAppContext {
     fn read_model<T: Entity>(&self, handle: &ModelHandle<T>) -> &T {
-        if let Some(model) = self.ctx.models.get(&handle.model_id) {
+        if let Some(model) = self.cx.models.get(&handle.model_id) {
             model
                 .as_any()
                 .downcast_ref()
@@ -1354,17 +1353,17 @@ impl UpdateModel for MutableAppContext {
         T: Entity,
         F: FnOnce(&mut T, &mut ModelContext<T>) -> S,
     {
-        if let Some(mut model) = self.ctx.models.remove(&handle.model_id) {
+        if let Some(mut model) = self.cx.models.remove(&handle.model_id) {
             self.pending_flushes += 1;
-            let mut ctx = ModelContext::new(self, handle.model_id);
+            let mut cx = ModelContext::new(self, handle.model_id);
             let result = update(
                 model
                     .as_any_mut()
                     .downcast_mut()
                     .expect("downcast is type safe"),
-                &mut ctx,
+                &mut cx,
             );
-            self.ctx.models.insert(handle.model_id, model);
+            self.cx.models.insert(handle.model_id, model);
             self.flush_effects();
             result
         } else {
@@ -1375,7 +1374,7 @@ impl UpdateModel for MutableAppContext {
 
 impl ReadView for MutableAppContext {
     fn read_view<T: View>(&self, handle: &ViewHandle<T>) -> &T {
-        if let Some(view) = self.ctx.views.get(&(handle.window_id, handle.view_id)) {
+        if let Some(view) = self.cx.views.get(&(handle.window_id, handle.view_id)) {
             view.as_any().downcast_ref().expect("downcast is type safe")
         } else {
             panic!("circular view reference");
@@ -1391,19 +1390,19 @@ impl UpdateView for MutableAppContext {
     {
         self.pending_flushes += 1;
         let mut view = self
-            .ctx
+            .cx
             .views
             .remove(&(handle.window_id, handle.view_id))
             .expect("circular view update");
 
-        let mut ctx = ViewContext::new(self, handle.window_id, handle.view_id);
+        let mut cx = ViewContext::new(self, handle.window_id, handle.view_id);
         let result = update(
             view.as_any_mut()
                 .downcast_mut()
                 .expect("downcast is type safe"),
-            &mut ctx,
+            &mut cx,
         );
-        self.ctx
+        self.cx
             .views
             .insert((handle.window_id, handle.view_id), view);
         self.flush_effects();
@@ -1413,7 +1412,7 @@ impl UpdateView for MutableAppContext {
 
 impl AsRef<AppContext> for MutableAppContext {
     fn as_ref(&self) -> &AppContext {
-        &self.ctx
+        &self.cx
     }
 }
 
@@ -1558,10 +1557,10 @@ pub trait AnyView: Send + Sync {
     fn as_any(&self) -> &dyn Any;
     fn as_any_mut(&mut self) -> &mut dyn Any;
     fn ui_name(&self) -> &'static str;
-    fn render<'a>(&self, app: &AppContext) -> ElementBox;
-    fn on_focus(&mut self, app: &mut MutableAppContext, window_id: usize, view_id: usize);
-    fn on_blur(&mut self, app: &mut MutableAppContext, window_id: usize, view_id: usize);
-    fn keymap_context(&self, app: &AppContext) -> keymap::Context;
+    fn render<'a>(&self, cx: &AppContext) -> ElementBox;
+    fn on_focus(&mut self, cx: &mut MutableAppContext, window_id: usize, view_id: usize);
+    fn on_blur(&mut self, cx: &mut MutableAppContext, window_id: usize, view_id: usize);
+    fn keymap_context(&self, cx: &AppContext) -> keymap::Context;
 }
 
 impl<T> AnyView for T
@@ -1580,22 +1579,22 @@ where
         T::ui_name()
     }
 
-    fn render<'a>(&self, app: &AppContext) -> ElementBox {
-        View::render(self, app)
+    fn render<'a>(&self, cx: &AppContext) -> ElementBox {
+        View::render(self, cx)
     }
 
-    fn on_focus(&mut self, app: &mut MutableAppContext, window_id: usize, view_id: usize) {
-        let mut ctx = ViewContext::new(app, window_id, view_id);
-        View::on_focus(self, &mut ctx);
+    fn on_focus(&mut self, cx: &mut MutableAppContext, window_id: usize, view_id: usize) {
+        let mut cx = ViewContext::new(cx, window_id, view_id);
+        View::on_focus(self, &mut cx);
     }
 
-    fn on_blur(&mut self, app: &mut MutableAppContext, window_id: usize, view_id: usize) {
-        let mut ctx = ViewContext::new(app, window_id, view_id);
-        View::on_blur(self, &mut ctx);
+    fn on_blur(&mut self, cx: &mut MutableAppContext, window_id: usize, view_id: usize) {
+        let mut cx = ViewContext::new(cx, window_id, view_id);
+        View::on_blur(self, &mut cx);
     }
 
-    fn keymap_context(&self, app: &AppContext) -> keymap::Context {
-        View::keymap_context(self, app)
+    fn keymap_context(&self, cx: &AppContext) -> keymap::Context {
+        View::keymap_context(self, cx)
     }
 }
 
@@ -1617,11 +1616,11 @@ impl<'a, T: Entity> ModelContext<'a, T> {
     }
 
     pub fn background_executor(&self) -> &Arc<executor::Background> {
-        &self.app.ctx.background
+        &self.app.cx.background
     }
 
     pub fn thread_pool(&self) -> &scoped_pool::Pool {
-        &self.app.ctx.thread_pool
+        &self.app.cx.thread_pool
     }
 
     pub fn halt_stream(&mut self) {
@@ -1654,8 +1653,8 @@ impl<'a, T: Entity> ModelContext<'a, T> {
                 callback: Box::new(move |model, payload, app, model_id| {
                     let model = model.downcast_mut().expect("downcast is type safe");
                     let payload = payload.downcast_ref().expect("downcast is type safe");
-                    let mut ctx = ModelContext::new(app, model_id);
-                    callback(model, payload, &mut ctx);
+                    let mut cx = ModelContext::new(app, model_id);
+                    callback(model, payload, &mut cx);
                 }),
             });
     }
@@ -1680,9 +1679,9 @@ impl<'a, T: Entity> ModelContext<'a, T> {
                 model_id: self.model_id,
                 callback: Box::new(move |model, observed_id, app, model_id| {
                     let model = model.downcast_mut().expect("downcast is type safe");
-                    let observed = ModelHandle::new(observed_id, &app.ctx.ref_counts);
-                    let mut ctx = ModelContext::new(app, model_id);
-                    callback(model, observed, &mut ctx);
+                    let observed = ModelHandle::new(observed_id, &app.cx.ref_counts);
+                    let mut cx = ModelContext::new(app, model_id);
+                    callback(model, observed, &mut cx);
                 }),
             });
     }
@@ -1696,7 +1695,7 @@ impl<'a, T: Entity> ModelContext<'a, T> {
     }
 
     pub fn handle(&self) -> ModelHandle<T> {
-        ModelHandle::new(self.model_id, &self.app.ctx.ref_counts)
+        ModelHandle::new(self.model_id, &self.app.cx.ref_counts)
     }
 
     pub fn spawn<F, Fut, S>(&self, f: F) -> Task<S>
@@ -1706,13 +1705,13 @@ impl<'a, T: Entity> ModelContext<'a, T> {
         S: 'static,
     {
         let handle = self.handle();
-        self.app.spawn(|ctx| f(handle, ctx))
+        self.app.spawn(|cx| f(handle, cx))
     }
 }
 
 impl<M> AsRef<AppContext> for ModelContext<'_, M> {
     fn as_ref(&self) -> &AppContext {
-        &self.app.ctx
+        &self.app.cx
     }
 }
 
@@ -1758,7 +1757,7 @@ impl<'a, T: View> ViewContext<'a, T> {
     }
 
     pub fn handle(&self) -> ViewHandle<T> {
-        ViewHandle::new(self.window_id, self.view_id, &self.app.ctx.ref_counts)
+        ViewHandle::new(self.window_id, self.view_id, &self.app.cx.ref_counts)
     }
 
     pub fn window_id(&self) -> usize {
@@ -1774,7 +1773,7 @@ impl<'a, T: View> ViewContext<'a, T> {
     }
 
     pub fn background_executor(&self) -> &Arc<executor::Background> {
-        &self.app.ctx.background
+        &self.app.cx.background
     }
 
     pub fn prompt<F>(&self, level: PromptLevel, msg: &str, answers: &[&str], done_fn: F)
@@ -1852,9 +1851,9 @@ impl<'a, T: View> ViewContext<'a, T> {
         F: 'static + FnMut(&mut T, ModelHandle<E>, &E::Event, &mut ViewContext<T>),
     {
         let emitter_handle = handle.downgrade();
-        self.subscribe(handle, move |model, payload, ctx| {
-            if let Some(emitter_handle) = emitter_handle.upgrade(ctx.as_ref()) {
-                callback(model, emitter_handle, payload, ctx);
+        self.subscribe(handle, move |model, payload, cx| {
+            if let Some(emitter_handle) = emitter_handle.upgrade(cx.as_ref()) {
+                callback(model, emitter_handle, payload, cx);
             }
         });
     }
@@ -1866,9 +1865,9 @@ impl<'a, T: View> ViewContext<'a, T> {
         F: 'static + FnMut(&mut T, ViewHandle<V>, &V::Event, &mut ViewContext<T>),
     {
         let emitter_handle = handle.downgrade();
-        self.subscribe(handle, move |view, payload, ctx| {
-            if let Some(emitter_handle) = emitter_handle.upgrade(ctx.as_ref()) {
-                callback(view, emitter_handle, payload, ctx);
+        self.subscribe(handle, move |view, payload, cx| {
+            if let Some(emitter_handle) = emitter_handle.upgrade(cx.as_ref()) {
+                callback(view, emitter_handle, payload, cx);
             }
         });
     }
@@ -1889,8 +1888,8 @@ impl<'a, T: View> ViewContext<'a, T> {
                 callback: Box::new(move |entity, payload, app, window_id, view_id| {
                     let entity = entity.downcast_mut().expect("downcast is type safe");
                     let payload = payload.downcast_ref().expect("downcast is type safe");
-                    let mut ctx = ViewContext::new(app, window_id, view_id);
-                    callback(entity, payload, &mut ctx);
+                    let mut cx = ViewContext::new(app, window_id, view_id);
+                    callback(entity, payload, &mut cx);
                 }),
             });
     }
@@ -1916,9 +1915,9 @@ impl<'a, T: View> ViewContext<'a, T> {
                 view_id: self.view_id,
                 callback: Box::new(move |view, observed_id, app, window_id, view_id| {
                     let view = view.downcast_mut().expect("downcast is type safe");
-                    let observed = ModelHandle::new(observed_id, &app.ctx.ref_counts);
-                    let mut ctx = ViewContext::new(app, window_id, view_id);
-                    callback(view, observed, &mut ctx);
+                    let observed = ModelHandle::new(observed_id, &app.cx.ref_counts);
+                    let mut cx = ViewContext::new(app, window_id, view_id);
+                    callback(view, observed, &mut cx);
                 }),
             });
     }
@@ -1946,10 +1945,10 @@ impl<'a, T: View> ViewContext<'a, T> {
                         let observed_handle = ViewHandle::new(
                             observed_view_id,
                             observed_window_id,
-                            &app.ctx.ref_counts,
+                            &app.cx.ref_counts,
                         );
-                        let mut ctx = ViewContext::new(app, observing_window_id, observing_view_id);
-                        callback(view, observed_handle, &mut ctx);
+                        let mut cx = ViewContext::new(app, observing_window_id, observing_view_id);
+                        callback(view, observed_handle, &mut cx);
                     },
                 ),
             });
@@ -1970,7 +1969,7 @@ impl<'a, T: View> ViewContext<'a, T> {
         S: 'static,
     {
         let handle = self.handle();
-        self.app.spawn(|ctx| f(handle, ctx))
+        self.app.spawn(|cx| f(handle, cx))
     }
 }
 
@@ -1982,7 +1981,7 @@ impl AsRef<AppContext> for &AppContext {
 
 impl<M> AsRef<AppContext> for ViewContext<'_, M> {
     fn as_ref(&self) -> &AppContext {
-        &self.app.ctx
+        &self.app.cx
     }
 }
 

gpui/src/elements.rs 🔗

@@ -38,11 +38,11 @@ use replace_with::replace_with_or_abort;
 use std::{any::Any, borrow::Cow};
 
 trait AnyElement {
-    fn layout(&mut self, constraint: SizeConstraint, ctx: &mut LayoutContext) -> Vector2F;
+    fn layout(&mut self, constraint: SizeConstraint, cx: &mut LayoutContext) -> Vector2F;
     fn after_layout(&mut self, _: &mut AfterLayoutContext) {}
-    fn paint(&mut self, origin: Vector2F, ctx: &mut PaintContext);
-    fn dispatch_event(&mut self, event: &Event, ctx: &mut EventContext) -> bool;
-    fn debug(&self, ctx: &DebugContext) -> serde_json::Value;
+    fn paint(&mut self, origin: Vector2F, cx: &mut PaintContext);
+    fn dispatch_event(&mut self, event: &Event, cx: &mut EventContext) -> bool;
+    fn debug(&self, cx: &DebugContext) -> serde_json::Value;
 
     fn size(&self) -> Vector2F;
     fn metadata(&self) -> Option<&dyn Any>;
@@ -55,21 +55,21 @@ pub trait Element {
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState);
 
     fn after_layout(
         &mut self,
         size: Vector2F,
         layout: &mut Self::LayoutState,
-        ctx: &mut AfterLayoutContext,
+        cx: &mut AfterLayoutContext,
     );
 
     fn paint(
         &mut self,
         bounds: RectF,
         layout: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState;
 
     fn dispatch_event(
@@ -78,7 +78,7 @@ pub trait Element {
         bounds: RectF,
         layout: &mut Self::LayoutState,
         paint: &mut Self::PaintState,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool;
 
     fn metadata(&self) -> Option<&dyn Any> {
@@ -90,7 +90,7 @@ pub trait Element {
         bounds: RectF,
         layout: &Self::LayoutState,
         paint: &Self::PaintState,
-        ctx: &DebugContext,
+        cx: &DebugContext,
     ) -> serde_json::Value;
 
     fn boxed(self) -> ElementBox
@@ -138,13 +138,13 @@ pub struct ElementBox {
 }
 
 impl<T: Element> AnyElement for Lifecycle<T> {
-    fn layout(&mut self, constraint: SizeConstraint, ctx: &mut LayoutContext) -> Vector2F {
+    fn layout(&mut self, constraint: SizeConstraint, cx: &mut LayoutContext) -> Vector2F {
         let mut result = None;
         replace_with_or_abort(self, |me| match me {
             Lifecycle::Init { mut element }
             | Lifecycle::PostLayout { mut element, .. }
             | Lifecycle::PostPaint { mut element, .. } => {
-                let (size, layout) = element.layout(constraint, ctx);
+                let (size, layout) = element.layout(constraint, cx);
                 debug_assert!(size.x().is_finite());
                 debug_assert!(size.y().is_finite());
 
@@ -160,7 +160,7 @@ impl<T: Element> AnyElement for Lifecycle<T> {
         result.unwrap()
     }
 
-    fn after_layout(&mut self, ctx: &mut AfterLayoutContext) {
+    fn after_layout(&mut self, cx: &mut AfterLayoutContext) {
         if let Lifecycle::PostLayout {
             element,
             size,
@@ -168,13 +168,13 @@ impl<T: Element> AnyElement for Lifecycle<T> {
             ..
         } = self
         {
-            element.after_layout(*size, layout, ctx);
+            element.after_layout(*size, layout, cx);
         } else {
             panic!("invalid element lifecycle state");
         }
     }
 
-    fn paint(&mut self, origin: Vector2F, ctx: &mut PaintContext) {
+    fn paint(&mut self, origin: Vector2F, cx: &mut PaintContext) {
         replace_with_or_abort(self, |me| {
             if let Lifecycle::PostLayout {
                 mut element,
@@ -184,7 +184,7 @@ impl<T: Element> AnyElement for Lifecycle<T> {
             } = me
             {
                 let bounds = RectF::new(origin, size);
-                let paint = element.paint(bounds, &mut layout, ctx);
+                let paint = element.paint(bounds, &mut layout, cx);
                 Lifecycle::PostPaint {
                     element,
                     constraint,
@@ -198,7 +198,7 @@ impl<T: Element> AnyElement for Lifecycle<T> {
         });
     }
 
-    fn dispatch_event(&mut self, event: &Event, ctx: &mut EventContext) -> bool {
+    fn dispatch_event(&mut self, event: &Event, cx: &mut EventContext) -> bool {
         if let Lifecycle::PostPaint {
             element,
             bounds,
@@ -207,7 +207,7 @@ impl<T: Element> AnyElement for Lifecycle<T> {
             ..
         } = self
         {
-            element.dispatch_event(event, *bounds, layout, paint, ctx)
+            element.dispatch_event(event, *bounds, layout, paint, cx)
         } else {
             panic!("invalid element lifecycle state");
         }
@@ -229,7 +229,7 @@ impl<T: Element> AnyElement for Lifecycle<T> {
         }
     }
 
-    fn debug(&self, ctx: &DebugContext) -> serde_json::Value {
+    fn debug(&self, cx: &DebugContext) -> serde_json::Value {
         match self {
             Lifecycle::PostPaint {
                 element,
@@ -238,7 +238,7 @@ impl<T: Element> AnyElement for Lifecycle<T> {
                 layout,
                 paint,
             } => {
-                let mut value = element.debug(*bounds, layout, paint, ctx);
+                let mut value = element.debug(*bounds, layout, paint, cx);
                 if let json::Value::Object(map) = &mut value {
                     let mut new_map: crate::json::Map<String, serde_json::Value> =
                         Default::default();
@@ -258,20 +258,20 @@ impl<T: Element> AnyElement for Lifecycle<T> {
 }
 
 impl ElementBox {
-    pub fn layout(&mut self, constraint: SizeConstraint, ctx: &mut LayoutContext) -> Vector2F {
-        self.element.layout(constraint, ctx)
+    pub fn layout(&mut self, constraint: SizeConstraint, cx: &mut LayoutContext) -> Vector2F {
+        self.element.layout(constraint, cx)
     }
 
-    pub fn after_layout(&mut self, ctx: &mut AfterLayoutContext) {
-        self.element.after_layout(ctx);
+    pub fn after_layout(&mut self, cx: &mut AfterLayoutContext) {
+        self.element.after_layout(cx);
     }
 
-    pub fn paint(&mut self, origin: Vector2F, ctx: &mut PaintContext) {
-        self.element.paint(origin, ctx);
+    pub fn paint(&mut self, origin: Vector2F, cx: &mut PaintContext) {
+        self.element.paint(origin, cx);
     }
 
-    pub fn dispatch_event(&mut self, event: &Event, ctx: &mut EventContext) -> bool {
-        self.element.dispatch_event(event, ctx)
+    pub fn dispatch_event(&mut self, event: &Event, cx: &mut EventContext) -> bool {
+        self.element.dispatch_event(event, cx)
     }
 
     pub fn size(&self) -> Vector2F {
@@ -282,8 +282,8 @@ impl ElementBox {
         self.element.metadata()
     }
 
-    pub fn debug(&self, ctx: &DebugContext) -> json::Value {
-        let mut value = self.element.debug(ctx);
+    pub fn debug(&self, cx: &DebugContext) -> json::Value {
+        let mut value = self.element.debug(cx);
 
         if let Some(name) = &self.name {
             if let json::Value::Object(map) = &mut value {

gpui/src/elements/align.rs 🔗

@@ -37,11 +37,11 @@ impl Element for Align {
     fn layout(
         &mut self,
         mut constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
         let mut size = constraint.max;
         constraint.min = Vector2F::zero();
-        let child_size = self.child.layout(constraint, ctx);
+        let child_size = self.child.layout(constraint, cx);
         if size.x().is_infinite() {
             size.set_x(child_size.x());
         }
@@ -55,16 +55,16 @@ impl Element for Align {
         &mut self,
         _: Vector2F,
         _: &mut Self::LayoutState,
-        ctx: &mut AfterLayoutContext,
+        cx: &mut AfterLayoutContext,
     ) {
-        self.child.after_layout(ctx);
+        self.child.after_layout(cx);
     }
 
     fn paint(
         &mut self,
         bounds: pathfinder_geometry::rect::RectF,
         _: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
         let my_center = bounds.size() / 2.;
         let my_target = my_center + my_center * self.alignment;
@@ -73,7 +73,7 @@ impl Element for Align {
         let child_target = child_center + child_center * self.alignment;
 
         self.child
-            .paint(bounds.origin() - (child_target - my_target), ctx);
+            .paint(bounds.origin() - (child_target - my_target), cx);
     }
 
     fn dispatch_event(
@@ -82,9 +82,9 @@ impl Element for Align {
         _: pathfinder_geometry::rect::RectF,
         _: &mut Self::LayoutState,
         _: &mut Self::PaintState,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool {
-        self.child.dispatch_event(event, ctx)
+        self.child.dispatch_event(event, cx)
     }
 
     fn debug(
@@ -92,13 +92,13 @@ impl Element for Align {
         bounds: pathfinder_geometry::rect::RectF,
         _: &Self::LayoutState,
         _: &Self::PaintState,
-        ctx: &DebugContext,
+        cx: &DebugContext,
     ) -> json::Value {
         json!({
             "type": "Align",
             "bounds": bounds.to_json(),
             "alignment": self.alignment.to_json(),
-            "child": self.child.debug(ctx),
+            "child": self.child.debug(cx),
         })
     }
 }

gpui/src/elements/canvas.rs 🔗

@@ -51,9 +51,9 @@ where
         &mut self,
         bounds: RectF,
         _: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
-        self.0(bounds, ctx)
+        self.0(bounds, cx)
     }
 
     fn after_layout(

gpui/src/elements/constrained_box.rs 🔗

@@ -58,12 +58,12 @@ impl Element for ConstrainedBox {
     fn layout(
         &mut self,
         mut constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
         constraint.min = constraint.min.max(self.constraint.min);
         constraint.max = constraint.max.min(self.constraint.max);
         constraint.max = constraint.max.max(constraint.min);
-        let size = self.child.layout(constraint, ctx);
+        let size = self.child.layout(constraint, cx);
         (size, ())
     }
 
@@ -71,18 +71,18 @@ impl Element for ConstrainedBox {
         &mut self,
         _: Vector2F,
         _: &mut Self::LayoutState,
-        ctx: &mut AfterLayoutContext,
+        cx: &mut AfterLayoutContext,
     ) {
-        self.child.after_layout(ctx);
+        self.child.after_layout(cx);
     }
 
     fn paint(
         &mut self,
         bounds: RectF,
         _: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
-        self.child.paint(bounds.origin(), ctx);
+        self.child.paint(bounds.origin(), cx);
     }
 
     fn dispatch_event(
@@ -91,9 +91,9 @@ impl Element for ConstrainedBox {
         _: RectF,
         _: &mut Self::LayoutState,
         _: &mut Self::PaintState,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool {
-        self.child.dispatch_event(event, ctx)
+        self.child.dispatch_event(event, cx)
     }
 
     fn debug(
@@ -101,8 +101,8 @@ impl Element for ConstrainedBox {
         _: RectF,
         _: &Self::LayoutState,
         _: &Self::PaintState,
-        ctx: &DebugContext,
+        cx: &DebugContext,
     ) -> json::Value {
-        json!({"type": "ConstrainedBox", "set_constraint": self.constraint.to_json(), "child": self.child.debug(ctx)})
+        json!({"type": "ConstrainedBox", "set_constraint": self.constraint.to_json(), "child": self.child.debug(cx)})
     }
 }

gpui/src/elements/container.rs 🔗

@@ -141,14 +141,14 @@ impl Element for Container {
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
         let size_buffer = self.margin_size() + self.padding_size() + self.border_size();
         let child_constraint = SizeConstraint {
             min: (constraint.min - size_buffer).max(Vector2F::zero()),
             max: (constraint.max - size_buffer).max(Vector2F::zero()),
         };
-        let child_size = self.child.layout(child_constraint, ctx);
+        let child_size = self.child.layout(child_constraint, cx);
         (child_size + size_buffer, ())
     }
 
@@ -156,16 +156,16 @@ impl Element for Container {
         &mut self,
         _: Vector2F,
         _: &mut Self::LayoutState,
-        ctx: &mut AfterLayoutContext,
+        cx: &mut AfterLayoutContext,
     ) {
-        self.child.after_layout(ctx);
+        self.child.after_layout(cx);
     }
 
     fn paint(
         &mut self,
         bounds: RectF,
         _: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
         let quad_bounds = RectF::from_points(
             bounds.origin() + vec2f(self.margin.left, self.margin.top),
@@ -173,14 +173,14 @@ impl Element for Container {
         );
 
         if let Some(shadow) = self.shadow.as_ref() {
-            ctx.scene.push_shadow(scene::Shadow {
+            cx.scene.push_shadow(scene::Shadow {
                 bounds: quad_bounds + shadow.offset,
                 corner_radius: self.corner_radius,
                 sigma: shadow.blur,
                 color: shadow.color,
             });
         }
-        ctx.scene.push_quad(Quad {
+        cx.scene.push_quad(Quad {
             bounds: quad_bounds,
             background: self.background_color,
             border: self.border,
@@ -190,7 +190,7 @@ impl Element for Container {
         let child_origin = quad_bounds.origin()
             + vec2f(self.padding.left, self.padding.top)
             + vec2f(self.border.left_width(), self.border.top_width());
-        self.child.paint(child_origin, ctx);
+        self.child.paint(child_origin, cx);
     }
 
     fn dispatch_event(
@@ -199,9 +199,9 @@ impl Element for Container {
         _: RectF,
         _: &mut Self::LayoutState,
         _: &mut Self::PaintState,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool {
-        self.child.dispatch_event(event, ctx)
+        self.child.dispatch_event(event, cx)
     }
 
     fn debug(
@@ -209,7 +209,7 @@ impl Element for Container {
         bounds: RectF,
         _: &Self::LayoutState,
         _: &Self::PaintState,
-        ctx: &crate::DebugContext,
+        cx: &crate::DebugContext,
     ) -> serde_json::Value {
         json!({
             "type": "Container",
@@ -222,7 +222,7 @@ impl Element for Container {
                 "corner_radius": self.corner_radius,
                 "shadow": self.shadow.to_json(),
             },
-            "child": self.child.debug(ctx),
+            "child": self.child.debug(cx),
         })
     }
 }

gpui/src/elements/event_handler.rs 🔗

@@ -35,9 +35,9 @@ impl Element for EventHandler {
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
-        let size = self.child.layout(constraint, ctx);
+        let size = self.child.layout(constraint, cx);
         (size, ())
     }
 
@@ -45,18 +45,18 @@ impl Element for EventHandler {
         &mut self,
         _: Vector2F,
         _: &mut Self::LayoutState,
-        ctx: &mut AfterLayoutContext,
+        cx: &mut AfterLayoutContext,
     ) {
-        self.child.after_layout(ctx);
+        self.child.after_layout(cx);
     }
 
     fn paint(
         &mut self,
         bounds: RectF,
         _: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
-        self.child.paint(bounds.origin(), ctx);
+        self.child.paint(bounds.origin(), cx);
     }
 
     fn dispatch_event(
@@ -65,16 +65,16 @@ impl Element for EventHandler {
         bounds: RectF,
         _: &mut Self::LayoutState,
         _: &mut Self::PaintState,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool {
-        if self.child.dispatch_event(event, ctx) {
+        if self.child.dispatch_event(event, cx) {
             true
         } else {
             match event {
                 Event::LeftMouseDown { position, .. } => {
                     if let Some(callback) = self.mouse_down.as_mut() {
                         if bounds.contains_point(*position) {
-                            return callback(ctx);
+                            return callback(cx);
                         }
                     }
                     false
@@ -89,11 +89,11 @@ impl Element for EventHandler {
         _: RectF,
         _: &Self::LayoutState,
         _: &Self::PaintState,
-        ctx: &DebugContext,
+        cx: &DebugContext,
     ) -> serde_json::Value {
         json!({
             "type": "EventHandler",
-            "child": self.child.debug(ctx),
+            "child": self.child.debug(cx),
         })
     }
 }

gpui/src/elements/flex.rs 🔗

@@ -53,7 +53,7 @@ impl Element for Flex {
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
         let mut total_flex = 0.0;
         let mut fixed_space = 0.0;
@@ -74,7 +74,7 @@ impl Element for Flex {
                         vec2f(constraint.max.x(), INFINITY),
                     ),
                 };
-                let size = child.layout(child_constraint, ctx);
+                let size = child.layout(child_constraint, cx);
                 fixed_space += size.along(self.axis);
                 cross_axis_max = cross_axis_max.max(size.along(cross_axis));
             }
@@ -105,7 +105,7 @@ impl Element for Flex {
                             vec2f(constraint.max.x(), child_max),
                         ),
                     };
-                    let child_size = child.layout(child_constraint, ctx);
+                    let child_size = child.layout(child_constraint, cx);
                     remaining_space -= child_size.along(self.axis);
                     remaining_flex -= flex;
                     cross_axis_max = cross_axis_max.max(child_size.along(cross_axis));
@@ -138,10 +138,10 @@ impl Element for Flex {
         &mut self,
         _: Vector2F,
         _: &mut Self::LayoutState,
-        ctx: &mut AfterLayoutContext,
+        cx: &mut AfterLayoutContext,
     ) {
         for child in &mut self.children {
-            child.after_layout(ctx);
+            child.after_layout(cx);
         }
     }
 
@@ -149,11 +149,11 @@ impl Element for Flex {
         &mut self,
         bounds: RectF,
         _: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
         let mut child_origin = bounds.origin();
         for child in &mut self.children {
-            child.paint(child_origin, ctx);
+            child.paint(child_origin, cx);
             match self.axis {
                 Axis::Horizontal => child_origin += vec2f(child.size().x(), 0.0),
                 Axis::Vertical => child_origin += vec2f(0.0, child.size().y()),
@@ -167,11 +167,11 @@ impl Element for Flex {
         _: RectF,
         _: &mut Self::LayoutState,
         _: &mut Self::PaintState,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool {
         let mut handled = false;
         for child in &mut self.children {
-            handled = child.dispatch_event(event, ctx) || handled;
+            handled = child.dispatch_event(event, cx) || handled;
         }
         handled
     }
@@ -181,13 +181,13 @@ impl Element for Flex {
         bounds: RectF,
         _: &Self::LayoutState,
         _: &Self::PaintState,
-        ctx: &DebugContext,
+        cx: &DebugContext,
     ) -> json::Value {
         json!({
             "type": "Flex",
             "bounds": bounds.to_json(),
             "axis": self.axis.to_json(),
-            "children": self.children.iter().map(|child| child.debug(ctx)).collect::<Vec<json::Value>>()
+            "children": self.children.iter().map(|child| child.debug(cx)).collect::<Vec<json::Value>>()
         })
     }
 }
@@ -217,9 +217,9 @@ impl Element for Expanded {
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
-        let size = self.child.layout(constraint, ctx);
+        let size = self.child.layout(constraint, cx);
         (size, ())
     }
 
@@ -227,18 +227,18 @@ impl Element for Expanded {
         &mut self,
         _: Vector2F,
         _: &mut Self::LayoutState,
-        ctx: &mut AfterLayoutContext,
+        cx: &mut AfterLayoutContext,
     ) {
-        self.child.after_layout(ctx);
+        self.child.after_layout(cx);
     }
 
     fn paint(
         &mut self,
         bounds: RectF,
         _: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
-        self.child.paint(bounds.origin(), ctx)
+        self.child.paint(bounds.origin(), cx)
     }
 
     fn dispatch_event(
@@ -247,9 +247,9 @@ impl Element for Expanded {
         _: RectF,
         _: &mut Self::LayoutState,
         _: &mut Self::PaintState,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool {
-        self.child.dispatch_event(event, ctx)
+        self.child.dispatch_event(event, cx)
     }
 
     fn metadata(&self) -> Option<&dyn Any> {
@@ -261,12 +261,12 @@ impl Element for Expanded {
         _: RectF,
         _: &Self::LayoutState,
         _: &Self::PaintState,
-        ctx: &DebugContext,
+        cx: &DebugContext,
     ) -> Value {
         json!({
             "type": "Expanded",
             "flex": self.metadata.flex,
-            "child": self.child.debug(ctx)
+            "child": self.child.debug(cx)
         })
     }
 }

gpui/src/elements/label.rs 🔗

@@ -109,20 +109,20 @@ impl Element for Label {
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
-        let font_id = ctx
+        let font_id = cx
             .font_cache
             .select_font(self.family_id, &self.font_properties)
             .unwrap();
-        let runs = self.compute_runs(&ctx.font_cache, font_id);
+        let runs = self.compute_runs(&cx.font_cache, font_id);
         let line =
-            ctx.text_layout_cache
+            cx.text_layout_cache
                 .layout_str(self.text.as_str(), self.font_size, runs.as_slice());
 
         let size = vec2f(
             line.width().max(constraint.min.x()).min(constraint.max.x()),
-            ctx.font_cache.line_height(font_id, self.font_size).ceil(),
+            cx.font_cache.line_height(font_id, self.font_size).ceil(),
         );
 
         (size, line)
@@ -135,12 +135,12 @@ impl Element for Label {
         &mut self,
         bounds: RectF,
         line: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
         line.paint(
             bounds.origin(),
             RectF::new(vec2f(0., 0.), bounds.size()),
-            ctx,
+            cx,
         )
     }
 
@@ -160,12 +160,12 @@ impl Element for Label {
         bounds: RectF,
         _: &Self::LayoutState,
         _: &Self::PaintState,
-        ctx: &DebugContext,
+        cx: &DebugContext,
     ) -> Value {
         json!({
             "type": "Label",
             "bounds": bounds.to_json(),
-            "font_family": ctx.font_cache.family_name(self.family_id).unwrap(),
+            "font_family": cx.font_cache.family_name(self.family_id).unwrap(),
             "font_size": self.font_size,
             "font_properties": self.font_properties.to_json(),
             "text": &self.text,
@@ -191,13 +191,13 @@ mod tests {
     use super::*;
 
     #[crate::test(self)]
-    fn test_layout_label_with_highlights(app: &mut crate::MutableAppContext) {
-        let menlo = app.font_cache().load_family(&["Menlo"]).unwrap();
-        let menlo_regular = app
+    fn test_layout_label_with_highlights(cx: &mut crate::MutableAppContext) {
+        let menlo = cx.font_cache().load_family(&["Menlo"]).unwrap();
+        let menlo_regular = cx
             .font_cache()
             .select_font(menlo, &Properties::new())
             .unwrap();
-        let menlo_bold = app
+        let menlo_bold = cx
             .font_cache()
             .select_font(menlo, Properties::new().weight(Weight::BOLD))
             .unwrap();
@@ -216,7 +216,7 @@ mod tests {
             ],
         );
 
-        let runs = label.compute_runs(app.font_cache().as_ref(), menlo_regular);
+        let runs = label.compute_runs(cx.font_cache().as_ref(), menlo_regular);
         assert_eq!(
             runs.as_slice(),
             &[

gpui/src/elements/line_box.rs 🔗

@@ -35,20 +35,20 @@ impl Element for LineBox {
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
-        match ctx
+        match cx
             .font_cache
             .select_font(self.family_id, &self.font_properties)
         {
             Ok(font_id) => {
-                let line_height = ctx.font_cache.line_height(font_id, self.font_size);
-                let character_height = ctx.font_cache.ascent(font_id, self.font_size)
-                    + ctx.font_cache.descent(font_id, self.font_size);
+                let line_height = cx.font_cache.line_height(font_id, self.font_size);
+                let character_height = cx.font_cache.ascent(font_id, self.font_size)
+                    + cx.font_cache.descent(font_id, self.font_size);
                 let child_max = vec2f(constraint.max.x(), character_height);
                 let child_size = self.child.layout(
                     SizeConstraint::new(constraint.min.min(child_max), child_max),
-                    ctx,
+                    cx,
                 );
                 let size = vec2f(child_size.x(), line_height);
                 (size, (line_height - character_height) / 2.)
@@ -64,19 +64,19 @@ impl Element for LineBox {
         &mut self,
         _: Vector2F,
         _: &mut Self::LayoutState,
-        ctx: &mut AfterLayoutContext,
+        cx: &mut AfterLayoutContext,
     ) {
-        self.child.after_layout(ctx);
+        self.child.after_layout(cx);
     }
 
     fn paint(
         &mut self,
         bounds: pathfinder_geometry::rect::RectF,
         padding_top: &mut f32,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
         self.child
-            .paint(bounds.origin() + vec2f(0., *padding_top), ctx);
+            .paint(bounds.origin() + vec2f(0., *padding_top), cx);
     }
 
     fn dispatch_event(
@@ -85,9 +85,9 @@ impl Element for LineBox {
         _: pathfinder_geometry::rect::RectF,
         _: &mut Self::LayoutState,
         _: &mut Self::PaintState,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool {
-        self.child.dispatch_event(event, ctx)
+        self.child.dispatch_event(event, cx)
     }
 
     fn debug(
@@ -95,14 +95,14 @@ impl Element for LineBox {
         bounds: RectF,
         _: &Self::LayoutState,
         _: &Self::PaintState,
-        ctx: &DebugContext,
+        cx: &DebugContext,
     ) -> serde_json::Value {
         json!({
             "bounds": bounds.to_json(),
-            "font_family": ctx.font_cache.family_name(self.family_id).unwrap(),
+            "font_family": cx.font_cache.family_name(self.family_id).unwrap(),
             "font_size": self.font_size,
             "font_properties": self.font_properties.to_json(),
-            "child": self.child.debug(ctx),
+            "child": self.child.debug(cx),
         })
     }
 }

gpui/src/elements/mouse_event_handler.rs 🔗

@@ -18,13 +18,13 @@ pub struct MouseState {
 }
 
 impl MouseEventHandler {
-    pub fn new<Tag, F>(id: usize, ctx: &AppContext, render_child: F) -> Self
+    pub fn new<Tag, F>(id: usize, cx: &AppContext, render_child: F) -> Self
     where
         Tag: 'static,
         F: FnOnce(MouseState) -> ElementBox,
     {
-        let state_handle = ctx.value::<Tag, _>(id);
-        let state = state_handle.read(ctx, |state| *state);
+        let state_handle = cx.value::<Tag, _>(id);
+        let state = state_handle.read(cx, |state| *state);
         let child = render_child(state);
         Self {
             state: state_handle,
@@ -46,27 +46,27 @@ impl Element for MouseEventHandler {
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
-        (self.child.layout(constraint, ctx), ())
+        (self.child.layout(constraint, cx), ())
     }
 
     fn after_layout(
         &mut self,
         _: Vector2F,
         _: &mut Self::LayoutState,
-        ctx: &mut AfterLayoutContext,
+        cx: &mut AfterLayoutContext,
     ) {
-        self.child.after_layout(ctx);
+        self.child.after_layout(cx);
     }
 
     fn paint(
         &mut self,
         bounds: RectF,
         _: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
-        self.child.paint(bounds.origin(), ctx);
+        self.child.paint(bounds.origin(), cx);
     }
 
     fn dispatch_event(
@@ -75,18 +75,18 @@ impl Element for MouseEventHandler {
         bounds: RectF,
         _: &mut Self::LayoutState,
         _: &mut Self::PaintState,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool {
         let click_handler = self.click_handler.as_mut();
 
-        let handled_in_child = self.child.dispatch_event(event, ctx);
+        let handled_in_child = self.child.dispatch_event(event, cx);
 
-        self.state.update(ctx.app, |state| match event {
+        self.state.update(cx.app, |state| match event {
             Event::MouseMoved { position } => {
                 let mouse_in = bounds.contains_point(*position);
                 if state.hovered != mouse_in {
                     state.hovered = mouse_in;
-                    ctx.notify();
+                    cx.notify();
                     true
                 } else {
                     handled_in_child
@@ -95,7 +95,7 @@ impl Element for MouseEventHandler {
             Event::LeftMouseDown { position, .. } => {
                 if !handled_in_child && bounds.contains_point(*position) {
                     state.clicked = true;
-                    ctx.notify();
+                    cx.notify();
                     true
                 } else {
                     handled_in_child
@@ -104,10 +104,10 @@ impl Element for MouseEventHandler {
             Event::LeftMouseUp { position, .. } => {
                 if !handled_in_child && state.clicked {
                     state.clicked = false;
-                    ctx.notify();
+                    cx.notify();
                     if let Some(handler) = click_handler {
                         if bounds.contains_point(*position) {
-                            handler(ctx);
+                            handler(cx);
                         }
                     }
                     true
@@ -124,11 +124,11 @@ impl Element for MouseEventHandler {
         _: RectF,
         _: &Self::LayoutState,
         _: &Self::PaintState,
-        ctx: &DebugContext,
+        cx: &DebugContext,
     ) -> serde_json::Value {
         json!({
             "type": "MouseEventHandler",
-            "child": self.child.debug(ctx),
+            "child": self.child.debug(cx),
         })
     }
 }

gpui/src/elements/stack.rs 🔗

@@ -24,11 +24,11 @@ impl Element for Stack {
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
         let mut size = constraint.min;
         for child in &mut self.children {
-            size = size.max(child.layout(constraint, ctx));
+            size = size.max(child.layout(constraint, cx));
         }
         (size, ())
     }
@@ -37,10 +37,10 @@ impl Element for Stack {
         &mut self,
         _: Vector2F,
         _: &mut Self::LayoutState,
-        ctx: &mut AfterLayoutContext,
+        cx: &mut AfterLayoutContext,
     ) {
         for child in &mut self.children {
-            child.after_layout(ctx);
+            child.after_layout(cx);
         }
     }
 
@@ -48,12 +48,12 @@ impl Element for Stack {
         &mut self,
         bounds: RectF,
         _: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
         for child in &mut self.children {
-            ctx.scene.push_layer(None);
-            child.paint(bounds.origin(), ctx);
-            ctx.scene.pop_layer();
+            cx.scene.push_layer(None);
+            child.paint(bounds.origin(), cx);
+            cx.scene.pop_layer();
         }
     }
 
@@ -63,10 +63,10 @@ impl Element for Stack {
         _: RectF,
         _: &mut Self::LayoutState,
         _: &mut Self::PaintState,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool {
         for child in self.children.iter_mut().rev() {
-            if child.dispatch_event(event, ctx) {
+            if child.dispatch_event(event, cx) {
                 return true;
             }
         }
@@ -78,12 +78,12 @@ impl Element for Stack {
         bounds: RectF,
         _: &Self::LayoutState,
         _: &Self::PaintState,
-        ctx: &DebugContext,
+        cx: &DebugContext,
     ) -> json::Value {
         json!({
             "type": "Stack",
             "bounds": bounds.to_json(),
-            "children": self.children.iter().map(|child| child.debug(ctx)).collect::<Vec<json::Value>>()
+            "children": self.children.iter().map(|child| child.debug(cx)).collect::<Vec<json::Value>>()
         })
     }
 }

gpui/src/elements/svg.rs 🔗

@@ -38,9 +38,9 @@ impl Element for Svg {
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
-        match ctx.asset_cache.svg(&self.path) {
+        match cx.asset_cache.svg(&self.path) {
             Ok(tree) => {
                 let size = if constraint.max.x().is_infinite() && constraint.max.y().is_infinite() {
                     let rect = from_usvg_rect(tree.svg_node().view_box.rect);
@@ -69,9 +69,9 @@ impl Element for Svg {
     fn after_layout(&mut self, _: Vector2F, _: &mut Self::LayoutState, _: &mut AfterLayoutContext) {
     }
 
-    fn paint(&mut self, bounds: RectF, svg: &mut Self::LayoutState, ctx: &mut PaintContext) {
+    fn paint(&mut self, bounds: RectF, svg: &mut Self::LayoutState, cx: &mut PaintContext) {
         if let Some(svg) = svg.clone() {
-            ctx.scene.push_icon(scene::Icon {
+            cx.scene.push_icon(scene::Icon {
                 bounds,
                 svg,
                 path: self.path.clone(),

gpui/src/elements/uniform_list.rs 🔗

@@ -72,7 +72,7 @@ where
         delta: Vector2F,
         precise: bool,
         scroll_max: f32,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool {
         if !precise {
             todo!("still need to handle non-precise scroll events from a mouse wheel");
@@ -80,7 +80,7 @@ where
 
         let mut state = self.state.0.lock();
         state.scroll_top = (state.scroll_top - delta.y()).max(0.0).min(scroll_max);
-        ctx.dispatch_action("uniform_list:scroll", state.scroll_top);
+        cx.dispatch_action("uniform_list:scroll", state.scroll_top);
 
         true
     }
@@ -119,7 +119,7 @@ where
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
         if constraint.max.y().is_infinite() {
             unimplemented!(
@@ -133,9 +133,9 @@ where
         let mut scroll_max = 0.;
 
         let mut items = Vec::new();
-        (self.append_items)(0..1, &mut items, ctx.app);
+        (self.append_items)(0..1, &mut items, cx.app);
         if let Some(first_item) = items.first_mut() {
-            let mut item_size = first_item.layout(item_constraint, ctx);
+            let mut item_size = first_item.layout(item_constraint, cx);
             item_size.set_x(size.x());
             item_constraint.min = item_size;
             item_constraint.max = item_size;
@@ -155,9 +155,9 @@ where
                 self.item_count,
                 start + (size.y() / item_height).ceil() as usize + 1,
             );
-            (self.append_items)(start..end, &mut items, ctx.app);
+            (self.append_items)(start..end, &mut items, cx.app);
             for item in &mut items {
-                item.layout(item_constraint, ctx);
+                item.layout(item_constraint, cx);
             }
         }
 
@@ -175,10 +175,10 @@ where
         &mut self,
         _: Vector2F,
         layout: &mut Self::LayoutState,
-        ctx: &mut AfterLayoutContext,
+        cx: &mut AfterLayoutContext,
     ) {
         for item in &mut layout.items {
-            item.after_layout(ctx);
+            item.after_layout(cx);
         }
     }
 
@@ -186,19 +186,19 @@ where
         &mut self,
         bounds: RectF,
         layout: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
-        ctx.scene.push_layer(Some(bounds));
+        cx.scene.push_layer(Some(bounds));
 
         let mut item_origin =
             bounds.origin() - vec2f(0.0, self.state.scroll_top() % layout.item_height);
 
         for item in &mut layout.items {
-            item.paint(item_origin, ctx);
+            item.paint(item_origin, cx);
             item_origin += vec2f(0.0, layout.item_height);
         }
 
-        ctx.scene.pop_layer();
+        cx.scene.pop_layer();
     }
 
     fn dispatch_event(
@@ -207,11 +207,11 @@ where
         bounds: RectF,
         layout: &mut Self::LayoutState,
         _: &mut Self::PaintState,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool {
         let mut handled = false;
         for item in &mut layout.items {
-            handled = item.dispatch_event(event, ctx) || handled;
+            handled = item.dispatch_event(event, cx) || handled;
         }
 
         match event {
@@ -221,7 +221,7 @@ where
                 precise,
             } => {
                 if bounds.contains_point(*position) {
-                    if self.scroll(*position, *delta, *precise, layout.scroll_max, ctx) {
+                    if self.scroll(*position, *delta, *precise, layout.scroll_max, cx) {
                         handled = true;
                     }
                 }
@@ -237,14 +237,14 @@ where
         bounds: RectF,
         layout: &Self::LayoutState,
         _: &Self::PaintState,
-        ctx: &crate::DebugContext,
+        cx: &crate::DebugContext,
     ) -> json::Value {
         json!({
             "type": "UniformList",
             "bounds": bounds.to_json(),
             "scroll_max": layout.scroll_max,
             "item_height": layout.item_height,
-            "items": layout.items.iter().map(|item| item.debug(ctx)).collect::<Vec<json::Value>>()
+            "items": layout.items.iter().map(|item| item.debug(cx)).collect::<Vec<json::Value>>()
 
         })
     }

gpui/src/keymap.rs 🔗

@@ -98,12 +98,12 @@ impl Matcher {
         &mut self,
         keystroke: Keystroke,
         view_id: usize,
-        ctx: &Context,
+        cx: &Context,
     ) -> MatchResult {
         let pending = self.pending.entry(view_id).or_default();
 
         if let Some(pending_ctx) = pending.context.as_ref() {
-            if pending_ctx != ctx {
+            if pending_ctx != cx {
                 pending.keystrokes.clear();
             }
         }
@@ -113,11 +113,7 @@ impl Matcher {
         let mut retain_pending = false;
         for binding in self.keymap.0.iter().rev() {
             if binding.keystrokes.starts_with(&pending.keystrokes)
-                && binding
-                    .context
-                    .as_ref()
-                    .map(|c| c.eval(ctx))
-                    .unwrap_or(true)
+                && binding.context.as_ref().map(|c| c.eval(cx)).unwrap_or(true)
             {
                 if binding.keystrokes.len() == pending.keystrokes.len() {
                     self.pending.remove(&view_id);
@@ -127,7 +123,7 @@ impl Matcher {
                     };
                 } else {
                     retain_pending = true;
-                    pending.context = Some(ctx.clone());
+                    pending.context = Some(cx.clone());
                 }
             }
         }
@@ -312,22 +308,20 @@ impl ContextPredicate {
         }
     }
 
-    fn eval(&self, ctx: &Context) -> bool {
+    fn eval(&self, cx: &Context) -> bool {
         match self {
-            Self::Identifier(name) => ctx.set.contains(name.as_str()),
-            Self::Equal(left, right) => ctx
+            Self::Identifier(name) => cx.set.contains(name.as_str()),
+            Self::Equal(left, right) => cx
                 .map
                 .get(left)
                 .map(|value| value == right)
                 .unwrap_or(false),
-            Self::NotEqual(left, right) => ctx
-                .map
-                .get(left)
-                .map(|value| value != right)
-                .unwrap_or(true),
-            Self::Not(pred) => !pred.eval(ctx),
-            Self::And(left, right) => left.eval(ctx) && right.eval(ctx),
-            Self::Or(left, right) => left.eval(ctx) || right.eval(ctx),
+            Self::NotEqual(left, right) => {
+                cx.map.get(left).map(|value| value != right).unwrap_or(true)
+            }
+            Self::Not(pred) => !pred.eval(cx),
+            Self::And(left, right) => left.eval(cx) && right.eval(cx),
+            Self::Or(left, right) => left.eval(cx) || right.eval(cx),
         }
     }
 }
@@ -488,10 +482,10 @@ mod tests {
             &mut self,
             keystroke: &str,
             view_id: usize,
-            ctx: &Context,
+            cx: &Context,
         ) -> Option<(String, Option<A>)> {
             if let MatchResult::Action { name, arg } =
-                self.push_keystroke(Keystroke::parse(keystroke).unwrap(), view_id, ctx)
+                self.push_keystroke(Keystroke::parse(keystroke).unwrap(), view_id, cx)
             {
                 Some((name, arg.and_then(|arg| arg.downcast_ref::<A>().cloned())))
             } else {

gpui/src/platform/mac/fonts.rs 🔗

@@ -145,7 +145,7 @@ impl FontSystemState {
             // Make room for subpixel variants.
             let bounds = RectI::new(bounds.origin(), bounds.size() + vec2i(1, 1));
             let mut pixels = vec![0; bounds.width() as usize * bounds.height() as usize];
-            let ctx = CGContext::create_bitmap_context(
+            let cx = CGContext::create_bitmap_context(
                 Some(pixels.as_mut_ptr() as *mut _),
                 bounds.width() as usize,
                 bounds.height() as usize,
@@ -157,9 +157,9 @@ impl FontSystemState {
 
             // Move the origin to bottom left and account for scaling, this
             // makes drawing text consistent with the font-kit's raster_bounds.
-            ctx.translate(0.0, bounds.height() as CGFloat);
+            cx.translate(0.0, bounds.height() as CGFloat);
             let transform = scale.translate(-bounds.origin().to_f32());
-            ctx.set_text_matrix(&CGAffineTransform {
+            cx.set_text_matrix(&CGAffineTransform {
                 a: transform.matrix.m11() as CGFloat,
                 b: -transform.matrix.m21() as CGFloat,
                 c: -transform.matrix.m12() as CGFloat,
@@ -168,9 +168,9 @@ impl FontSystemState {
                 ty: -transform.vector.y() as CGFloat,
             });
 
-            ctx.set_font(&font.native_font().copy_to_CGFont());
-            ctx.set_font_size(font_size as CGFloat);
-            ctx.show_glyphs_at_positions(
+            cx.set_font(&font.native_font().copy_to_CGFont());
+            cx.set_font_size(font_size as CGFloat);
+            cx.show_glyphs_at_positions(
                 &[glyph_id as CGGlyph],
                 &[CGPoint::new(
                     (subpixel_shift.x() / scale_factor) as CGFloat,

gpui/src/presenter.rs 🔗

@@ -31,11 +31,11 @@ impl Presenter {
         font_cache: Arc<FontCache>,
         text_layout_cache: TextLayoutCache,
         asset_cache: Arc<AssetCache>,
-        app: &MutableAppContext,
+        cx: &MutableAppContext,
     ) -> Self {
         Self {
             window_id,
-            rendered_views: app.render_views(window_id),
+            rendered_views: cx.render_views(window_id),
             parents: HashMap::new(),
             font_cache,
             text_layout_cache,
@@ -55,7 +55,7 @@ impl Presenter {
         path
     }
 
-    pub fn invalidate(&mut self, mut invalidation: WindowInvalidation, app: &AppContext) {
+    pub fn invalidate(&mut self, mut invalidation: WindowInvalidation, cx: &AppContext) {
         for view_id in invalidation.removed {
             invalidation.updated.remove(&view_id);
             self.rendered_views.remove(&view_id);
@@ -63,7 +63,7 @@ impl Presenter {
         }
         for view_id in invalidation.updated {
             self.rendered_views
-                .insert(view_id, app.render_view(self.window_id, view_id).unwrap());
+                .insert(view_id, cx.render_view(self.window_id, view_id).unwrap());
         }
     }
 
@@ -71,25 +71,25 @@ impl Presenter {
         &mut self,
         window_size: Vector2F,
         scale_factor: f32,
-        app: &mut MutableAppContext,
+        cx: &mut MutableAppContext,
     ) -> Scene {
         let mut scene = Scene::new(scale_factor);
 
-        if let Some(root_view_id) = app.root_view_id(self.window_id) {
-            self.layout(window_size, app.as_ref());
-            self.after_layout(app);
-            let mut ctx = PaintContext {
+        if let Some(root_view_id) = cx.root_view_id(self.window_id) {
+            self.layout(window_size, cx.as_ref());
+            self.after_layout(cx);
+            let mut paint_cx = PaintContext {
                 scene: &mut scene,
                 font_cache: &self.font_cache,
                 text_layout_cache: &self.text_layout_cache,
                 rendered_views: &mut self.rendered_views,
-                app: app.as_ref(),
+                app: cx.as_ref(),
             };
-            ctx.paint(root_view_id, Vector2F::zero());
+            paint_cx.paint(root_view_id, Vector2F::zero());
             self.text_layout_cache.finish_frame();
 
             if let Some(event) = self.last_mouse_moved_event.clone() {
-                self.dispatch_event(event, app)
+                self.dispatch_event(event, cx)
             }
         } else {
             log::error!("could not find root_view_id for window {}", self.window_id);
@@ -98,8 +98,8 @@ impl Presenter {
         scene
     }
 
-    fn layout(&mut self, size: Vector2F, app: &AppContext) {
-        if let Some(root_view_id) = app.root_view_id(self.window_id) {
+    fn layout(&mut self, size: Vector2F, cx: &AppContext) {
+        if let Some(root_view_id) = cx.root_view_id(self.window_id) {
             let mut layout_ctx = LayoutContext {
                 rendered_views: &mut self.rendered_views,
                 parents: &mut self.parents,
@@ -107,49 +107,49 @@ impl Presenter {
                 text_layout_cache: &self.text_layout_cache,
                 asset_cache: &self.asset_cache,
                 view_stack: Vec::new(),
-                app,
+                app: cx,
             };
             layout_ctx.layout(root_view_id, SizeConstraint::strict(size));
         }
     }
 
-    fn after_layout(&mut self, app: &mut MutableAppContext) {
-        if let Some(root_view_id) = app.root_view_id(self.window_id) {
-            let mut ctx = AfterLayoutContext {
+    fn after_layout(&mut self, cx: &mut MutableAppContext) {
+        if let Some(root_view_id) = cx.root_view_id(self.window_id) {
+            let mut layout_cx = AfterLayoutContext {
                 rendered_views: &mut self.rendered_views,
                 font_cache: &self.font_cache,
                 text_layout_cache: &self.text_layout_cache,
-                app,
+                app: cx,
             };
-            ctx.after_layout(root_view_id);
+            layout_cx.after_layout(root_view_id);
         }
     }
 
-    pub fn dispatch_event(&mut self, event: Event, app: &mut MutableAppContext) {
-        if let Some(root_view_id) = app.root_view_id(self.window_id) {
+    pub fn dispatch_event(&mut self, event: Event, cx: &mut MutableAppContext) {
+        if let Some(root_view_id) = cx.root_view_id(self.window_id) {
             if matches!(event, Event::MouseMoved { .. }) {
                 self.last_mouse_moved_event = Some(event.clone());
             }
 
-            let mut ctx = EventContext {
+            let mut event_cx = EventContext {
                 rendered_views: &mut self.rendered_views,
                 actions: Default::default(),
                 font_cache: &self.font_cache,
                 text_layout_cache: &self.text_layout_cache,
                 view_stack: Default::default(),
                 invalidated_views: Default::default(),
-                app: app.as_ref(),
+                app: cx.as_ref(),
             };
-            ctx.dispatch_event(root_view_id, &event);
+            event_cx.dispatch_event(root_view_id, &event);
 
-            let invalidated_views = ctx.invalidated_views;
-            let actions = ctx.actions;
+            let invalidated_views = event_cx.invalidated_views;
+            let actions = event_cx.actions;
 
             for view_id in invalidated_views {
-                app.notify_view(self.window_id, view_id);
+                cx.notify_view(self.window_id, view_id);
             }
             for action in actions {
-                app.dispatch_action_any(
+                cx.dispatch_action_any(
                     self.window_id,
                     &action.path,
                     action.name,
@@ -159,14 +159,14 @@ impl Presenter {
         }
     }
 
-    pub fn debug_elements(&self, ctx: &AppContext) -> Option<json::Value> {
-        ctx.root_view_id(self.window_id)
+    pub fn debug_elements(&self, cx: &AppContext) -> Option<json::Value> {
+        cx.root_view_id(self.window_id)
             .and_then(|root_view_id| self.rendered_views.get(&root_view_id))
             .map(|root_element| {
                 root_element.debug(&DebugContext {
                     rendered_views: &self.rendered_views,
                     font_cache: &self.font_cache,
-                    app: ctx,
+                    app: cx,
                 })
             })
     }
@@ -380,9 +380,9 @@ impl Element for ChildView {
     fn layout(
         &mut self,
         constraint: SizeConstraint,
-        ctx: &mut LayoutContext,
+        cx: &mut LayoutContext,
     ) -> (Vector2F, Self::LayoutState) {
-        let size = ctx.layout(self.view_id, constraint);
+        let size = cx.layout(self.view_id, constraint);
         (size, ())
     }
 
@@ -390,18 +390,18 @@ impl Element for ChildView {
         &mut self,
         _: Vector2F,
         _: &mut Self::LayoutState,
-        ctx: &mut AfterLayoutContext,
+        cx: &mut AfterLayoutContext,
     ) {
-        ctx.after_layout(self.view_id);
+        cx.after_layout(self.view_id);
     }
 
     fn paint(
         &mut self,
         bounds: pathfinder_geometry::rect::RectF,
         _: &mut Self::LayoutState,
-        ctx: &mut PaintContext,
+        cx: &mut PaintContext,
     ) -> Self::PaintState {
-        ctx.paint(self.view_id, bounds.origin());
+        cx.paint(self.view_id, bounds.origin());
     }
 
     fn dispatch_event(
@@ -410,9 +410,9 @@ impl Element for ChildView {
         _: pathfinder_geometry::rect::RectF,
         _: &mut Self::LayoutState,
         _: &mut Self::PaintState,
-        ctx: &mut EventContext,
+        cx: &mut EventContext,
     ) -> bool {
-        ctx.dispatch_event(self.view_id, event)
+        cx.dispatch_event(self.view_id, event)
     }
 
     fn debug(
@@ -420,14 +420,14 @@ impl Element for ChildView {
         bounds: pathfinder_geometry::rect::RectF,
         _: &Self::LayoutState,
         _: &Self::PaintState,
-        ctx: &DebugContext,
+        cx: &DebugContext,
     ) -> serde_json::Value {
         json!({
             "type": "ChildView",
             "view_id": self.view_id,
             "bounds": bounds.to_json(),
-            "child": if let Some(view) = ctx.rendered_views.get(&self.view_id) {
-                view.debug(ctx)
+            "child": if let Some(view) = cx.rendered_views.get(&self.view_id) {
+                view.debug(cx)
             } else {
                 json!(null)
             }
@@ -441,9 +441,9 @@ mod tests {
     // fn test_responder_chain() {
     //     let settings = settings_rx(None);
     //     let mut app = App::new().unwrap();
-    //     let workspace = app.add_model(|ctx| Workspace::new(Vec::new(), ctx));
+    //     let workspace = app.add_model(|cx| Workspace::new(Vec::new(), cx));
     //     let (window_id, workspace_view) =
-    //         app.add_window(|ctx| WorkspaceView::new(workspace.clone(), settings, ctx));
+    //         app.add_window(|cx| WorkspaceView::new(workspace.clone(), settings, cx));
 
     //     let invalidations = Rc::new(RefCell::new(Vec::new()));
     //     let invalidations_ = invalidations.clone();
@@ -451,8 +451,8 @@ mod tests {
     //         invalidations_.borrow_mut().push(invalidation)
     //     });
 
-    //     let active_pane_id = workspace_view.update(&mut app, |view, ctx| {
-    //         ctx.focus(view.active_pane());
+    //     let active_pane_id = workspace_view.update(&mut app, |view, cx| {
+    //         cx.focus(view.active_pane());
     //         view.active_pane().id()
     //     });
 
@@ -468,7 +468,7 @@ mod tests {
     //         }
 
     //         assert_eq!(
-    //             presenter.responder_chain(app.ctx()).unwrap(),
+    //             presenter.responder_chain(app.cx()).unwrap(),
     //             vec![workspace_view.id(), active_pane_id]
     //         );
     //     });

gpui/src/text_layout.rs 🔗

@@ -200,7 +200,7 @@ impl Line {
         }
     }
 
-    pub fn paint(&self, origin: Vector2F, visible_bounds: RectF, ctx: &mut PaintContext) {
+    pub fn paint(&self, origin: Vector2F, visible_bounds: RectF, cx: &mut PaintContext) {
         let padding_top = (visible_bounds.height() - self.layout.ascent - self.layout.descent) / 2.;
         let baseline_origin = vec2f(0., padding_top + self.layout.ascent);
 
@@ -209,7 +209,7 @@ impl Line {
         let mut color = ColorU::black();
 
         for run in &self.layout.runs {
-            let max_glyph_width = ctx
+            let max_glyph_width = cx
                 .font_cache
                 .bounding_box(run.font_id, self.layout.font_size)
                 .x();
@@ -234,7 +234,7 @@ impl Line {
                     }
                 }
 
-                ctx.scene.push_glyph(scene::Glyph {
+                cx.scene.push_glyph(scene::Glyph {
                     font_id: run.font_id,
                     font_size: self.layout.font_size,
                     id: glyph.id,

gpui_macros/src/lib.rs 🔗

@@ -34,8 +34,8 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
             fn #outer_fn_name() {
                 #inner_fn
 
-                #namespace::App::test_async((), move |ctx| async {
-                    #inner_fn_name(ctx).await;
+                #namespace::App::test_async((), move |cx| async {
+                    #inner_fn_name(cx).await;
                 });
             }
         }
@@ -45,8 +45,8 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
             fn #outer_fn_name() {
                 #inner_fn
 
-                #namespace::App::test((), |ctx| {
-                    #inner_fn_name(ctx);
+                #namespace::App::test((), |cx| {
+                    #inner_fn_name(cx);
                 });
             }
         }