diff --git a/gpui/src/app.rs b/gpui/src/app.rs index 3f05ec969d..0bcc0a4c29 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -747,12 +747,12 @@ impl MutableAppContext { self.cx.focused_view_id(window_id) } - pub fn render_view(&self, window_id: usize, view_id: usize) -> Result { - self.cx.render_view(window_id, view_id) - } - - pub fn render_views(&self, window_id: usize) -> HashMap { - self.cx.render_views(window_id) + pub fn render_views( + &self, + window_id: usize, + titlebar_height: f32, + ) -> HashMap { + self.cx.render_views(window_id, titlebar_height) } pub fn update T>(&mut self, callback: F) -> T { @@ -1019,6 +1019,7 @@ impl MutableAppContext { let text_layout_cache = TextLayoutCache::new(self.cx.platform.fonts()); let presenter = Rc::new(RefCell::new(Presenter::new( window_id, + window.titlebar_height(), self.cx.font_cache.clone(), text_layout_cache, self.assets.clone(), @@ -1211,10 +1212,11 @@ impl MutableAppContext { { { let mut presenter = presenter.borrow_mut(); - presenter.invalidate(invalidation, self.as_ref()); + let titlebar_height = window.titlebar_height(); + presenter.invalidate(invalidation, titlebar_height, self.as_ref()); let scene = presenter.build_scene( window.size(), - window.titlebar_height(), + titlebar_height, window.scale_factor(), self, ); @@ -1540,19 +1542,31 @@ impl AppContext { .map(|window| window.focused_view_id) } - pub fn render_view(&self, window_id: usize, view_id: usize) -> Result { + pub fn render_view( + &self, + window_id: usize, + view_id: usize, + titlebar_height: f32, + ) -> Result { self.views .get(&(window_id, view_id)) - .map(|v| v.render(window_id, view_id, self)) + .map(|v| v.render(window_id, view_id, titlebar_height, self)) .ok_or(anyhow!("view not found")) } - pub fn render_views(&self, window_id: usize) -> HashMap { + pub fn render_views( + &self, + window_id: usize, + titlebar_height: f32, + ) -> HashMap { self.views .iter() .filter_map(|((win_id, view_id), view)| { if *win_id == window_id { - Some((*view_id, view.render(*win_id, *view_id, self))) + Some(( + *view_id, + view.render(*win_id, *view_id, titlebar_height, self), + )) } else { None } @@ -1703,7 +1717,13 @@ pub trait AnyView: Send + Sync { fn as_any_mut(&mut self) -> &mut dyn Any; fn release(&mut self, cx: &mut MutableAppContext); fn ui_name(&self) -> &'static str; - fn render<'a>(&self, window_id: usize, view_id: usize, cx: &AppContext) -> ElementBox; + fn render<'a>( + &self, + window_id: usize, + view_id: usize, + titlebar_height: f32, + 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; @@ -1729,7 +1749,13 @@ where T::ui_name() } - fn render<'a>(&self, window_id: usize, view_id: usize, cx: &AppContext) -> ElementBox { + fn render<'a>( + &self, + window_id: usize, + view_id: usize, + titlebar_height: f32, + cx: &AppContext, + ) -> ElementBox { View::render( self, &RenderContext { @@ -1737,6 +1763,7 @@ where view_id, app: cx, view_type: PhantomData::, + titlebar_height, }, ) } @@ -2170,6 +2197,7 @@ impl<'a, T: View> ViewContext<'a, T> { pub struct RenderContext<'a, T: View> { pub app: &'a AppContext, + pub titlebar_height: f32, window_id: usize, view_id: usize, view_type: PhantomData, diff --git a/gpui/src/presenter.rs b/gpui/src/presenter.rs index 05aa2acc46..a2047a2540 100644 --- a/gpui/src/presenter.rs +++ b/gpui/src/presenter.rs @@ -28,6 +28,7 @@ pub struct Presenter { impl Presenter { pub fn new( window_id: usize, + titlebar_height: f32, font_cache: Arc, text_layout_cache: TextLayoutCache, asset_cache: Arc, @@ -35,7 +36,7 @@ impl Presenter { ) -> Self { Self { window_id, - rendered_views: cx.render_views(window_id), + rendered_views: cx.render_views(window_id, titlebar_height), parents: HashMap::new(), font_cache, text_layout_cache, @@ -55,15 +56,23 @@ impl Presenter { path } - pub fn invalidate(&mut self, mut invalidation: WindowInvalidation, cx: &AppContext) { + pub fn invalidate( + &mut self, + mut invalidation: WindowInvalidation, + titlebar_height: f32, + cx: &AppContext, + ) { for view_id in invalidation.removed { invalidation.updated.remove(&view_id); self.rendered_views.remove(&view_id); self.parents.remove(&view_id); } for view_id in invalidation.updated { - self.rendered_views - .insert(view_id, cx.render_view(self.window_id, view_id).unwrap()); + self.rendered_views.insert( + view_id, + cx.render_view(self.window_id, view_id, titlebar_height) + .unwrap(), + ); } }