Skip to main content

Window

Struct Window 

Source
pub struct Window<Msg> { /* private fields */ }
Expand description

A window: a title strip one row tall above a body, with no border lines, for applications that put surfaces where the user drags them, such as a desktop or a tool box. Place it with View::place inside a stack; the body is built with View::add_with.

The title strip shows the icon and the name, then a faint subtitle (a program’s own title, a folder). A window that is focused is one tone raised, its name bright, and the pillar runs down its whole left edge; others sit one tone lower with a quieter name. On a narrow window the subtitle shortens first, then the name, each with . The body keeps the pillar column and one cell after it on the left, and the right column and the bottom row free for the handles.

With no options the window is only a surface. on_event makes it one the pointer moves: the three marks at the right end of the title (minimize, maximize or restore, close) light up together under the pointer like every close mark; dragging the title moves the window and double-clicking it maximizes; the body’s right column, bottom row and their corner are handles that brighten under the pointer and take the accent while dragged, like a splitter’s boundary; alt with the left button drags the window from anywhere, alt with the right button resizes it from the nearest edge or corner (the left and top edges too). A drag belongs to the window until the button comes up, which arrives as WindowEvent::Dropped, wherever the pointer goes. The title, the marks, the handles and alt drags are the window’s even when the body holds a Terminal whose program reads the mouse; other presses in the body reach the body. The window reports all of it through WindowEvents and changes nothing itself: stacking order, focus, size limits and snapping are the application’s.

shadow darkens one column right of the window and one row below it. It is not drawn with reduced motion or in 16 colours.

Style keys: window (bg, pillar), window-title (bg, fg, bold), window-subtitle (fg), all with focus for a focused window; close-mark for the marks (active while focused, hover); split-handle for the handles (hover, active while dragged); window-shadow (scrim, strength in percent).

Implementations§

Source§

impl<Msg: 'static> Window<Msg>

Source

pub fn new(title: impl Into<String>) -> Self

A window named title, unfocused, with an empty body.

Source

pub fn subtitle(self, subtitle: impl Into<String>) -> Self

A faint second title after the name, such as the title a program set or its folder.

Source

pub fn icon(self, glyph: impl Into<Glyph>) -> Self

The glyph before the name: an icon key such as "folder", or a Glyph::literal.

Source

pub fn focused(self, focused: bool) -> Self

Whether this is the window the user works in: raised one tone, bright name and the pillar down its left edge. A press on a window that is not focused sends WindowEvent::Focus.

Source

pub fn maximized(self, maximized: bool) -> Self

Whether the window fills its desktop; the maximize mark then offers to restore it.

Source

pub fn shadow(self, shadow: bool) -> Self

Darkens one column right of the window and one row below it, as if it floated; drawn in the cell a placed child may reach past its rectangle. Not drawn with reduced motion or in 16 colours.

Source

pub fn on_event(self, message: impl Fn(WindowEvent) -> Msg + 'static) -> Self

Makes the window one the pointer moves, resizes and closes, and shows its marks; message turns each WindowEvent into the application’s message.

Trait Implementations§

Source§

impl<Msg: 'static> Container<Msg> for Window<Msg>

Source§

fn set_children(&mut self, children: Vec<Node<Msg>>)

Receives the children built for this widget.
Source§

impl<Msg: 'static> Widget<Msg> for Window<Msg>

Source§

fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size

The size the widget wants when it may use up to available.
Source§

fn paint(&self, cx: &mut PaintCx<'_>, area: Rect)

Draws the widget into area.
Source§

fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool

Handles input. Returns true when the event was used; unused key and scroll events bubble to the parent widget.
Source§

fn children(&self) -> &[Node<Msg>]

Child nodes, for widgets that contain other widgets.
Source§

fn children_mut(&mut self) -> &mut [Node<Msg>]

Mutable child nodes, used to assign ids.
Source§

fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)

Draws the widget’s overlay after the whole view was painted, when it asked for one with PaintCx::request_overlay. anchor is the area the widget was painted in.
Source§

fn focusable(&self) -> bool

Whether the widget can take keyboard focus.

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for Window<Msg>

§

impl<Msg> !Send for Window<Msg>

§

impl<Msg> !Sync for Window<Msg>

§

impl<Msg> !UnwindSafe for Window<Msg>

§

impl<Msg> Freeze for Window<Msg>
where Option<Box<dyn Fn(WindowEvent) -> Msg>>: Freeze, Vec<Node<Msg>>: Freeze,

§

impl<Msg> Unpin for Window<Msg>
where Option<Box<dyn Fn(WindowEvent) -> Msg>>: Unpin, Vec<Node<Msg>>: Unpin,

§

impl<Msg> UnsafeUnpin for Window<Msg>
where Option<Box<dyn Fn(WindowEvent) -> Msg>>: UnsafeUnpin, Vec<Node<Msg>>: UnsafeUnpin,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.