-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathwindow.rs
More file actions
105 lines (86 loc) · 2.54 KB
/
Copy pathwindow.rs
File metadata and controls
105 lines (86 loc) · 2.54 KB
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
use cursor_icon::CursorIcon;
use raw_window_handle::{RawWindowHandle, HasWindowHandle, HasDisplayHandle};
use crate::platform::os_window_handle::OsWindowHandle;
use crate::LogicalPosition;
use crate::dimensions::LogicalSize;
use crate::error::Error;
use crate::event::EventCallback;
use crate::platform::{window::OsWindow, interface::OsWindowInterface};
#[derive(Clone)]
pub struct WindowAttributes {
pub(crate) size: LogicalSize,
pub(crate) scale: f64,
}
impl WindowAttributes {
pub fn new(size: LogicalSize, scale: f64) -> Self {
Self {
size,
scale,
}
}
pub fn with_size(size: LogicalSize) -> Self {
Self::new(size, 1.0)
}
pub fn size(&self) -> LogicalSize {
self.size
}
pub fn scale(&self) -> f64 {
self.scale
}
pub fn scaled_size(&self) -> LogicalSize {
self.size * self.scale
}
}
pub struct Window {
attributes: WindowAttributes,
os_window_handle: OsWindowHandle,
}
impl Window {
pub fn open(
parent: RawWindowHandle,
attributes: WindowAttributes,
event_callback: Box<EventCallback>,
) -> Result<Window, Error> {
let os_window_handle = OsWindow::open(
parent,
attributes.clone(),
event_callback,
)?;
Ok(Self {
attributes,
os_window_handle,
})
}
pub fn attributes(&self) -> &WindowAttributes {
&self.attributes
}
pub fn os_scale(&self) -> f64 {
self.os_window_handle.os_scale()
}
pub fn resized(&self, size: LogicalSize, scale: f64) {
self.os_window_handle.resized(size, scale);
}
/// This only needs to be called on Linux
pub fn poll_events(&self) -> Result<(), Error> {
self.os_window_handle.poll_events()
}
pub fn set_cursor(&self, cursor: Option<CursorIcon>) {
self.os_window_handle.set_cursor(cursor);
}
pub fn set_input_focus(&self, focus: bool) {
self.os_window_handle.set_input_focus(focus);
}
pub fn warp_mouse(&self, position: LogicalPosition) {
self.os_window_handle.warp_mouse(position);
}
}
impl HasWindowHandle for Window {
fn window_handle(&self) -> Result<raw_window_handle::WindowHandle<'_>, raw_window_handle::HandleError> {
self.os_window_handle.window_handle()
}
}
impl HasDisplayHandle for Window {
fn display_handle(&self) -> Result<raw_window_handle::DisplayHandle<'_>, raw_window_handle::HandleError> {
self.os_window_handle.display_handle()
}
}