Remove MutableAppContext::downgrade

This commit is contained in:
Nathan Sobo 2021-04-10 00:14:26 -06:00
parent 620eedb727
commit 4638391412
3 changed files with 11 additions and 16 deletions

View file

@ -308,7 +308,7 @@ impl TestAppContext {
}
pub fn read<T, F: FnOnce(&AppContext) -> T>(&self, callback: F) -> T {
callback(self.0.borrow().downgrade())
callback(self.0.borrow().as_ref())
}
pub fn update<T, F: FnOnce(&mut MutableAppContext) -> T>(&mut self, callback: F) -> T {
@ -438,10 +438,6 @@ impl MutableAppContext {
App(self.weak_self.as_ref().unwrap().upgrade().unwrap())
}
pub fn downgrade(&self) -> &AppContext {
&self.ctx
}
pub fn platform(&self) -> Rc<dyn platform::Platform> {
self.platform.clone()
}
@ -679,7 +675,7 @@ impl MutableAppContext {
.get(&window_id)
.and_then(|w| w.views.get(view_id))
{
context.extend(view.keymap_context(self.downgrade()));
context.extend(view.keymap_context(self.as_ref()));
context_chain.push(context.clone());
} else {
return Err(anyhow!(
@ -772,7 +768,7 @@ impl MutableAppContext {
if ctx
.dispatch_keystroke(
window_id,
presenter.borrow().dispatch_path(ctx.downgrade()),
presenter.borrow().dispatch_path(ctx.as_ref()),
keystroke,
)
.unwrap()
@ -781,9 +777,8 @@ impl MutableAppContext {
}
}
let actions = presenter
.borrow_mut()
.dispatch_event(event, ctx.downgrade());
let actions =
presenter.borrow_mut().dispatch_event(event, ctx.as_ref());
for action in actions {
ctx.dispatch_action_any(
window_id,
@ -815,7 +810,7 @@ impl MutableAppContext {
let presenter = presenter.clone();
self.on_window_invalidated(window_id, move |invalidation, ctx| {
let mut presenter = presenter.borrow_mut();
presenter.invalidate(invalidation, ctx.downgrade());
presenter.invalidate(invalidation, ctx.as_ref());
let scene =
presenter.build_scene(window.size(), window.scale_factor(), ctx);
window.present_scene(scene);
@ -1771,7 +1766,7 @@ impl<'a, T: View> ViewContext<'a, T> {
window_id: self.window_id,
view_id: self.view_id,
callback: Box::new(move |view, payload, app, window_id, view_id| {
if let Some(emitter_handle) = emitter_handle.upgrade(app.downgrade()) {
if let Some(emitter_handle) = emitter_handle.upgrade(app.as_ref()) {
let model = view.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);
@ -1797,7 +1792,7 @@ impl<'a, T: View> ViewContext<'a, T> {
window_id: self.window_id,
view_id: self.view_id,
callback: Box::new(move |view, payload, app, window_id, view_id| {
if let Some(emitter_handle) = emitter_handle.upgrade(app.downgrade()) {
if let Some(emitter_handle) = emitter_handle.upgrade(app.as_ref()) {
let model = view.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);

View file

@ -69,14 +69,14 @@ impl Presenter {
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.downgrade());
self.layout(window_size, app.as_ref());
self.after_layout(app);
let mut ctx = PaintContext {
scene: &mut scene,
font_cache: &self.font_cache,
text_layout_cache: &self.text_layout_cache,
rendered_views: &mut self.rendered_views,
app: app.downgrade(),
app: app.as_ref(),
};
ctx.paint(root_view_id, Vector2F::zero());
self.text_layout_cache.finish_frame();

View file

@ -402,7 +402,7 @@ impl Element for BufferElement {
ctx: &mut AfterLayoutContext,
) {
if let Some(layout) = layout {
let app = ctx.app.downgrade();
let app = ctx.app.as_ref();
let view = self.view.read(app);
view.clamp_scroll_left(