use super::IServerObject;
use crate::platform::IBitmapImpl;
use std::cell::RefCell;
use std::rc::Rc;
#[derive(Default)]
pub struct ServerCompositionSurfaceChanged {
handlers: RefCell<Vec<(usize, Rc<dyn Fn()>)>>,
}
impl ServerCompositionSurfaceChanged {
pub fn new() -> Self {
Self::default()
}
pub fn add(&self, key: usize, handler: Rc<dyn Fn()>) {
self.handlers.borrow_mut().push((key, handler));
}
pub fn remove(&self, key: usize) {
let mut handlers = self.handlers.borrow_mut();
if let Some(index) = handlers.iter().rposition(|(k, _)| *k == key) {
handlers.remove(index);
}
}
pub fn invoke(&self) {
let handlers: Vec<_> = self.handlers.borrow().iter().map(|(_, h)| h.clone()).collect();
for handler in handlers {
handler();
}
}
}
pub trait IServerCompositionSurface: IServerObject {
fn bitmap(&self) -> Option<std::sync::Arc<crate::platform::SharedBitmapImpl>>;
fn changed(&self) -> &ServerCompositionSurfaceChanged;
}