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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use conrod_core as conrod;
const BACKEND_GRAPH_RESIZE_CHUNK: usize = 100;
pub struct ConrodBackendReusableGraph {
pub(crate) line: ConrodBackendReusableGraphAtom,
pub(crate) rect: ConrodBackendReusableGraphAtom,
pub(crate) path: ConrodBackendReusableGraphAtom,
pub(crate) circle: ConrodBackendReusableGraphAtom,
pub(crate) text: ConrodBackendReusableGraphAtom,
pub(crate) fill: ConrodBackendReusableGraphAtom,
}
pub(crate) struct ConrodBackendReusableGraphAtom(conrod::widget::id::List, usize);
impl ConrodBackendReusableGraph {
pub fn build() -> Self {
Self {
line: ConrodBackendReusableGraphAtom::new(),
rect: ConrodBackendReusableGraphAtom::new(),
path: ConrodBackendReusableGraphAtom::new(),
circle: ConrodBackendReusableGraphAtom::new(),
text: ConrodBackendReusableGraphAtom::new(),
fill: ConrodBackendReusableGraphAtom::new(),
}
}
#[inline(always)]
pub(crate) fn prepare(&mut self) {
let Self {
line,
rect,
path,
circle,
text,
fill,
} = self;
line.reset();
rect.reset();
path.reset();
circle.reset();
text.reset();
fill.reset();
}
}
impl ConrodBackendReusableGraphAtom {
fn new() -> Self {
Self(conrod::widget::id::List::new(), 0)
}
#[inline(always)]
pub(crate) fn next(&mut self, ui: &mut conrod::UiCell) -> conrod::widget::Id {
let current_index = self.1;
if current_index >= self.0.len() {
self.0.resize(
self.0.len() + BACKEND_GRAPH_RESIZE_CHUNK,
&mut ui.widget_id_generator(),
);
}
self.1 += 1;
self.0[current_index]
}
#[inline(always)]
fn reset(&mut self) {
self.1 = 0;
}
}