Struct ClickAction

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

Source

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"]);
Source

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

Source§

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