Skip to main content

Drive

Struct Drive 

Source
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: C

The core being driven.

§exts: Extensions

The extensions filling the frame’s slots, routed as the runner routes them. Empty unless Drive::extension loaded one.

§viewport: Size

The viewport every frame lays out against, logical px.

§scale: f32

The display’s scale: 1 unless a test sets it.

Implementations§

Source§

impl<C: BorrowMut<Core>> Drive<C>

Source

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.

Source

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.

Source

pub fn extension( &mut self, ns: &str, ext: impl Extension + 'static, ) -> Result<(), String>

Loads an extension under ns, as Launcher::extension_as would.

Source

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

Source

pub fn advance(&mut self, secs: f64)

Moves the frame clock secs forward; the next frame sees it.

Source

pub fn frames(&self) -> u64

The frames built so far.

Source

pub fn key_of(&mut self, label: &str) -> Option<Key>

The key a node was opened under label, from the last frame.

Source

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.

Source

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.

Source

pub fn warnings(&mut self) -> Vec<String>

Every warning the core raised since the last call, as code: message: a test asserts it empty.

Source

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.

Source

pub fn move_to(&mut self, app: &mut impl App, x: f32, y: f32) -> Vec<UiEvent>

The pointer to a point, nothing pressed.

Source

pub fn hover(&mut self, app: &mut impl App, key: Key) -> Vec<UiEvent>

The pointer to the middle of the node key names.

Source

pub fn click(&mut self, app: &mut impl App, x: f32, y: f32) -> Vec<UiEvent>

A primary click at a point: move, press, release.

Source

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.

Source

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.

Source

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.

Source

pub fn wheel( &mut self, app: &mut impl App, x: f32, y: f32, dx: f32, dy: f32, ) -> Vec<UiEvent>

The wheel over a point.

Source

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.

Source

pub fn button_click( &mut self, app: &mut impl App, x: f32, y: f32, button: MouseButton, ) -> Vec<UiEvent>

A non-primary button pressed and released at a point: what an on_button node claiming it hears as press and release.

Source

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.

Source

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.

Source

pub fn text(&mut self, app: &mut impl App, s: &str) -> Vec<UiEvent>

Typed text, as the OS delivers it to the focused editor.

Source

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.

Source

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.

Source

pub fn check(&self, cond: bool, what: &str) -> Result<(), String>

Ok when cond holds, else Err(what), so a scripted drive reads as a list of checks. Prints ok <what> on success.

Source

pub fn log(&self) -> &[String]

Everything delivered so far, one line each: frame key payload.

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

Convert 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)

Convert &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)

Convert &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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more