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
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*!

Window shell abstraction layer used by OrbTk. Provides support for desktop and web.

# Example

Basic usage of the shell:

```rust,no_run

use orbtk_shell::prelude::*;

let shell = WindowBuilder::new(MyCustomWindowAdapter::new())
                        .title("Window")
                        .bounds((0.0, 0.0, 100.0, 100.0))
                        .build();

let runner = ShellRunner {
    shell,
    updater: Box::new(MyCustomUpdater::new())
};

runner.run()
```

 */
#[macro_use]
extern crate lazy_static;

pub mod event;
pub mod prelude;
pub mod window_adapter;

pub use orbtk_utils::prelude as utils;

#[cfg(all(not(target_arch = "wasm32"), feature = "pfinder"))]
#[path = "glutin/mod.rs"]
pub mod platform;

#[cfg(all(
    not(target_arch = "wasm32"),
    feature = "default",
    not(feature = "pfinder")
))]
#[path = "minifb/mod.rs"]
pub mod platform;

#[cfg(not(target_arch = "wasm32"))]
pub mod native;

#[cfg(target_arch = "wasm32")]
#[path = "web/mod.rs"]
pub mod platform;

pub use orbtk_render::prelude as render;

use std::{collections::HashMap, sync::mpsc};

/// Used to send a request to the window.
#[derive(Clone, Debug)]
pub enum WindowRequest {
    /// Request redraw of the `Windows`s content.
    Redraw,

    /// Request to close the `Windows`.
    Close,

    /// Request to change the title of the `Windows`.
    ChangeTitle(String),
}

/// Used to send a request to the application shell.
pub enum ShellRequest<W>
where
    W: window_adapter::WindowAdapter,
{
    /// Request redraw of the `Windows`s content.
    CreateWindow(W, WindowSettings, mpsc::Receiver<WindowRequest>),

    None,
}

impl<W> Default for ShellRequest<W>
where
    W: window_adapter::WindowAdapter,
{
    fn default() -> Self {
        ShellRequest::None
    }
}

/// Contains settings of a window.
#[derive(Clone, Debug, Default)]
pub struct WindowSettings {
    /// Title of the window.
    pub title: String,

    /// Is the window borderless / without decorations?
    pub borderless: bool,

    /// Is the window resizable?
    pub resizeable: bool,

    /// Will the window always shown on top of other windows.
    pub always_on_top: bool,

    /// The initial position of the window.
    pub position: (f64, f64),

    /// The initial size of the window.
    pub size: (f64, f64),

    /// List of fonts to register.
    pub fonts: HashMap<String, &'static [u8]>,
}