Struct EventContext

Source
pub struct EventContext<A> { /* private fields */ }
Expand description

Mutable capabilities exposed while routing one event to one element.

The context clones a single-threaded RuntimeHandle, stores the strict target ID, and starts with propagation enabled. Directly constructed contexts have no host event metadata.

§Examples

use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventContext;
let ctx = EventContext::<()>::new(RuntimeHandle::new(), ElementId(4));
assert_eq!(ctx.target(), ElementId(4));
assert!(ctx.event_meta().is_none());

Implementations§

Source§

impl<A> EventContext<A>

Provides the operations defined for EventContext<A>.

Source

pub fn new(runtime: RuntimeHandle<A>, target: ElementId) -> Self

Creates a metadata-free context for target.

This is primarily useful for direct/legacy dispatch and tests; host event routing uses an internal constructor that attaches EventMeta.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let ctx = EventCtx::<u8>::new(RuntimeHandle::new(), ElementId(2));
assert!(!ctx.is_propagation_stopped());
Source

pub fn target(&self) -> ElementId

Returns the strict element that originally received the event.

This remains unchanged while the same context bubbles to ancestors.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let ctx = EventCtx::<()>::new(RuntimeHandle::new(), ElementId(8));
assert_eq!(ctx.target(), ElementId(8));
Source

pub fn event_meta(&self) -> Option<&EventMeta>

Metadata for the currently routed event. Legacy direct dispatches do not have host metadata and return None.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
assert!(EventCtx::<()>::new(RuntimeHandle::new(), ElementId(1)).event_meta().is_none());
Source

pub fn dispatch(&mut self, action: A)

Queues one application action on the shared runtime handle.

Actions are retained in FIFO order until the host drains them.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<u8>::new();
let mut ctx = EventCtx::new(runtime.clone(), ElementId(1));
ctx.dispatch(9);
assert_eq!(runtime.take_actions(), vec![9]);
Source

pub fn runtime(&self) -> RuntimeHandle<A>

Clones the shared runtime handle for longer-lived UI operations.

The clone shares queues and state but retains this tree namespace.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let ctx = EventCtx::<()>::new(RuntimeHandle::new(), ElementId(1));
assert_eq!(ctx.runtime().element_tree_id(), ctx.runtime().element_tree_id());
Source

pub fn request_close(&self)

Requests application close; repeated requests coalesce to one flag.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<()>::new();
EventCtx::new(runtime.clone(), ElementId(1)).request_close();
assert!(runtime.take_close_requested());
Source

pub fn request_minimize_window( &self, logical_window_id: impl Into<LogicalWindowId>, )

Queues a minimize operation for a logical window ID.

Requests preserve FIFO order and are not deduplicated.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::{RuntimeHandle, WindowChromeOp};
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<()>::new();
EventCtx::new(runtime.clone(), ElementId(1)).request_minimize_window("main");
assert_eq!(runtime.take_window_chrome_ops()[0].1, WindowChromeOp::Minimize);
Source

pub fn request_toggle_maximize_window( &self, logical_window_id: impl Into<LogicalWindowId>, )

Queues a maximize/restore toggle for a logical window ID.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::{RuntimeHandle, WindowChromeOp};
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<()>::new();
EventCtx::new(runtime.clone(), ElementId(1)).request_toggle_maximize_window("main");
assert_eq!(runtime.take_window_chrome_ops()[0].1, WindowChromeOp::ToggleMaximize);
Source

pub fn stop_propagation(&mut self)

Stops bubbling after the current widget callback returns.

Calling this repeatedly is idempotent and does not undo work already performed by the target callback.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let mut ctx = EventCtx::<()>::new(RuntimeHandle::new(), ElementId(1));
ctx.stop_propagation();
assert!(ctx.is_propagation_stopped());
Source

pub fn is_propagation_stopped(&self) -> bool

Returns whether an event handler requested that bubbling stop.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let ctx = EventCtx::<()>::new(RuntimeHandle::new(), ElementId(1));
assert!(!ctx.is_propagation_stopped());
Source

pub fn request_repaint(&mut self)

Marks the target for paint work with event provenance.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<()>::new();
EventCtx::new(runtime.clone(), ElementId(3)).request_repaint();
assert_eq!(runtime.take_dirty_elements(), vec![ElementId(3)]);
Source

pub fn request_repaint_after(&mut self, delay: Duration)

Schedules target paint invalidation no earlier than delay from now.

Equal target/kind timers are deduplicated by the runtime’s earliest due instant. Duration-to-instant overflow behavior is delegated to it.

