Skip to main content

Window

Struct Window 

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

A floating panel with a draggable/resizable title bar and a single content child.

Implementations§

Source§

impl Window

Source

pub fn with_live_content(self, live: bool) -> Self

Treat the window’s content as live: invalidate the backbuffer every frame so custom paint code reading from a mutating data source (network feed, simulation state, sensor stream) is rasterised fresh. Automatically skipped when the window is collapsed or hidden — no wasted work when the user can’t see the content.

Use this for diagnostics graphs, telemetry views, or any widget whose paint() reads from an Rc<RefCell<…>> model that the framework can’t observe. The alternative — composing live UI from widgets that auto-invalidate on setter calls (Label::set_text, etc.) — is preferred when feasible, but for custom direct-to-DrawCtx widgets this is the simplest correct fix.

See Window::new for the full discussion of the back-buffer invalidation contract and the canonical “stale pixels” gotcha this flag solves.

Source

pub fn on_raised(self, cb: impl FnMut(&str) + 'static) -> Self

Register a callback fired whenever this window requests a raise (click-to-front or visibility rising-edge from the sidebar). Receives the window title. The demo uses this to feed a shared z-order tracker that gets persisted to disk.

Source

pub fn with_bounds(self, b: Rect) -> Self

Source

pub fn with_font_size(self, size: f64) -> Self

Source

pub fn with_visible_cell(self, cell: Rc<Cell<bool>>) -> Self

Source

pub fn with_reset_cell(self, cell: Rc<Cell<Option<Rect>>>) -> Self

Source

pub fn with_position_cell(self, cell: Rc<Cell<Rect>>) -> Self

Source

pub fn with_maximized_cell(self, cell: Rc<Cell<bool>>) -> Self

Wire the window’s canvas-maximized state into external persistence.

Call after [with_bounds] when restoring saved state so the current bounds become the pre-maximize bounds used by the first layout pass.

Source

pub fn with_margin(self, m: Insets) -> Self

Source

pub fn with_h_anchor(self, h: HAnchor) -> Self

Source

pub fn with_v_anchor(self, v: VAnchor) -> Self

Source

pub fn with_min_size(self, s: Size) -> Self

Source

pub fn with_max_size(self, s: Size) -> Self

Source

pub fn with_constrain(self, constrain: bool) -> Self

Source

pub fn with_gl_backbuffer(self, enabled: bool) -> Self

Opt this window in/out of the generic retained GL-FBO backbuffer. Disabling renders directly into the inherited parent target.

Source

pub fn with_auto_size(self, auto: bool) -> Self

Make the window size itself to the content’s preferred size every frame. Top-left pin: as content grows/shrinks, the title bar stays where it is.

Source

pub fn with_resizable(self, on: bool) -> Self

Toggle user-dragged resize. false hides every edge/corner handle and disables resize hit-tests. Default: true. Matches egui’s Window::resizable(bool).

Source

pub fn with_resizable_axes(self, h: bool, v: bool) -> Self

Fine-grained axis-locking of the resize handles — pass (true, false) for a horizontally-only resizable window, etc. Implies with_resizable(true). Matches egui’s Window::resizable([h, v]).

Source

pub fn with_tight_content_fit(self, on: bool) -> Self

Lock the window’s height to its content’s required height. The user can grab a vertical resize handle but the next layout snaps back — egui’s W4 “no scroll, no clip, no whitespace” contract. Requires the content tree to expose its required height via [Widget::measure_min_height]; our FlexColumn, Label, TextArea, and Container::with_fit_height all do.

Source

pub fn with_height_floor_to_content(self, on: bool) -> Self

Floor-only variant of [with_tight_content_fit]: refuses to shrink past content but allows the user to pull the window taller (whitespace below). Used for windows whose content includes a flex-fill child like a multiline TextArea — matches egui’s W5 where the TextEdit fills extra height and the user can grow the window further.

Source

pub fn with_vscroll(self, vscroll: bool) -> Self

Wrap the window’s content in a built-in vertical [ScrollView]. Matches egui’s Window::vscroll(true): lets the user shrink the window below content height without the caller having to wrap the content in a ScrollView manually. Eager — happens at builder time so the rest of the layout / event / paint paths see a single child as usual. Has no effect when called with false (matches the default).

Don’t combine with [with_auto_size]: the ScrollView claims its full available height, which would make auto-sizing grow the window to the canvas. egui’s demo never combines the two flags either.

Source

pub fn on_close(self, cb: impl FnMut() + 'static) -> Self

Source§

impl Window

Source

pub fn new( title: impl Into<String>, font: Arc<Font>, content: Box<dyn Widget>, ) -> Self

Create a new window with the given title, font, and content widget.

Default position: (60, 60) with size = (360, 280). Call [with_bounds] to override.

Windows keep a retained backbuffer. Live content must either call Window::invalidate_backbuffer when external data changes or use Window::with_live_content to force repaint while visible.

Source

pub fn title(&self) -> &str

Returns the window title as it was passed to Window::new.

Source

pub fn invalidate_backbuffer(&mut self)

Force the window’s retained backbuffer to re-rasterise on the next paint pass. Use this when the content widget reads from a live data source (network feed, animation curve, simulation state) that the framework can’t observe. Otherwise the cached pixels blit unchanged and your live data never reaches the screen.

Pair with Window::with_live_content for streaming data that changes every frame: that flag self-invalidates here automatically (and skips when collapsed/hidden).

See Window::new for the full discussion of when this matters and the alternative (“compose live UI out of widgets that invalidate on data change”) that avoids needing to call this at all.

Source

pub fn show(&mut self)

Source

pub fn hide(&mut self)

Source

pub fn toggle(&mut self)

Source

pub fn is_visible(&self) -> bool

Current visibility — honours an optional shared visible_cell when wired (sidebar toggles, programmatic show/hide). The inherent self.visible field is a fallback for windows that aren’t wired to a cell. Must match the Widget-trait impl below so rising-edge detection in layout() observes sidebar toggles.

Trait Implementations§

Source§

impl Snappable for Window

Source§

fn snap_id(&self) -> SnapId

Identity used to skip self-matches in the target list.
Source§

fn snap_rect(&self) -> Rect

Current rect — both the source of the moving candidate and what the engine reads to build the target list for stationary neighbors.
Source§

fn set_snap_rect(&mut self, r: Rect)

Apply a snapped rect back to the implementor. Called once per drag tick after compute_snap returns. Default implementors just overwrite their internal bounds with r.
Source§

fn is_snap_source(&self) -> bool

false to opt this rect OUT of being the moving rect in a snap. Rare — most movable things stay sources.
Source§

fn is_snap_target(&self) -> bool

false to opt this rect OUT of being a snap target for other rects (the moving rect still won’t snap to it). Useful for transient overlays, hidden windows, etc.
Source§

impl Widget for Window

Source§

fn id(&self) -> Option<&str>

External identity for z-order persistence, inspector lookup, etc.

Source§

fn needs_draw(&self) -> bool

Collapsed or closed windows should not keep the host loop awake.

Source§

fn take_raise_request(&mut self) -> bool

Pop this window to the top of the parent Stack when the false→true visibility edge fires (see layout).

Source§

fn clip_children_rect(&self) -> Option<(f64, f64, f64, f64)>

Clip child painting to the content area (below the title bar). When collapsed bounds.height == TITLE_H so the content rect has zero height, preventing any child from drawing outside the visible title-bar strip.

Source§

fn type_name(&self) -> &'static str

A static name for this widget type, used by the inspector. Default: “Widget”.
Source§

fn is_visible(&self) -> bool

Return false to suppress painting this widget and all its children. The widget’s own paint() will not be called. Default: true.
Source§

fn next_draw_deadline(&self) -> Option<Instant>

Return the earliest wall-clock instant at which this widget (or any visible descendant) wants the next draw. None = no scheduled wake. The host loop turns a Some(t) into ControlFlow::WaitUntil(t) so e.g. a cursor blink fires without continuous polling. Read more
Source§

fn bounds(&self) -> Rect

Bounding rectangle in parent-local Y-up coordinates.
Source§

fn margin(&self) -> Insets

Outer margin around this widget in logical units. Read more
Source§

fn widget_base(&self) -> Option<&WidgetBase>

Direct read access to the widget’s embedded WidgetBase. Read more
Source§

fn widget_base_mut(&mut self) -> Option<&mut WidgetBase>

Mutable counterpart of widget_base. Read more
Source§

fn h_anchor(&self) -> HAnchor

Horizontal anchor: how this widget sizes/positions itself horizontally within the slot the parent assigns. Default: HAnchor::FIT (take natural content width).
Source§

fn v_anchor(&self) -> VAnchor

Vertical anchor: how this widget sizes/positions itself vertically within the slot the parent assigns. Default: VAnchor::FIT (take natural content height).
Source§

fn min_size(&self) -> Size

Minimum size constraint (logical units). Read more
Source§

fn max_size(&self) -> Size

Maximum size constraint (logical units). Read more
Source§

fn properties(&self) -> Vec<(&'static str, String)>

Return type-specific properties for the inspector properties pane. Read more
Source§

fn set_bounds(&mut self, b: Rect)

Set the bounding rectangle. Called by the parent during layout.
Source§

fn children(&self) -> &[Box<dyn Widget>]

Immutable access to child widgets.
Source§

fn children_mut(&mut self) -> &mut Vec<Box<dyn Widget>>

Mutable access to child widgets (required for event dispatch + layout).
Source§

fn backbuffer_spec(&mut self) -> BackbufferSpec

Unified widget-owned backbuffer request.
Source§

fn backbuffer_state_mut(&mut self) -> Option<&mut BackbufferState>

Mutable retained backbuffer state for widgets that request a BackbufferSpec other than BackbufferKind::None.
Source§

fn hit_test(&self, local_pos: Point) -> bool

Return true if local_pos (in this widget’s local coordinates) falls inside this widget’s interactive area. Default: axis-aligned rect test.
Source§

fn claims_pointer_exclusively(&self, local_pos: Point) -> bool

When true, hit_test_subtree stops recursing into this widget’s children and returns this widget as the hit target. Used for floating overlays (e.g. a scrollbar painted above its content) that must claim the pointer before children that happen to share the same pixels. Default: false.
Source§

fn layout(&mut self, available: Size) -> Size

Compute desired size given available space, and update internal layout. Read more
Source§

fn paint(&mut self, ctx: &mut dyn DrawCtx)

Paint this widget’s own content into ctx. Read more
Source§

fn paint_overlay(&mut self, ctx: &mut dyn DrawCtx)

Paint decorations that must appear on top of all children. Read more
Source§

fn finish_paint(&mut self, ctx: &mut dyn DrawCtx)

Called after paint, child painting, and optional overlay painting. Read more
Source§

fn on_event(&mut self, event: &Event) -> EventResult

Handle an event. The event’s positions are already in local Y-up coordinates. Return EventResult::Consumed to stop bubbling. Read more
Source§

fn hit_test_global_overlay(&self, _local_pos: Point) -> bool

Return true when local_pos hits an app-level overlay owned by this widget. Unlike normal hit testing, ancestors may be missed because the overlay is painted outside their bounds.
Source§

fn has_active_modal(&self) -> bool

Whether this widget currently owns an app-modal interaction layer. Read more
Source§

fn on_unconsumed_key( &mut self, _key: &Key, _modifiers: Modifiers, ) -> EventResult

Handle a key that was not consumed by the focused widget path. Read more
Source§

fn is_focusable(&self) -> bool

Whether this widget can receive keyboard focus. Default: false.
Source§

fn focus_id(&self) -> Option<FocusId>

Stable identifier for the programmatic focus channel (crate::focus::request_focus). Read more
Source§

fn accepts_text_input(&self) -> bool

true when this widget accepts free-form character input (typing arbitrary letters, numbers, punctuation). Used by the on-screen software keyboard (crate::widgets::on_screen_keyboard) to decide whether to slide up when this widget gains focus. Read more
Source§

fn text_input_value(&self) -> Option<String>

Current text contents of this widget if it is text-bearing. Used by the on-screen software keyboard to apply the sentence-start auto-capitalize heuristic: an empty field (or one ending in ., !, ?, newline) opens the keyboard with Shift active. Read more
Source§

fn text_input_mode(&self) -> KeyboardInputMode

Preferred keyboard input mode for this widget — used by the on-screen software keyboard to pick the initial layer when this widget gains focus. Default is KeyboardInputMode::Text; numeric fields override to Numeric so the digit pad slides up instead of the letter row. Read more
Source§

fn try_scroll_to_lift(&mut self, _amount: f64) -> f64

Try to lift this widget’s visible content upward by amount pixels. Used by the on-screen-keyboard auto-scroll so a focused text field doesn’t end up hidden behind the keyboard panel: the App walks UP the focus path and asks each ancestor to absorb some of the deficit. Read more
Source§

fn set_label_color(&mut self, _color: Color)

If this widget is text-bearing (e.g. Label), update its foreground colour. Default is a no-op. Composite widgets call this on their children to retint labels without rebuilding them — used by Button when toggling between active (white text on accent) and inactive (theme text on subtle bg) appearances.
Source§

fn set_label_text(&mut self, _text: &str)

If this widget is text-bearing (e.g. Label), update its displayed text. Default is a no-op. Composite widgets that own a Label child use this to push live values (e.g. an FPS counter) into the child without bypassing the standard backbuffered glyph cache — calling this on a Label only invalidates the cache when the text actually changed.
Source§

fn as_reflect(&self) -> Option<&dyn Reflect>

Opt-in reflection accessor for the inspector’s typed property editors. Read more
Source§

fn as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>

Mutable counterpart of as_reflect. Used by the inspector to write edits back into the live widget.
Source§

fn has_backbuffer(&self) -> bool

Whether this widget renders into its own offscreen buffer before compositing into the parent. Read more
Source§

fn compositing_layer(&mut self) -> Option<CompositingLayer>

Request that this widget subtree be painted into a transient transparent compositing layer before being blended into its parent. Read more
Source§

fn mark_dirty(&mut self)

Mark this widget’s own retained surface dirty, if it owns one. Read more
Source§

fn backbuffer_cache_mut(&mut self) -> Option<&mut BackbufferCache>

Opt into per-widget CPU bitmap caching with a dirty flag. Read more
Source§

fn backbuffer_mode(&self) -> BackbufferMode

Storage format for this widget’s backbuffer. Ignored unless [backbuffer_cache_mut] returns Some. Default BackbufferMode::Rgba — correct for any widget. Opt into BackbufferMode::LcdCoverage only when the widget paints opaque content covering its full bounds.
Source§

fn contributes_children_to_inspector(&self) -> bool

Whether the inspector should recurse into this widget’s children. Read more
Source§

fn show_in_inspector(&self) -> bool

Return false to hide this widget (and its subtree) from the inspector node snapshot entirely. Intended for zero-size utility widgets such as layout-time watchers / tickers / invisible composers — they bloat the inspector tree without providing user-relevant information and, at scale, can make the inspector’s per-frame tree rebuild expensive.
Source§

fn lcd_preference(&self) -> Option<bool>

Per-widget LCD subpixel preference for backbuffered text rendering. Read more
Source§

fn paint_global_overlay(&mut self, _ctx: &mut dyn DrawCtx)

Paint app-level overlays after the entire widget tree has been painted. Read more
Source§

fn inspector_child_transform(&self) -> TransAffine

Affine transform applied between this widget and its children during inspector traversal. Mirrors what paint() does — e.g. a widget that pushes pan/zoom in paint() and pops it in finish_paint() makes the framework recurse into its children with pan/zoom active, so collect_inspector_nodes must apply the same transform when accumulating descendant screen bounds. Without this hook the inspector hover overlay lands at the un-transformed canvas position when the widget sits inside a panning/zooming container. Read more
Source§

fn padding(&self) -> Insets

Inner padding — space the widget reserves between its own bounds and its child layout area. Only container widgets carry padding; leaf widgets default to Insets::ZERO. Read more
Source§

fn enforce_integer_bounds(&self) -> bool

Whether paint_subtree should snap this widget’s incoming translation to the physical pixel grid. Read more
Source§

fn measure_min_height(&self, _available_w: f64) -> f64

Report the minimum height this widget needs to fully render its content when given the supplied available_w for width. Read more

Auto Trait Implementations§

§

impl !Freeze for Window

§

impl !RefUnwindSafe for Window

§

impl !Send for Window

§

impl !Sync for Window

§

impl !UnwindSafe for Window

§

impl Unpin for Window

§

impl UnsafeUnpin for Window

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> Downcast for T
where T: Any,

Source§

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

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

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

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

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

Converts &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)

Converts &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> 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<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.