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<U: UiNode>(func: impl Fn(D) -> U + Send + Sync + 'static) -> Self
pub fn new<U: UiNode>(func: impl Fn(D) -> U + 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 NilUiNode
.
No heap allocation happens to create this value.
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) -> BoxedUiNode
pub fn call(&self, data: D) -> BoxedUiNode
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<BoxedUiNode>
pub fn call_checked(&self, data: D) -> Option<BoxedUiNode>
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 UiNode) -> Self
pub fn singleton(widget: impl UiNode) -> 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 Twhere
T: VarValue,
impl<T> AnyVarValue for Twhere
T: VarValue,
source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
dyn Any
methods.source§fn clone_boxed(&self) -> Box<dyn AnyVarValue>
fn clone_boxed(&self) -> Box<dyn AnyVarValue>
source§fn clone_boxed_var(&self) -> Box<dyn AnyVar>
fn clone_boxed_var(&self) -> Box<dyn AnyVar>
LocalVar<Self>
.source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self
equals other
.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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§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