Struct zng::widget::builder::WidgetBuilder

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

Widget instance builder.

Implementations§

source§

impl WidgetBuilder

source

pub fn new(widget: WidgetType) -> WidgetBuilder

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>( &mut self, build: impl FnMut(WidgetBuilder) -> R + Send + 'static, )
where R: UiNode,

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) -> Box<dyn UiNodeBoxed>

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) -> Box<dyn UiNodeBoxed>

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) -> WidgetBuilder

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<(), Error>

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) -> &<WidgetBuilder as Deref>::Target

Dereferences the value.
source§

impl DerefMut for WidgetBuilder

source§

fn deref_mut(&mut self) -> &mut <WidgetBuilder as Deref>::Target

Mutably dereferences the value.
source§

impl From<StyleBuilder> for WidgetBuilder

source§

fn from(t: StyleBuilder) -> WidgetBuilder

Converts to this type from the input type.
source§

impl From<WidgetBuilder> for StyleBuilder

source§

fn from(p: WidgetBuilder) -> StyleBuilder

Converts to this type from the input type.

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn as_any(&self) -> &(dyn Any + 'static)

Access any.
§

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> Instrument for T

source§

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

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

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> Same for T

source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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> WithSubscriber for T

source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T

source§

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