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