maplibre/
event_loop.rs

1use thiserror::Error;
2
3use crate::{
4    environment::Environment,
5    map::Map,
6    window::{HeadedMapWindow, MapWindowConfig},
7};
8
9pub trait EventLoopConfig {
10    type EventType: 'static;
11    type EventLoopProxy: EventLoopProxy<Self::EventType>;
12
13    fn create_proxy() -> Self::EventLoopProxy;
14}
15
16/// When sending events to an event loop errors can occur.
17#[derive(Error, Debug)]
18pub enum SendEventError {
19    /// The event loop was already closed
20    #[error("event loop is closed")]
21    Closed,
22}
23
24/// When sending events to an event loop errors can occur.
25#[derive(Error, Debug)]
26#[error("event loop creation failed")]
27pub struct EventLoopError;
28
29pub trait EventLoopProxy<T: 'static> {
30    fn send_event(&self, event: T) -> Result<(), SendEventError>;
31}
32
33pub trait EventLoop<ET: 'static + PartialEq> {
34    type EventLoopProxy: EventLoopProxy<ET>;
35
36    fn run<E>(self, map: Map<E>, max_frames: Option<u64>) -> Result<(), EventLoopError>
37    where
38        E: Environment,
39        <E::MapWindowConfig as MapWindowConfig>::MapWindow: HeadedMapWindow;
40
41    fn create_proxy(&self) -> Self::EventLoopProxy;
42}