1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::graphics::Graphic;
use crate::platform::{DefaultRenderPlatform, RenderPlatform};
pub trait WidgetGraphic<'a, 'b, P = DefaultRenderPlatform>
where
P: RenderPlatform + ?Sized,
{
type Before: Graphic<P> + 'b;
type After: Graphic<P> + 'a;
fn before_children(&'b mut self) -> Self::Before;
fn after_children(&'a mut self) -> Self::After;
fn ordered() -> bool {
true
}
}
impl<'a, 'b, P, T> WidgetGraphic<'a, 'b, P> for T
where
Self: Sized,
T: Graphic<P> + 'b,
P: RenderPlatform,
{
type Before = WidgetGraphicProxy<'b, T>;
type After = WidgetGraphicProxy<'a, [(); 0]>;
fn before_children(&'b mut self) -> Self::Before {
WidgetGraphicProxy { graphic: self }
}
fn after_children(&'a mut self) -> Self::After {
WidgetGraphicProxy { graphic: &mut [] }
}
fn ordered() -> bool {
false
}
}
pub struct WidgetGraphicProxy<'a, T> {
graphic: &'a mut T,
}
impl<'a, P, T> Graphic<P> for WidgetGraphicProxy<'a, T>
where
P: RenderPlatform,
T: Graphic<P>,
{
fn draw(&mut self, ctx: &mut crate::graphics::DrawContext<P>) {
self.graphic.draw(ctx);
}
}