Replace WindowContext::notify with WindowContext::refresh

This commit is contained in:
Antonio Scandurra 2024-01-10 17:27:02 +01:00
parent d0c101cb6e
commit 2923b71f83
11 changed files with 35 additions and 30 deletions

View File

@ -109,7 +109,7 @@ impl CopilotCodeVerification {
let user_code = data.user_code.clone();
move |_, cx| {
cx.write_to_clipboard(ClipboardItem::new(user_code.clone()));
cx.notify();
cx.refresh();
}
})
.child(Label::new(data.user_code.clone()))

View File

@ -1027,7 +1027,7 @@ impl Interactivity {
if e.modifiers.command != command_held
&& text_bounds.contains(&cx.mouse_position())
{
cx.notify();
cx.refresh();
}
}
});
@ -1038,7 +1038,7 @@ impl Interactivity {
if phase == DispatchPhase::Capture
&& bounds.contains(&event.position) != hovered
{
cx.notify();
cx.refresh();
}
},
);
@ -1188,7 +1188,7 @@ impl Interactivity {
if phase == DispatchPhase::Capture
&& group_bounds.contains(&event.position) != hovered
{
cx.notify();
cx.refresh();
}
});
}
@ -1203,7 +1203,7 @@ impl Interactivity {
if phase == DispatchPhase::Capture
&& bounds.contains(&event.position) != hovered
{
cx.notify();
cx.refresh();
}
});
}
@ -1237,7 +1237,7 @@ impl Interactivity {
if can_drop {
listener(drag.value.as_ref(), cx);
cx.notify();
cx.refresh();
cx.stop_propagation();
}
}
@ -1268,7 +1268,7 @@ impl Interactivity {
&& interactive_bounds.visibly_contains(&event.position, cx)
{
*pending_mouse_down.borrow_mut() = Some(event.clone());
cx.notify();
cx.refresh();
}
}
});
@ -1299,7 +1299,7 @@ impl Interactivity {
cursor_offset,
});
pending_mouse_down.take();
cx.notify();
cx.refresh();
cx.stop_propagation();
}
}
@ -1319,7 +1319,7 @@ impl Interactivity {
pending_mouse_down.borrow_mut();
if pending_mouse_down.is_some() {
captured_mouse_down = pending_mouse_down.take();
cx.notify();
cx.refresh();
}
}
// Fire click handlers during the bubble phase.
@ -1413,7 +1413,7 @@ impl Interactivity {
_task: None,
},
);
cx.notify();
cx.refresh();
})
.ok();
}
@ -1453,7 +1453,7 @@ impl Interactivity {
cx.on_mouse_event(move |_: &MouseUpEvent, phase, cx| {
if phase == DispatchPhase::Capture {
*active_state.borrow_mut() = ElementClickedState::default();
cx.notify();
cx.refresh();
}
});
} else {
@ -1471,7 +1471,7 @@ impl Interactivity {
if group || element {
*active_state.borrow_mut() =
ElementClickedState { group, element };
cx.notify();
cx.refresh();
}
}
});
@ -1531,7 +1531,7 @@ impl Interactivity {
}
if *scroll_offset != old_scroll_offset {
cx.notify();
cx.refresh();
cx.stop_propagation();
}
}

View File

@ -109,7 +109,7 @@ impl Element for Img {
} else {
cx.spawn(|mut cx| async move {
if image_future.await.ok().is_some() {
cx.on_next_frame(|cx| cx.notify());
cx.on_next_frame(|cx| cx.refresh());
}
})
.detach();

View File

@ -258,7 +258,7 @@ impl StateInner {
);
}
cx.notify();
cx.refresh();
}
fn logical_scroll_top(&self) -> ListOffset {

View File

@ -389,7 +389,7 @@ impl Element for InteractiveText {
}
mouse_down.take();
cx.notify();
cx.refresh();
}
});
} else {
@ -399,7 +399,7 @@ impl Element for InteractiveText {
text_state.index_for_position(bounds, event.position)
{
mouse_down.set(Some(mouse_down_index));
cx.notify();
cx.refresh();
}
}
});

View File

