Skip to main content

ConfigCx

Struct ConfigCx 

Source
pub struct ConfigCx<'a> { /* private fields */ }
Expand description

Widget configuration and update context

This type supports access to EventState via Deref / DerefMut and to SizeCx via Self::size_cx.

Implementations§

Source§

impl<'a> ConfigCx<'a>

Source

pub fn register_nav_fallback(&mut self, id: Id)

Sets the fallback recipient of Event::Command

Where a key-press translates to a Command, this is first sent to widgets with applicable key, selection and/or navigation focus as an Event::Command. If this event goes unhandled and a fallback recipient is set using this method, then this fallback recipient will be sent the same event.

There may be one fallback recipient per window; do not use an Id from another window. If this method is called multiple times, the last such call succeeds.

Source§

impl<'a> ConfigCx<'a>

Source

pub fn size_cx<'b>(&'b mut self) -> SizeCx<'b>
where 'a: 'b,

Access a SizeCx

Source

pub fn configure(&mut self, widget: Node<'_>, id: Id)

Configure a widget

All widgets must be configured after construction; see widget lifecycle and configuration. Widgets must always be sized after configuration.

Assigns id to the widget. This must be valid and is usually constructed with Events::make_child_id.

Source

pub fn update(&mut self, widget: Node<'_>)

Update a widget

All widgets must be updated after input data changes; see update.

Source

pub fn set_disabled(&mut self, target: Id, disable: bool)

Set/unset a widget as disabled

Disabled status applies to all descendants and blocks reception of events (Unused is returned automatically when the recipient or any ancestor is disabled).

Disabling a widget clears navigation, selection and key focus when the target is disabled, and also cancels press/pan grabs.

Source

pub fn set_send_target_for<M: Debug + 'static>(&mut self, id: Id)

Set a target for messages of a specific type when sent to Id::default()

Messages of this type sent to Id::default() from any window will be sent to id.

Source

pub fn redraw(&mut self)

Notify that a widget must be redrawn

“The current widget” is inferred from the widget tree traversal through which the EventCx is made accessible. The resize is handled locally during the traversal unwind if possible.

Source

pub fn resize(&mut self)

Require that the current widget (and its descendants) be resized

“The current widget” is inferred from the widget tree traversal through which the EventCx is made accessible. The resize is handled locally during the traversal unwind if possible.

Methods from Deref<Target = EventState>§

Source

pub fn has_input_focus(&self, w_id: &Id) -> Option<bool>

Get whether this widget has input focus

Return values:

  • None if the widget does not have selection focus
  • Some(false) if the widget has selection focus but not keyboard or IME focus
  • Some(true) if the widget has keyboard and/or IME focus
Source

pub fn modifiers(&self) -> ModifiersState

Get the current modifier state

Source

pub fn set_ime_cursor_area(&mut self, target: &Id, rect: Rect)

Set IME cursor area

This should be called after receiving Event::Ime(Ime::Enabled), and any time that the rect parameter changes, until Event::Ime(Ime::Disabled) is received.

This sets the text cursor’s area, rect, relative to the widget’s own coordinate space. If never called, then the widget’s whole rect is used.

This does nothing if target does not have IME-enabled input focus.

Source

pub fn cancel_ime_focus(&mut self, target: &Id)

Explicitly clear Input Method Editor focus on target

This method may be used to disable IME focus while retaining selection focus. IME focus is lost automatically when selection focus is lost.

Source

pub fn has_nav_focus(&self, w_id: &Id) -> bool

Get whether this widget has navigation focus

Source

pub fn nav_focus(&self) -> Option<&Id>

Get the current navigation focus, if any

This is the widget selected by navigating the UI with the Tab key.

Note: changing navigation focus (e.g. via EventCx::clear_nav_focus, EventCx::request_nav_focus or EventCx::next_nav_focus) does not immediately affect the result of this method.

Source

pub fn is_depressed(&self, w_id: &Id) -> bool

Check whether the given widget is visually depressed

Source

pub fn is_under_mouse(&self, w_id: &Id) -> bool

Get whether the widget is under the mouse pointer

Source

pub fn any_grab_on(&self, id: &Id) -> bool

Returns true if there is a mouse or touch grab on id or any descendant of id

Source

pub fn press_velocity(&self, source: PressSource) -> Option<Vec2>

Get velocity of the mouse pointer or a touch

The velocity is calculated at the time this method is called using existing samples of motion.

Where the source is a mouse this always succeeds. For touch events this requires an active grab and is not guaranteed to succeed; currently only a limited number of presses with mode GrabMode::Grab are tracked for velocity.

Source

pub fn send<M: Debug + 'static>(&mut self, id: Id, msg: M)

Send a message to id

When calling this method, be aware that some widgets use an inner component to handle events, thus calling with the outer widget’s id may not have the desired effect. Tile::try_probe and EventCx::next_nav_focus are usually able to find the appropriate event-handling target.

This uses a tree traversal as with event handling, thus ancestors will have a chance to handle an unhandled event and any messages on the stack after their child.

§Special cases sent as an Event

When M is Command, this will send Event::Command to the widget.

When M is ScrollDelta, this will send Event::Scroll to the widget.

§Other messages

The message is pushed to the message stack. The target widget may pop or peek the message from Events::handle_messages.

§Send target

The target id may be under another window. In this case, sending may be delayed slightly.

If id = Id::default() and a send target has been assigned for M, then msg will be sent to that target.

If id identifies a widget, that widget must be configured but does not need to be sized.

If id does not resolve a widget, the message is dropped with only a DEBUG log message of the form _replay: $WIDGET cannot find path to $ID. This is not considered an error since it happens frequently (e.g. any widget using asynchronous loading sends itself a message; if the view changes before loading completes then that widget may no longer be accessible or no longer exist).

§Ordering and failure

Messages sent via send and send_erased should be received in the same order sent relative to other messages sent from the same window via these methods.

Message delivery may fail for widgets not currently visible. This is dependent on widgets implementation of Widget::child_node (e.g. in the case of virtual scrolling, the target may have scrolled out of range).

Source

pub fn send_erased(&mut self, id: Id, msg: Erased)

Push a type-erased message to the stack

This is a lower-level variant of Self::send.

Source

pub fn send_async<Fut, M>(&mut self, id: Id, fut: Fut)
where Fut: IntoFuture<Output = M> + 'static, M: Debug + 'static,

Send a message to id via a Future

The future is polled after event handling and after drawing and is able to wake the event loop. This future is executed on the main thread; for high-CPU tasks use Self::send_spawn instead.

The future must resolve to a message on completion. Its message is then sent to id via stack traversal identically to Self::send.

§Cancellation, ordering and failure

Futures passed to these methods should only be cancelled if they fail to complete before the window is closed, and even in this case will be polled at least once.

Messages sent via send_async, send_async_erased and send_spawn may be received in any order.

Message delivery may fail for widgets not currently visible. This is dependent on widgets implementation of Widget::child_node (e.g. in the case of virtual scrolling, the target may have scrolled out of range).

Source

pub fn send_async_erased<Fut>(&mut self, id: Id, fut: Fut)
where Fut: IntoFuture<Output = Erased> + 'static,

Send a type-erased message to id via a Future

This is a low-level variant of Self::send_async.

Source

pub fn send_spawn<Fut, M>(&mut self, id: Id, fut: Fut)
where Fut: IntoFuture<Output = M> + 'static, Fut::IntoFuture: Send, M: Debug + Send + 'static,

Available on crate feature spawn only.

Spawn a task, run on a thread pool

The future is spawned to a thread-pool before the event-handling loop sleeps, and is able to wake the loop on completion. Tasks involving significant CPU work should use this method over Self::send_async.

This method is simply a wrapper around async_global_executor::spawn and Self::send_async; if a different multi-threaded executor is available, that may be used instead. See also async_global_executor documentation of configuration.

Source

pub fn request_timer(&mut self, id: Id, handle: TimerHandle, delay: Duration)

Schedule a timed update

Widget updates may be used for delayed action. For animation, prefer to use Draw::animate or Self::request_frame_timer.

Widget id will receive Event::Timer with this handle at approximately time = now + delay (or possibly a little later due to frame-rate limiters and processing time).

Requesting an update with delay == 0 is valid, except from an Event::Timer handler (where it may cause an infinite loop).

Multiple timer requests with the same id and handle are merged (see TimerHandle documentation).

Source

pub fn request_frame_timer(&mut self, id: Id, handle: TimerHandle)

Schedule a frame timer update

Widget id will receive Event::Timer with this handle either before or soon after the next frame is drawn.

This may be useful for animations which mutate widget state. Animations which don’t mutate widget state may use Draw::animate instead.

It is expected that handle.earliest() == true (style guide).

Source

pub fn platform(&self) -> Platform

Get the platform

Source

pub fn window_has_focus(&self) -> bool

True when the window has focus

Source

pub fn is_disabled(&self, w_id: &Id) -> bool

Check whether a widget is disabled

A widget is disabled if any ancestor is.

Source

pub fn config(&self) -> &WindowConfig

Access configuration data

All widgets will be reconfigured if configuration data changes.

Source

pub fn config_enable_pan(&self, source: PressSource) -> bool

Is mouse panning enabled?

Source

pub fn config_enable_mouse_text_pan(&self) -> bool

Is mouse text panning enabled?

Source

pub fn config_test_pan_thresh(&self, dist: Offset) -> bool

Test pan threshold against config, adjusted for scale factor

Returns true when dist is large enough to switch to pan mode.

Source

pub fn redraw(&mut self, id: impl HasId)

Notify that a widget must be redrawn

This method is designed to support partial redraws though these are not currently implemented. See also Self::action_redraw.

Source

pub fn region_moved(&mut self)

Notify that widgets under self may have moved

This updates the widget(s) under mouse and touch events.

Source

pub fn close_own_window(&mut self)

Request that the window be closed

Source

pub fn action_moved(&mut self, action: impl Into<Option<ActionMoved>>)

Notify of an ActionMoved or Option<ActionMoved>

Source

pub fn action_redraw(&mut self, action: impl Into<Option<ActionRedraw>>)

Notify of an ActionRedraw or Option<ActionRedraw>

This will force a redraw of the whole window. See also Self::redraw.

Trait Implementations§

Source§

impl<'a> Deref for ConfigCx<'a>

Source§

type Target = EventState

The resulting type after dereferencing.
Source§

fn deref(&self) -> &EventState

Dereferences the value.
Source§

impl<'a> DerefMut for ConfigCx<'a>

Source§

fn deref_mut(&mut self) -> &mut EventState

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'a> Freeze for ConfigCx<'a>

§

impl<'a> !RefUnwindSafe for ConfigCx<'a>

§

impl<'a> !Send for ConfigCx<'a>

§

impl<'a> !Sync for ConfigCx<'a>

§

impl<'a> Unpin for ConfigCx<'a>

§

impl<'a> !UnwindSafe for ConfigCx<'a>

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<S, T> Cast<T> for S
where T: Conv<S>,

Source§

fn cast(self) -> T

Cast from Self to T Read more
Source§

fn try_cast(self) -> Result<T, Error>

Try converting from Self to T Read more
Source§

impl<S, T> CastApprox<T> for S
where T: ConvApprox<S>,

Source§

fn try_cast_approx(self) -> Result<T, Error>

Try approximate conversion from Self to T Read more
Source§

fn cast_approx(self) -> T

Cast approximately from Self to T Read more
Source§

impl<S, T> CastFloat<T> for S
where T: ConvFloat<S>,

Source§

fn cast_trunc(self) -> T

Cast to integer, truncating Read more
Source§

fn cast_nearest(self) -> T

Cast to the nearest integer Read more
Source§

fn cast_floor(self) -> T

Cast the floor to an integer Read more
Source§

fn cast_ceil(self) -> T

Cast the ceiling to an integer Read more
Source§

fn try_cast_trunc(self) -> Result<T, Error>

Try converting to integer with truncation Read more
Source§

fn try_cast_nearest(self) -> Result<T, Error>

Try converting to the nearest integer Read more
Source§

fn try_cast_floor(self) -> Result<T, Error>

Try converting the floor to an integer Read more
Source§

fn try_cast_ceil(self) -> Result<T, Error>

Try convert the ceiling to an integer Read more
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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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