Struct Monitor

Source
pub struct Monitor;
Expand description

Expose basic properties of the monitor(s) on the system and the virtual screen.

This object cannot be instanced. The methods should be used this way:

// Creating and centering a window in the main monitor

use native_windows_gui as nwg;

fn create_window(width: i32, height: i32) -> nwg::Window {
    let [total_width, total_height] = [nwg::Monitor::width(), nwg::Monitor::height()];
    let mut window = nwg::Window::default();

    let x = (total_width-width)/2;
    let y = (total_height-height)/2;

    nwg::Window::builder()
        .size((width, height))
        .position((x, y))
        .build(&mut window)
        .unwrap();

    window
}
    

Implementations§

Source§

impl Monitor

Source

pub fn width_from_window<H: Into<ControlHandle>>(window: H) -> i32

Returns the width in pixel of the monitor that has the largest area of intersection with the bounding rectangle of a specified window If the window does not intersect any display monitor, returns the nearest monitor width Panics if window is not a window like control.

Source

pub fn height_from_window<H: Into<ControlHandle>>(window: H) -> i32

Returns the height in pixel of the monitor that has the largest area of intersection with the bounding rectangle of a specified window If the window does not intersect any display monitor, returns the nearest monitor height Panics if window is not a window like control.

Source

pub fn monitor_rect_from_window<H: Into<ControlHandle>>(window: H) -> [i32; 4]

Returns a [left, top, right, bottom] rectangle that specifies the display monitor rectangle, expressed in virtual-screen coordinates. Note that if the monitor is not the primary display monitor, some of the rectangle’s coordinates may be negative values. Panics if window is not a window like control.

Source

pub fn width() -> i32

Returns the primary monitor width in pixel Use Monitor::virtual_width to get the dimensions of the virtual screen

Source

pub fn height() -> i32

Returns the primary monitor height in pixel Use Monitor::virtual_height to get the dimensions of the virtual screen

Source

pub fn virtual_width() -> i32

Returns the primary monitor width in pixel Use Monitor::width to get the dimensions of the virtual screen

Source

pub fn virtual_height() -> i32

Returns the primary monitor height in pixel Use Monitor::height to get the dimensions of the virtual screen

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.