pub struct App { /* private fields */ }Expand description
Owns the widget tree, handles focus, and converts OS events to Y-up coords.
Create with App::new, call App::layout every frame before
App::paint, and feed OS events through the on_* methods.
Implementations§
Source§impl App
impl App
Sourcepub fn root(&self) -> &dyn Widget
pub fn root(&self) -> &dyn Widget
Access the root widget — used by tests and inspectors that need to
introspect the laid-out tree without re-routing events through the
full dispatch machinery. Pair with find_widget_by_id to locate
a specific widget by its Widget::id() (e.g. a Window’s title).
Sourcepub fn root_mut(&mut self) -> &mut dyn Widget
pub fn root_mut(&mut self) -> &mut dyn Widget
Mutable counterpart to [root]. Required when a test wants to
drive a specific sub-widget directly (e.g. reading ScrollView
scroll offset) after the App has routed an event.
Sourcepub fn focused_widget_type_name(&self) -> Option<&'static str>
pub fn focused_widget_type_name(&self) -> Option<&'static str>
Return the type name of the currently focused widget, if any.
Sourcepub fn set_global_key_handler(
&mut self,
handler: impl FnMut(Key, Modifiers) -> bool + 'static,
)
pub fn set_global_key_handler( &mut self, handler: impl FnMut(Key, Modifiers) -> bool + 'static, )
Sourcepub fn layout(&mut self, viewport: Size)
pub fn layout(&mut self, viewport: Size)
Lay out the widget tree to fill viewport. viewport is in physical
pixels (e.g. window.inner_size() on native, canvas.width/height on
wasm); this method divides by the current device scale factor so the
widget tree lays out in logical (device-independent) units. Call once
per frame before paint.
Sourcepub fn paint(&mut self, ctx: &mut dyn DrawCtx)
pub fn paint(&mut self, ctx: &mut dyn DrawCtx)
Paint the entire widget tree into ctx. Call after layout.
Applies a ctx.scale(dps, dps) transform up-front so the whole tree —
widget dimensions, font sizes, margins — is rendered at physical pixel
density on HiDPI screens without any widget having to know about DPI.
Also clears the immediate draw flag so widgets can re-request it during
this paint if they need another frame; hosts read [wants_draw]
after paint returns to decide whether to schedule continuous draws.
Sourcepub fn wants_draw(&self) -> bool
pub fn wants_draw(&self) -> bool
After a paint pass, returns true if any widget requested another frame
(e.g. an in-progress hover animation). Hosts should use this to set
their event-loop control flow to continuous polling while it’s true.
Combines the visibility-gated tree-walk signal (Widget::needs_draw)
with the immediate draw request flag (crate::animation::wants_draw).
Widgets call request_draw for ordinary visual invalidation; scheduled
draw needs such as cursor blink should use needs_draw /
next_draw_deadline so hidden subtrees do not keep the loop awake.
Sourcepub fn next_draw_deadline(&self) -> Option<Instant>
pub fn next_draw_deadline(&self) -> Option<Instant>
Earliest scheduled draw deadline across the visible widget tree.
Hosts translate Some(t) into ControlFlow::WaitUntil(t) so that
e.g. a text field’s cursor blink wakes the loop exactly at the flip
boundary. Invisible subtrees contribute nothing.
Sourcepub fn on_mouse_move(&mut self, screen_x: f64, screen_y: f64)
pub fn on_mouse_move(&mut self, screen_x: f64, screen_y: f64)
Mouse cursor moved. screen_y is Y-down physical pixels.
Sourcepub fn on_mouse_down(
&mut self,
screen_x: f64,
screen_y: f64,
button: MouseButton,
mods: Modifiers,
)
pub fn on_mouse_down( &mut self, screen_x: f64, screen_y: f64, button: MouseButton, mods: Modifiers, )
Mouse button pressed. screen_y is Y-down physical pixels.
Sourcepub fn on_mouse_up(
&mut self,
screen_x: f64,
screen_y: f64,
button: MouseButton,
mods: Modifiers,
)
pub fn on_mouse_up( &mut self, screen_x: f64, screen_y: f64, button: MouseButton, mods: Modifiers, )
Mouse button released. screen_y is Y-down.
Sourcepub fn on_key_down(&mut self, key: Key, mods: Modifiers)
pub fn on_key_down(&mut self, key: Key, mods: Modifiers)
Key pressed. Delivered to the focused widget first, then to the visible widget tree as an unconsumed key if focus ignores it.
Sourcepub fn on_key_up(&mut self, key: Key, mods: Modifiers)
pub fn on_key_up(&mut self, key: Key, mods: Modifiers)
Key released. Delivered to the focused widget.
Sourcepub fn on_mouse_wheel(&mut self, screen_x: f64, screen_y: f64, delta_y: f64)
pub fn on_mouse_wheel(&mut self, screen_x: f64, screen_y: f64, delta_y: f64)
Mouse wheel scrolled. screen_y is Y-down. delta_y positive = scroll up.
delta_x positive = content moves right.
Sourcepub fn on_mouse_wheel_xy(
&mut self,
screen_x: f64,
screen_y: f64,
delta_x: f64,
delta_y: f64,
)
pub fn on_mouse_wheel_xy( &mut self, screen_x: f64, screen_y: f64, delta_x: f64, delta_y: f64, )
Mouse wheel with an explicit horizontal component (trackpad pan, shift+wheel via the platform harness).
Sourcepub fn on_mouse_wheel_xy_mods(
&mut self,
screen_x: f64,
screen_y: f64,
delta_x: f64,
delta_y: f64,
modifiers: Modifiers,
)
pub fn on_mouse_wheel_xy_mods( &mut self, screen_x: f64, screen_y: f64, delta_x: f64, delta_y: f64, modifiers: Modifiers, )
Mouse wheel with explicit horizontal component and modifier state.
Sourcepub fn collect_inspector_nodes(&self) -> Vec<InspectorNode>
pub fn collect_inspector_nodes(&self) -> Vec<InspectorNode>
Snapshot the entire widget tree for the inspector.
Sourcepub fn has_captured_pointer(&self) -> bool
pub fn has_captured_pointer(&self) -> bool
true while a widget is actively capturing the pointer — i.e. the
user is mid-drag (a window edge, slider thumb, scrollbar, etc.).
Used by the demo harness to throttle expensive per-frame snapshots
(the inspector tree walk) during interactions; the snapshot can
safely defer until the user releases without changing the visible
outcome (the underlying widget tree topology doesn’t change during
a drag, only the widgets’ bounds).
Sourcepub fn dump_tree_json(&self) -> String
pub fn dump_tree_json(&self) -> String
Serialize the widget tree — types, bounds, depth, properties — as JSON.
Produces a flat array of nodes in paint-order DFS. Suitable for writing to a file and diffing between runs to verify layout stability. Used by the demo harness’s debug hotkey.
Sourcepub fn has_focus(&self) -> bool
pub fn has_focus(&self) -> bool
Returns true if any widget currently holds keyboard focus.
Used by the render loop to schedule cursor-blink repaints.
Sourcepub fn on_mouse_leave(&mut self)
pub fn on_mouse_leave(&mut self)
Call when the cursor leaves the window to clear hover state.
pub fn on_touch_start( &mut self, device: TouchDeviceId, id: TouchId, screen_x: f64, screen_y: f64, force: Option<f32>, )
pub fn on_touch_move( &mut self, device: TouchDeviceId, id: TouchId, screen_x: f64, screen_y: f64, force: Option<f32>, )
pub fn on_touch_end(&mut self, device: TouchDeviceId, id: TouchId)
pub fn on_touch_cancel(&mut self, device: TouchDeviceId, id: TouchId)
Sourcepub fn active_touch_count(&self) -> usize
pub fn active_touch_count(&self) -> usize
Current number of fingers down across all devices. Used by
widgets that want to know the gesture has begun before the
first frame has had a chance to produce a delta (where
current_multi_touch() may still be None).
Auto Trait Implementations§
impl Freeze for App
impl !RefUnwindSafe for App
impl !Send for App
impl !Sync for App
impl Unpin for App
impl UnsafeUnpin for App
impl !UnwindSafe for App
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