Skip to main content

EventCtx

Struct EventCtx 

Source
pub struct EventCtx<'a, M> {
    pub bounds: Rect,
    pub theme: &'a Theme,
    pub text: &'a mut TextEngine,
    pub state: VisualState,
    pub now_ms: u64,
    /* private fields */
}
Expand description

What a widget can do while handling an event.

Fields§

§bounds: Rect

Absolute bounds of this widget, in surface pixels.

§theme: &'a Theme

The active theme.

§text: &'a mut TextEngine

Fonts and the glyph cache.

Needed while handling events, not only while painting: a text field with a proportional font cannot work out where its caret is without measuring the text in front of it.

§state: VisualState

Hover, press, focus and enabled state.

§now_ms: u64

Milliseconds from an arbitrary epoch.

Implementations§

Source§

impl<'a, M> EventCtx<'a, M>

Source

pub fn emit(&mut self, message: M)

Queues a message for the application to pick up with Ui::drain_messages.

This is the whole event-handling story: no callbacks, no Rc<RefCell<_>>, no widget holding a reference to another widget. The application dispatches centrally, where it can see all of its own state.

Source

pub fn invalidate(&mut self)

Marks this widget’s rectangle for repaint.

Rarely needed: returning Handled::Yes already does it.

Source

pub fn request_focus(&mut self)

Asks the tree to move keyboard focus here.

Source

pub fn request_animation(&mut self)

Asks the tree to start calling Widget::animate on this widget.

Called at the moment the widget starts needing frames — a knob that just began sliding, a caret whose field just took focus. The calls continue until animate answers next_ms: None, which is the widget saying it has arrived. See Widget::animate for what that hand-back means on a device that is supposed to spend its day asleep.

Source

pub fn reveal(&mut self, rect: Rect)

Asks the tree to scroll rect — in absolute surface coordinates, like EventCtx::bounds — into view in every scrollable ancestor.

For a widget whose interior moves: a list whose selection walked below the fold reveals the selected row’s rectangle, and the viewport follows the selection the way it follows focus. Widgets that are themselves the focus target need nothing — focus already reveals.

Source

pub fn resize_height(&mut self, height: i32, duration_ms: u64)

Asks the tree to carry this node’s height to height over duration_ms, through the same tween Ui::animate_layout drives.

A widget does not own its geometry — the tree does — which is why this is a request rather than a call, and why it sits beside reveal rather than anywhere else: those are the two things a widget can want and cannot do.

Reach for it only where nothing else can act. The one use in this crate is a Collapse with no message: a section that reports its toggles is telling the application to drive the fold, and one that reports nothing has nobody else to.

Source

pub fn scrolled(&mut self, within: Rect, by: Point)

Records that this widget moved its own content by by inside within — a rectangle in surface coordinates, like bounds — and changed nothing else there.

For a widget that scrolls itself: a log that keeps its own top line, a table with a pinned header. It is what lets the tree move the rows still on screen instead of drawing them again, the optimisation a viewport scrolled through Ui::set_scroll already gets, on a target that can shift its own pixels. The rest of the widget’s rectangle is repainted as usual, which is where a scrollbar that did not move belongs: leave it out of within.

Only a vertical by is moved today; a sideways one repaints. The claim is trusted — a widget that says its content moved by by and then paints something else inside within gets whatever that looks like. Answer the event Handled::Yes as usual; do not also invalidate, which says “repaint me” and takes the move back.

Trait Implementations§

Source§

impl<'a, M: Debug> Debug for EventCtx<'a, M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, M> !RefUnwindSafe for EventCtx<'a, M>

§

impl<'a, M> !Send for EventCtx<'a, M>

§

impl<'a, M> !Sync for EventCtx<'a, M>

§

impl<'a, M> !UnwindSafe for EventCtx<'a, M>

§

impl<'a, M> Freeze for EventCtx<'a, M>
where &'a mut Vec<M>: Freeze,

§

impl<'a, M> Unpin for EventCtx<'a, M>
where &'a mut Vec<M>: Unpin,

§

impl<'a, M> UnsafeUnpin for EventCtx<'a, M>
where &'a mut Vec<M>: 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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Borrows as dyn Any.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Mutably borrows as dyn Any.
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 = !

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.