pub mod base64;
pub mod executor;
pub use executor::ImageExecutor;
use std::sync::Arc;
use imbl::HashMap;
use logisheets_base::{CellId, SheetId};
#[derive(Debug, Clone)]
pub struct CellImage {
pub id: String,
pub format: String,
pub data: Arc<Vec<u8>>,
}
#[derive(Debug, Clone, Default)]
pub struct ImageManager {
pub images: HashMap<(SheetId, CellId), CellImage>,
}
impl ImageManager {
pub fn new() -> Self {
Self::default()
}
pub fn get(&self, sheet_id: SheetId, cell_id: CellId) -> Option<&CellImage> {
self.images.get(&(sheet_id, cell_id))
}
pub fn insert(&mut self, sheet_id: SheetId, cell_id: CellId, image: CellImage) {
self.images.insert((sheet_id, cell_id), image);
}
pub fn remove(&mut self, sheet_id: SheetId, cell_id: CellId) -> Option<CellImage> {
self.images.remove(&(sheet_id, cell_id))
}
pub fn images_of_sheet(&self, sheet_id: SheetId) -> Vec<(CellId, CellImage)> {
self.images
.iter()
.filter(|((s, _), _)| *s == sheet_id)
.map(|((_, c), img)| (*c, img.clone()))
.collect()
}
}