Module builder

Module builder 

Source
Expand description

Widget and property builder types.

§Examples

The example declares a new widget type, ShowProperties!, that inherits from Text! and display what properties are set on itself by accessing the WidgetBuilder at two points. First call is directly in the widget_intrinsic that is called after inherited intrinsics, but before the instance properties are set. Second call is in a build action that is called when the widget starts building, after the instance properties are set.

mod widgets {
    use std::fmt::Write as _;
    use zng::prelude_wgt::*;

    #[widget($crate::widgets::ShowProperties)]
    pub struct ShowProperties(zng::text::Text);

    impl ShowProperties {
        fn widget_intrinsic(&mut self) {
            let txt = var(Txt::from(""));
            widget_set! {
                self;
                txt = txt.clone();
            }

            let builder = self.widget_builder();

            let mut t = Txt::from("Properties set by default:\n");
            for p in builder.properties() {
                writeln!(&mut t, "• {}", p.args.property().name).unwrap();
            }

            builder.push_build_action(move |builder| {
                writeln!(&mut t, "\nAll properties set:").unwrap();
                for p in builder.properties() {
                    writeln!(&mut t, "• {}", p.args.property().name).unwrap();
                }
                txt.set(t.clone());
            });
        }
    }
}

widgets::ShowProperties! {
    font_size = 20;
}

§Full API

See zng_app::widget::builder for the full API.

Macros§

property_args
New Box<PropertyArgs> box from a property and value.
property_id
New PropertyId that represents the type and name.
property_info
New PropertyInfo from property path.
property_input_types
Gets the strong input storage types from a property path.
source_location
New SourceLocation that represents the location you call this macro.
widget_type
Gets the WidgetType info of a widget.

Structs§

AnyWhenArcHandlerBuilder
A when builder for AnyArcHandler values.
BuilderProperty
Represents a property removed from WidgetBuilding.
BuilderPropertyMut
Represents a mutable reference to property in WidgetBuilder or WidgetBuilding.
BuilderPropertyRef
Represents a property in WidgetBuilder or WidgetBuilding.
Importance
Value that indicates the override importance of a property instance, higher overrides lower.
NestGroup
Property nest position group.
NestPosition
Represents the sort index of a property or intrinsic node in a widget instance.
PropertyAttribute
Represents a custom build action targeting a property input that is applied after when is build.
PropertyAttributeArgs
Arguments for PropertyAttribute<I> build action.
PropertyAttributeWhen
Data for a property attribute associated with an WhenInfo.
PropertyId
Unique ID of a property implementation.
PropertyInfo
Property info.
PropertyInput
Property input info.
PropertyInputTypes
Represents the strong types of each input of a property.
PropertyNewArgs
Args for PropertyInfo::new closure.
SourceLocation
A location in source-code.
WhenInfo
Represents a when block in a widget.
WhenInput
Input var read in a when condition expression.
WhenInputVar
Represents a WhenInput variable that can be rebound.
WidgetBuilder
Widget instance builder.
WidgetBuilderProperties
Direct property access in WidgetBuilder and WidgetBuilding.
WidgetBuilding
Represents a finalizing WidgetBuilder.
WidgetType
Unique identifier of a widget type.

Enums§

InputKind
Kind of property input.
WhenInputMember
Represents what member and how it was accessed in a WhenInput.

Traits§

PropertyArgs
Represents a property instantiation request.

Type Aliases§

PropertyAttributes
Property attribute build actions that must be applied to property args.
PropertyAttributesWhenData
Data for property build actions associated with when condition assigns.