summaryrefslogtreecommitdiffstats
path: root/widget/src/helpers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'widget/src/helpers.rs')
-rw-r--r--widget/src/helpers.rs56
1 files changed, 27 insertions, 29 deletions
diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs
index 52290a54..33dff647 100644
--- a/widget/src/helpers.rs
+++ b/widget/src/helpers.rs
@@ -363,12 +363,11 @@ where
Theme: 'a,
Renderer: core::Renderer + 'a,
{
- use crate::core::event::{self, Event};
use crate::core::layout::{self, Layout};
use crate::core::mouse;
use crate::core::renderer;
use crate::core::widget::tree::{self, Tree};
- use crate::core::{Rectangle, Shell, Size};
+ use crate::core::{Event, Rectangle, Shell, Size};
struct Opaque<'a, Message, Theme, Renderer> {
content: Element<'a, Message, Theme, Renderer>,
@@ -439,7 +438,7 @@ where
.operate(state, layout, renderer, operation);
}
- fn on_event(
+ fn update(
&mut self,
state: &mut Tree,
event: Event,
@@ -449,25 +448,19 @@ where
clipboard: &mut dyn core::Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
- ) -> event::Status {
+ ) {
let is_mouse_press = matches!(
event,
core::Event::Mouse(mouse::Event::ButtonPressed(_))
);
- if let core::event::Status::Captured =
- self.content.as_widget_mut().on_event(
- state, event, layout, cursor, renderer, clipboard, shell,
- viewport,
- )
- {
- return event::Status::Captured;
- }
+ self.content.as_widget_mut().update(
+ state, event, layout, cursor, renderer, clipboard, shell,
+ viewport,
+ );
if is_mouse_press && cursor.is_over(layout.bounds()) {
- event::Status::Captured
- } else {
- event::Status::Ignored
+ shell.capture_event();
}
}
@@ -530,18 +523,18 @@ where
Theme: 'a,
Renderer: core::Renderer + 'a,
{
- use crate::core::event::{self, Event};
use crate::core::layout::{self, Layout};
use crate::core::mouse;
use crate::core::renderer;
use crate::core::widget::tree::{self, Tree};
- use crate::core::{Rectangle, Shell, Size};
+ use crate::core::{Event, Rectangle, Shell, Size};
struct Hover<'a, Message, Theme, Renderer> {
base: Element<'a, Message, Theme, Renderer>,
top: Element<'a, Message, Theme, Renderer>,
is_top_focused: bool,
is_top_overlay_active: bool,
+ is_hovered: bool,
}
impl<'a, Message, Theme, Renderer> Widget<Message, Theme, Renderer>
@@ -648,7 +641,7 @@ where
}
}
- fn on_event(
+ fn update(
&mut self,
tree: &mut Tree,
event: Event,
@@ -658,11 +651,13 @@ where
clipboard: &mut dyn core::Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
- ) -> event::Status {
+ ) {
let mut children = layout.children().zip(&mut tree.children);
let (base_layout, base_tree) = children.next().unwrap();
let (top_layout, top_tree) = children.next().unwrap();
+ let is_hovered = cursor.is_over(layout.bounds());
+
if matches!(event, Event::Window(window::Event::RedrawRequested(_)))
{
let mut count_focused = operation::focusable::count();
@@ -678,19 +673,23 @@ where
operation::Outcome::Some(count) => count.focused.is_some(),
_ => false,
};
+
+ self.is_hovered = is_hovered;
+ } else if is_hovered != self.is_hovered {
+ shell.request_redraw();
}
- let top_status = if matches!(
+ if matches!(
event,
Event::Mouse(
mouse::Event::CursorMoved { .. }
| mouse::Event::ButtonReleased(_)
)
- ) || cursor.is_over(layout.bounds())
+ ) || is_hovered
|| self.is_top_focused
|| self.is_top_overlay_active
{
- self.top.as_widget_mut().on_event(
+ self.top.as_widget_mut().update(
top_tree,
event.clone(),
top_layout,
@@ -699,16 +698,14 @@ where
clipboard,
shell,
viewport,
- )
- } else {
- event::Status::Ignored
+ );
};
- if top_status == event::Status::Captured {
- return top_status;
+ if shell.is_event_captured() {
+ return;
}
- self.base.as_widget_mut().on_event(
+ self.base.as_widget_mut().update(
base_tree,
event.clone(),
base_layout,
@@ -717,7 +714,7 @@ where
clipboard,
shell,
viewport,
- )
+ );
}
fn mouse_interaction(
@@ -777,6 +774,7 @@ where
top: top.into(),
is_top_focused: false,
is_top_overlay_active: false,
+ is_hovered: false,
})
}