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
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_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.
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_paint(&self) -> bool
fn needs_paint(&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_paint_deadline(&self) -> Option<Instant>
fn next_paint_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 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 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 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 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 on_event(&mut self, event: &Event) -> EventResult
fn on_event(&mut self, event: &Event) -> EventResult
EventResult::Consumed to stop bubbling.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 is_focusable(&self) -> bool
fn is_focusable(&self) -> bool
Source§fn properties(&self) -> Vec<(&'static str, String)>
fn properties(&self) -> Vec<(&'static str, String)>
Source§fn has_backbuffer(&self) -> bool
fn has_backbuffer(&self) -> bool
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 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 more