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 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.

Source

pub fn title(&self) -> &str

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

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_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_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 on_close(self, cb: impl FnMut() + 'static) -> Self

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 Widget for Window

Source§

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

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

Source§

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

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_paint_deadline(&self) -> Option<Instant>

Return the earliest wall-clock instant at which this widget (or any visible descendant) wants the next paint. 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 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 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 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 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 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.
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 is_focusable(&self) -> bool

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

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

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

fn has_backbuffer(&self) -> bool

Whether this widget renders into its own offscreen buffer before compositing into the parent. 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 enforce_integer_bounds(&self) -> bool

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

Auto 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> 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> 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 = 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.