Skip to main content

freya_core/
user_event.rs

1use std::{
2    any::Any,
3    borrow::Cow,
4    fmt::Debug,
5};
6
7use bytes::Bytes;
8
9use crate::prelude::AccessibilityFocusStrategy;
10
11#[derive(Debug)]
12pub enum UserEvent {
13    RequestRedraw,
14
15    /// Focus with the given strategy
16    FocusAccessibilityNode(AccessibilityFocusStrategy),
17
18    /// Set a custom scale factor.
19    SetCustomScaleFactor(f64),
20
21    /// Load a font at runtime.
22    LoadFont {
23        font_name: Cow<'static, str>,
24        font_data: Bytes,
25    },
26
27    Erased(SingleThreadErasedEvent),
28}
29
30pub struct SingleThreadErasedEvent(pub Box<dyn Any>);
31
32impl Debug for SingleThreadErasedEvent {
33    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34        f.write_str("SingleThreadErasedEvent")
35    }
36}
37
38/// # Safety
39/// The values are never sent, received or accessed by other threads other than the main thread.
40/// This is needed to send `Rc<T>` and other non-Send and non-Sync values from WindowConfig
41/// to the winit EventLoop
42unsafe impl Send for SingleThreadErasedEvent {}
43unsafe impl Sync for SingleThreadErasedEvent {}