vizia_baseview/
proxy.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::collections::VecDeque;
use std::sync::{LazyLock, Mutex};
use vizia_core::context::EventProxy;
use vizia_core::events::Event;

pub(crate) static PROXY_QUEUE: LazyLock<Mutex<VecDeque<Event>>> = LazyLock::new(Mutex::default);

pub(crate) fn queue_put(event: Event) {
    PROXY_QUEUE.lock().unwrap().push_back(event)
}

pub(crate) fn queue_get() -> Option<Event> {
    PROXY_QUEUE.lock().unwrap().pop_front()
}

#[derive(Clone)]
pub(crate) struct BaseviewProxy;

impl EventProxy for BaseviewProxy {
    fn send(&self, event: Event) -> Result<(), ()> {
        queue_put(event);
        Ok(())
    }

    fn make_clone(&self) -> Box<dyn EventProxy> {
        Box::new(self.clone())
    }
}