pub struct WidgetBuilder { /* private fields */ }
Expand description
Widget instance builder.
Implementations§
source§impl WidgetBuilder
impl WidgetBuilder
sourcepub fn new(widget: WidgetType) -> Self
pub fn new(widget: WidgetType) -> Self
New empty default.
sourcepub fn widget_type(&self) -> WidgetType
pub fn widget_type(&self) -> WidgetType
The widget that started this builder.
sourcepub fn push_property(
&mut self,
importance: Importance,
args: Box<dyn PropertyArgs>,
)
pub fn push_property( &mut self, importance: Importance, args: Box<dyn PropertyArgs>, )
Insert/override a property.
You can use the property_args!
macro to collect args for a property.
sourcepub fn push_property_positioned(
&mut self,
importance: Importance,
position: NestPosition,
args: Box<dyn PropertyArgs>,
)
pub fn push_property_positioned( &mut self, importance: Importance, position: NestPosition, args: Box<dyn PropertyArgs>, )
Insert property with custom nest position.
sourcepub fn push_when(&mut self, importance: Importance, when: WhenInfo)
pub fn push_when(&mut self, importance: Importance, when: WhenInfo)
Insert a when
block.
sourcepub fn push_unset(&mut self, importance: Importance, property_id: PropertyId)
pub fn push_unset(&mut self, importance: Importance, property_id: PropertyId)
Insert a name = unset!;
property.
sourcepub fn push_property_build_action(
&mut self,
property_id: PropertyId,
action_name: &'static str,
importance: Importance,
input_actions: Vec<Box<dyn AnyPropertyBuildAction>>,
)
pub fn push_property_build_action( &mut self, property_id: PropertyId, action_name: &'static str, importance: Importance, input_actions: Vec<Box<dyn AnyPropertyBuildAction>>, )
Add or override custom builder actions that are called to finalize the inputs for a property.
The importance
overrides previous build action of the same name and property. The input_actions
vec must
contain one action for each property input.
sourcepub fn push_unset_property_build_action(
&mut self,
property_id: PropertyId,
action_name: &'static str,
importance: Importance,
)
pub fn push_unset_property_build_action( &mut self, property_id: PropertyId, action_name: &'static str, importance: Importance, )
Insert a property build action filter.
sourcepub fn clear_property_build_actions(&mut self)
pub fn clear_property_build_actions(&mut self)
Remove all registered property build actions.
sourcepub fn push_build_action(
&mut self,
action: impl FnMut(&mut WidgetBuilding) + Send + 'static,
)
pub fn push_build_action( &mut self, action: impl FnMut(&mut WidgetBuilding) + Send + 'static, )
Add an action
closure that is called every time this builder or a clone of it builds a widget instance.
sourcepub fn clear_build_actions(&mut self)
pub fn clear_build_actions(&mut self)
Remove all registered build actions.
sourcepub fn is_custom_build(&self) -> bool
pub fn is_custom_build(&self) -> bool
Returns true
if a custom build handler is registered.
sourcepub fn set_custom_build<R: UiNode>(
&mut self,
build: impl FnMut(WidgetBuilder) -> R + Send + 'static,
)
pub fn set_custom_build<R: UiNode>( &mut self, build: impl FnMut(WidgetBuilder) -> R + Send + 'static, )
Set a build
closure to run instead of default_build
when build
is called.
Overrides the previous custom build, if any was set.
sourcepub fn clear_custom_build(&mut self)
pub fn clear_custom_build(&mut self)
Remove the custom build handler, if any was set.
sourcepub fn extend(&mut self, other: WidgetBuilder)
pub fn extend(&mut self, other: WidgetBuilder)
Apply other
over self
.
All properties, unsets, whens, build actions and custom build of other
are inserted in self
,
override importance rules apply, other
items only replace self
items if they have the
same or greater importance.
Note that properties of the same position index from other
are pushed after properties of the
same position in self
, this means that fill properties of other
will render over fill properties
of self
.
sourcepub fn has_properties(&self) -> bool
pub fn has_properties(&self) -> bool
If any property is present in the builder.
sourcepub fn has_unsets(&self) -> bool
pub fn has_unsets(&self) -> bool
If any unset filter is present in the builder.
sourcepub fn split_off(
&mut self,
properties: impl IntoIterator<Item = PropertyId>,
out: &mut WidgetBuilder,
)
pub fn split_off( &mut self, properties: impl IntoIterator<Item = PropertyId>, out: &mut WidgetBuilder, )
Move all properties
to a new builder.
The properties are removed from self
, any when
assign is also moved, properties used in WhenInput
that
affect the properties are cloned or moved into the new builder.
Note that properties can depend on others in the widget contextually, this is not preserved on split-off.
sourcepub fn build(self) -> BoxedUiNode
pub fn build(self) -> BoxedUiNode
Instantiate the widget.
If a custom build is set it is run, unless it is already running, otherwise the default_build
is called.
sourcepub fn default_build(self) -> BoxedUiNode
pub fn default_build(self) -> BoxedUiNode
Instantiate the widget.
Runs all build actions, but ignores custom build.
Methods from Deref<Target = WidgetBuilderProperties>§
sourcepub fn property(
&self,
property_id: PropertyId,
) -> Option<BuilderPropertyRef<'_>>
pub fn property( &self, property_id: PropertyId, ) -> Option<BuilderPropertyRef<'_>>
Reference the property, if it is present.
sourcepub fn property_mut(
&mut self,
property_id: PropertyId,
) -> Option<BuilderPropertyMut<'_>>
pub fn property_mut( &mut self, property_id: PropertyId, ) -> Option<BuilderPropertyMut<'_>>
Modify the property, if it is present.
sourcepub fn properties(&self) -> impl Iterator<Item = BuilderPropertyRef<'_>>
pub fn properties(&self) -> impl Iterator<Item = BuilderPropertyRef<'_>>
Iterate over the current properties.
The properties may not be sorted in the correct order if the builder has never built.
sourcepub fn properties_mut(&mut self) -> impl Iterator<Item = BuilderPropertyMut<'_>>
pub fn properties_mut(&mut self) -> impl Iterator<Item = BuilderPropertyMut<'_>>
iterate over mutable references to the current properties.
sourcepub fn capture_value<T>(&mut self, property_id: PropertyId) -> Option<T>where
T: VarValue,
pub fn capture_value<T>(&mut self, property_id: PropertyId) -> Option<T>where
T: VarValue,
Flags the property as captured and downcast the input value.
Unlike other property kinds you can capture values in the WidgetBuilder
, note that the value may not
the final value, unless you are capturing on build.
Other property kinds can only be captured in WidgetBuilding
as
their values strongly depend on the final when
blocks that are only applied after building starts.
sourcepub fn capture_value_or_else<T>(
&mut self,
property_id: PropertyId,
or_else: impl FnOnce() -> T,
) -> Twhere
T: VarValue,
pub fn capture_value_or_else<T>(
&mut self,
property_id: PropertyId,
or_else: impl FnOnce() -> T,
) -> Twhere
T: VarValue,
Flags the property as captured and downcast the input value, or calls or_else
to generate the value.
sourcepub fn capture_value_or_default<T>(&mut self, property_id: PropertyId) -> T
pub fn capture_value_or_default<T>(&mut self, property_id: PropertyId) -> T
Flags the property as captured and downcast the input value, or returns the default value.
Trait Implementations§
source§impl Clone for WidgetBuilder
impl Clone for WidgetBuilder
source§impl Debug for WidgetBuilder
impl Debug for WidgetBuilder
source§impl Deref for WidgetBuilder
impl Deref for WidgetBuilder
Auto Trait Implementations§
impl Freeze for WidgetBuilder
impl !RefUnwindSafe for WidgetBuilder
impl Send for WidgetBuilder
impl Sync for WidgetBuilder
impl Unpin for WidgetBuilder
impl !UnwindSafe for WidgetBuilder
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
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> 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