zng/
widget.rs

1//! Widget info, builder and base, UI node and list.
2//!
3//! The [`Wgt!`](struct@Wgt) widget is a blank widget that entirely shaped by properties.
4//!
5//! ```
6//! use zng::prelude::*;
7//! # fn example() {
8//!
9//! # let _ =
10//! Wgt! {
11//!     id = "sun";
12//!
13//!     widget::background_gradient = {
14//!         axis: 0.deg(),
15//!         stops: color::gradient::stops![hex!(#ff5226), hex!(#ffc926)],
16//!     };
17//!     layout::size = 100;
18//!     widget::corner_radius = 100;
19//!     layout::align = layout::Align::BOTTOM;
20//!
21//!     #[easing(2.secs())]
22//!     layout::y = 100;
23//!     when *#widget::is_inited {
24//!         layout::y = -30;
25//!     }
26//! }
27//! # ; }
28//! ```
29//!
30//! To learn more about the widget macros syntax see [`widget_set!`].
31//!
32//! To learn more about how widgets are declared see [`widget`].
33//!
34//! To learn more about how properties are declared see [`property`].
35//!
36//! # Full API
37//!
38//! See [`zng_app::widget`], [`zng_wgt`], [`zng_wgt_fill`], [`zng_wgt_image::border`], [`zng_wgt_image::fill`] for the full API.
39
40pub use zng_app::widget::base::{HitTestMode, NonWidgetBase, PARALLEL_VAR, Parallel, WidgetBase, WidgetExt, WidgetImpl};
41
42pub use zng_app::widget::{WIDGET, WidgetId, WidgetUpdateMode, widget_impl, widget_set};
43
44pub use zng_app::widget::border::{
45    BORDER, BorderSide, BorderSides, BorderStyle, CornerRadius, CornerRadiusFit, LineOrientation, LineStyle,
46};
47pub use zng_app::widget::info::Visibility;
48pub use zng_app::widget::node::ZIndex;
49
50pub use zng_app::render::RepeatMode;
51
52pub use zng_wgt::{
53    EDITORS, EditorRequestArgs, IS_MOBILE_VAR, OnNodeOpArgs, WeakWidgetFn, Wgt, WidgetFn, auto_hide, border, border_align, border_over,
54    clip_to_bounds, corner_radius, corner_radius_fit, enabled, hit_test_mode, inline, interactive, is_collapsed, is_disabled, is_enabled,
55    is_hidden, is_hit_testable, is_inited, is_mobile, is_visible, modal, modal_included, modal_includes, on_block, on_blocked_changed,
56    on_collapse, on_deinit, on_disable, on_enable, on_enabled_changed, on_hide, on_info_init, on_init, on_interactivity_changed, on_move,
57    on_node_op, on_pre_block, on_pre_blocked_changed, on_pre_collapse, on_pre_deinit, on_pre_disable, on_pre_enable,
58    on_pre_enabled_changed, on_pre_hide, on_pre_init, on_pre_interactivity_changed, on_pre_move, on_pre_node_op, on_pre_show,
59    on_pre_transform_changed, on_pre_unblock, on_pre_update, on_pre_vis_disable, on_pre_vis_enable, on_pre_vis_enabled_changed,
60    on_pre_visibility_changed, on_show, on_transform_changed, on_unblock, on_update, on_vis_disable, on_vis_enable, on_vis_enabled_changed,
61    on_visibility_changed, parallel, visibility, wgt_fn, z_index,
62};
63
64#[cfg(feature = "image")]
65pub use zng_wgt_image::{
66    border::{BorderRepeats, border_img, border_img_fill, border_img_repeat},
67    fill::{
68        background_img, background_img_align, background_img_crop, background_img_fit, background_img_offset, background_img_opacity,
69        background_img_repeat, background_img_repeat_spacing, foreground_img, foreground_img_align, foreground_img_crop,
70        foreground_img_fit, foreground_img_offset, foreground_img_opacity, foreground_img_repeat, foreground_img_repeat_spacing,
71    },
72};
73
74pub use zng_wgt_fill::{
75    background, background_color, background_conic, background_fn, background_gradient, background_radial, foreground, foreground_color,
76    foreground_conic, foreground_fn, foreground_gradient, foreground_highlight, foreground_radial,
77};
78
79/// Widget and property builder types.
80///
81/// # Examples
82///
83/// The example declares a new widget type, `ShowProperties!`, that inherits from `Text!` and display what properties
84/// are set on itself by accessing the [`WidgetBuilder`] at two points. First call is directly in the `widget_intrinsic` that
85/// is called after inherited intrinsics, but before the instance properties are set. Second call is in a build action that is called when
86/// the widget starts building, after the instance properties are set.
87///
88/// [`WidgetBuilder`]: builder::WidgetBuilder
89///
90/// ```
91/// mod widgets {
92///     use std::fmt::Write as _;
93///     use zng::prelude_wgt::*;
94///
95///     #[widget($crate::widgets::ShowProperties)]
96///     pub struct ShowProperties(zng::text::Text);
97///
98///     impl ShowProperties {
99///         fn widget_intrinsic(&mut self) {
100///             let txt = var(Txt::from(""));
101///             widget_set! {
102///                 self;
103///                 txt = txt.clone();
104///             }
105///
106///             let builder = self.widget_builder();
107///
108///             let mut t = Txt::from("Properties set by default:\n");
109///             for p in builder.properties() {
110///                 writeln!(&mut t, "• {}", p.args.property().name).unwrap();
111///             }
112///
113///             builder.push_build_action(move |builder| {
114///                 writeln!(&mut t, "\nAll properties set:").unwrap();
115///                 for p in builder.properties() {
116///                     writeln!(&mut t, "• {}", p.args.property().name).unwrap();
117///                 }
118///                 txt.set(t.clone());
119///             });
120///         }
121///     }
122/// }
123///
124/// # fn main() {
125/// # let _scope = zng::APP.defaults();
126/// # let _ =
127/// widgets::ShowProperties! {
128///     font_size = 20;
129/// }
130/// # ;
131/// # }
132/// ```
133///
134/// # Full API
135///
136/// See [`zng_app::widget::builder`] for the full API.
137pub mod builder {
138    pub use zng_app::widget::builder::{
139        AnyWhenArcHandlerBuilder, BuilderProperty, BuilderPropertyMut, BuilderPropertyRef, Importance, InputKind, NestGroup, NestPosition,
140        PropertyArgs, PropertyAttribute, PropertyAttributeArgs, PropertyAttributeWhen, PropertyAttributes, PropertyAttributesWhenData,
141        PropertyId, PropertyInfo, PropertyInput, PropertyInputTypes, PropertyNewArgs, SourceLocation, WhenInfo, WhenInput, WhenInputMember,
142        WhenInputVar, WidgetBuilder, WidgetBuilderProperties, WidgetBuilding, WidgetType, property_args, property_id, property_info,
143        property_input_types, source_location, widget_type,
144    };
145}
146
147/// Widget info tree and info builder.
148///
149/// # Examples
150///
151/// The example declares a new info state for widgets and a property that sets the new state. The new state is then used
152/// in a widget.
153///
154/// ```
155/// mod custom {
156///     use zng::prelude_wgt::*;
157///
158///     static_id! {
159///         static ref STATE_ID: StateId<bool>;
160///     }
161///
162///     #[property(CONTEXT)]
163///     pub fn flag_state(child: impl IntoUiNode, state: impl IntoVar<bool>) -> UiNode {
164///         let state = state.into_var();
165///         match_node(child, move |_, op| match op {
166///             UiNodeOp::Init => {
167///                 WIDGET.sub_var_info(&state);
168///             }
169///             UiNodeOp::Info { info } => {
170///                 info.set_meta(*STATE_ID, state.get());
171///             }
172///             _ => {}
173///         })
174///     }
175///
176///     pub trait StateExt {
177///         fn state(&self) -> Option<bool>;
178///     }
179///     impl StateExt for WidgetInfo {
180///         fn state(&self) -> Option<bool> {
181///             self.meta().get_clone(*STATE_ID)
182///         }
183///     }
184/// }
185///
186/// # fn example() {
187/// # use zng::prelude::*;
188/// # let _ =
189/// Wgt! {
190///     custom::flag_state = true;
191///     widget::on_info_init = hn!(|_| {
192///         use custom::StateExt as _;
193///         let info = WIDGET.info();
194///         println!("state: {:?}", info.state());
195///     });
196/// }
197/// # ;
198/// # }
199/// ```
200pub mod info {
201    pub use zng_app::widget::info::{
202        HitInfo, HitTestInfo, INTERACTIVITY_CHANGED_EVENT, InlineSegmentInfo, InteractionPath, Interactivity, InteractivityChangedArgs,
203        InteractivityFilterArgs, ParallelBuilder, RelativeHitZ, TRANSFORM_CHANGED_EVENT, TransformChangedArgs, TreeFilter,
204        VISIBILITY_CHANGED_EVENT, VisibilityChangedArgs, WIDGET_INFO_CHANGED_EVENT, WidgetBorderInfo, WidgetBoundsInfo,
205        WidgetDescendantsRange, WidgetInfo, WidgetInfoBuilder, WidgetInfoChangedArgs, WidgetInfoMeta, WidgetInfoTree, WidgetInfoTreeStats,
206        WidgetInlineInfo, WidgetInlineMeasure, WidgetPath, iter,
207    };
208
209    /// Accessibility metadata types.
210    pub mod access {
211        pub use zng_app::widget::info::access::{AccessBuildArgs, WidgetAccessInfo, WidgetAccessInfoBuilder};
212    }
213
214    /// Helper types for inspecting an UI tree.
215    ///
216    /// See also [`zng::window::inspector`] for higher level inspectors.
217    pub mod inspector {
218        pub use zng_app::widget::inspector::{
219            InspectPropertyPattern, InspectWidgetPattern, InspectorActualVars, InspectorInfo, InstanceItem, WidgetInfoInspectorExt,
220        };
221    }
222}
223
224/// Widget node types, [`UiNode`], [`UiVec`] and others.
225///
226/// [`UiNode`]: crate::prelude::UiNode
227/// [`UiVec`]: crate::prelude::UiVec
228pub mod node {
229    pub use zng_app::widget::node::{
230        AdoptiveChildNode, AdoptiveNode, ArcNode, ChainList, DefaultPanelListData, EditableUiVec, EditableUiVecRef, FillUiNode, IntoUiNode,
231        MatchNodeChild, MatchWidgetChild, OffsetUiListObserver, PanelList, PanelListData, PanelListRange, SORTING_LIST, SortingList,
232        UiNode, UiNodeImpl, UiNodeListObserver, UiNodeMethod, UiNodeOp, UiVec, WeakNode, WhenUiNodeBuilder, WidgetUiNode, WidgetUiNodeImpl,
233        Z_INDEX, extend_widget, match_node, match_node_leaf, match_widget, ui_vec,
234    };
235
236    pub use zng_wgt::node::{
237        bind_state, bind_state_init, border_node, event_state, event_state2, event_state3, event_state4, fill_node, interactive_node,
238        list_presenter, list_presenter_from_iter, presenter, presenter_opt, widget_state_get_state, widget_state_is_state,
239        with_context_blend, with_context_local, with_context_local_init, with_context_var, with_context_var_init, with_index_len_node,
240        with_index_node, with_rev_index_node, with_widget_state, with_widget_state_modify,
241    };
242}
243
244/// Expands a struct to a widget struct and macro.
245///
246/// Each widget is a struct and macro pair of the same name that builds a custom widget using [`WidgetBuilder`]. Widgets
247/// *inherit* from one other widget and can also inherit multiple mixins. Widgets can have intrinsic nodes, default properties
248/// and can build to a custom output type.
249///
250/// Properties can be strongly associated with the widget using the `#[property(.., widget_impl(Widget))]` directive, existing properties
251/// can be implemented for the widget using the [`widget_impl!`] macro.
252///
253/// # Attribute
254///
255/// The widget attribute must be placed in a `struct Name(Parent);` declaration, only struct following the exact pattern are allowed,
256/// different struct syntaxes will generate a compile error.
257///
258/// The attribute requires one argument, it must be a macro style `$crate` path to the widget struct, this is used in the generated macro
259/// to find the struct during instantiation. The path must be to the *public* path to the struct, that is, the same path that will be used
260/// to import the widget. After the required widget path [custom rules](#custom-rules) for the generated macro can be declared.
261///
262/// ```
263/// # fn main() { }
264/// use zng::prelude_wgt::*;
265///
266/// /// Minimal widget.
267/// #[widget($crate::Foo)]
268/// pub struct Foo(WidgetBase);
269/// ```
270///
271/// # Inherit
272///
273/// The widget struct field must be the parent widget type. All widgets inherit from another or the
274/// [`WidgetBase`], the parent widgets intrinsic properties and nodes are all included in the new widget. The intrinsic
275/// properties are included by deref, the new widget will dereference to the parent widget, during widget build auto-deref will select
276/// the property methods first, this mechanism even allows for property overrides.
277///
278/// # Intrinsic
279///
280/// The widget struct can define a method `widget_intrinsic` that includes custom build actions in the [`WidgetBuilder`], this special
281/// method will be called once for the widget. The same method is also called for the inherited widgets.
282///
283/// ```
284/// # fn main() { }
285/// use zng::prelude_wgt::*;
286///
287/// #[widget($crate::Foo)]
288/// pub struct Foo(WidgetBase);
289///
290/// impl Foo {
291///     fn widget_intrinsic(&mut self) {
292///         self.widget_builder().push_build_action(|b| {
293///             // push_intrinsic, capture_var.
294///         });
295///     }
296/// }
297/// ```
298///
299/// The example above demonstrates the intrinsic method used to [`push_build_action`]. This is the primary mechanism for widgets to define their
300/// own behavior that does not depend on properties. Note that the widget inherits from [`WidgetBase`], during instantiation
301/// of `Foo!` the base `widget_intrinsic` is called first, then the `Foo!` `widget_intrinsic` is called.
302///
303/// The method does not need to be `pub`, and it is not required.
304///
305/// # Build
306///
307/// The widget struct can define a method that builds the final widget instance.
308///
309/// ```
310/// # fn main() { }
311/// use zng::prelude_wgt::*;
312///
313/// #[widget($crate::Foo)]
314/// pub struct Foo(WidgetBase);
315///
316/// impl Foo {
317///     /// Custom build.
318///     pub fn widget_build(&mut self) -> UiNode {
319///         println!("on build!");
320///         WidgetBase::widget_build(self)
321///     }
322/// }
323/// ```
324///
325/// The build method must have the same visibility as the widget, and can define its own
326/// return type, this is the widget instance type. If the build method is not defined the inherited parent build method is used.
327///
328/// Unlike the [intrinsic](#intrinsic) method, the widget only has one `widget_build`, if defined it overrides the parent
329/// `widget_build`. Most widgets don't define their own build, leaving it to be inherited from [`WidgetBase`]. The base instance type
330/// is an opaque `UiNode`.
331///
332/// Normal widgets instance types must implement [`IntoUiNode`], otherwise they cannot be used as child of other widgets.
333/// The widget outer-node also must implement the widget context, to ensure that the widget is correctly placed in the UI tree.
334/// Note that you can still use the parent type build implementation, so even if you need
335/// to run code on build or define a custom type you don't need to deref to the parent type to build.
336///
337/// # Defaults
338///
339/// The [`widget_set!`] macro can be used inside `widget_intrinsic` to set properties and when conditions that are applied on the widget by default,
340/// if not overridden by derived widgets or the widget instance. During the call to `widget_intrinsic` the `self.importance()` value is
341/// [`Importance::WIDGET`], after it is changed to [`Importance::INSTANCE`], so just by setting properties in `widget_intrinsic` they
342/// will have less importance allowing for the override mechanism to replace them.
343///
344/// # Impl Properties
345///
346/// The [`widget_impl!`] macro can be used inside a `impl WgtIdent { }` block to strongly associate a property with the widget,
347/// and the [`property`] attribute has a `widget_impl(WgtIdent)` directive that also strongly associates a property with the widget.
348///
349/// These two mechanisms can be used to define properties for the widget, the impl properties don't need to be imported and are
350/// always selected over other properties of the same name. They also appear in the widget documentation and can have a distinct
351/// visual in IDEs as they are represented by immutable methods while standalone properties are represented by mutable trait methods.
352///
353/// As a general rule only properties that are captured by the widget, or only work with the widget, or have an special meaning in the widget
354/// are implemented like this, standalone properties that can be used in any widget are not implemented.
355///
356/// # Generated Macro
357///
358/// The generated widget macro has the same syntax as [`widget_set!`], except that is also starts the widget and builds it at the end.
359///
360/// This widget macro call:
361///
362/// ```
363/// # use zng::prelude_wgt::*;
364/// # #[widget($crate::Foo)]
365/// # pub struct Foo(WidgetBase);
366/// #
367/// # fn main() {
368/// let wgt = Foo! {
369///     id = "foo";
370/// };
371/// # }
372/// ```
373///
374/// Expands to this:
375///
376/// ```
377/// # use zng::prelude_wgt::*;
378/// # #[widget($crate::Foo)]
379/// # pub struct Foo(WidgetBase);
380/// #
381/// # fn main() {
382/// let wgt = {
383///     let mut wgt = Foo::widget_new();
384///     widget_set! {
385///         &mut wgt;
386///         id = "foo";
387///     }
388///     wgt.widget_build()
389/// };
390/// # }
391/// ```
392///
393/// #### Custom Rules
394///
395/// You can declare custom rules for the widget macro, this can be used to declare custom shorthand syntax for the widget.
396///
397/// The custom rules are declared inside braces after the widget path in the widget attribute. The syntax is similar to `macro_rules!`
398/// rules, but the expanded tokens are the direct input of the normal widget expansion.
399///
400/// ```txt
401/// (<rule>) => { <init> };
402/// ```
403///
404/// The `<rule>` is any macro pattern rule, the `<init>` is the normal widget init code that the rule expands to.
405///
406/// Note that custom rules are not inherited, they apply only to the declaring widget macro, inherited widgets must replicate
407/// the rules if desired.
408///
409/// Example of a widget that declares a shorthand syntax to implicitly set the `id` property:
410///
411/// ```
412/// use zng::prelude_wgt::*;
413///
414/// #[widget($crate::Foo { ($id:expr) => { id = $id; }; })]
415/// pub struct Foo(WidgetBase);
416///
417/// # fn main() {
418/// let wgt = Foo!("foo");
419/// # }
420/// ```
421///
422/// The macro instance above is equivalent to:
423///
424/// ```
425/// # use zng::prelude_wgt::*;
426/// # #[widget($crate::Foo)]
427/// # pub struct Foo(WidgetBase);
428/// #
429/// # fn main() {
430/// let wgt = Foo! {
431///     id = "foo";
432/// };
433/// # }
434/// ```
435///
436/// #### Limitations
437///
438/// The expanded tokens can only be a recursive input for the same widget macro, you can't expand to a different widget.
439///
440/// Some rules are intercepted by the default widget rules:
441///
442/// * `$(#[$attr:meta])* $($property:ident)::+ = $($rest:tt)*`, blocks all custom `$ident = $tt*` patterns.
443/// * `$(#[$attr:meta])* when $($rest:tt)*`, blocks all custom `when $tt*` patterns.
444///
445/// Note that the default single property shorthand syntax is not blocked, for example `Text!(font_size)` will match
446/// the custom shorthand rule and try to set the `txt` with the `font_size` variable, without the shorthand it would create a widget without
447/// `txt` that sets `font_size`. So a custom rule `$p:expr` is only recommended for widgets that have a property of central importance.
448///
449/// # Widget Type
450///
451/// A public associated function `widget_type` is also generated for the widget, it returns a [`WidgetType`] instance that describes the
452/// widget type. Note that this is not the widget instance type, only the struct and macro type. If compiled with the `"inspector"` feature
453/// the type is also available in the widget info.
454///
455/// # See Also
456///
457/// See the [`WidgetBase`], [`WidgetBuilder`], [`WidgetBuilding`], [`NestGroup`] and [`Importance`] for more details.
458///
459/// [`WidgetBuilder`]: builder::WidgetBuilder
460/// [`WidgetType`]: builder::WidgetType
461/// [`WidgetBuilding`]: builder::WidgetBuilding
462/// [`NestGroup`]: builder::NestGroup
463/// [`Importance`]: builder::Importance
464/// [`push_build_action`]: builder::WidgetBuilder::push_build_action
465/// [`UiNode`]: node::UiNode
466/// [`IntoUiNode`]: node::IntoUiNode
467/// [`WidgetBase`]: struct@WidgetBase
468/// [`Importance::WIDGET`]: builder::Importance::WIDGET
469/// [`Importance::INSTANCE`]: builder::Importance::INSTANCE
470///
471/// <script>
472/// // hide re-exported docs
473/// let me = document.currentScript;
474/// document.addEventListener("DOMContentLoaded", function() {
475///     while(me.nextElementSibling !== null) {
476///         me.nextElementSibling.remove();
477///     }
478/// });
479/// </script>
480pub use zng_app::widget::widget;
481
482/// Expands a struct to a widget mixin.
483///
484/// Widget mixins can be inserted on a widgets inheritance chain, but they cannot be instantiated directly. Unlike
485/// the full widgets it defines its parent as a generic type, that must be filled with a real widget when used.
486///
487/// By convention mixins have the suffix `Mix` and the generic parent is named `P`. The `P` must not have any generic bounds
488/// in the declaration, the expansion will bound it to [`WidgetImpl`].
489///
490/// # Examples
491///
492/// ```
493/// # fn main() { }
494/// use zng::prelude_wgt::*;
495///
496/// /// Make a widget capable of receiving keyboard focus.
497/// #[widget_mixin]
498/// pub struct FocusableMix<P>(P);
499/// impl<P: WidgetImpl> FocusableMix<P> {
500///     fn widget_intrinsic(&mut self) {
501///         widget_set! {
502///             self;
503///             focusable = true;
504///         }
505///     }
506///
507///     widget_impl! {
508///         /// If the widget can receive focus, enabled by default.
509///         pub zng::focus::focusable(enabled: impl IntoVar<bool>);
510///     }
511/// }
512///
513/// /// Foo is focusable.
514/// #[widget($crate::Foo)]
515/// pub struct Foo(FocusableMix<WidgetBase>);
516/// ```
517///
518/// The example above declares a mixin `FocusableMix<P>` and a widget `Foo`, the mixin is used as a parent of the widget, only
519/// the `Foo! { }` widget can be instantiated, and it will have the strongly associated property `focusable` from the mixin.
520///
521/// All widget `impl` items can be declared in a mixin, including the `fn widget_build(&mut self) -> T`. Multiple mixins can be inherited
522/// by nesting the types in a full widget `Foo(AMix<BMix<Base>>)`. Mixins cannot inherit from other mixins.
523///
524/// <script>
525/// // hide re-exported docs
526/// let me = document.currentScript;
527/// document.addEventListener("DOMContentLoaded", function() {
528///     while(me.nextElementSibling !== null) {
529///         me.nextElementSibling.remove();
530///     }
531/// });
532/// </script>
533pub use zng_app::widget::widget_mixin;
534
535/// Expands a property assign to include an easing animation.
536///
537/// The attribute generates a [property attribute] that applies [`Var::easing`] to the final variable inputs of the property.
538///
539/// # Arguments
540///
541/// The attribute takes one required argument and one optional that matches the [`Var::easing`]
542/// parameters. The required first arg is the duration, the second arg is an easing function, if not present the [`easing::linear`] is used.
543///
544/// Some items are auto-imported in each argument scope, [`TimeUnits`] for the first arg and the [`easing`] functions
545/// for the second. This enables syntax like `#[easing(300.ms(), expo)]`.
546///
547/// ## Unset
548///
549/// An alternative argument `unset` can be used instead to remove animations set by the inherited context or styles.
550///
551/// [`TimeUnits`]: zng::layout::TimeUnits
552/// [`easing`]: mod@zng::var::animation::easing
553/// [`easing::linear`]: zng::var::animation::easing::linear
554/// [property attribute]: crate::widget::builder::WidgetBuilder::push_property_attribute
555/// [`Var::easing`]: crate::var::Var::easing
556///
557/// ## When
558///
559/// The attribute can also be set in `when` assigns, in this case the easing will be applied when the condition is active, so
560/// only the transition to the `true` value is animated using the conditional easing.
561///
562/// Note that you can't `unset` easing in when conditions, but you can set it to `0.ms()`, if all easing set for a property are `0`
563/// no easing variable is generated, in contexts that actually have animation the `when` value will be set immediately,
564/// by a zero sized animation.
565///
566/// # Examples
567///
568/// The example demonstrates setting and removing easing animations.
569///
570/// ```
571/// # use zng::prelude_wgt::*;
572/// # #[widget($crate::Foo)] pub struct Foo(WidgetBase);
573/// # #[property(FILL, default(colors::BLACK))]
574/// # pub fn background_color(child: impl IntoUiNode, color: impl IntoVar<Rgba>) -> UiNode {
575/// # child.into_node()
576/// # }
577/// # #[property(LAYOUT, default(0))]
578/// # pub fn margin(child: impl IntoUiNode, color: impl IntoVar<SideOffsets>) -> UiNode {
579/// # child.into_node()
580/// # }
581/// # fn main() {
582/// Foo! {
583///     #[easing(300.ms(), expo)] // set/override the easing.
584///     background_color = colors::RED;
585///
586///     #[easing(unset)] // remove easing set by style or widget defaults.
587///     margin = 0;
588/// }
589/// # ; }
590/// ```
591///
592/// # Limitations
593///
594/// The attribute only works in properties that only have variable inputs of types that are [`Transitionable`], if the attribute
595/// is set in a property that does not match this a compile time type error occurs, with a mention of `easing_property_input_Transitionable`.
596///
597/// <script>
598/// // hide re-exported docs
599/// let me = document.currentScript;
600/// document.addEventListener("DOMContentLoaded", function() {
601///     while(me.nextElementSibling !== null) {
602///         me.nextElementSibling.remove();
603///     }
604/// });
605/// </script>
606///
607/// [`Transitionable`]: crate::var::animation::Transitionable
608pub use zng_app::widget::easing;
609
610/// Expands a function to a widget property.
611///
612/// Property functions take one [`IntoUiNode`] child input and one or more other inputs and produces an [`UiNode`] that implements
613/// the property feature. Alternatively it takes one [`WidgetBuilding`] input plus other inputs and modifies the widget build.
614///
615/// The attribute expansion does not modify the function, it can still be used as a function directly. Some
616/// properties are implemented by calling other property functions to generate a derived effect.
617///
618/// The attribute expansion generates a hidden trait of the same name and visibility, the trait is implemented for widget builders,
619/// the widget macros use this to set the property. Because it has the same name it is imported together with the property
620/// function, in practice this only matters in doc links where you must use the `fn@` disambiguator.
621///
622/// # Attribute Args
623///
624/// The property attribute has one required argument and three optional.
625///
626/// #### Nest Group
627///
628/// The first argument is the property [`NestGroup`]. The group defines the overall nest position
629/// of the property, for example, `LAYOUT` properties always wrap `FILL` properties. This is important as widgets are open and any combination
630/// of properties may end-up instantiated in the same widget.
631///
632/// ```
633/// # fn main() { }
634/// use zng::prelude_wgt::*;
635///
636/// #[property(LAYOUT)]
637/// pub fn align(child: impl IntoUiNode, align: impl IntoVar<Align>) -> UiNode {
638///     // ..
639///     # child.into_node()
640/// }
641/// ```
642///
643/// The nest group can be tweaked, by adding or subtracting integers, in the example bellow both properties are in the `SIZE` group,
644/// but `size` is always inside `max_size`.
645///
646/// ```
647/// # fn main() { }
648/// use zng::prelude_wgt::*;
649///
650/// #[property(SIZE+1)]
651/// pub fn size(child: impl IntoUiNode, size: impl IntoVar<Size>) -> UiNode {
652///     // ..
653///     # child.into_node()
654/// }
655///
656/// #[property(SIZE)]
657/// pub fn max_size(child: impl IntoUiNode, size: impl IntoVar<Size>) -> UiNode {
658///     // ..
659///     # child.into_node()
660/// }
661/// ```
662///
663/// #### Default
664///
665/// The next argument is an optional `default(args..)`. It defines the value to use when the property must be instantiated and no value was provided.
666/// The defaults should cause the property to behave as if it is not set, as the default value will be used in widgets that only set the
667/// property in `when` blocks.
668///
669/// ```
670/// # fn main() { }
671/// use zng::prelude_wgt::*;
672///
673/// #[property(FILL, default(rgba(0, 0, 0, 0)))]
674/// pub fn background_color(child: impl IntoUiNode, color: impl IntoVar<Rgba>) -> UiNode {
675///     // ..
676///     # child.into_node()
677/// }
678/// ```
679///
680/// In the example above the `background_color` defines a transparent color as the default, so if the background color is only set in a `when`
681/// block if will only be visible when it is active.
682///
683/// For properties with multiple inputs the default args may be defined in a comma separated list of params, `default(dft0, ..)`.
684///
685/// #### Impl For
686///
687/// The last argument is an optional `impl(<widget-type>,...)`, it strongly associates the property with one or more widgets.
688/// When a property is implemented on a widget users can set it without needing to import the property.
689///
690/// Note that this makes the property have priority over all others of the same name, only a derived widget can override
691/// with another strongly associated property.
692///
693/// Note that you can also use the [`widget_impl!`] in widget declarations to implement existing properties for a widget.
694///
695/// # Function Args
696///
697/// The property function requires at least two args, the first is the child node and the other(s) the input values. The
698/// number and type of inputs is validated at compile time, the types are limited and are identified and validated by their
699/// token name, so you cannot use renamed types.
700///
701/// #### Child
702///
703/// The first function arg must be of type `impl IntoUiNode`, it represents the child node and the property node must
704/// delegate to it so that the UI tree functions correctly. The type must be an `impl` generic, a full path to [`IntoUiNode`]
705/// is allowed, but no import renames as the proc-macro attribute can only use tokens to identify the type.
706///
707/// ##### Or Building
708///
709/// Alternatively, the first function arg must be of type `&mut WidgetBuilding`, in this case the property function runs
710/// during widget build and can do things like insert multiple nodes on the widget or set the widget child node.
711///
712/// #### Inputs
713///
714/// The second arg and optional other args define the property inputs. When a property is assigned in a widget only these inputs
715/// are defined by the user, the child arg is provided by the widget builder. Property inputs are limited, and must be identifiable
716/// by their token name alone. The types are validated at compile time, they must be declared using `impl` generics,
717/// a full path to the generic traits is allowed, but no import renames.
718///
719/// #### Input Types
720///
721/// These are the allowed input types:
722///
723/// ##### `impl IntoVar<T>`
724///
725/// The most common type, accepts any value that can be converted [`IntoVar<T>`], usually the property defines the `T`, but it can be generic.
726/// The property node must respond to var updates. The input kind is [`InputKind::Var`]. No auto-default is generated for this type, property
727/// implementation should provide a default value that causes the property to behave as if it was not set.
728///
729/// The input can be read in `when` expressions and can be assigned in `when` blocks.
730///
731/// ##### `impl IntoValue<T>`
732///
733/// Accepts any value that can be converted [`IntoValue<T>`] that does not change, usually the property
734/// defines the `T`, but it can be generic. The input kind is [`InputKind::Value`]. No auto-default is generated for this type.
735///
736/// The input can be read in `when` expressions, but cannot be assigned in `when` blocks.
737///
738/// ##### `impl IntoUiNode`
739///
740/// This input accepts another [`UiNode`], the implementation must handle it like it handles the child node, delegating all methods. The
741/// input kind is [`InputKind::UiNode`]. The [`UiNode::nil`] is used as the default value if no other is provided.
742///
743/// The input cannot be read in `when` expressions, but can be assigned in `when` blocks.
744///
745/// Note that UI lists like [`ui_vec!`] are also nodes, so panel children properties also receive `impl IntoUiNode`.
746///
747/// ##### `Handler<A>`
748///
749/// This input is the type alias [`Handler<A>`], generic for the argument type `A`, usually the property defines the `A`, but it can be generic.
750/// The input kind is [`InputKind::Handler`]. A no-op handler is used for the default if no other is provided.
751///
752/// Event handler properties usually have the `on_` name prefix. You can use the [`event_property!`] macro to generate standard event properties.
753///
754/// The input cannot be read in `when` expressions, but can be assigned in `when` blocks.
755///
756/// # Getter Properties
757///
758/// Most properties with var inputs are *setters*, that is the inputs affect the widget. Some properties
759/// can be *getters*, detecting widget state and setting it on the *input* variable. These properties are usually named with
760/// a prefix that indicates their input is actually for getting state, the prefixes `is_` and `has_` mark a property with
761/// a single `bool` input that reads a widget state, the prefix `get_` and `actual_` marks a property that reads a non-boolean state from
762/// the widget.
763///
764/// Getter properties are configured with a default read-write variable, so that they can be used in `when` expressions directly,
765/// for example, `when *#is_pressed`, the `is_pressed` property has a `default(var(false))`, so it automatically initializes
766/// with a read-write variable that is used in the when condition. The property attribute generates defaults automatically
767/// based on the prefix, the default is `var(T::default())`, this can be overwritten just by setting the default,
768/// it is not possible to declare a getter property without default.
769///
770/// Note that if a property is used in `when` condition without being set and without default value the when block is discarded on
771/// widget build. If you are implementing a getter property that is not named using the prefixes listed above you must set `default(var(T::default())`.
772///
773/// # Generics
774///
775/// Apart from the `impl` generics of inputs and child, there is some support for named generic types, only one named generic is allowed
776/// for inputs `impl IntoVar<T>`, `impl IntoValue<T>` and `Handler<A>`.
777///
778/// # Output
779///
780/// The property output type must be [`UiNode`]. The property node implementation can be anything, as long as it delegates
781/// to the child node, see [`match_node`] or [`ui_node`] about implementing a node.
782///
783/// Some common property patterns have helper functions, for example, to setup a context var you can use the [`with_context_var`] function.
784///
785/// # Build Action Properties
786///
787/// Property functions can take a `&mut WidgetBuilding` first arg, in this case they are *build action properties*. These properties cannot
788/// be instantiated into a node, they only work if set on an widget. The property function is called during widget build, after property resolution
789/// and widget intrinsic build actions, the function can modify the [`WidgetBuilding`], just like an intrinsic build action.
790///
791/// ```
792/// # fn main() { }
793/// use zng::prelude_wgt::*;
794///
795/// #[property(CHILD)]
796/// pub fn child(wgt: &mut WidgetBuilding, child: impl IntoUiNode) {
797///     wgt.set_child(child);
798/// }
799/// ```
800///
801/// The example above declares a simple property that replaces the widget child.
802///
803/// ## Capture Only
804///
805/// Some widgets intrinsic behavior depend on the value of multiple properties that cannot provide any implementation by themselves. In
806/// this case the property should be declared as a build action property and call [`expect_property_capture`].
807/// The widget them must capture the property during build, if it does not an error is logged in build with debug assertions enabled.
808///
809/// ```
810/// # fn main() { }
811/// use zng::prelude_wgt::*;
812/// # #[widget($crate::MyPanel)]
813/// # pub struct MyPanel(WidgetBase);
814///
815/// #[property(CHILD, widget_impl(MyPanel))]
816/// pub fn children(wgt: &mut WidgetBuilding, children: impl IntoUiNode) {
817///     let _ = children;
818///     wgt.expect_property_capture();
819/// }
820/// ```
821///
822/// The example above declares a property that expects to be captured, if the property function actually runs it will log an error
823/// in builds with debug assertions enabled.
824///
825/// # More Details
826///
827/// See [`property_id!`] and [`property_args!`] for more details about what kind of meta-code is generated for properties.
828///
829/// [`NestGroup`]: crate::widget::builder::NestGroup
830/// [`WidgetBuilding`]: crate::widget::builder::WidgetBuilding
831/// [`expect_property_capture`]: crate::widget::builder::WidgetBuilding::expect_property_capture
832/// [`property_id!`]: crate::widget::builder::property_id
833/// [`property_args!`]: crate::widget::builder::property_args
834/// [`ui_node`]: macro@ui_node
835/// [`match_node`]: crate::widget::node::match_node
836/// [`with_context_var`]: crate::widget::node::with_context_var
837/// [`VarValue`]: crate::var::VarValue
838/// [`IntoValue<T>`]: crate::var::IntoValue
839/// [`IntoVar<T>`]: crate::var::IntoVar
840/// [`Handler<A>`]: crate::handler::Handler
841/// [`UiNode`]: crate::widget::node::UiNode
842/// [`IntoUiNode`]: crate::widget::node::IntoUiNode
843/// [`UiNode::nil`]: crate::widget::node::UiNode::nil
844/// [`ui_vec!`]: crate::widget::node::ui_vec
845/// [`InputKind::Var`]: crate::widget::builder::InputKind::Var
846/// [`InputKind::Value`]: crate::widget::builder::InputKind::Value
847/// [`InputKind::UiNode`]: crate::widget::builder::InputKind::UiNode
848/// [`InputKind::UiNodeList`]: crate::widget::builder::InputKind::UiNodeList
849/// [`InputKind::Handler`]: crate::widget::builder::InputKind::Handler
850/// [`event_property!`]: crate::event::event_property
851///
852/// <script>
853/// // hide re-exported docs
854/// let me = document.currentScript;
855/// document.addEventListener("DOMContentLoaded", function() {
856///     while(me.nextElementSibling !== null) {
857///         me.nextElementSibling.remove();
858///     }
859/// });
860/// </script>
861pub use zng_app::widget::property;