iced_graphics/
shell.rs

1//! Control the windowing runtime from a renderer.
2use std::sync::Arc;
3
4/// A windowing shell.
5#[derive(Clone)]
6pub struct Shell(Arc<dyn Notifier>);
7
8impl Shell {
9    /// Creates a new [`Shell`].
10    pub fn new(notifier: impl Notifier) -> Self {
11        Self(Arc::new(notifier))
12    }
13
14    /// Creates a headless [`Shell`].
15    pub fn headless() -> Self {
16        struct Headless;
17
18        impl Notifier for Headless {
19            fn request_redraw(&self) {}
20
21            fn invalidate_layout(&self) {}
22        }
23
24        Self::new(Headless)
25    }
26
27    /// Requests for all windows of the [`Shell`] to be redrawn.
28    pub fn request_redraw(&self) {
29        self.0.request_redraw();
30    }
31
32    /// Requests for all layouts of the [`Shell`] to be recomputed.
33    pub fn invalidate_layout(&self) {
34        self.0.invalidate_layout();
35    }
36}
37
38/// A type that can notify a shell of certain events.
39pub trait Notifier: Send + Sync + 'static {
40    /// Requests for all windows of the [`Shell`] to be redrawn.
41    fn request_redraw(&self);
42
43    /// Requests for all layouts of the [`Shell`] to be recomputed.
44    fn invalidate_layout(&self);
45}