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
impl Window
Sourcepub fn new(
title: impl Into<String>,
font: Arc<Font>,
content: Box<dyn Widget>,
) -> Self
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.
Sourcepub fn title(&self) -> &str
pub fn title(&self) -> &str
Returns the window title as it was passed to Window::new.
Sourcepub fn on_raised(self, cb: impl FnMut(&str) + 'static) -> Self
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.
pub fn with_bounds(self, b: Rect) -> Self
pub fn with_font_size(self, size: f64) -> Self
pub fn with_visible_cell(self, cell: Rc<Cell<bool>>) -> Self
pub fn with_reset_cell(self, cell: Rc<Cell<Option<Rect>>>) -> Self
pub fn with_position_cell(self, cell: Rc<Cell<Rect>>) -> Self
Sourcepub fn with_maximized_cell(self, cell: Rc<Cell<bool>>) -> Self
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.
pub fn with_margin(self, m: Insets) -> Self
pub fn with_h_anchor(self, h: HAnchor) -> Self
pub fn with_v_anchor(self, v: VAnchor) -> Self
pub fn with_min_size(self, s: Size) -> Self
pub fn with_max_size(self, s: Size) -> Self
pub fn with_constrain(self, constrain: bool) -> Self
Sourcepub fn with_gl_backbuffer(self, enabled: bool) -> Self
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.
Sourcepub fn with_auto_size(self, auto: bool) -> Self
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.
Sourcepub fn with_resizable(self, on: bool) -> Self
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).
Sourcepub fn with_resizable_axes(self, h: bool, v: bool) -> Self
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]).
Sourcepub fn with_tight_content_fit(self, on: bool) -> Self
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.
Sourcepub fn with_height_floor_to_content(self, on: bool) -> Self
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.
Sourcepub fn with_vscroll(self, vscroll: bool) -> Self
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.
pub fn on_close(self, cb: impl FnMut() + 'static) -> Self
pub fn show(&mut self)
pub fn hide(&mut self)
pub fn toggle(&mut self)
Sourcepub fn is_visible(&self) -> bool
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 Widget for Window
impl Widget for Window
Source§fn id(&self) -> Option<&str>
fn id(&self) -> Option<&str>
External identity for z-order persistence, inspector lookup, etc.
Source§fn needs_draw(&self) -> bool
fn needs_draw(&self) -> bool
A collapsed window paints only its title bar — nothing inside the
content area is visible, so no child can legitimately request a
repaint. Closing (is_visible false) also short-circuits, matching
the default trait impl. Without these overrides a cursor blink or
hover tween inside a collapsed/closed window would keep the host
loop awake despite being invisible.
Source§fn take_raise_request(&mut self) -> bool
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)>
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
fn type_name(&self) -> &'static str
Source§fn is_visible(&self) -> bool
fn is_visible(&self) -> bool
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>
fn next_draw_deadline(&self) -> Option<Instant>
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 moreSource§fn widget_base(&self) -> Option<&WidgetBase>
fn widget_base(&self) -> Option<&WidgetBase>
WidgetBase. Read moreSource§fn widget_base_mut(&mut self) -> Option<&mut WidgetBase>
fn widget_base_mut(&mut self) -> Option<&mut WidgetBase>
widget_base. Read moreSource§fn h_anchor(&self) -> HAnchor
fn h_anchor(&self) -> HAnchor
HAnchor::FIT (take natural content width).Source§fn v_anchor(&self) -> VAnchor
fn v_anchor(&self) -> VAnchor
VAnchor::FIT (take natural content height).Source§fn properties(&self) -> Vec<(&'static str, String)>
fn properties(&self) -> Vec<(&'static str, String)>
Source§fn set_bounds(&mut self, b: Rect)
fn set_bounds(&mut self, b: Rect)
Source§fn children_mut(&mut self) -> &mut Vec<Box<dyn Widget>>
fn children_mut(&mut self) -> &mut Vec<Box<dyn Widget>>
Source§fn backbuffer_spec(&mut self) -> BackbufferSpec
fn backbuffer_spec(&mut self) -> BackbufferSpec
Source§fn backbuffer_state_mut(&mut self) -> Option<&mut BackbufferState>
fn backbuffer_state_mut(&mut self) -> Option<&mut BackbufferState>
BackbufferSpec other than BackbufferKind::None.Source§fn hit_test(&self, local_pos: Point) -> bool
fn hit_test(&self, local_pos: Point) -> bool
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
fn claims_pointer_exclusively(&self, local_pos: Point) -> bool
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
fn layout(&mut self, available: Size) -> Size
Source§fn paint(&mut self, ctx: &mut dyn DrawCtx)
fn paint(&mut self, ctx: &mut dyn DrawCtx)
ctx. Read moreSource§fn paint_overlay(&mut self, ctx: &mut dyn DrawCtx)
fn paint_overlay(&mut self, ctx: &mut dyn DrawCtx)
Source§fn finish_paint(&mut self, ctx: &mut dyn DrawCtx)
fn finish_paint(&mut self, ctx: &mut dyn DrawCtx)
paint, child painting, and optional overlay painting. Read moreSource§fn on_event(&mut self, event: &Event) -> EventResult
fn on_event(&mut self, event: &Event) -> EventResult
EventResult::Consumed to stop bubbling. Read moreSource§fn hit_test_global_overlay(&self, _local_pos: Point) -> bool
fn hit_test_global_overlay(&self, _local_pos: Point) -> bool
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
fn has_active_modal(&self) -> bool
Source§fn on_unconsumed_key(
&mut self,
_key: &Key,
_modifiers: Modifiers,
) -> EventResult
fn on_unconsumed_key( &mut self, _key: &Key, _modifiers: Modifiers, ) -> EventResult
Source§fn is_focusable(&self) -> bool
fn is_focusable(&self) -> bool
Source§fn set_label_color(&mut self, _color: Color)
fn set_label_color(&mut self, _color: Color)
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)
fn set_label_text(&mut self, _text: &str)
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>
fn as_reflect(&self) -> Option<&dyn Reflect>
Source§fn as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
fn as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
as_reflect. Used by the
inspector to write edits back into the live widget.Source§fn has_backbuffer(&self) -> bool
fn has_backbuffer(&self) -> bool
Source§fn compositing_layer(&mut self) -> Option<CompositingLayer>
fn compositing_layer(&mut self) -> Option<CompositingLayer>
Source§fn mark_dirty(&mut self)
fn mark_dirty(&mut self)
Source§fn backbuffer_cache_mut(&mut self) -> Option<&mut BackbufferCache>
fn backbuffer_cache_mut(&mut self) -> Option<&mut BackbufferCache>
Source§fn backbuffer_mode(&self) -> BackbufferMode
fn backbuffer_mode(&self) -> BackbufferMode
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
fn contributes_children_to_inspector(&self) -> bool
Source§fn show_in_inspector(&self) -> bool
fn show_in_inspector(&self) -> bool
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>
fn lcd_preference(&self) -> Option<bool>
Source§fn paint_global_overlay(&mut self, _ctx: &mut dyn DrawCtx)
fn paint_global_overlay(&mut self, _ctx: &mut dyn DrawCtx)
Source§fn padding(&self) -> Insets
fn padding(&self) -> Insets
Insets::ZERO. Read moreSource§fn enforce_integer_bounds(&self) -> bool
fn enforce_integer_bounds(&self) -> bool
paint_subtree should snap this widget’s incoming
translation to the physical pixel grid. Read moreAuto Trait Implementations§
impl !Freeze for Window
impl !RefUnwindSafe for Window
impl !Send for Window
impl !Sync for Window
impl Unpin for Window
impl UnsafeUnpin for Window
impl !UnwindSafe for Window
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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