use cranpose_core::RecordRef;
use cranpose_ui_graphics::Point;
use crate::{draw::RenderItem, scene::RasterScene, shift::Shift};
pub(crate) struct Frame {
pub(crate) record: RecordRef,
pub(crate) anchor: Point,
}
#[derive(Default)]
pub(crate) struct Frames {
list: Vec<Frame>,
}
impl Frames {
pub(crate) fn clear(&mut self) {
self.list.clear();
}
pub(crate) fn is_empty(&self) -> bool {
self.list.is_empty()
}
pub(crate) fn records(&self) -> impl Iterator<Item = RecordRef> + '_ {
self.list.iter().map(|frame| frame.record)
}
pub(crate) fn position(&self, record: RecordRef) -> Option<usize> {
self.list.iter().position(|frame| frame.record == record)
}
pub(crate) fn add(&mut self, frame: Frame) -> usize {
self.list.push(frame);
self.list.len() - 1
}
pub(crate) fn anchor(&self, position: usize) -> Point {
self.list[position].anchor
}
pub(crate) fn set_anchor(&mut self, position: usize, anchor: Point) {
self.list[position].anchor = anchor;
}
pub(crate) fn retain(&mut self, mut keep: impl FnMut(RecordRef) -> bool) {
self.list.retain(|frame| keep(frame.record));
}
}
pub(crate) fn shift_item(scene: &mut RasterScene, item: RenderItem, shift: Shift) {
match item {
RenderItem::Shape(at) => scene.shapes[at].shift_by(shift),
RenderItem::Image(at) => scene.images[at].shift_by(shift),
RenderItem::Text(at) => scene.texts[at].shift_by(shift),
RenderItem::Shadow(_) => {}
}
}