mirror of
https://github.com/danbulant/cushy
synced 2026-06-18 05:51:20 +00:00
Fixed cursor hover events
Broken in 4f3ef7d9ed. Thanks to @pepone42
for reporting this.
This commit is contained in:
parent
b0a870aceb
commit
a129e64d77
2 changed files with 20 additions and 5 deletions
|
|
@ -21,7 +21,9 @@ use crate::styles::{ComponentDefinition, FontFamilyList, Styles, Theme, ThemePai
|
|||
use crate::tree::Tree;
|
||||
use crate::value::{IntoValue, Source, Value};
|
||||
use crate::widget::{EventHandling, MountedWidget, RootBehavior, WidgetId, WidgetInstance};
|
||||
use crate::window::{CursorState, DeviceId, KeyEvent, PlatformWindow, ThemeMode};
|
||||
use crate::window::{
|
||||
CursorState, DeviceId, KeyEvent, PlatformWindow, ThemeMode, WidgetCursorState,
|
||||
};
|
||||
use crate::ConstraintLimit;
|
||||
|
||||
/// A context to an event function.
|
||||
|
|
@ -316,13 +318,17 @@ impl<'context> EventContext<'context> {
|
|||
continue;
|
||||
};
|
||||
let relative = location - widget_layout.origin;
|
||||
let widget_hover = Some(WidgetCursorState {
|
||||
id: widget.id(),
|
||||
last_hovered: location,
|
||||
});
|
||||
|
||||
if widget_context.hit_test(relative) {
|
||||
if current_hover != Some(widget.id()) {
|
||||
if current_hover != widget_hover {
|
||||
widget_context.hover(location);
|
||||
}
|
||||
drop(widget_context);
|
||||
self.cursor.widget = Some(widget.id());
|
||||
self.cursor.widget = widget_hover;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2378,7 +2378,10 @@ where
|
|||
if let (ElementState::Pressed, Some(location), Some(hovered)) = (
|
||||
state,
|
||||
self.cursor.location,
|
||||
self.cursor.widget.and_then(|id| self.tree.widget(id)),
|
||||
self.cursor
|
||||
.widget
|
||||
.as_ref()
|
||||
.and_then(|hover| self.tree.widget(hover.id)),
|
||||
) {
|
||||
if let Some(handler) = recursively_handle_event(
|
||||
&mut EventContext::new(
|
||||
|
|
@ -2943,7 +2946,13 @@ fn recursively_handle_event(
|
|||
#[derive(Default)]
|
||||
pub(crate) struct CursorState {
|
||||
pub(crate) location: Option<Point<Px>>,
|
||||
pub(crate) widget: Option<WidgetId>,
|
||||
pub(crate) widget: Option<WidgetCursorState>,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub(crate) struct WidgetCursorState {
|
||||
pub(crate) id: WidgetId,
|
||||
pub(crate) last_hovered: Point<Px>,
|
||||
}
|
||||
|
||||
pub(crate) mod sealed {
|
||||
|
|
|
|||
Loading…
Reference in a new issue