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;
}
}