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>.
impl<A> EventContext<A>
Provides the operations defined for EventContext<A>.
Sourcepub fn new(runtime: RuntimeHandle<A>, target: ElementId) -> Self
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());Sourcepub fn target(&self) -> ElementId
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));Sourcepub fn event_meta(&self) -> Option<&EventMeta>
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());Sourcepub fn dispatch(&mut self, action: A)
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]);Sourcepub fn runtime(&self) -> RuntimeHandle<A>
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());Sourcepub fn request_close(&self)
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());Sourcepub fn request_minimize_window(
&self,
logical_window_id: impl Into<LogicalWindowId>,
)
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);Sourcepub fn request_toggle_maximize_window(
&self,
logical_window_id: impl Into<LogicalWindowId>,
)
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);Sourcepub fn stop_propagation(&mut self)
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());Sourcepub fn is_propagation_stopped(&self) -> bool
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());Sourcepub fn request_repaint(&mut self)
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)]);Sourcepub fn request_repaint_after(&mut self, delay: Duration)
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());Sourcepub fn invalidate(&mut self, invalidation: Invalidation)
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());Sourcepub fn request_layout(&mut self)
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());Sourcepub fn request_build(&mut self)
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());Sourcepub fn request_layout_after(&mut self, delay: Duration)
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());Sourcepub fn request_build_after(&mut self, delay: Duration)
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());Sourcepub fn request_focus_key(&self, key: impl Into<String>)
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"));Sourcepub fn read_clipboard_text(&self) -> Option<String>
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(""));Sourcepub fn write_clipboard_text(&self, text: &str) -> Result<(), String>
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"));Sourcepub fn open_external_url(&self, url: &ExternalUrl) -> Result<(), OpenUrlError>
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());