1use std::any::Any;
4use std::cell::Cell;
5use std::fmt::{self, Debug};
6use std::rc::Rc;
7
8use waft_foundation::{App, Handle};
9use waft_gestures::{DragEndDetails, DragStartDetails, DragUpdateDetails};
10use waft_rendering::ScrollDirection;
11
12use crate::framework::{BuildContext, Element, Notification, NotificationNode, NotificationTarget};
13use crate::widgets::notification_listener::LayoutChangedNotification;
14use crate::widgets::scroll_metrics::ScrollMetrics;
15
16#[derive(Debug, Default)]
21pub struct ViewportNotificationData {
22 depth: Cell<u32>,
23}
24
25impl ViewportNotificationData {
26 pub fn new() -> ViewportNotificationData {
28 ViewportNotificationData::default()
29 }
30
31 pub fn with_depth(depth: u32) -> ViewportNotificationData {
33 ViewportNotificationData {
34 depth: Cell::new(depth),
35 }
36 }
37
38 pub fn depth_cell(&self) -> &Cell<u32> {
41 &self.depth
42 }
43}
44
45pub trait ViewportNotificationMixin: Notification {
50 fn viewport_notification_data(&self) -> &ViewportNotificationData;
52
53 fn depth(&self) -> u32 {
62 self.viewport_notification_data().depth.get()
63 }
64
65 fn debug_fill_description(&self, description: &mut Vec<String>) {
67 let depth = self.depth();
68 let locality = if depth == 0 { "local" } else { "remote" };
69 description.push(format!("depth: {depth} ({locality})"));
70 }
71}
72
73pub trait ViewportElementMixin: Element {
84 fn attach_notification_tree(self: Handle<Self>, app: &mut App) {
86 let this = self.as_element();
87 let parent_tree = this
88 .parent(app)
89 .and_then(|parent| parent.notification_tree(app));
90 this.set_notification_tree(app, Some(Rc::new(NotificationNode::new(parent_tree, this))));
91 }
92
93 fn on_notification(self: Handle<Self>, app: &mut App, notification: &dyn Notification) -> bool {
95 let _ = app;
96 if let Some(depth) = notification.viewport_depth() {
97 depth.set(depth.get() + 1);
98 }
99 false
100 }
101}
102
103pub struct ScrollNotificationData {
105 pub metrics: Rc<dyn ScrollMetrics>,
108
109 pub context: Option<BuildContext>,
114}
115
116pub trait ScrollNotification: LayoutChangedNotification + ViewportNotificationMixin {
154 fn scroll_notification_data(&self) -> &ScrollNotificationData;
156
157 fn metrics(&self) -> &Rc<dyn ScrollMetrics> {
160 &self.scroll_notification_data().metrics
161 }
162
163 fn context(&self) -> Option<BuildContext> {
165 self.scroll_notification_data().context
166 }
167}
168
169impl NotificationTarget for dyn ScrollNotification {
170 fn cast(notification: &dyn Notification) -> Option<&dyn ScrollNotification> {
171 notification.as_scroll_notification()
172 }
173}
174
175fn fill_scroll_description(notification: &dyn ScrollNotification, description: &mut Vec<String>) {
177 ViewportNotificationMixin::debug_fill_description(notification, description);
178 description.push(format!("{:?}", notification.metrics()));
179}
180
181pub struct ScrollStartNotification {
188 viewport_notification: ViewportNotificationData,
189 scroll_notification: ScrollNotificationData,
190
191 pub drag_details: Option<DragStartDetails>,
196}
197
198impl ScrollStartNotification {
199 pub fn new(
201 metrics: Rc<dyn ScrollMetrics>,
202 context: Option<BuildContext>,
203 ) -> ScrollStartNotification {
204 ScrollStartNotification {
205 viewport_notification: ViewportNotificationData::new(),
206 scroll_notification: ScrollNotificationData { metrics, context },
207 drag_details: None,
208 }
209 }
210
211 pub fn drag_details(mut self, drag_details: DragStartDetails) -> ScrollStartNotification {
213 self.drag_details = Some(drag_details);
214 self
215 }
216}
217
218impl Notification for ScrollStartNotification {
219 fn as_any(&self) -> &dyn Any {
220 self
221 }
222
223 fn viewport_depth(&self) -> Option<&Cell<u32>> {
224 Some(&self.viewport_notification.depth)
225 }
226
227 fn as_scroll_notification(&self) -> Option<&dyn ScrollNotification> {
228 Some(self)
229 }
230
231 fn as_layout_changed_notification(&self) -> Option<&dyn LayoutChangedNotification> {
232 Some(self)
233 }
234}
235
236impl LayoutChangedNotification for ScrollStartNotification {}
237
238impl ViewportNotificationMixin for ScrollStartNotification {
239 fn viewport_notification_data(&self) -> &ViewportNotificationData {
240 &self.viewport_notification
241 }
242}
243
244impl ScrollNotification for ScrollStartNotification {
245 fn scroll_notification_data(&self) -> &ScrollNotificationData {
246 &self.scroll_notification
247 }
248}
249
250impl Debug for ScrollStartNotification {
251 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
252 let mut description = Vec::new();
253 fill_scroll_description(self, &mut description);
254 if let Some(drag_details) = &self.drag_details {
255 description.push(format!("{drag_details:?}"));
256 }
257 write!(f, "ScrollStartNotification({})", description.join(", "))
258 }
259}
260
261pub struct ScrollUpdateNotification {
270 viewport_notification: ViewportNotificationData,
271 scroll_notification: ScrollNotificationData,
272
273 pub drag_details: Option<DragUpdateDetails>,
278
279 pub scroll_delta: Option<f64>,
281}
282
283impl ScrollUpdateNotification {
284 pub fn new(metrics: Rc<dyn ScrollMetrics>, context: BuildContext) -> ScrollUpdateNotification {
287 ScrollUpdateNotification {
288 viewport_notification: ViewportNotificationData::new(),
289 scroll_notification: ScrollNotificationData {
290 metrics,
291 context: Some(context),
292 },
293 drag_details: None,
294 scroll_delta: None,
295 }
296 }
297
298 pub fn drag_details(mut self, drag_details: DragUpdateDetails) -> ScrollUpdateNotification {
300 self.drag_details = Some(drag_details);
301 self
302 }
303
304 pub fn scroll_delta(mut self, scroll_delta: f64) -> ScrollUpdateNotification {
306 self.scroll_delta = Some(scroll_delta);
307 self
308 }
309
310 pub fn with_depth(mut self, depth: u32) -> ScrollUpdateNotification {
313 self.viewport_notification = ViewportNotificationData::with_depth(depth);
314 self
315 }
316}
317
318impl Notification for ScrollUpdateNotification {
319 fn as_any(&self) -> &dyn Any {
320 self
321 }
322
323 fn viewport_depth(&self) -> Option<&Cell<u32>> {
324 Some(&self.viewport_notification.depth)
325 }
326
327 fn as_scroll_notification(&self) -> Option<&dyn ScrollNotification> {
328 Some(self)
329 }
330
331 fn as_layout_changed_notification(&self) -> Option<&dyn LayoutChangedNotification> {
332 Some(self)
333 }
334}
335
336impl LayoutChangedNotification for ScrollUpdateNotification {}
337
338impl ViewportNotificationMixin for ScrollUpdateNotification {
339 fn viewport_notification_data(&self) -> &ViewportNotificationData {
340 &self.viewport_notification
341 }
342}
343
344impl ScrollNotification for ScrollUpdateNotification {
345 fn scroll_notification_data(&self) -> &ScrollNotificationData {
346 &self.scroll_notification
347 }
348}
349
350impl Debug for ScrollUpdateNotification {
351 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
352 let mut description = Vec::new();
353 fill_scroll_description(self, &mut description);
354 description.push(match self.scroll_delta {
355 Some(scroll_delta) => format!("scrollDelta: {scroll_delta:?}"),
356 None => "scrollDelta: null".to_string(),
357 });
358 if let Some(drag_details) = &self.drag_details {
359 description.push(format!("{drag_details:?}"));
360 }
361 write!(f, "ScrollUpdateNotification({})", description.join(", "))
362 }
363}
364
365pub struct OverscrollNotification {
375 viewport_notification: ViewportNotificationData,
376 scroll_notification: ScrollNotificationData,
377
378 pub drag_details: Option<DragUpdateDetails>,
383
384 pub overscroll: f64,
389
390 pub velocity: f64,
397}
398
399impl OverscrollNotification {
400 pub fn new(
403 metrics: Rc<dyn ScrollMetrics>,
404 context: BuildContext,
405 overscroll: f64,
406 ) -> OverscrollNotification {
407 debug_assert!(overscroll.is_finite());
408 debug_assert!(overscroll != 0.0);
409 OverscrollNotification {
410 viewport_notification: ViewportNotificationData::new(),
411 scroll_notification: ScrollNotificationData {
412 metrics,
413 context: Some(context),
414 },
415 drag_details: None,
416 overscroll,
417 velocity: 0.0,
418 }
419 }
420
421 pub fn drag_details(mut self, drag_details: DragUpdateDetails) -> OverscrollNotification {
423 self.drag_details = Some(drag_details);
424 self
425 }
426
427 pub fn velocity(mut self, velocity: f64) -> OverscrollNotification {
429 self.velocity = velocity;
430 self
431 }
432}
433
434impl Notification for OverscrollNotification {
435 fn as_any(&self) -> &dyn Any {
436 self
437 }
438
439 fn viewport_depth(&self) -> Option<&Cell<u32>> {
440 Some(&self.viewport_notification.depth)
441 }
442
443 fn as_scroll_notification(&self) -> Option<&dyn ScrollNotification> {
444 Some(self)
445 }
446
447 fn as_layout_changed_notification(&self) -> Option<&dyn LayoutChangedNotification> {
448 Some(self)
449 }
450}
451
452impl LayoutChangedNotification for OverscrollNotification {}
453
454impl ViewportNotificationMixin for OverscrollNotification {
455 fn viewport_notification_data(&self) -> &ViewportNotificationData {
456 &self.viewport_notification
457 }
458}
459
460impl ScrollNotification for OverscrollNotification {
461 fn scroll_notification_data(&self) -> &ScrollNotificationData {
462 &self.scroll_notification
463 }
464}
465
466impl Debug for OverscrollNotification {
467 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
468 let mut description = Vec::new();
469 fill_scroll_description(self, &mut description);
470 description.push(format!("overscroll: {:.1}", self.overscroll));
471 description.push(format!("velocity: {:.1}", self.velocity));
472 if let Some(drag_details) = &self.drag_details {
473 description.push(format!("{drag_details:?}"));
474 }
475 write!(f, "OverscrollNotification({})", description.join(", "))
476 }
477}
478
479pub struct ScrollEndNotification {
486 viewport_notification: ViewportNotificationData,
487 scroll_notification: ScrollNotificationData,
488
489 pub drag_details: Option<DragEndDetails>,
503}
504
505impl ScrollEndNotification {
506 pub fn new(metrics: Rc<dyn ScrollMetrics>, context: BuildContext) -> ScrollEndNotification {
508 ScrollEndNotification {
509 viewport_notification: ViewportNotificationData::new(),
510 scroll_notification: ScrollNotificationData {
511 metrics,
512 context: Some(context),
513 },
514 drag_details: None,
515 }
516 }
517
518 pub fn drag_details(mut self, drag_details: DragEndDetails) -> ScrollEndNotification {
520 self.drag_details = Some(drag_details);
521 self
522 }
523}
524
525impl Notification for ScrollEndNotification {
526 fn as_any(&self) -> &dyn Any {
527 self
528 }
529
530 fn viewport_depth(&self) -> Option<&Cell<u32>> {
531 Some(&self.viewport_notification.depth)
532 }
533
534 fn as_scroll_notification(&self) -> Option<&dyn ScrollNotification> {
535 Some(self)
536 }
537
538 fn as_layout_changed_notification(&self) -> Option<&dyn LayoutChangedNotification> {
539 Some(self)
540 }
541}
542
543impl LayoutChangedNotification for ScrollEndNotification {}
544
545impl ViewportNotificationMixin for ScrollEndNotification {
546 fn viewport_notification_data(&self) -> &ViewportNotificationData {
547 &self.viewport_notification
548 }
549}
550
551impl ScrollNotification for ScrollEndNotification {
552 fn scroll_notification_data(&self) -> &ScrollNotificationData {
553 &self.scroll_notification
554 }
555}
556
557impl Debug for ScrollEndNotification {
558 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
559 let mut description = Vec::new();
560 fill_scroll_description(self, &mut description);
561 if let Some(drag_details) = &self.drag_details {
562 description.push(format!("{drag_details:?}"));
563 }
564 write!(f, "ScrollEndNotification({})", description.join(", "))
565 }
566}
567
568pub struct UserScrollNotification {
578 viewport_notification: ViewportNotificationData,
579 scroll_notification: ScrollNotificationData,
580
581 pub direction: ScrollDirection,
588}
589
590impl UserScrollNotification {
591 pub fn new(
594 metrics: Rc<dyn ScrollMetrics>,
595 context: BuildContext,
596 direction: ScrollDirection,
597 ) -> UserScrollNotification {
598 UserScrollNotification {
599 viewport_notification: ViewportNotificationData::new(),
600 scroll_notification: ScrollNotificationData {
601 metrics,
602 context: Some(context),
603 },
604 direction,
605 }
606 }
607}
608
609impl Notification for UserScrollNotification {
610 fn as_any(&self) -> &dyn Any {
611 self
612 }
613
614 fn viewport_depth(&self) -> Option<&Cell<u32>> {
615 Some(&self.viewport_notification.depth)
616 }
617
618 fn as_scroll_notification(&self) -> Option<&dyn ScrollNotification> {
619 Some(self)
620 }
621
622 fn as_layout_changed_notification(&self) -> Option<&dyn LayoutChangedNotification> {
623 Some(self)
624 }
625}
626
627impl LayoutChangedNotification for UserScrollNotification {}
628
629impl ViewportNotificationMixin for UserScrollNotification {
630 fn viewport_notification_data(&self) -> &ViewportNotificationData {
631 &self.viewport_notification
632 }
633}
634
635impl ScrollNotification for UserScrollNotification {
636 fn scroll_notification_data(&self) -> &ScrollNotificationData {
637 &self.scroll_notification
638 }
639}
640
641impl Debug for UserScrollNotification {
642 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
643 let mut description = Vec::new();
644 fill_scroll_description(self, &mut description);
645 description.push(format!("direction: {:?}", self.direction));
646 write!(f, "UserScrollNotification({})", description.join(", "))
647 }
648}
649
650pub type ScrollNotificationPredicate = Rc<dyn Fn(&dyn ScrollNotification) -> bool>;
653
654pub fn default_scroll_notification_predicate(notification: &dyn ScrollNotification) -> bool {
658 notification.depth() == 0
659}
660
661#[cfg(test)]
662mod tests {
663 use std::cell::RefCell;
664 use waft_foundation::AppCell;
665
666 use waft_painting::AxisDirection;
667
668 use super::*;
669 use crate::framework::{
670 AnyElement, ComponentElement, ComponentElementData, ElementData, IntoWidget, KeyRef,
671 ProxyElement, Slot, Widget, WidgetKind, WidgetRef, component_element_overrides,
672 downcast_widget,
673 };
674 use crate::test_harness::Harness;
675 use crate::widgets::basic::{Builder, SizedBox};
676 use crate::widgets::notification_listener::{
677 NotificationListener, PlainLayoutChangedNotification,
678 };
679 use crate::widgets::scroll_metrics::FixedScrollMetrics;
680
681 #[derive(Debug)]
684 struct TestViewport {
685 child: WidgetRef,
686 }
687
688 fn viewport<K>(child: impl IntoWidget<K>) -> WidgetRef {
689 Rc::new(TestViewport {
690 child: child.into_widget(),
691 })
692 }
693
694 impl Widget for TestViewport {
695 fn key(&self) -> Option<&KeyRef> {
696 None
697 }
698
699 fn create_element(&self, app: &mut App, this: WidgetRef) -> AnyElement {
700 let element = app.create(TestViewportElement {
701 element: ElementData::new(this),
702 component: ComponentElementData::default(),
703 });
704 element.as_element()
705 }
706
707 fn as_any(&self) -> &dyn Any {
708 self
709 }
710
711 fn widget_type(&self) -> std::any::TypeId {
712 std::any::TypeId::of::<TestViewport>()
713 }
714
715 fn kind(&self) -> WidgetKind {
716 WidgetKind::Other
717 }
718 }
719
720 struct TestViewportElement {
721 element: ElementData,
722 component: ComponentElementData,
723 }
724
725 impl ComponentElement for TestViewportElement {
726 fn component_data(self: Handle<Self>, app: &App) -> &ComponentElementData {
727 &app.get(self).component
728 }
729
730 fn component_data_mut(self: Handle<Self>, app: &mut App) -> &mut ComponentElementData {
731 &mut app.get_mut(self).component
732 }
733
734 fn build(self: Handle<Self>, app: &mut App) -> WidgetRef {
735 self.proxied_child(app)
736 }
737 }
738
739 impl ProxyElement for TestViewportElement {
740 fn proxied_child(self: Handle<Self>, app: &App) -> WidgetRef {
741 downcast_widget::<TestViewport>(&**self.as_element().widget(app))
742 .expect("a TestViewportElement holds its TestViewport")
743 .child
744 .clone()
745 }
746
747 fn notify_clients(self: Handle<Self>, _app: &mut App, _old_widget: WidgetRef) {}
748 }
749
750 impl ViewportElementMixin for TestViewportElement {}
751
752 impl Element for TestViewportElement {
753 crate::element_accessors!();
754 component_element_overrides!();
755
756 #[inline(always)]
757 fn mount(
758 self: Handle<Self>,
759 app: &mut App,
760 parent: Option<AnyElement>,
761 new_slot: Option<Slot>,
762 ) {
763 ComponentElement::mount(self, app, parent, new_slot);
764 }
765
766 #[inline(always)]
767 fn update(self: Handle<Self>, app: &mut App, new_widget: WidgetRef) {
768 ProxyElement::update(self, app, new_widget);
769 }
770
771 #[inline(always)]
772 fn perform_rebuild(self: Handle<Self>, app: &mut App) {
773 ComponentElement::perform_rebuild(self, app);
774 }
775
776 fn attach_notification_tree(self: Handle<Self>, app: &mut App) {
777 ViewportElementMixin::attach_notification_tree(self, app);
778 }
779
780 fn on_notification(
781 self: Handle<Self>,
782 app: &mut App,
783 notification: &dyn Notification,
784 ) -> bool {
785 ViewportElementMixin::on_notification(self, app, notification)
786 }
787 }
788
789 fn test_metrics() -> Rc<dyn ScrollMetrics> {
790 Rc::new(FixedScrollMetrics::new(
791 Some(0.0),
792 Some(400.0),
793 Some(20.0),
794 Some(600.0),
795 AxisDirection::Down,
796 3.0,
797 ))
798 }
799
800 type Log = Rc<RefCell<Vec<(&'static str, u32)>>>;
801
802 fn listener(log: &Log, name: &'static str, child: WidgetRef) -> WidgetRef {
803 let log = Rc::clone(log);
804 NotificationListener::<ScrollUpdateNotification>::new(child)
805 .on_notification(move |_app, notification| {
806 log.borrow_mut().push((name, notification.depth()));
807 false
808 })
809 .into_widget()
810 }
811
812 #[test]
813 fn a_family_listener_receives_every_kind_of_scroll_notification() {
814 let cell = AppCell::new();
815 let mut app = cell.borrow_mut();
816 let seen: Rc<RefCell<Vec<String>>> = Rc::default();
817 let dispatcher = Builder::new(|app, context| {
818 ScrollStartNotification::new(test_metrics(), Some(context))
819 .dispatch(app, Some(context));
820 ScrollUpdateNotification::new(test_metrics(), context)
821 .scroll_delta(4.0)
822 .dispatch(app, Some(context));
823 ScrollEndNotification::new(test_metrics(), context).dispatch(app, Some(context));
824 SizedBox::shrink().into_widget()
825 });
826 let tree = NotificationListener::<dyn ScrollNotification>::new(dispatcher)
827 .on_notification({
828 let seen = Rc::clone(&seen);
829 move |_app, notification| {
830 seen.borrow_mut().push(format!("{notification:?}"));
831 false
832 }
833 })
834 .into_widget();
835 let harness = Harness::mount(&mut app, tree);
836 harness.pump(&mut app);
837 let seen = seen.borrow();
838 assert_eq!(seen.len(), 3);
839 assert!(
840 seen[0].starts_with("ScrollStartNotification"),
841 "{}",
842 seen[0]
843 );
844 assert!(
845 seen[1].starts_with("ScrollUpdateNotification"),
846 "{}",
847 seen[1]
848 );
849 assert!(seen[2].starts_with("ScrollEndNotification"), "{}", seen[2]);
850 }
851
852 #[test]
853 fn a_layout_changed_listener_receives_scroll_notifications_and_plain_layout_changes() {
854 let cell = AppCell::new();
855 let mut app = cell.borrow_mut();
856 let seen: Rc<RefCell<Vec<String>>> = Rc::default();
857 let dispatcher = Builder::new(|app, context| {
858 PlainLayoutChangedNotification.dispatch(app, Some(context));
859 ScrollUpdateNotification::new(test_metrics(), context)
860 .scroll_delta(4.0)
861 .dispatch(app, Some(context));
862 UserScrollNotification::new(test_metrics(), context, ScrollDirection::Idle)
863 .dispatch(app, Some(context));
864 SizedBox::shrink().into_widget()
865 });
866 let tree = NotificationListener::<dyn LayoutChangedNotification>::new(dispatcher)
867 .on_notification({
868 let seen = Rc::clone(&seen);
869 move |_app, notification| {
870 seen.borrow_mut().push(format!("{notification:?}"));
871 false
872 }
873 })
874 .into_widget();
875 let harness = Harness::mount(&mut app, tree);
876 harness.pump(&mut app);
877 let seen = seen.borrow();
878 assert_eq!(seen.len(), 3);
879 assert_eq!(seen[0], "PlainLayoutChangedNotification");
880 assert!(
881 seen[1].starts_with("ScrollUpdateNotification"),
882 "{}",
883 seen[1]
884 );
885 assert!(seen[2].starts_with("UserScrollNotification"), "{}", seen[2]);
886 }
887
888 #[test]
889 fn a_scroll_update_notification_bubbles_and_each_viewport_adds_to_its_depth() {
890 let cell = AppCell::new();
891 let mut app = cell.borrow_mut();
892 let log: Log = Rc::default();
893 let dispatcher = Builder::new(|app, context| {
894 ScrollUpdateNotification::new(test_metrics(), context)
895 .scroll_delta(4.0)
896 .dispatch(app, Some(context));
897 SizedBox::shrink().into_widget()
898 });
899 let tree = listener(
900 &log,
901 "outer",
902 viewport(listener(
903 &log,
904 "middle",
905 viewport(listener(&log, "inner", dispatcher.into_widget())),
906 )),
907 );
908 let harness = Harness::mount(&mut app, tree);
909 harness.pump(&mut app);
910
911 assert_eq!(
912 *log.borrow(),
913 vec![("inner", 0), ("middle", 1), ("outer", 2)]
914 );
915 }
916
917 #[test]
918 fn a_notification_reports_its_depth_and_its_metrics() {
919 let notification = ScrollUpdateNotification::new(
920 test_metrics(),
921 {
923 let cell = AppCell::new();
924 let mut app = cell.borrow_mut();
925 let harness = Harness::mount(&mut app, SizedBox::shrink().into_widget());
926 harness.root.as_element()
927 },
928 )
929 .scroll_delta(4.0)
930 .with_depth(2);
931
932 assert_eq!(notification.depth(), 2);
933 assert!(default_scroll_notification_predicate(
934 &ScrollUpdateNotification::new(
935 test_metrics(),
936 notification.context().expect("a context was given"),
937 )
938 ));
939 assert!(!default_scroll_notification_predicate(¬ification));
940 assert_eq!(
941 format!("{notification:?}"),
942 "ScrollUpdateNotification(depth: 2 (remote), \
943 FixedScrollMetrics(20.0..[600.0]..380.0), scrollDelta: 4.0)"
944 );
945 }
946
947 #[test]
948 fn the_overscroll_notification_reports_its_overscroll_and_velocity() {
949 let cell = AppCell::new();
950 let mut app = cell.borrow_mut();
951 let harness = Harness::mount(&mut app, SizedBox::shrink().into_widget());
952 let context = harness.root.as_element();
953 let notification =
954 OverscrollNotification::new(test_metrics(), context, -12.0).velocity(3.0);
955 assert_eq!(notification.overscroll, -12.0);
956 assert_eq!(
957 format!("{notification:?}"),
958 "OverscrollNotification(depth: 0 (local), \
959 FixedScrollMetrics(20.0..[600.0]..380.0), overscroll: -12.0, velocity: 3.0)"
960 );
961
962 let user_scroll =
963 UserScrollNotification::new(test_metrics(), context, ScrollDirection::Reverse);
964 assert_eq!(
965 format!("{user_scroll:?}"),
966 "UserScrollNotification(depth: 0 (local), \
967 FixedScrollMetrics(20.0..[600.0]..380.0), direction: Reverse)"
968 );
969 }
970}