@ -290,6 +290,7 @@ impl Element for AnyView {
&& cache_key.stacking_order == *cx.stacking_order()
&& cache_key.text_style == cx.text_style()
&& !cx.window.dirty_views.contains(&self.entity_id())
&& !cx.window.refreshing
{
cx.reuse_geometry();
return;

View File

@ -269,6 +269,7 @@ pub struct Window {
bounds_observers: SubscriberSet<(), AnyObserver>,
active: bool,
pub(crate) dirty: bool,
pub(crate) refreshing: bool,
pub(crate) drawing: bool,
activation_observers: SubscriberSet<(), AnyObserver>,
pub(crate) focus: Option<FocusId>,
@ -424,6 +425,7 @@ impl Window {
bounds_observers: SubscriberSet::new(),
active: false,
dirty: false,
refreshing: false,
drawing: false,
activation_observers: SubscriberSet::new(),
focus: None,
@ -478,8 +480,9 @@ impl<'a> WindowContext<'a> {
}
/// Mark the window as dirty, scheduling it to be redrawn on the next frame.
pub fn notify(&mut self) {
pub fn refresh(&mut self) {
if !self.window.drawing {
self.window.refreshing = true;
self.window.dirty = true;
}
}
@ -519,7 +522,7 @@ impl<'a> WindowContext<'a> {
self.window.focus_invalidated = true;
}
self.notify();
self.refresh();
}
/// Remove focus from all elements within this context's window.
@ -529,7 +532,7 @@ impl<'a> WindowContext<'a> {
}
self.window.focus = None;
self.notify();
self.refresh();
}
pub fn disable_focus(&mut self) {
@ -795,7 +798,7 @@ impl<'a> WindowContext<'a> {
self.window.viewport_size = self.window.platform_window.content_size();
self.window.bounds = self.window.platform_window.bounds();
self.window.display_id = self.window.platform_window.display().id();
self.notify();
self.refresh();
self.window
.bounds_observers
@ -1499,6 +1502,7 @@ impl<'a> WindowContext<'a> {
self.platform.set_cursor_style(cursor_style);
}
self.window.refreshing = false;
self.window.drawing = false;
ELEMENT_ARENA.with_borrow_mut(|element_arena| element_arena.clear());
@ -1641,12 +1645,12 @@ impl<'a> WindowContext<'a> {
if event.is::<MouseMoveEvent>() {
// If this was a mouse move event, redraw the window so that the
// active drag can follow the mouse cursor.
self.notify();
self.refresh();
} else if event.is::<MouseUpEvent>() {
// If this was a mouse up event, cancel the active drag and redraw
// the window.
self.active_drag = None;
self.notify();
self.refresh();
}
}
}
@ -2169,7 +2173,7 @@ impl VisualContext for WindowContext<'_> {
{
let view = self.new_view(build_view);
self.window.root_view = Some(view.clone().into());
self.notify();
self.refresh();
view
}
@ -2583,7 +2587,7 @@ impl<'a, V: 'static> ViewContext<'a, V> {
}
if !self.window.drawing {
self.window_cx.notify();
self.window_cx.window.dirty = true;
self.window_cx.app.push_effect(Effect::Notify {
emitter: self.view.model.entity_id,
});

View File

@ -584,7 +584,7 @@ impl TerminalElement {
this.update(cx, |term, _| term.try_modifiers_change(&event.modifiers));
if handled {
cx.notify();
cx.refresh();
}
}
});

View File

@ -55,7 +55,7 @@ impl<M: ManagedView> PopoverMenu<M> {
}
}
*menu2.borrow_mut() = None;
cx.notify();
cx.refresh();
})
.detach();
cx.focus_view(&new_menu);

View File

@ -153,7 +153,7 @@ impl<M: ManagedView> Element for RightClickMenu<M> {
}
}
*menu2.borrow_mut() = None;
cx.notify();
cx.refresh();
})
.detach();
cx.focus_view(&new_menu);
@ -166,7 +166,7 @@ impl<M: ManagedView> Element for RightClickMenu<M> {
} else {
cx.mouse_position()
};
cx.notify();
cx.refresh();
}
});
}

View File

@ -698,7 +698,7 @@ mod element {
// todo!(schedule serialize)
// workspace.schedule_serialize(cx);
cx.notify();
cx.refresh();
}
fn push_handle(