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
impl WindowRef
Sourcepub fn id(&self) -> &str
pub fn id(&self) -> &str
Its id: the app’s ("main" is a conventional first-window id, with
no special behavior).
Sourcepub fn is_main(&self) -> bool
pub fn is_main(&self) -> bool
Whether its id is "main" (a conventional first-window id; there
is no privileged window).
Sourcepub fn state(&self) -> Option<WindowState>
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.
Sourcepub fn set(&self, attributes: WindowAttributes)
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.
Sourcepub fn show(&self)
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.
Sourcepub fn focus(&self)
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.
Sourcepub fn close(&self)
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).
Sourcepub fn title_bar(&self) -> Edges<Points>
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.
Sourcepub fn set_mode(&self, mode: WindowMode)
pub fn set_mode(&self, mode: WindowMode)
Puts it in mode; doing it again changes nothing.
Sourcepub fn set_bounds(&self, frame: WindowFrame)
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.
Sourcepub fn set_placement(&self, placement: WindowPlacement)
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.
Sourcepub fn request_attention(&self, critical: bool)
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.
Sourcepub fn on_close_press(&self, f: impl Fn(CloseReason) + 'static)
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.
Sourcepub fn on_focus_change(&self, f: impl Fn(bool) + 'static)
pub fn on_focus_change(&self, f: impl Fn(bool) + 'static)
Runs f with focused when it gains or loses the focus.
Sourcepub fn on_mode_change(&self, f: impl Fn(WindowMode, bool) + 'static)
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.
Sourcepub fn on_bounds_change(&self, f: impl Fn(Bounds<Points>) + 'static)
pub fn on_bounds_change(&self, f: impl Fn(Bounds<Points>) + 'static)
Runs f with its bounds once a move or a resize settles.
Sourcepub fn on_display_change(&self, f: impl Fn(DisplayId) + 'static)
pub fn on_display_change(&self, f: impl Fn(DisplayId) + 'static)
Runs f with the display it moved to.