Cleanups preparing for WindowContext refactor (#22475)

* Remove unnecessary WindowContext and ViewContext '_ lifetimes

* Removed some cases where WindowContext has a different name than `cx`.

Release Notes:

- N/A
This commit is contained in:
Michael Sloan
2024-12-28 21:36:14 +00:00
committed by GitHub
parent 9815358bdd
commit 016b5d60e1
41 changed files with 127 additions and 152 deletions
+1 -1
View File
@@ -1490,7 +1490,7 @@ impl Context for AppContext {
fn update_window<T, F>(&mut self, handle: AnyWindowHandle, update: F) -> Result<T>
where
F: FnOnce(AnyView, &mut WindowContext<'_>) -> T,
F: FnOnce(AnyView, &mut WindowContext) -> T,
{
self.update(|cx| {
let mut window = cx
+5 -5
View File
@@ -84,7 +84,7 @@ impl Context for AsyncAppContext {
fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
where
F: FnOnce(AnyView, &mut WindowContext<'_>) -> T,
F: FnOnce(AnyView, &mut WindowContext) -> T,
{
let app = self.app.upgrade().context("app was released")?;
let mut lock = app.borrow_mut();
@@ -349,7 +349,7 @@ impl Context for AsyncWindowContext {
fn update_window<T, F>(&mut self, window: AnyWindowHandle, update: F) -> Result<T>
where
F: FnOnce(AnyView, &mut WindowContext<'_>) -> T,
F: FnOnce(AnyView, &mut WindowContext) -> T,
{
self.app.update_window(window, update)
}
@@ -369,7 +369,7 @@ impl Context for AsyncWindowContext {
impl VisualContext for AsyncWindowContext {
fn new_view<V>(
&mut self,
build_view_state: impl FnOnce(&mut ViewContext<'_, V>) -> V,
build_view_state: impl FnOnce(&mut ViewContext<V>) -> V,
) -> Self::Result<View<V>>
where
V: 'static + Render,
@@ -381,7 +381,7 @@ impl VisualContext for AsyncWindowContext {
fn update_view<V: 'static, R>(
&mut self,
view: &View<V>,
update: impl FnOnce(&mut V, &mut ViewContext<'_, V>) -> R,
update: impl FnOnce(&mut V, &mut ViewContext<V>) -> R,
) -> Self::Result<R> {
self.window
.update(self, |_, cx| cx.update_view(view, update))
@@ -389,7 +389,7 @@ impl VisualContext for AsyncWindowContext {
fn replace_root_view<V>(
&mut self,
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
build_view: impl FnOnce(&mut ViewContext<V>) -> V,
) -> Self::Result<View<V>>
where
V: 'static + Render,
+1 -1
View File
@@ -263,7 +263,7 @@ impl<'a, T> Context for ModelContext<'a, T> {
fn update_window<R, F>(&mut self, window: AnyWindowHandle, update: F) -> Result<R>
where
F: FnOnce(AnyView, &mut WindowContext<'_>) -> R,
F: FnOnce(AnyView, &mut WindowContext) -> R,
{
self.app.update_window(window, update)
}
+6 -6
View File
@@ -77,7 +77,7 @@ impl Context for TestAppContext {
fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
where
F: FnOnce(AnyView, &mut WindowContext<'_>) -> T,
F: FnOnce(AnyView, &mut WindowContext) -> T,
{
let mut lock = self.app.borrow_mut();
lock.update_window(window, f)
@@ -916,7 +916,7 @@ impl Context for VisualTestContext {
fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
where
F: FnOnce(AnyView, &mut WindowContext<'_>) -> T,
F: FnOnce(AnyView, &mut WindowContext) -> T,
{
self.cx.update_window(window, f)
}
@@ -936,7 +936,7 @@ impl Context for VisualTestContext {
impl VisualContext for VisualTestContext {
fn new_view<V>(
&mut self,
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
build_view: impl FnOnce(&mut ViewContext<V>) -> V,
) -> Self::Result<View<V>>
where
V: 'static + Render,
@@ -949,7 +949,7 @@ impl VisualContext for VisualTestContext {
fn update_view<V: 'static, R>(
&mut self,
view: &View<V>,
update: impl FnOnce(&mut V, &mut ViewContext<'_, V>) -> R,
update: impl FnOnce(&mut V, &mut ViewContext<V>) -> R,
) -> Self::Result<R> {
self.window
.update(&mut self.cx, |_, cx| cx.update_view(view, update))
@@ -958,7 +958,7 @@ impl VisualContext for VisualTestContext {
fn replace_root_view<V>(
&mut self,
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
build_view: impl FnOnce(&mut ViewContext<V>) -> V,
) -> Self::Result<View<V>>
where
V: 'static + Render,
@@ -993,7 +993,7 @@ impl AnyWindowHandle {
pub fn build_view<V: Render + 'static>(
&self,
cx: &mut TestAppContext,
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
build_view: impl FnOnce(&mut ViewContext<V>) -> V,
) -> View<V> {
self.update(cx, |_, cx| cx.new_view(build_view)).unwrap()
}
+1 -1
View File
@@ -2499,7 +2499,7 @@ impl ScrollAnchor {
}
}
/// Request scroll to this item on the next frame.
pub fn scroll_to(&self, cx: &mut WindowContext<'_>) {
pub fn scroll_to(&self, cx: &mut WindowContext) {
let this = self.clone();
cx.on_next_frame(move |_| {
+6 -6
View File
@@ -472,9 +472,9 @@ pub struct InteractiveText {
element_id: ElementId,
text: StyledText,
click_listener:
Option<Box<dyn Fn(&[Range<usize>], InteractiveTextClickEvent, &mut WindowContext<'_>)>>,
hover_listener: Option<Box<dyn Fn(Option<usize>, MouseMoveEvent, &mut WindowContext<'_>)>>,
tooltip_builder: Option<Rc<dyn Fn(usize, &mut WindowContext<'_>) -> Option<AnyView>>>,
Option<Box<dyn Fn(&[Range<usize>], InteractiveTextClickEvent, &mut WindowContext)>>,
hover_listener: Option<Box<dyn Fn(Option<usize>, MouseMoveEvent, &mut WindowContext)>>,
tooltip_builder: Option<Rc<dyn Fn(usize, &mut WindowContext) -> Option<AnyView>>>,
clickable_ranges: Vec<Range<usize>>,
}
@@ -510,7 +510,7 @@ impl InteractiveText {
pub fn on_click(
mut self,
ranges: Vec<Range<usize>>,
listener: impl Fn(usize, &mut WindowContext<'_>) + 'static,
listener: impl Fn(usize, &mut WindowContext) + 'static,
) -> Self {
self.click_listener = Some(Box::new(move |ranges, event, cx| {
for (range_ix, range) in ranges.iter().enumerate() {
@@ -528,7 +528,7 @@ impl InteractiveText {
/// index of the hovered character, or None if the mouse leaves the text.
pub fn on_hover(
mut self,
listener: impl Fn(Option<usize>, MouseMoveEvent, &mut WindowContext<'_>) + 'static,
listener: impl Fn(Option<usize>, MouseMoveEvent, &mut WindowContext) + 'static,
) -> Self {
self.hover_listener = Some(Box::new(listener));
self
@@ -537,7 +537,7 @@ impl InteractiveText {
/// tooltip lets you specify a tooltip for a given character index in the string.
pub fn tooltip(
mut self,
builder: impl Fn(usize, &mut WindowContext<'_>) -> Option<AnyView> + 'static,
builder: impl Fn(usize, &mut WindowContext) -> Option<AnyView> + 'static,
) -> Self {
self.tooltip_builder = Some(Rc::new(builder));
self
+4 -4
View File
@@ -202,7 +202,7 @@ pub trait Context {
/// Update a window for the given handle.
fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
where
F: FnOnce(AnyView, &mut WindowContext<'_>) -> T;
F: FnOnce(AnyView, &mut WindowContext) -> T;
/// Read a window off of the application context.
fn read_window<T, R>(
@@ -231,7 +231,7 @@ pub trait VisualContext: Context {
/// Construct a new view in the window referenced by this context.
fn new_view<V>(
&mut self,
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
build_view: impl FnOnce(&mut ViewContext<V>) -> V,
) -> Self::Result<View<V>>
where
V: 'static + Render;
@@ -240,13 +240,13 @@ pub trait VisualContext: Context {
fn update_view<V: 'static, R>(
&mut self,
view: &View<V>,
update: impl FnOnce(&mut V, &mut ViewContext<'_, V>) -> R,
update: impl FnOnce(&mut V, &mut ViewContext<V>) -> R,
) -> Self::Result<R>;
/// Replace the root view of a window with a new view.
fn replace_root_view<V>(
&mut self,
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
build_view: impl FnOnce(&mut ViewContext<V>) -> V,
) -> Self::Result<View<V>>
where
V: 'static + Render;
+2 -2
View File
@@ -69,7 +69,7 @@ impl<V: 'static> View<V> {
pub fn update<C, R>(
&self,
cx: &mut C,
f: impl FnOnce(&mut V, &mut ViewContext<'_, V>) -> R,
f: impl FnOnce(&mut V, &mut ViewContext<V>) -> R,
) -> C::Result<R>
where
C: VisualContext,
@@ -183,7 +183,7 @@ impl<V: 'static> WeakView<V> {
pub fn update<C, R>(
&self,
cx: &mut C,
f: impl FnOnce(&mut V, &mut ViewContext<'_, V>) -> R,
f: impl FnOnce(&mut V, &mut ViewContext<V>) -> R,
) -> Result<R>
where
C: VisualContext,