Automatically reset cursor style when hit test changes (#9289)
Release Notes: - N/A Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
7f0e373358
commit
139bb3275a
3 changed files with 22 additions and 22 deletions
|
@ -956,12 +956,6 @@ impl<'a> WindowContext<'a> {
|
||||||
self.window.next_frame.focus = self.window.focus;
|
self.window.next_frame.focus = self.window.focus;
|
||||||
self.window.next_frame.window_active = self.window.active.get();
|
self.window.next_frame.window_active = self.window.active.get();
|
||||||
|
|
||||||
// Set the cursor only if we're the active window.
|
|
||||||
if self.is_window_active() {
|
|
||||||
let cursor_style = self.compute_cursor_style().unwrap_or(CursorStyle::Arrow);
|
|
||||||
self.platform.set_cursor_style(cursor_style);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register requested input handler with the platform window.
|
// Register requested input handler with the platform window.
|
||||||
if let Some(input_handler) = self.window.next_frame.input_handlers.pop() {
|
if let Some(input_handler) = self.window.next_frame.input_handlers.pop() {
|
||||||
self.window
|
self.window
|
||||||
|
@ -1017,6 +1011,8 @@ impl<'a> WindowContext<'a> {
|
||||||
.clone()
|
.clone()
|
||||||
.retain(&(), |listener| listener(&event, self));
|
.retain(&(), |listener| listener(&event, self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.reset_cursor_style();
|
||||||
self.window.refreshing = false;
|
self.window.refreshing = false;
|
||||||
self.window.draw_phase = DrawPhase::None;
|
self.window.draw_phase = DrawPhase::None;
|
||||||
self.window.needs_present.set(true);
|
self.window.needs_present.set(true);
|
||||||
|
@ -1031,16 +1027,20 @@ impl<'a> WindowContext<'a> {
|
||||||
profiling::finish_frame!();
|
profiling::finish_frame!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_cursor_style(&mut self) -> Option<CursorStyle> {
|
fn reset_cursor_style(&self) {
|
||||||
// TODO: maybe we should have a HashMap keyed by HitboxId.
|
// Set the cursor only if we're the active window.
|
||||||
let request = self
|
if self.is_window_active() {
|
||||||
.window
|
let style = self
|
||||||
.next_frame
|
.window
|
||||||
.cursor_styles
|
.rendered_frame
|
||||||
.iter()
|
.cursor_styles
|
||||||
.rev()
|
.iter()
|
||||||
.find(|request| request.hitbox_id.is_hovered(self))?;
|
.rev()
|
||||||
Some(request.style)
|
.find(|request| request.hitbox_id.is_hovered(self))
|
||||||
|
.map(|request| request.style)
|
||||||
|
.unwrap_or(CursorStyle::Arrow);
|
||||||
|
self.platform.set_cursor_style(style);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dispatch a given keystroke as though the user had typed it.
|
/// Dispatch a given keystroke as though the user had typed it.
|
||||||
|
@ -1175,7 +1175,11 @@ impl<'a> WindowContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_mouse_event(&mut self, event: &dyn Any) {
|
fn dispatch_mouse_event(&mut self, event: &dyn Any) {
|
||||||
self.window.mouse_hit_test = self.window.rendered_frame.hit_test(self.mouse_position());
|
let hit_test = self.window.rendered_frame.hit_test(self.mouse_position());
|
||||||
|
if hit_test != self.window.mouse_hit_test {
|
||||||
|
self.window.mouse_hit_test = hit_test;
|
||||||
|
self.reset_cursor_style();
|
||||||
|
}
|
||||||
|
|
||||||
let mut mouse_listeners = mem::take(&mut self.window.rendered_frame.mouse_listeners);
|
let mut mouse_listeners = mem::take(&mut self.window.rendered_frame.mouse_listeners);
|
||||||
self.with_element_context(|cx| {
|
self.with_element_context(|cx| {
|
||||||
|
|
|
@ -79,7 +79,7 @@ impl Hitbox {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default, Eq, PartialEq)]
|
||||||
pub(crate) struct HitTest(SmallVec<[HitboxId; 8]>);
|
pub(crate) struct HitTest(SmallVec<[HitboxId; 8]>);
|
||||||
|
|
||||||
pub(crate) struct DeferredDraw {
|
pub(crate) struct DeferredDraw {
|
||||||
|
|
|
@ -941,8 +941,6 @@ mod element {
|
||||||
let flexes = self.flexes.clone();
|
let flexes = self.flexes.clone();
|
||||||
let child_bounds = child.bounds;
|
let child_bounds = child.bounds;
|
||||||
let axis = self.axis;
|
let axis = self.axis;
|
||||||
let handle_hitbox = handle.hitbox.clone();
|
|
||||||
let was_hovered = handle_hitbox.is_hovered(cx);
|
|
||||||
move |e: &MouseMoveEvent, phase, cx| {
|
move |e: &MouseMoveEvent, phase, cx| {
|
||||||
let dragged_handle = dragged_handle.borrow();
|
let dragged_handle = dragged_handle.borrow();
|
||||||
if phase.bubble() {
|
if phase.bubble() {
|
||||||
|
@ -957,8 +955,6 @@ mod element {
|
||||||
workspace.clone(),
|
workspace.clone(),
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
} else if was_hovered != handle_hitbox.is_hovered(cx) {
|
|
||||||
cx.refresh();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue