Skip to main content

WindowConfig

Struct WindowConfig 

Source
pub struct WindowConfig {
Show 22 fields pub title: String, pub string_id: Option<String>, pub size: (u32, u32), pub position: Option<(i32, i32)>, pub min_size: Option<(u32, u32)>, pub max_size: Option<(u32, u32)>, pub restore_geometry: bool, pub initial_placement: WindowPlacement, pub decorations: DecorationsMode, pub resizable: bool, pub size_to_content: SizeToContent, pub always_on_top: bool, pub skip_taskbar: bool, pub activate_from_env: bool, pub icon: Option<WindowIcon>, pub modal: Option<ModalConfig>, pub root_builder: Option<Box<dyn FnOnce(&mut WidgetTree, WindowState) -> WidgetId>>, pub post_root_builder: Option<Box<dyn FnOnce(&mut WidgetTree, WidgetId) -> WidgetId>>, pub on_close_requested: Option<Rc<dyn Fn(&mut EventContext<'_>) -> CloseResponse>>, pub can_close: Option<Prop<bool>>, pub on_close_blocked: Option<Rc<dyn Fn(&mut EventContext<'_>)>>, pub on_removed: Option<Rc<dyn Fn(&WindowRemovedEvent)>>,
}
Expand description

Configuration for creating a new window.

Fields§

§title: String§string_id: Option<String>§size: (u32, u32)§position: Option<(i32, i32)>§min_size: Option<(u32, u32)>§max_size: Option<(u32, u32)>§restore_geometry: bool

Whether this window’s geometry is restored from the persisted window state at creation. Default true.

Persisting and restoring are usually the same decision, so string_id normally governs both. They come apart in one common case: a multi-window (or multi-process) app where every window shares one geometry slot. Restoring the saved geometry into every window would stack them exactly on top of each other; you want the first window to land where the user left it, and any window opened alongside it to be placed by the OS (which cascades). But you still want every window to save its geometry, so whichever the user moved or closed last is what reopens next time — the behaviour of Word, Firefox and most document apps.

Set false for those later windows: they still persist under their string_id, they simply don’t read the saved value back. With position left None, the window manager picks the spot.

§initial_placement: WindowPlacement§decorations: DecorationsMode§resizable: bool§size_to_content: SizeToContent

Whether the OS window resizes itself to fit its content’s intrinsic size. See SizeToContent. Default SizeToContent::Off.

§always_on_top: bool§skip_taskbar: bool§activate_from_env: bool

When set, this window consumes an xdg_activation_v1 startup token from the environment at creation so it comes up focused on Wayland (the launching process set it via set_child_activation_env). No effect off Wayland/X11.

§icon: Option<WindowIcon>§modal: Option<ModalConfig>§root_builder: Option<Box<dyn FnOnce(&mut WidgetTree, WindowState) -> WidgetId>>§post_root_builder: Option<Box<dyn FnOnce(&mut WidgetTree, WidgetId) -> WidgetId>>

Optional post-root wrapper. When set, the framework calls it after root_builder and uses the returned id as the window’s effective root. See PostRootBuilder.

§on_close_requested: Option<Rc<dyn Fn(&mut EventContext<'_>) -> CloseResponse>>

Optional close guard. Consulted before this window closes in response to a user gesture; returning CloseResponse::Veto cancels the close. See WindowConfig::on_close_requested.

§can_close: Option<Prop<bool>>

Optional reactive “may this window close?” signal. Sugar over on_close_requested: when present and false, a close attempt is vetoed and on_close_blocked fires (if set). See WindowConfig::can_close.

§on_close_blocked: Option<Rc<dyn Fn(&mut EventContext<'_>)>>

Optional notification fired when the can_close signal blocks a close — the hook that presents the confirmation UI. See WindowConfig::on_close_blocked.

§on_removed: Option<Rc<dyn Fn(&WindowRemovedEvent)>>

Optional teardown hook, fired once this window has been fully removed from the window manager. See WindowConfig::on_removed.

Implementations§

Source§

impl WindowConfig

Source

pub fn new() -> WindowConfig

Start a config with sensible defaults.

Defaults: title "Teksilo", size 800x600, WindowPlacement::Floating, DecorationsMode::Native, resizable, no parent, no id, no root builder.

Source

pub fn title(self, title: impl Into<String>) -> WindowConfig

User-visible title. Also becomes the initial value of WindowState::title.

Source

pub fn size(self, width: u32, height: u32) -> WindowConfig

Restored size in logical pixels. This is the size the window returns to when leaving Maximized or Fullscreen, and the current size when placement is Floating.

Source

pub fn position(self, x: i32, y: i32) -> WindowConfig

Restored on-screen position in logical pixels. None lets the window manager pick.

Source

pub fn min_size(self, width: u32, height: u32) -> WindowConfig

Lower bound on the floating size. The OS prevents the user from resizing the window below this.

Source

pub fn max_size(self, width: u32, height: u32) -> WindowConfig

Upper bound on the floating size.

Source

pub fn restore_geometry(self, restore: bool) -> WindowConfig

Whether to restore this window’s persisted geometry at creation (default true). See WindowConfig::restore_geometry.

Pass false for a window that should still save its geometry but be placed by the OS rather than reopened at the remembered spot — the second and later windows of an app whose windows share one geometry slot, which would otherwise all land exactly on top of each other.

Source

pub fn id(self, id: impl Into<String>) -> WindowConfig

Stable string identifier for later lookup via EventContext::find_window. Optional — omit for “open a fresh window every time.”

Source

pub fn initial_placement(self, placement: WindowPlacement) -> WindowConfig

Initial placement. Defaults to Floating; pass WindowPlacement::Fullscreen / Maximized to start in that state.

Source

pub fn decorations(self, mode: DecorationsMode) -> WindowConfig

Chrome mode. Native draws OS decorations; CustomChrome constructs a PlatformTitleBarHost (on X11, falls back to Native when the window manager lacks _NET_WM_MOVERESIZE); None is borderless.

Source

pub fn resizable(self, resizable: bool) -> WindowConfig

Whether the user can resize the window interactively. Also affects whether maximize gestures are accepted on some platforms.

Source

pub fn size_to_content(self, mode: SizeToContent) -> WindowConfig

Make this window resize itself to fit its content’s intrinsic size. See SizeToContent. The configured size / min_size act as a floor. Used for native modal dialogs (e.g. MessageBox) so the OS window grows when the content does — matching the in-tree overlay path.

Do NOT also call .resizable(false): winit encodes non-resizable as equal min/max size hints (notably on X11), which would clamp away the programmatic growth this relies on.

Source

pub fn always_on_top(self, on_top: bool) -> WindowConfig

Keep this window above all others regardless of focus.

Source

pub fn skip_taskbar(self, skip: bool) -> WindowConfig

Hide this window from the taskbar / dock. Useful for tool palettes and secondary overlays.

Source

pub fn activate_from_env(self, on: bool) -> WindowConfig

Consume an xdg_activation_v1 startup token from the environment at creation so this window comes up focused on Wayland. Set on the initial window of a process spawned by another instance’s “open in new window”.

Source

pub fn icon(self, icon: WindowIcon) -> WindowConfig

Set the window’s icon from a raw RGBA8 buffer. The icon is used by the taskbar / dock and the window’s title bar on platforms where it applies.

Invalid buffers (rgba.len() != width * height * 4) are logged and dropped at creation time — the window still opens, just with the platform default icon.

Source

pub fn modal_to(self, parent: TeksiloWindowId) -> WindowConfig

Make this window modal to the given parent, with no explicit focus target. Prefer this over constructing ModalConfig yourself when you already have the parent id handy.

Source

pub fn modal(self, config: ModalConfig) -> WindowConfig

Make this window modal using a caller-built ModalConfig. Use this form when you need to specify an explicit focus_target.

Source

pub fn root( self, builder: impl FnOnce(&mut WidgetTree, WindowState) -> WidgetId + 'static, ) -> WindowConfig

Root-widget builder. Called once during window creation with the new window’s WidgetTree and a cloned WindowState so widgets can bind against window-level signals.

Source

pub fn take_root_builder( &mut self, ) -> Option<Box<dyn FnOnce(&mut WidgetTree, WindowState) -> WidgetId>>

Take the root builder out of the config, leaving None in its place. Consumed by the window manager exactly once during create_window.

Source

pub fn post_root( self, builder: impl FnOnce(&mut WidgetTree, WidgetId) -> WidgetId + 'static, ) -> WindowConfig

Attach a per-window post-root hook. Runs after the user’s root_builder returns; receives the user’s root id and may return either the same id or a wrapper’s id. The framework uses the returned id as the window’s effective root.

Typically used by the debug inspector. Apps that want to install a default wrapper across all windows should use the app-level mechanism instead of setting this per-config.

Source

pub fn take_post_root_builder( &mut self, ) -> Option<Box<dyn FnOnce(&mut WidgetTree, WidgetId) -> WidgetId>>

Take the post-root builder out of the config.

Source

pub fn on_close_requested( self, guard: impl Fn(&mut EventContext<'_>) -> CloseResponse + 'static, ) -> WindowConfig

Install a close guard consulted before this window closes in response to a user gesture — the OS close button / Alt+F4 / Cmd+W, a custom-chrome close button, or EventContext::close_window.

The guard runs with a real EventContext for this window’s tree. Return CloseResponse::Close to let the close proceed, or CloseResponse::Veto to cancel it. The canonical pattern is veto-then-reissue:

WindowConfig::new()
    .on_close_requested(move |ctx| {
        if has_unsaved_changes() {
            ctx.show_message_box(/* "Save before closing?" */);
            CloseResponse::Veto
        } else {
            CloseResponse::Close
        }
    });

// …and from the confirmation dialog's "Discard & Close" button:
ctx.close_window_forced();

close_window_forced bypasses the guard, so the second close actually goes through. The guard is not consulted for framework-internal teardown (modal cleanup, the final-window shutdown drain).

Source

pub fn can_close(self, may_close: impl Into<Prop<bool>>) -> WindowConfig

Reactive sugar over on_close_requested: bind a Signal<bool> that answers “may this window close right now?”. While the signal reads false, every user-initiated close attempt is vetoed and on_close_blocked (if set) fires so the app can surface a confirmation.

can_close is evaluated before the on_close_requested guard: a false signal short-circuits to a veto; a true signal (or no signal) falls through to the guard, then to closing.

Source

pub fn on_close_blocked( self, on_blocked: impl Fn(&mut EventContext<'_>) + 'static, ) -> WindowConfig

Notification fired when the can_close signal blocks a close attempt. Runs with this window’s EventContext; use it to open the confirmation dialog / modal that, on confirm, calls close_window_forced. No-op unless a can_close signal is also set.

Source

pub fn take_close_guard( &mut self, ) -> Option<Rc<dyn Fn(&mut EventContext<'_>) -> CloseResponse>>

Take the close guard out of the config. Consumed by the window manager once during create_window, which stores it on the managed window for the window’s lifetime.

Source

pub fn take_can_close(&mut self) -> Option<Prop<bool>>

Take the can_close prop out of the config.

Source

pub fn take_close_blocked( &mut self, ) -> Option<Rc<dyn Fn(&mut EventContext<'_>)>>

Take the on_close_blocked callback out of the config.

Source

pub fn on_removed( self, hook: impl Fn(&WindowRemovedEvent) + 'static, ) -> WindowConfig

Register a teardown hook for this window: an Fn, not FnOnce or FnMut, because a shared closure (Rc-cloned config, or a closure built once and attached to several windows opened for the same document) may run once per window it’s attached to.

Fires exactly once, no matter which of the two ways this window closes:

because the window manager funnels both through the same, single teardown routine.

Runs after the window is gone: its tree has been dropped, its platform window destroyed, and every framework-internal registration for it (native menu, drag-and-drop target, pending async completions, …) purged. This is the deliberate choice — it is what lets WindowRemovedEvent::remaining_windows already exclude the window being removed, so a handler that wants to know “was this the last window [for my Work]” gets an unambiguous answer rather than having to remember to subtract one. The trade-off is that the callback cannot reach into the removed window’s own widget tree — by the time it runs, there isn’t one. If a hook needs to read tree state before it’s torn down, that has to happen earlier, in on_close_requested or on_close_blocked.

The intended use is releasing whatever an app keeps keyed by a window’s TeksiloWindowId — a shared-document refcount, an entry in the app’s own “windows open for this Work” map — so that bookkeeping is decremented exactly when the framework agrees the window is really gone, instead of a hand-maintained registry that only ever grows.

Source

pub fn take_on_removed(&mut self) -> Option<Rc<dyn Fn(&WindowRemovedEvent)>>

Take the on_removed teardown hook out of the config.

Source

pub fn is_modal(&self) -> bool

Source

pub fn modal_parent(&self) -> Option<TeksiloWindowId>

Source

pub fn modal_focus_target(&self) -> Option<WidgetId>

Trait Implementations§

Source§

impl Debug for WindowConfig

Source§

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

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

impl Default for WindowConfig

Source§

fn default() -> WindowConfig

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more