1use crate::{Event, Loop};
2
3#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Deserialize, Serialize, Hash)]
5pub struct AfterRenderArgs;
6
7pub trait AfterRenderEvent: Sized {
9 fn from_after_render_args(args: &AfterRenderArgs, old_event: &Self) -> Option<Self>;
11 fn after_render<U, F>(&self, f: F) -> Option<U>
13 where
14 F: FnMut(&AfterRenderArgs) -> U;
15 fn after_render_args(&self) -> Option<AfterRenderArgs> {
17 self.after_render(|args| *args)
18 }
19}
20
21impl AfterRenderEvent for Event {
22 fn from_after_render_args(args: &AfterRenderArgs, _old_event: &Self) -> Option<Self> {
23 Some(Event::Loop(Loop::AfterRender(*args)))
24 }
25
26 fn after_render<U, F>(&self, mut f: F) -> Option<U>
27 where
28 F: FnMut(&AfterRenderArgs) -> U,
29 {
30 match *self {
31 Event::Loop(Loop::AfterRender(ref args)) => Some(f(args)),
32 _ => None,
33 }
34 }
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn test_input_after_render() {
43 use AfterRenderArgs;
44
45 let e: Event = AfterRenderArgs.into();
46 let x: Option<Event> = AfterRenderEvent::from_after_render_args(&AfterRenderArgs, &e);
47 let y: Option<Event> = x
48 .clone()
49 .unwrap()
50 .after_render(|args| {
51 AfterRenderEvent::from_after_render_args(args, x.as_ref().unwrap())
52 })
53 .unwrap();
54 assert_eq!(x, y);
55 }
56}