pub struct ClickAction<A> { /* private fields */ }Expand description
Executable UI-thread callback for one click-like activation.
§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::{ClickAction, EventCtx};
let runtime = RuntimeHandle::<u8>::new();
let mut ctx = EventCtx::new(runtime.clone(), ElementId(1));
ClickAction::handler(|ctx| ctx.dispatch(7)).run(&mut ctx);
assert_eq!(runtime.take_actions(), vec![7]);Implementations§
Source§impl<A> ClickAction<A>
Provides the operations defined for ClickAction<A>.
impl<A> ClickAction<A>
Provides the operations defined for ClickAction<A>.
Sourcepub fn handler(handler: impl Fn(&mut EventCtx<A>) + 'static) -> Self
pub fn handler(handler: impl Fn(&mut EventCtx<A>) + 'static) -> Self
Wraps a UI-thread event-context callback.
The callback is retained by Rc; captured resources live until every
action clone/internal reference is dropped. Callback panics propagate.
§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::{ClickAction, EventCtx};
let runtime = RuntimeHandle::<&'static str>::new();
let mut ctx = EventCtx::new(runtime.clone(), ElementId(1));
let action = ClickAction::handler(|ctx| ctx.dispatch("open"));
action.run(&mut ctx);
assert_eq!(runtime.take_actions(), vec!["open"]);Sourcepub fn run(&self, ctx: &mut EventCtx<A>)
pub fn run(&self, ctx: &mut EventCtx<A>)
Runs the stored callback synchronously with ctx.
§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::input::{ClickAction, EventCtx};
let runtime = RuntimeHandle::<i32>::new();
let mut ctx = EventCtx::new(runtime.clone(), ElementId(9));
ClickAction::handler(|ctx| ctx.dispatch(3)).run(&mut ctx);
assert_eq!(runtime.take_actions(), vec![3]);Trait Implementations§
Source§impl<A> IntoClickAction<A> for ClickAction<A>
Implements the IntoClickAction<A> contract for ClickAction<A>.
impl<A> IntoClickAction<A> for ClickAction<A>
Implements the IntoClickAction<A> contract for ClickAction<A>.
Source§fn into_click_action(self) -> ClickAction<A>
fn into_click_action(self) -> ClickAction<A>
Implements the into_click_action helper used by this module.
Auto Trait Implementations§
impl<A> Freeze for ClickAction<A>
impl<A> !RefUnwindSafe for ClickAction<A>
impl<A> !Send for ClickAction<A>
impl<A> !Sync for ClickAction<A>
impl<A> Unpin for ClickAction<A>
impl<A> !UnwindSafe for ClickAction<A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more