§Examples
use std::time::Duration;
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<()>::new();
EventCtx::new(runtime.clone(), ElementId(1)).request_repaint_after(Duration::from_millis(5));
assert!(runtime.next_scheduled_repaint_due().is_some());
Source

pub fn invalidate(&mut self, invalidation: Invalidation)

Marks the target with an explicit invalidation and event provenance.

Repeated requests coalesce to the strongest level: build, layout, then paint. Diagnostics retain whether a request was coalesced.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::{Invalidation, RuntimeHandle};
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<()>::new();
EventCtx::new(runtime.clone(), ElementId(2)).invalidate(Invalidation::Layout);
assert!(runtime.frame_work_plan().needs_layout());
Source

pub fn request_layout(&mut self)

Marks the target for layout and paint work with event provenance.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<()>::new();
EventCtx::new(runtime.clone(), ElementId(2)).request_layout();
assert!(runtime.frame_work_plan().needs_layout());
Source

pub fn request_build(&mut self)

Marks the target for build, layout, and paint work with event provenance.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<()>::new();
EventCtx::new(runtime.clone(), ElementId(2)).request_build();
assert!(runtime.frame_work_plan().needs_build());
Source

pub fn request_layout_after(&mut self, delay: Duration)

Schedules target layout invalidation after delay.

§Examples
use std::time::Duration;
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<()>::new();
EventCtx::new(runtime.clone(), ElementId(1)).request_layout_after(Duration::from_millis(1));
assert!(runtime.next_scheduled_repaint_due().is_some());
Source

pub fn request_build_after(&mut self, delay: Duration)

Schedules target build invalidation after delay.

§Examples
use std::time::Duration;
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<()>::new();
EventCtx::new(runtime.clone(), ElementId(1)).request_build_after(Duration::from_millis(1));
assert!(runtime.next_scheduled_repaint_due().is_some());
Source

pub fn request_focus_key(&self, key: impl Into<String>)

Replaces the pending declarative focus-key request for this tree.

The latest request wins; an empty string is stored as a real key rather than interpreted as None.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<()>::new();
EventCtx::new(runtime.clone(), ElementId(1)).request_focus_key("search");
assert_eq!(runtime.take_focus_key_request().as_deref(), Some("search"));
Source

pub fn read_clipboard_text(&self) -> Option<String>

Reads text from the configured clipboard provider.

None means no text is available; provider-specific failures are also represented as None by this interface. The built-in memory provider starts with an available empty string, so it returns Some("").

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let ctx = EventCtx::<()>::new(RuntimeHandle::new(), ElementId(1));
assert_eq!(ctx.read_clipboard_text().as_deref(), Some(""));
Source

pub fn write_clipboard_text(&self, text: &str) -> Result<(), String>

Writes text through the configured clipboard provider.

Provider errors are returned as strings. The built-in memory provider accepts empty and arbitrary UTF-8 strings.

§Errors

Returns the configured clipboard provider’s display string when it rejects or cannot complete the write.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::EventCtx;
let runtime = RuntimeHandle::<()>::new();
let ctx = EventCtx::new(runtime, ElementId(1));
ctx.write_clipboard_text("copied").unwrap();
assert_eq!(ctx.read_clipboard_text().as_deref(), Some("copied"));
Source

pub fn open_external_url(&self, url: &ExternalUrl) -> Result<(), OpenUrlError>

Opens an already validated HTTP(S) URL through the configured provider.

Provider failure is returned and also recorded by the runtime handle as a non-fatal error. No parsing, shell escaping, or scheme validation is performed here; construct URLs with ExternalUrl::parse.

§Errors

Returns OpenUrlError::Unavailable when no opener is available or OpenUrlError::LaunchFailed when the configured opener rejects the request. The runtime also records the same non-fatal error.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::{ExternalUrl, RuntimeHandle};
use ailloli_ui_runtime::input::EventCtx;
let ctx = EventCtx::<()>::new(RuntimeHandle::new(), ElementId(1));
let url = ExternalUrl::parse("https://example.com/docs").unwrap();
assert!(ctx.open_external_url(&url).is_ok());

Auto Trait Implementations§

§

impl<A> Freeze for EventContext<A>

§

impl<A> !RefUnwindSafe for EventContext<A>

§

impl<A> !Send for EventContext<A>

§

impl<A> !Sync for EventContext<A>

§

impl<A> Unpin for EventContext<A>

§

impl<A> !UnwindSafe for EventContext<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<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> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> ErasedDestructor for T
where T: 'static,