parent
bf4796bbeb
commit
c711750be7
1 changed files with 10 additions and 5 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
//! A container for capturing mouse events.
|
//! A container for capturing mouse events.
|
||||||
|
|
||||||
use crate::core::event::{self, Event};
|
use crate::core::event::{self, Event};
|
||||||
use crate::core::layout;
|
use crate::core::layout;
|
||||||
use crate::core::mouse;
|
use crate::core::mouse;
|
||||||
|
|
@ -123,6 +122,8 @@ impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct State {
|
struct State {
|
||||||
is_hovered: bool,
|
is_hovered: bool,
|
||||||
|
bounds: Rectangle,
|
||||||
|
cursor_position: Option<Point>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> {
|
impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> {
|
||||||
|
|
@ -313,13 +314,17 @@ fn update<Message: Clone, Theme, Renderer>(
|
||||||
cursor: mouse::Cursor,
|
cursor: mouse::Cursor,
|
||||||
shell: &mut Shell<'_, Message>,
|
shell: &mut Shell<'_, Message>,
|
||||||
) -> event::Status {
|
) -> event::Status {
|
||||||
if let Event::Mouse(mouse::Event::CursorMoved { .. })
|
let state: &mut State = tree.state.downcast_mut();
|
||||||
| Event::Touch(touch::Event::FingerMoved { .. }) = event
|
|
||||||
{
|
|
||||||
let state: &mut State = tree.state.downcast_mut();
|
|
||||||
|
|
||||||
|
let cursor_position = cursor.position();
|
||||||
|
let bounds = layout.bounds();
|
||||||
|
|
||||||
|
if state.cursor_position != cursor_position && state.bounds != bounds {
|
||||||
let was_hovered = state.is_hovered;
|
let was_hovered = state.is_hovered;
|
||||||
|
|
||||||
state.is_hovered = cursor.is_over(layout.bounds());
|
state.is_hovered = cursor.is_over(layout.bounds());
|
||||||
|
state.cursor_position = cursor_position;
|
||||||
|
state.bounds = bounds;
|
||||||
|
|
||||||
match (
|
match (
|
||||||
widget.on_enter.as_ref(),
|
widget.on_enter.as_ref(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue