pub struct Drive<C: BorrowMut<Core> = Core> {
pub core: C,
pub exts: Extensions,
pub viewport: Size,
pub scale: f32,
/* private fields */
}Expand description
The headless driver; see the module docs for an example.
C is the core it drives: its own Core by default, or a &mut Core
borrowed from a harness that built one.
Fields§
§core: CThe core being driven.
exts: ExtensionsThe extensions filling the frame’s slots, routed as the runner
routes them. Empty unless Drive::extension loaded one.
viewport: SizeThe viewport every frame lays out against, logical px.
scale: f32The display’s scale: 1 unless a test sets it.
Implementations§
Source§impl<C: BorrowMut<Core>> Drive<C>
impl<C: BorrowMut<Core>> Drive<C>
Sourcepub fn new(core: C, w: f32, h: f32) -> Self
pub fn new(core: C, w: f32, h: f32) -> Self
A drive over core with a w by h viewport. Turns the node
snapshot on (Core::set_inspect) so Self::texts_under and
Self::rect_of have a frame to read.
Sourcepub fn framing(self) -> Self
pub fn framing(self) -> Self
Frames after every gesture (a click, a key, typed text, the wheel, a hover, a drag), and once while a drag is held.
Sourcepub fn extension(
&mut self,
ns: &str,
ext: impl Extension + 'static,
) -> Result<(), String>
pub fn extension( &mut self, ns: &str, ext: impl Extension + 'static, ) -> Result<(), String>
Loads an extension under ns, as Launcher::extension_as would.
Sourcepub fn frame(&mut self, app: &mut impl App)
pub fn frame(&mut self, app: &mut impl App)
Builds one frame from app.view, then hands app whatever the
frame produced on its own (a resize, a layout, a window event).
Sourcepub fn advance(&mut self, secs: f64)
pub fn advance(&mut self, secs: f64)
Moves the frame clock secs forward; the next frame sees it.
Sourcepub fn key_of(&mut self, label: &str) -> Option<Key>
pub fn key_of(&mut self, label: &str) -> Option<Key>
The key a node was opened under label, from the last frame.
Sourcepub fn rect_of(&self, key: Key) -> Option<Rect>
pub fn rect_of(&self, key: Key) -> Option<Rect>
Where the last frame put the node key names, in logical px:
where it is hit when it takes input (clipped, on top), else where
layout put it.
Sourcepub fn texts_under(&self, label: &str) -> Vec<String>
pub fn texts_under(&self, label: &str) -> Vec<String>
The text of every text node under the first node labelled label
in the last frame, in tree order; empty when none is labelled so.
Sourcepub fn warnings(&mut self) -> Vec<String>
pub fn warnings(&mut self) -> Vec<String>
Every warning the core raised since the last call, as
code: message: a test asserts it empty.
Sourcepub fn input(&mut self, app: &mut impl App, ev: InputEvent) -> Vec<UiEvent>
pub fn input(&mut self, app: &mut impl App, ev: InputEvent) -> Vec<UiEvent>
One input, its events to app, and back to the caller too.
Sourcepub fn move_to(&mut self, app: &mut impl App, x: f32, y: f32) -> Vec<UiEvent>
pub fn move_to(&mut self, app: &mut impl App, x: f32, y: f32) -> Vec<UiEvent>
The pointer to a point, nothing pressed.
Sourcepub fn hover(&mut self, app: &mut impl App, key: Key) -> Vec<UiEvent>
pub fn hover(&mut self, app: &mut impl App, key: Key) -> Vec<UiEvent>
The pointer to the middle of the node key names.
Sourcepub fn click(&mut self, app: &mut impl App, x: f32, y: f32) -> Vec<UiEvent>
pub fn click(&mut self, app: &mut impl App, x: f32, y: f32) -> Vec<UiEvent>
A primary click at a point: move, press, release.
Sourcepub fn double_click(
&mut self,
app: &mut impl App,
x: f32,
y: f32,
) -> Vec<UiEvent>
pub fn double_click( &mut self, app: &mut impl App, x: f32, y: f32, ) -> Vec<UiEvent>
Two clicks at a point, the second counted as the second, as the OS counts a double click into the press.
Sourcepub fn click_key(&mut self, app: &mut impl App, key: Key) -> Vec<UiEvent>
pub fn click_key(&mut self, app: &mut impl App, key: Key) -> Vec<UiEvent>
A click on the node key names, the way assistive technology
presses it — no geometry needed.
Sourcepub fn drag(&mut self, app: &mut impl App, from: Vec2, to: Vec2) -> Vec<UiEvent>
pub fn drag(&mut self, app: &mut impl App, from: Vec2, to: Vec2) -> Vec<UiEvent>
A press at from, the pointer taken past the click slop and on to
to, the release: an on_drag node hears start, moves and end,
and the release is no click.
Sourcepub fn wheel(
&mut self,
app: &mut impl App,
x: f32,
y: f32,
dx: f32,
dy: f32,
) -> Vec<UiEvent>
pub fn wheel( &mut self, app: &mut impl App, x: f32, y: f32, dx: f32, dy: f32, ) -> Vec<UiEvent>
The wheel over a point.
Sourcepub fn scroll_gesture(
&mut self,
app: &mut impl App,
x: f32,
y: f32,
delta: Vec2,
begins: bool,
) -> Vec<UiEvent>
pub fn scroll_gesture( &mut self, app: &mut impl App, x: f32, y: f32, delta: Vec2, begins: bool, ) -> Vec<UiEvent>
One event of a scroll gesture over a point: begins on its first,
and the rest go to the target that first one picked, wherever the
pointer or the content has gone since, as a native swipe latches.
Self::wheel is a gesture of its own.
A non-primary button pressed and released at a point: what an
on_button node claiming it hears as press and release.
Sourcepub fn key(
&mut self,
app: &mut impl App,
name: &str,
mods: KeyMods,
) -> Vec<UiEvent>
pub fn key( &mut self, app: &mut impl App, name: &str, mods: KeyMods, ) -> Vec<UiEvent>
A key pressed and released, by the name a binding spells it
("a", "enter", "f2"): the raw press — carrying the character
(or the space) as its text when no chord modifier is held, as a
keyboard’s would — then the editor event the same press means
(KeyPress::edit_event, the one table every driver sends from),
then the release.
Sourcepub fn keys(&mut self, app: &mut impl App, seq: &str) -> Vec<UiEvent>
pub fn keys(&mut self, app: &mut impl App, seq: &str) -> Vec<UiEvent>
keys(app, "jj ww"): Self::key for each character, unmodified,
a space being the space key.
Sourcepub fn text(&mut self, app: &mut impl App, s: &str) -> Vec<UiEvent>
pub fn text(&mut self, app: &mut impl App, s: &str) -> Vec<UiEvent>
Typed text, as the OS delivers it to the focused editor.
Sourcepub fn commit(&mut self, app: &mut impl App, s: &str) -> Vec<UiEvent>
pub fn commit(&mut self, app: &mut impl App, s: &str) -> Vec<UiEvent>
Text that did not come from a key press — an IME’s commit — as the
OS delivers it: to a focused editor, or to a key sink as text.
Sourcepub fn focus(&mut self, app: &mut impl App, key: Key) -> Vec<UiEvent>
pub fn focus(&mut self, app: &mut impl App, key: Key) -> Vec<UiEvent>
Focuses the node key names, as Tab or a screen reader would.
Auto Trait Implementations§
impl<C = Core> !RefUnwindSafe for Drive<C>
impl<C = Core> !Send for Drive<C>
impl<C = Core> !Sync for Drive<C>
impl<C = Core> !UnwindSafe for Drive<C>
impl<C> Freeze for Drive<C>where
C: Freeze,
impl<C> Unpin for Drive<C>where
C: Unpin,
impl<C> UnsafeUnpin for Drive<C>where
C: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>. Box<dyn Any> can
then be further downcast into Box<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>. Rc<Any> 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.