Skip to main content

Window

Struct Window 

Source
pub struct Window<T = Value<String>> { /* private fields */ }
Expand description

A window the app opens while it runs: shown while open is true, with its content built when it opens and disposed when it closes. Declare it anywhere in the tree, next to the state that opens it; it closes with the scope that declared it, and belongs to the window it’s declared in.

The close button asks: bind closes it by setting the flag, or on_close_request lets the app decide (to ask about unsaved changes, say). Without either, the close button does nothing.

ⓘ
let editing = signal(false);
Column::new().children((
    Button::new("Edit…").on_click(move || editing.set(true)),
    Window::new("Machine").bind(editing).content(|| machine_form()),
))

In view!, its title is an attribute and its children are its content: <Window title="Machine" bind=editing>…</Window>.

Implementations§

Source§

impl Window

Source

pub fn new(title: impl IntoValue<String>) -> Window

Open, 480 wide, as tall as its content.

Source§

impl<T> Window<T>

Source

pub fn size(self, size: impl IntoValue<WindowSize>) -> Window<T>

Its content size when it opens: a Size, WindowSize::FitHeight to fit the height to the content, or WindowSize::FollowHeight to follow it as it changes. Read each time it opens, as its modality is, so a change applies at the next opening.

Source

pub fn modal(self, modality: Modality) -> Window<T>

Modal: while it’s open, it blocks the window it’s declared in (Modality::Window, a sheet on macOS) or the whole app (Modality::Application), and stays above that window. Set before it opens. Like any dialog, Escape asks it to close, as its close button does (on AppKit a ButtonRole::Cancel button takes Escape first). A sheet has no close button: give its content a way out, e.g. that Cancel button.

Source

pub fn modality(self, modality: impl IntoValue<Option<Modality>>) -> Window<T>

Modal or not, as a value that can change: read each time it opens, so a change applies at the next opening.

Source

pub fn open(self, open: impl IntoValue<bool>) -> Window<T>

Shown while true.

Source

pub fn bind(self, open: Signal<bool>) -> Window<T>

Shown while the signal is true; the close button sets it false.

Source

pub fn full_screen(self, full_screen: Signal<bool>) -> Window<T>

In full screen while full_screen is true, the platform’s own way: a Space of its own on macOS, the whole screen elsewhere, with the platform’s own way out. The user can change it too (the title bar’s button on macOS, the window manager’s key), which sets the signal.

Source

pub fn maximized(self, maximized: Signal<bool>) -> Window<T>

Maximized while maximized is true, as the platform maximizes a window: its screen’s working area (on macOS, zoomed to fit it). The user can change it too (the title bar’s button, a double-click on it, the window manager’s key), which sets the signal.

Source

pub fn resizable(self, resizable: impl IntoValue<bool>) -> Window<T>

Whether the user can resize it; they can unless it’s set false. The app can still size it, and a window that follows its content’s height still does.

Source

pub fn min_size(self, size: impl IntoValue<Size>) -> Window<T>

The smallest content size the user can make it. Smaller when it’s set, it grows to it.

Source

pub fn on_open(self, handler: impl Fn() + 'static) -> Window<T>

Called each time it opens, before its content is built: to start a form from what’s saved, say.

Source

pub fn on_close_request(self, handler: impl Fn() + 'static) -> Window<T>

Called when the user asks to close it (the close button, ⌘W, Alt+F4). It stays open unless the app closes it.

Source

pub fn on_active_changed(self, handler: impl Fn(bool) + 'static) -> Window<T>

Called when it becomes the active window, the one taking keys, or stops being it.

Source

pub fn node_ref(self, node: NodeRef) -> Window<T>

Points node at the window while it’s open, to bring it forward from code (NodeRef::present): open.set(true) alone does nothing to a window that’s open behind other apps’ windows.

Source

pub fn content<V: View>(self, content: impl Fn() -> V + 'static) -> Window<T>

What it shows, built each time it opens.

Trait Implementations§

Source§

impl View for Window

Source§

fn build(self, ui: &Ui) -> NodeId

A placeholder in the tree, which takes no room; the window is top-level.

Auto Trait Implementations§

§

impl<T = Value<String>> !RefUnwindSafe for Window<T>

§

impl<T = Value<String>> !Send for Window<T>

§

impl<T = Value<String>> !Sync for Window<T>

§

impl<T = Value<String>> !UnwindSafe for Window<T>

§

impl<T> Forget for Window<T>

§

impl<T> Freeze for Window<T>
where T: Freeze,

§

impl<T> Move for Window<T>

§

impl<T> Unpin for Window<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Window<T>
where T: 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<V> Children for V
where V: View,

Source§

fn into_views(self, out: &mut Vec<AnyView>)

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 = !

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.