1use crate::*;
2use std::any::Any;
3
4pub struct AnimView<V, F> {
5 child: V,
6 func: F,
7}
8
9impl<V, F> AnimView<V, F>
10where
11 V: View,
12 F: Fn(&mut Context, f32) + 'static + Clone,
13{
14 pub fn new(child: V, func: F) -> Self {
15 Self { child, func }
16 }
17}
18
19impl<V, F> View for AnimView<V, F>
20where
21 V: View,
22 F: Fn(&mut Context, f32) + 'static + Clone,
23{
24 fn process(
25 &self,
26 event: &Event,
27 id: ViewId,
28 cx: &mut Context,
29 actions: &mut Vec<Box<dyn Any>>,
30 ) {
31 if let Event::Anim = event {
32 (self.func)(cx, 1.0 / 60.0) }
34
35 self.child.process(event, id.child(&0), cx, actions);
36 }
37
38 fn draw(&self, id: ViewId, args: &mut DrawArgs) {
39 self.child.draw(id.child(&0), args);
40 }
41
42 fn layout(&self, id: ViewId, args: &mut LayoutArgs) -> LocalSize {
43 self.child.layout(id.child(&0), args)
44 }
45
46 fn dirty(&self, id: ViewId, xform: LocalToWorld, cx: &mut Context) {
47 self.child.dirty(id.child(&0), xform, cx);
48 }
49
50 fn hittest(&self, id: ViewId, pt: LocalPoint, cx: &mut Context) -> Option<ViewId> {
51 self.child.hittest(id.child(&0), pt, cx)
52 }
53
54 fn commands(&self, id: ViewId, cx: &mut Context, cmds: &mut Vec<CommandInfo>) {
55 self.child.commands(id.child(&0), cx, cmds);
56 }
57
58 fn gc(&self, id: ViewId, cx: &mut Context, map: &mut Vec<ViewId>) {
59 map.push(id);
60 self.child.gc(id.child(&0), cx, map);
61 }
62
63 fn access(
64 &self,
65 id: ViewId,
66 cx: &mut Context,
67 nodes: &mut Vec<(accesskit::NodeId, accesskit::Node)>,
68 ) -> Option<accesskit::NodeId> {
69 self.child.access(id.child(&0), cx, nodes)
70 }
71}
72
73impl<V, F> private::Sealed for AnimView<V, F> {}