Skip to main content

WindowRef

Struct WindowRef 

Source
pub struct WindowRef { /* private fields */ }
Expand description

A window (TS: WindowRef): the app root’s ref (main_window, the invisible host, not a user window) or a window of the app’s own (window), as current_window gives it. Setting its attributes and its requests are commands that go out with the commit; the platform may decline or adjust a request, and Self::state reports what happened. Commands to a closed window do nothing.

Implementations§

Source§

impl WindowRef

Source

pub fn id(&self) -> &str

Its id: the app’s ("main" is a conventional first-window id, with no special behavior).

Source

pub fn is_main(&self) -> bool

Whether its id is "main" (a conventional first-window id; there is no privileged window).

Source

pub fn state(&self) -> Option<WindowState>

What the platform reports of it (reading subscribes): its mode, bounds, display, whether it is focused, minimized or visible. None off desktops, while it is not open, and once it closed.

Source

pub fn set(&self, attributes: WindowAttributes)

Changes the attributes attributes sets (TS: set(partial)); the others keep their values. One command per window and commit carries what changed. An attribute the app’s capabilities do not grant is left as it is, with a warning.

Source

pub fn show(&self)

Shows it, restoring it when minimized. The app root’s ref never shows: the host is invisible in window model v2.

Source

pub fn hide(&self)

Hides it.

Source

pub fn focus(&self)

Shows it, brings it to the front of its level and focuses it. The app root’s ref never shows or takes focus.

Source

pub fn close(&self)

Closes it, whatever close_on_press says. A window reports it to Window::on_open_change with WindowCloseCause::Close, so the app’s open state follows. Only this window closes; the app’s last-window policy decides whether the app ends (an embedding host decides).

Source

pub fn title_bar(&self) -> Edges<Points>

Its hidden title bar’s area (reading subscribes): the bar’s height (top) and the widths its window controls take (left, right), as title_bar gives the main window’s.

Source

pub fn minimize(&self)

Minimizes it.

Source

pub fn restore(&self)

Brings it back from being minimized, in the mode it had.

Source

pub fn set_mode(&self, mode: WindowMode)

Puts it in mode; doing it again changes nothing.

Source

pub fn set_bounds(&self, frame: WindowFrame)

Moves and sizes it in points, in screen coordinates; fields left out keep their values. Widths and heights take positive finite numbers, x and y finite ones: other values keep the field’s value.

Source

pub fn set_placement(&self, placement: WindowPlacement)

Restores a placement saved earlier (WindowState::placement): restored to its bounds, then maximized or in full screen when its mode says so. The bounds are first fitted on the displays there are now: unchanged when at least 100 × 20 points of the window’s top 40 points are on a display’s visible bounds, where the user can take it by its title bar; otherwise centered on the primary display’s visible bounds, no larger than them.

Source

pub fn center(&self, display: Option<DisplayId>)

Centers it on display (its own with None).

Source

pub fn request_attention(&self, critical: bool)

Asks for the user’s attention: the Dock’s icon bounces, the taskbar button flashes; critical until the user activates the app.

Source

pub fn on_close_press(&self, f: impl Fn(CloseReason) + 'static)

Runs f with the reason each time the user asks to close it (its close button, a shortcut, a menu, the taskbar, the system), under the current owner (TS: on("closePress", …)). With close_on_press: false it stays open: save or ask, then Self::close.

Source

pub fn on_focus_change(&self, f: impl Fn(bool) + 'static)

Runs f with focused when it gains or loses the focus.

Source

pub fn on_mode_change(&self, f: impl Fn(WindowMode, bool) + 'static)

Runs f with its mode and whether it is minimized when either changes.

Source

pub fn on_bounds_change(&self, f: impl Fn(Bounds<Points>) + 'static)

Runs f with its bounds once a move or a resize settles.

Source

pub fn on_display_change(&self, f: impl Fn(DisplayId) + 'static)

Runs f with the display it moved to.

Trait Implementations§

Source§

impl Clone for WindowRef

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WindowRef

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for WindowRef

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.