pub struct WidgetFn<D>(/* private fields */)
where
D: ?Sized;
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>(func: impl Fn(D) -> U + Send + Sync + 'static) -> WidgetFn<D>where
U: UiNode,
pub fn new<U>(func: impl Fn(D) -> U + Send + Sync + 'static) -> WidgetFn<D>where
U: UiNode,
New from a closure that generates a node from data.
sourcepub const fn nil() -> WidgetFn<D>
pub const fn nil() -> WidgetFn<D>
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) -> Box<dyn UiNodeBoxed>
pub fn call(&self, data: D) -> Box<dyn UiNodeBoxed>
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<Box<dyn UiNodeBoxed>>
pub fn call_checked(&self, data: D) -> Option<Box<dyn UiNodeBoxed>>
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) -> WidgetFn<D>
pub fn singleton(widget: impl UiNode) -> WidgetFn<D>
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§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> FsChangeNote for T
impl<T> FsChangeNote for T
§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§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.