summaryrefslogtreecommitdiff
path: root/engine/src/windowing/monitor.rs
blob: 894448a630df7694c6f41424fd4272c2093a498c (plain)
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
use crate::windowing::dpi::{PhysicalPosition, PhysicalSize};

/// Handle to a monitor that may or may not exist any longer.
#[derive(Debug, Clone)]
pub struct Handle
{
    inner: winit::monitor::MonitorHandle,
}

impl Handle
{
    /// Returns a human-readable name of the monitor.
    #[inline]
    pub fn name(&self) -> Option<String>
    {
        self.inner.name()
    }

    /// Returns the monitor's resolution.
    #[inline]
    pub fn size(&self) -> PhysicalSize<u32>
    {
        self.inner.size().into()
    }

    /// Returns the top-left corner position of the monitor relative to the larger full
    /// screen area.
    #[inline]
    pub fn position(&self) -> PhysicalPosition<i32>
    {
        self.inner.position().into()
    }

    /// Returns the scale factor of the underlying monitor.
    #[inline]
    pub fn scale_factor(&self) -> f64
    {
        self.inner.scale_factor()
    }
}

impl Handle
{
    pub(super) fn from_winit_monitor_handle(
        monitor: winit::monitor::MonitorHandle,
    ) -> Self
    {
        Self { inner: monitor }
    }
}