Struct zng_app::widget::builder::WidgetBuilder

source ·
pub struct WidgetBuilder { /* private fields */ }
Expand description

Widget instance builder.

Implementations§

source§

impl WidgetBuilder

source

pub fn new(widget: WidgetType) -> Self

New empty default.

source

pub fn widget_type(&self) -> WidgetType

The widget that started this builder.

source

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.

source

pub fn push_property_positioned( &mut self, importance: Importance, position: NestPosition, args: Box<dyn PropertyArgs>, )

Insert property with custom nest position.

source

pub fn push_when(&mut self, importance: Importance, when: WhenInfo)

Insert a when block.

source

pub fn push_unset(&mut self, importance: Importance, property_id: PropertyId)

Insert a name = unset!; property.

source

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.

source

pub fn push_unset_property_build_action( &mut self, property_id: PropertyId, action_name: &'static str, importance: Importance, )

Insert a property build action filter.

source

pub fn clear_property_build_actions(&mut self)

Remove all registered property build actions.

source

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.

source

pub fn clear_build_actions(&mut self)

Remove all registered build actions.

source

pub fn is_custom_build(&self) -> bool

Returns true if a custom build handler is registered.

source

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.

source

pub fn clear_custom_build(&mut self)

Remove the custom build handler, if any was set.

source

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.

source

pub fn has_properties(&self) -> bool

If any property is present in the builder.

source

pub fn has_unsets(&self) -> bool

If any unset filter is present in the builder.

source

pub fn has_whens(&self) -> bool

If any when block is present in the builder.

source

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.

source

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.

source

pub fn default_build(self) -> BoxedUiNode

Instantiate the widget.

Runs all build actions, but ignores custom build.

Methods from Deref<Target = WidgetBuilderProperties>§

source

pub fn property( &self, property_id: PropertyId, ) -> Option<BuilderPropertyRef<'_>>

Reference the property, if it is present.

source

pub fn property_mut( &mut self, property_id: PropertyId, ) -> Option<BuilderPropertyMut<'_>>

Modify the property, if it is present.

source

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.

source

pub fn properties_mut(&mut self) -> impl Iterator<Item = BuilderPropertyMut<'_>>

iterate over mutable references to the current properties.

source

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.

source

pub fn capture_value_or_else<T>( &mut self, property_id: PropertyId, or_else: impl FnOnce() -> T, ) -> T
where T: VarValue,

Flags the property as captured and downcast the input value, or calls or_else to generate the value.

source

pub fn capture_value_or_default<T>(&mut self, property_id: PropertyId) -> T
where T: VarValue + Default,

Flags the property as captured and downcast the input value, or returns the default value.

Trait Implementations§

source§

impl Clone for WidgetBuilder

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for WidgetBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for WidgetBuilder

source§

type Target = WidgetBuilderProperties

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for WidgetBuilder

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> StateValue for T
where T: Any + Send + Sync,