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: RectAbsolute bounds of this widget, in surface pixels.
theme: &'a ThemeThe active theme.
text: &'a mut TextEngineFonts 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: VisualStateHover, press, focus and enabled state.
now_ms: u64Milliseconds from an arbitrary epoch.
Implementations§
Source§impl<'a, M> EventCtx<'a, M>
impl<'a, M> EventCtx<'a, M>
Sourcepub fn emit(&mut self, message: M)
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.
Sourcepub fn invalidate(&mut self)
pub fn invalidate(&mut self)
Marks this widget’s rectangle for repaint.
Rarely needed: returning Handled::Yes already does it.
Sourcepub fn request_focus(&mut self)
pub fn request_focus(&mut self)
Asks the tree to move keyboard focus here.
Sourcepub fn request_animation(&mut self)
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.
Sourcepub fn reveal(&mut self, rect: Rect)
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.
Sourcepub fn resize_height(&mut self, height: i32, duration_ms: u64)
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.
Sourcepub fn scrolled(&mut self, within: Rect, by: Point)
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.