From 752403d70c851ece620c4007710062b158e8dec3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 25 Oct 2024 15:40:05 +0200 Subject: Split `Shell::request_redraw` into two different methods --- widget/src/lazy/component.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'widget/src/lazy/component.rs') diff --git a/widget/src/lazy/component.rs b/widget/src/lazy/component.rs index c7bc1264..e45c24ac 100644 --- a/widget/src/lazy/component.rs +++ b/widget/src/lazy/component.rs @@ -7,6 +7,7 @@ use crate::core::overlay; use crate::core::renderer; use crate::core::widget; use crate::core::widget::tree::{self, Tree}; +use crate::core::window; use crate::core::{ self, Clipboard, Element, Length, Point, Rectangle, Shell, Size, Vector, Widget, @@ -342,7 +343,14 @@ where local_shell.revalidate_layout(|| shell.invalidate_layout()); if let Some(redraw_request) = local_shell.redraw_request() { - shell.request_redraw(redraw_request); + match redraw_request { + window::RedrawRequest::NextFrame => { + shell.request_redraw(); + } + window::RedrawRequest::At(at) => { + shell.request_redraw_at(at); + } + } } if !local_messages.is_empty() { @@ -620,7 +628,14 @@ where local_shell.revalidate_layout(|| shell.invalidate_layout()); if let Some(redraw_request) = local_shell.redraw_request() { - shell.request_redraw(redraw_request); + match redraw_request { + window::RedrawRequest::NextFrame => { + shell.request_redraw(); + } + window::RedrawRequest::At(at) => { + shell.request_redraw_at(at); + } + } } if !local_messages.is_empty() { -- cgit From dcc184b01b753dbecb500205391f6eaaa21c8683 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 25 Oct 2024 19:28:18 +0200 Subject: Replace `event::Status` in `Widget::on_event` with `Shell::capture_event` --- widget/src/lazy/component.rs | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'widget/src/lazy/component.rs') diff --git a/widget/src/lazy/component.rs b/widget/src/lazy/component.rs index e45c24ac..062e6f35 100644 --- a/widget/src/lazy/component.rs +++ b/widget/src/lazy/component.rs @@ -1,6 +1,5 @@ //! Build and reuse custom widgets using The Elm Architecture. #![allow(deprecated)] -use crate::core::event; use crate::core::layout::{self, Layout}; use crate::core::mouse; use crate::core::overlay; @@ -322,12 +321,12 @@ where clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, viewport: &Rectangle, - ) -> event::Status { + ) { let mut local_messages = Vec::new(); let mut local_shell = Shell::new(&mut local_messages); let t = tree.state.downcast_mut::>>>(); - let event_status = self.with_element_mut(|element| { + self.with_element_mut(|element| { element.as_widget_mut().on_event( &mut t.borrow_mut().as_mut().unwrap().children[0], event, @@ -337,9 +336,13 @@ where clipboard, &mut local_shell, viewport, - ) + ); }); + if local_shell.is_event_captured() { + shell.capture_event(); + } + local_shell.revalidate_layout(|| shell.invalidate_layout()); if let Some(redraw_request) = local_shell.redraw_request() { @@ -377,8 +380,6 @@ where shell.invalidate_layout(); } - - event_status } fn operate( @@ -608,22 +609,24 @@ where renderer: &Renderer, clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, - ) -> event::Status { + ) { let mut local_messages = Vec::new(); let mut local_shell = Shell::new(&mut local_messages); - let event_status = self - .with_overlay_mut_maybe(|overlay| { - overlay.on_event( - event, - layout, - cursor, - renderer, - clipboard, - &mut local_shell, - ) - }) - .unwrap_or(event::Status::Ignored); + let _ = self.with_overlay_mut_maybe(|overlay| { + overlay.on_event( + event, + layout, + cursor, + renderer, + clipboard, + &mut local_shell, + ); + }); + + if local_shell.is_event_captured() { + shell.capture_event(); + } local_shell.revalidate_layout(|| shell.invalidate_layout()); @@ -673,8 +676,6 @@ where shell.invalidate_layout(); } - - event_status } fn is_over( -- cgit From f02bfc3f68322bea0c56283d76888714be401ec2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 25 Oct 2024 22:06:06 +0200 Subject: Rename `Widget::on_event` to `update` --- widget/src/lazy/component.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'widget/src/lazy/component.rs') diff --git a/widget/src/lazy/component.rs b/widget/src/lazy/component.rs index 062e6f35..6f661ef6 100644 --- a/widget/src/lazy/component.rs +++ b/widget/src/lazy/component.rs @@ -311,7 +311,7 @@ where }) } - fn on_event( + fn update( &mut self, tree: &mut Tree, event: core::Event, @@ -327,7 +327,7 @@ where let t = tree.state.downcast_mut::>>>(); self.with_element_mut(|element| { - element.as_widget_mut().on_event( + element.as_widget_mut().update( &mut t.borrow_mut().as_mut().unwrap().children[0], event, layout, -- cgit From e5f1e31a5c068fe992cab076661cb6e2d120bdf1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 6 Nov 2024 00:02:46 +0100 Subject: Rename `Overlay::on_event` to `update` --- widget/src/lazy/component.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'widget/src/lazy/component.rs') diff --git a/widget/src/lazy/component.rs b/widget/src/lazy/component.rs index 6f661ef6..1758b963 100644 --- a/widget/src/lazy/component.rs +++ b/widget/src/lazy/component.rs @@ -601,7 +601,7 @@ where .unwrap_or_default() } - fn on_event( + fn update( &mut self, event: core::Event, layout: Layout<'_>, @@ -614,7 +614,7 @@ where let mut local_shell = Shell::new(&mut local_messages); let _ = self.with_overlay_mut_maybe(|overlay| { - overlay.on_event( + overlay.update( event, layout, cursor, -- cgit