ferroui_base/rendering/composition/server/
server_composition_surface.rs1use super::IServerObject;
2use crate::platform::IBitmapImpl;
3use std::cell::RefCell;
4use std::rc::Rc;
5
6#[derive(Default)]
9pub struct ServerCompositionSurfaceChanged {
10 handlers: RefCell<Vec<(usize, Rc<dyn Fn()>)>>,
11}
12
13impl ServerCompositionSurfaceChanged {
14 pub fn new() -> Self {
15 Self::default()
16 }
17
18 pub fn add(&self, key: usize, handler: Rc<dyn Fn()>) {
20 self.handlers.borrow_mut().push((key, handler));
21 }
22
23 pub fn remove(&self, key: usize) {
25 let mut handlers = self.handlers.borrow_mut();
26 if let Some(index) = handlers.iter().rposition(|(k, _)| *k == key) {
27 handlers.remove(index);
28 }
29 }
30
31 pub fn invoke(&self) {
33 let handlers: Vec<_> = self.handlers.borrow().iter().map(|(_, h)| h.clone()).collect();
34 for handler in handlers {
35 handler();
36 }
37 }
38}
39
40pub trait IServerCompositionSurface: IServerObject {
43 fn bitmap(&self) -> Option<std::sync::Arc<crate::platform::SharedBitmapImpl>>;
45
46 fn changed(&self) -> &ServerCompositionSurfaceChanged;
48}