pub struct WidgetFn<D: ?Sized>(/* private fields */);Expand description
Boxed shared closure that generates a widget for a given data.
You can also use the wgt_fn! macro do instantiate.
See presenter for a way to quickly use the widget function in the UI.
Implementations§
Source§impl<D> WidgetFn<D>
impl<D> WidgetFn<D>
Sourcepub fn new(func: impl Fn(D) -> UiNode + Send + Sync + 'static) -> Self
pub fn new(func: impl Fn(D) -> UiNode + Send + Sync + 'static) -> Self
New from a closure that generates a node from data.
Sourcepub const fn nil() -> Self
pub const fn nil() -> Self
Function that always produces the UiNode::nil.
No heap allocation happens to create this WidgetFn.
Sourcepub fn is_nil(&self) -> bool
pub fn is_nil(&self) -> bool
If this is the nil function.
If true the function always generates a node that is UiNode::is_nil, if
false the function may still return a nil node some of the time.
See call_checked for more details.
Sourcepub fn call(&self, data: D) -> UiNode
pub fn call(&self, data: D) -> UiNode
Calls the function with data argument.
Note that you can call the widget function directly where D: 'static:
fn foo(func: &WidgetFn<bool>) {
let a = func.call(true);
let b = func(true);
}In the example above a and b are both calls to the widget function.
Sourcepub fn call_checked(&self, data: D) -> Option<UiNode>
pub fn call_checked(&self, data: D) -> Option<UiNode>
Calls the function with data argument and only returns a node if is not nil.
Returns None if is_nil or UiNode::is_nil.
Sourcepub fn singleton(widget: impl IntoUiNode) -> Self
pub fn singleton(widget: impl IntoUiNode) -> Self
New widget function that returns the same widget for every call.
The widget is wrapped in an ArcNode and every function call returns an ArcNode::take_on_init node.
Note that take_on_init is not always the widget on init as it needs to wait for it to deinit first if
it is already in use, this could have an effect if the widget function caller always expects a full widget.
Sourcepub fn downgrade(&self) -> WeakWidgetFn<D>
pub fn downgrade(&self) -> WeakWidgetFn<D>
Creates a WeakWidgetFn<D> reference to this function.
Trait Implementations§
Auto Trait Implementations§
impl<D> Freeze for WidgetFn<D>where
D: ?Sized,
impl<D> !RefUnwindSafe for WidgetFn<D>
impl<D> Send for WidgetFn<D>where
D: ?Sized,
impl<D> Sync for WidgetFn<D>where
D: ?Sized,
impl<D> Unpin for WidgetFn<D>where
D: ?Sized,
impl<D> !UnwindSafe for WidgetFn<D>
Blanket Implementations§
Source§impl<T> AnyVarValue for T
impl<T> AnyVarValue for T
Source§fn clone_boxed(&self) -> BoxAnyVarValue
fn clone_boxed(&self) -> BoxAnyVarValue
Source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self and other are equal.Source§fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
other if both are of the same type.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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more