1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
//! Widget info, builder and base, UI node and list.
//!
//! The [`Wgt!`](struct@Wgt) widget is a blank widget that entirely shaped by properties.
//!
//! ```
//! use zng::prelude::*;
//! # let _scope = APP.defaults();
//!
//! # let _ =
//! Wgt! {
//!     id = "sun";
//!
//!     widget::background_gradient = {
//!         axis: 0.deg(),
//!         stops: color::gradient::stops![hex!(#ff5226), hex!(#ffc926)],
//!     };
//!     layout::size = 100;
//!     widget::corner_radius = 100;
//!     layout::align = layout::Align::BOTTOM;
//!
//!     #[easing(2.secs())]
//!     layout::y = 100;
//!     when *#widget::is_inited {
//!         layout::y = -30;
//!     }
//! }
//! # ;
//! ```
//!
//! To learn more about the widget macros syntax see [`widget_set!`].
//!
//! To learn more about how widgets are declared see [`widget`].
//!
//! To learn more about how properties are declared see [`property`].
//!
//! # Full API
//!
//! See [`zng_app::widget`] for the full API.

pub use zng_app::widget::base::{HitTestMode, NonWidgetBase, Parallel, WidgetBase, WidgetExt, WidgetImpl, PARALLEL_VAR};

pub use zng_app::widget::{widget_impl, widget_set, WidgetId, WidgetUpdateMode, WIDGET};

pub use zng_app::widget::border::{
    BorderSide, BorderSides, BorderStyle, CornerRadius, CornerRadiusFit, LineOrientation, LineStyle, BORDER,
};
pub use zng_app::widget::info::Visibility;
pub use zng_app::widget::node::ZIndex;

pub use zng_wgt::{
    auto_hide, border, border_align, border_over, clip_to_bounds, corner_radius, corner_radius_fit, enabled, hit_test_mode, inline,
    interactive, is_collapsed, is_disabled, is_enabled, is_hidden, is_hit_testable, is_inited, is_mobile, is_visible, modal,
    modal_included, modal_includes, on_block, on_blocked_changed, on_collapse, on_deinit, on_disable, on_enable, on_enabled_changed,
    on_hide, on_info_init, on_init, on_interactivity_changed, on_move, on_node_op, on_pre_block, on_pre_blocked_changed, on_pre_collapse,
    on_pre_deinit, on_pre_disable, on_pre_enable, on_pre_enabled_changed, on_pre_hide, on_pre_init, on_pre_interactivity_changed,
    on_pre_move, on_pre_node_op, on_pre_show, on_pre_transform_changed, on_pre_unblock, on_pre_update, on_pre_vis_disable,
    on_pre_vis_enable, on_pre_vis_enabled_changed, on_pre_visibility_changed, on_show, on_transform_changed, on_unblock, on_update,
    on_vis_disable, on_vis_enable, on_vis_enabled_changed, on_visibility_changed, parallel, visibility, wgt_fn, z_index, EditorRequestArgs,
    OnNodeOpArgs, WeakWidgetFn, Wgt, WidgetFn, EDITORS, IS_MOBILE_VAR,
};

pub use zng_wgt_fill::{
    background, background_color, background_conic, background_fn, background_gradient, background_radial, foreground, foreground_color,
    foreground_conic, foreground_fn, foreground_gradient, foreground_highlight, foreground_radial,
};

/// 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.
///
/// [`WidgetBuilder`]: builder::WidgetBuilder
///
/// ```
/// 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());            
///             });
///         }
///     }
/// }
///
/// # fn main() {
/// # let _scope = zng::APP.defaults();
/// # let _ =
/// widgets::ShowProperties! {
///     font_size = 20;
/// }
/// # ;
/// # }
/// ```
///
/// # Full API
///
/// See [`zng_app::widget::builder`] for the full API.
pub mod builder {
    pub use zng_app::widget::builder::{
        property_args, property_id, property_info, property_input_types, source_location, widget_type, AnyWhenArcWidgetHandlerBuilder,
        ArcWidgetHandler, BuilderProperty, BuilderPropertyMut, BuilderPropertyRef, Importance, InputKind, NestGroup, NestPosition,
        PropertyArgs, PropertyBuildAction, PropertyBuildActionArgs, PropertyBuildActions, PropertyBuildActionsWhenData, PropertyId,
        PropertyInfo, PropertyInput, PropertyInputTypes, PropertyNewArgs, SourceLocation, WhenBuildAction, WhenInfo, WhenInput,
        WhenInputMember, WhenInputVar, WidgetBuilder, WidgetBuilderProperties, WidgetBuilding, WidgetType,
    };
}

/// Widget info tree and info builder.
///
/// # Examples
///
/// The example declares a new info state for widgets and a property that sets the new state. The new state is then used
/// in a widget.
///
/// ```
/// mod custom {
///     use zng::prelude_wgt::*;
///
///     static_id! {
///         static ref STATE_ID: StateId<bool>;
///     }
///
///     #[property(CONTEXT)]
///     pub fn flag_state(child: impl UiNode, state: impl IntoVar<bool>) -> impl UiNode {
///         let state = state.into_var();
///         match_node(child, move |_, op| match op {
///             UiNodeOp::Init => {
///                 WIDGET.sub_var_info(&state);
///             }
///             UiNodeOp::Info { info } => {
///                 info.set_meta(*STATE_ID, state.get());
///             }
///             _ => {}
///         })
///     }
///
///     pub trait StateExt {
///         fn state(&self) -> Option<bool>;
///     }
///     impl StateExt for WidgetInfo {
///         fn state(&self) -> Option<bool> {
///             self.meta().get_clone(*STATE_ID)
///         }
///     }
/// }
///
/// # fn main() {
/// # use zng::prelude::*;
/// # let _scope = APP.defaults();
/// # let _ =
/// Wgt! {
///     custom::flag_state = true;
///     widget::on_info_init = hn!(|_| {
///         use custom::StateExt as _;
///         let info = WIDGET.info();
///         println!("state: {:?}", info.state());
///     });
/// }
/// # ;
/// # }
/// ```
pub mod info {
    pub use zng_app::widget::info::{
        iter, HitInfo, HitTestInfo, InlineSegmentInfo, InteractionPath, Interactivity, InteractivityChangedArgs, InteractivityFilterArgs,
        ParallelBuilder, RelativeHitZ, TransformChangedArgs, TreeFilter, VisibilityChangedArgs, WidgetBorderInfo, WidgetBoundsInfo,
        WidgetDescendantsRange, WidgetInfo, WidgetInfoBuilder, WidgetInfoChangedArgs, WidgetInfoMeta, WidgetInfoTree, WidgetInfoTreeStats,
        WidgetInlineInfo, WidgetInlineMeasure, WidgetPath, INTERACTIVITY_CHANGED_EVENT, TRANSFORM_CHANGED_EVENT, VISIBILITY_CHANGED_EVENT,
        WIDGET_INFO_CHANGED_EVENT,
    };

    /// Accessibility metadata types.
    pub mod access {
        pub use zng_app::widget::info::access::{AccessBuildArgs, WidgetAccessInfo, WidgetAccessInfoBuilder};
    }

    /// Helper types for inspecting an UI tree.
    pub mod inspector {
        pub use zng_app::widget::inspector::{
            InspectPropertyPattern, InspectWidgetPattern, InspectorActualVars, InspectorInfo, InstanceItem, WidgetInfoInspectorExt,
        };
    }
}

/// Widget node types, [`UiNode`], [`UiNodeList`] and others.
///
/// [`UiNode`]: crate::prelude::UiNode
/// [`UiNodeList`]: crate::prelude::UiNodeList
pub mod node {
    pub use zng_app::widget::node::{
        extend_widget, match_node, match_node_leaf, match_node_list, match_node_typed, match_widget, ui_vec, AdoptiveChildNode,
        AdoptiveNode, ArcNode, ArcNodeList, BoxedUiNode, BoxedUiNodeList, DefaultPanelListData, EditableUiNodeList, EditableUiNodeListRef,
        FillUiNode, MatchNodeChild, MatchNodeChildren, MatchWidgetChild, NilUiNode, OffsetUiListObserver, PanelList, PanelListData,
        PanelListRange, SortingList, UiNode, UiNodeList, UiNodeListChain, UiNodeListChainImpl, UiNodeListObserver, UiNodeOp,
        UiNodeOpMethod, UiVec, WeakNode, WeakNodeList, WhenUiNodeBuilder, WhenUiNodeListBuilder, SORTING_LIST, Z_INDEX,
    };

    pub use zng_wgt::node::{
        bind_state, bind_state_init, border_node, event_state, event_state2, event_state3, event_state4, fill_node, interactive_node,
        list_presenter, presenter, presenter_opt, widget_state_get_state, widget_state_is_state, with_context_blend, with_context_local,
        with_context_local_init, with_context_var, with_context_var_init, with_index_len_node, with_index_node, with_rev_index_node,
        with_widget_state, with_widget_state_modify,
    };
}

/// Expands a struct to a widget struct and macro.
///
/// Each widget is a struct and macro pair of the same name that builds a custom widget using [`WidgetBuilder`]. Widgets
/// *inherit* from one other widget and can also inherit multiple mix-ins. Widgets can have intrinsic nodes, default properties
/// and can build to a custom output type.
///
/// Properties can be strongly associated with the widget using the `#[property(.., widget_impl(Widget))]` directive, existing properties
/// can be implemented for the widget using the [`widget_impl!`] macro.
///
/// # Attribute
///
/// The widget attribute must be placed in a `struct Name(Parent);` declaration, only struct following the exact pattern are allowed,
/// different struct syntaxes will generate a compile error.
///
/// The attribute requires one argument, it must be a macro style `$crate` path to the widget struct, this is used in the generated macro
/// 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
/// to import the widget. After the required widget path [custom rules](#custom-rules) for the generated macro can be declared.
///
/// ```
/// # fn main() { }
/// use zng::prelude_wgt::*;
///
/// /// Minimal widget.
/// #[widget($crate::Foo)]
/// pub struct Foo(WidgetBase);
/// ```
///
/// # Inherit
///
/// The widget struct field must be the parent widget type. All widgets inherit from another or the
/// [`WidgetBase`], the parent widgets intrinsic properties and nodes are all included in the new widget. The intrinsic
/// properties are included by deref, the new widget will dereference to the parent widget, during widget build auto-deref will select
/// the property methods first, this mechanism even allows for property overrides.
///
/// # Intrinsic
///
/// The widget struct can define a method `widget_intrinsic` that includes custom build actions in the [`WidgetBuilder`], this special
/// method will be called once for the widget. The same method is also called for the inherited widgets.
///
/// ```
/// # fn main() { }
/// use zng::prelude_wgt::*;
///
/// #[widget($crate::Foo)]
/// pub struct Foo(WidgetBase);
///
/// impl Foo {
///     fn widget_intrinsic(&mut self) {
///         self.widget_builder().push_build_action(|b| {
///             // push_intrinsic, capture_var.
///         });
///     }
/// }
/// ```
///
/// The example above demonstrates the intrinsic method used to [`push_build_action`]. This is the primary mechanism for widgets to define their
/// own behavior that does not depend on properties. Note that the widget inherits from [`WidgetBase`], during instantiation
/// of `Foo!` the base `widget_intrinsic` is called first, then the `Foo!` `widget_intrinsic` is called.
///
/// The method does not need to be `pub`, and it is not required.
///
/// # Build
///
/// The widget struct can define a method that builds the final widget instance.
///
/// ```
/// # fn main() { }
/// use zng::prelude_wgt::*;
///
/// #[widget($crate::Foo)]
/// pub struct Foo(WidgetBase);
///
/// impl Foo {
///     /// Custom build.
///     pub fn widget_build(&mut self) -> impl UiNode {
///         println!("on build!");
///         WidgetBase::widget_build(self)
///     }
/// }
/// ```
///
/// The build method must have the same visibility as the widget, and can define its own
/// return type, this is the widget instance type. If the build method is not defined the inherited parent build method is used.
///
/// Unlike the [intrinsic](#intrinsic) method, the widget only has one `widget_build`, if defined it overrides the parent
/// `widget_build`. Most widgets don't define their own build, leaving it to be inherited from [`WidgetBase`]. The base instance type
/// is an opaque `impl UiNode`.
///
/// Normal widgets must implement [`UiNode`], otherwise they cannot be used as child of other widgets.
/// The widget outer-node also must implement the widget context, to ensure that the widget is correctly placed in the UI tree.
/// Note that you can still use the parent type build implementation, so even if you need
/// to run code on build or define a custom type you don't need to deref to the parent type to build.
///
/// # Defaults
///
/// The [`widget_set!`] macro can be used inside `widget_intrinsic` to set properties and when conditions that are applied on the widget by default,
/// if not overridden by derived widgets or the widget instance. During the call to `widget_intrinsic` the `self.importance()` value is
/// [`Importance::WIDGET`], after it is changed to [`Importance::INSTANCE`], so just by setting properties in `widget_intrinsic` they
/// will have less importance allowing for the override mechanism to replace them.
///
/// # Impl Properties
///
/// The [`widget_impl!`] macro can be used inside a `impl WgtIdent { }` block to strongly associate a property with the widget,
/// and the [`property`] attribute has a `widget_impl(WgtIdent)` directive that also strongly associates a property with the widget.
///
/// These two mechanisms can be used to define properties for the widget, the impl properties don't need to be imported and are
/// always selected over other properties of the same name. They also appear in the widget documentation and can have a distinct
/// visual in IDEs as they are represented by immutable methods while standalone properties are represented by mutable trait methods.
///
/// 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
/// are implemented like this, standalone properties that can be used in any widget are not implemented.
///
/// # Generated Macro
///
/// The generated widget macro has the same syntax as [`widget_set!`], except that is also starts the widget and builds it at the end.
///
/// This widget macro call:
///
/// ```
/// # use zng::prelude_wgt::*;
/// # #[widget($crate::Foo)]
/// # pub struct Foo(WidgetBase);
/// #
/// # fn main() {
/// let wgt = Foo! {
///     id = "foo";
/// };
/// # }
/// ```
///
/// Expands to this:
///
/// ```
/// # use zng::prelude_wgt::*;
/// # #[widget($crate::Foo)]
/// # pub struct Foo(WidgetBase);
/// #
/// # fn main() {
/// let wgt = {
///     let mut wgt = Foo::widget_new();
///     widget_set! {
///         &mut wgt;
///         id = "foo";
///     }
///     wgt.widget_build()
/// };
/// # }
/// ```
///
/// #### Custom Rules
///
/// You can declare custom rules for the widget macro, this can be used to declare custom shorthand syntax for the widget.
///
/// The custom rules are declared inside braces after the widget path in the widget attribute. The syntax is similar to `macro_rules!`
/// rules, but the expanded tokens are the direct input of the normal widget expansion.
///
/// ```txt
/// (<rule>) => { <init> };
/// ```
///
/// The `<rule>` is any macro pattern rule, the `<init>` is the normal widget init code that the rule expands to.
///
/// Note that custom rules are not inherited, they apply only to the declaring widget macro, inherited widgets must replicate
/// the rules if desired.
///
/// Example of a widget that declares a shorthand syntax to implicitly set the `id` property:
///
/// ```
/// use zng::prelude_wgt::*;
///
/// #[widget($crate::Foo {
///     ($id:expr) => {
///         id = $id;
///     };
/// })]
/// pub struct Foo(WidgetBase);
///
/// # fn main() {
/// let wgt = Foo!("foo");
/// # }
/// ```
///
/// The macro instance above is equivalent to:
///
/// ```
/// # use zng::prelude_wgt::*;
/// # #[widget($crate::Foo)]
/// # pub struct Foo(WidgetBase);
/// #
/// # fn main() {
/// let wgt = Foo! {
///     id = "foo";
/// };
/// # }
/// ```
///
/// #### Limitations
///
/// The expanded tokens can only be a recursive input for the same widget macro, you can't expand to a different widget.
///
/// Some rules are intercepted by the default widget rules:
///
/// * `$(#[$attr:meta])* $($property:ident)::+ = $($rest:tt)*`, blocks all custom `$ident = $tt*` patterns.
/// * `$(#[$attr:meta])* when $($rest:tt)*`, blocks all custom `when $tt*` patterns.
///
/// Note that the default single property shorthand syntax is not blocked, for example `Text!(font_size)` will match
/// the custom shorthand rule and try to set the `txt` with the `font_size` variable, without the shorthand it would create a widget without
/// `txt` that sets `font_size`. So a custom rule `$p:expr` is only recommended for widgets that have a property of central importance.
///
/// # Widget Type
///
/// A public associated function `widget_type` is also generated for the widget, it returns a [`WidgetType`] instance that describes the
/// widget type. Note that this is not the widget instance type, only the struct and macro type. If compiled with the `"inspector"` feature
/// the type is also available in the widget info.
///
/// # See Also
///
/// See the [`WidgetBase`], [`WidgetBuilder`], [`WidgetBuilding`], [`NestGroup`] and [`Importance`] for more details.
///
/// [`WidgetBuilder`]: builder::WidgetBuilder
/// [`WidgetType`]: builder::WidgetType
/// [`WidgetBuilding`]: builder::WidgetBuilding
/// [`NestGroup`]: builder::NestGroup
/// [`Importance`]: builder::Importance
/// [`push_build_action`]: builder::WidgetBuilder::push_build_action
/// [`UiNode`]: node::UiNode
/// [`WidgetBase`]: struct@WidgetBase
/// [`Importance::WIDGET`]: builder::Importance::WIDGET
/// [`Importance::INSTANCE`]: builder::Importance::INSTANCE
///
/// <script>
/// // hide re-exported docs
/// let me = document.currentScript;
/// document.addEventListener("DOMContentLoaded", function() {
///     while(me.nextElementSibling !== null) {
///         me.nextElementSibling.remove();
///     }
/// });
/// </script>
pub use zng_app::widget::widget;

/// Expands a struct to a widget mix-in.
///
/// Widget mix-ins can be inserted on a widgets inheritance chain, but they cannot be instantiated directly. Unlike
/// the full widgets it defines its parent as a generic type, that must be filled with a real widget when used.
///
/// By convention mix-ins have the suffix `Mix` and the generic parent is named `P`. The `P` must not have any generic bounds
/// in the declaration, the expansion will bound it to [`WidgetImpl`].
///
/// # Examples
///
/// ```
/// # fn main() { }
/// use zng::prelude_wgt::*;
///
/// /// Make a widget capable of receiving keyboard focus.
/// #[widget_mixin]
/// pub struct FocusableMix<P>(P);
/// impl<P: WidgetImpl> FocusableMix<P> {
///     fn widget_intrinsic(&mut self) {
///         widget_set! {
///             self;
///             focusable = true;
///         }
///     }
///     
///     widget_impl! {
///         /// If the widget can receive focus, enabled by default.
///         pub zng::focus::focusable(enabled: impl IntoVar<bool>);
///     }
/// }
///
/// /// Foo is focusable.
/// #[widget($crate::Foo)]
/// pub struct Foo(FocusableMix<WidgetBase>);
/// ```
///
/// The example above declares a mix-in `FocusableMix<P>` and a widget `Foo`, the mix-in is used as a parent of the widget, only
/// the `Foo! { }` widget can be instantiated, and it will have the strongly associated property `focusable` from the mix-in.
///
/// All widget `impl` items can be declared in a mix-in, including the `fn widget_build(&mut self) -> T`. Multiple mix-ins can be inherited
/// by nesting the types in a full widget `Foo(AMix<BMix<Base>>)`. Mix-ins cannot inherit from other mix-ins.
///
/// <script>
/// // hide re-exported docs
/// let me = document.currentScript;
/// document.addEventListener("DOMContentLoaded", function() {
///     while(me.nextElementSibling !== null) {
///         me.nextElementSibling.remove();
///     }
/// });
/// </script>
pub use zng_app::widget::widget_mixin;

/// Expands a property assign to include an easing animation.
///
/// The attribute generates a [property build action] that applies [`Var::easing`] to the final variable inputs of the property.
///
/// # Arguments
///
/// The attribute takes one required argument and one optional that matches the [`Var::easing`]
/// parameters. The required first arg is the duration, the second arg is an easing function, if not present the [`easing::linear`] is used.
///
/// Some items are auto-imported in each argument scope, [`TimeUnits`] for the first arg and the [`easing`] functions
/// for the second. This enables syntax like `#[easing(300.ms(), expo)]`.
///
/// ## Unset
///
/// An alternative argument `unset` can be used instead to remove animations set by the inherited context or styles.
///
/// [`TimeUnits`]: zng::layout::TimeUnits
/// [`easing`]: mod@zng::var::animation::easing
/// [`easing::linear`]: zng::var::animation::easing::linear
/// [property build action]: crate::widget::builder::WidgetBuilder::push_property_build_action
/// [`Var::easing`]: crate::var::Var::easing
///
/// ## When
///
/// The attribute can also be set in `when` assigns, in this case the easing will be applied when the condition is active, so
/// only the transition to the `true` value is animated using the conditional easing.
///
/// 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`
/// no easing variable is generated, in contexts that actually have animation the `when`` value will be set immediately,
/// by a zero sized animation.
///
/// # Examples
///
/// The example demonstrates setting and removing easing animations.
///
/// ```
/// # use zng::prelude_wgt::*;
/// # #[widget($crate::Foo)] pub struct Foo(WidgetBase);
/// # #[property(FILL, default(colors::BLACK))]
/// # pub fn background_color(child: impl UiNode, color: impl IntoVar<Rgba>) -> impl UiNode {
/// #    child
/// # }
/// # #[property(LAYOUT, default(0))]
/// # pub fn margin(child: impl UiNode, color: impl IntoVar<SideOffsets>) -> impl UiNode {
/// #    child
/// # }
/// # fn main() {
/// Foo! {
///     #[easing(300.ms(), expo)] // set/override the easing.
///     background_color = colors::RED;
///
///     #[easing(unset)] // remove easing set by style or widget defaults.
///     margin = 0;
/// }
/// # ; }
/// ```
///
/// # Limitations
///
/// The attribute only works in properties that only have variable inputs of types that are [`Transitionable`], if the attribute
/// is set in a property that does not match this a cryptic type error occurs, with a mention of `easing_property_input_Transitionable`.
///
/// <script>
/// // hide re-exported docs
/// let me = document.currentScript;
/// document.addEventListener("DOMContentLoaded", function() {
///     while(me.nextElementSibling !== null) {
///         me.nextElementSibling.remove();
///     }
/// });
/// </script>
///
/// [`Transitionable`]: crate::var::animation::Transitionable
pub use zng_app::widget::easing;

/// Expands a function to a widget property.
///
/// Property functions take one [`UiNode`] child input and one or more other inputs and produces an [`UiNode`] that implements
/// the property feature.
///
/// The attribute expansion does not modify the function, it can still be used as a function directly. Some
/// properties are implemented by calling other property functions to generate a derived effect.
///
/// The attribute expansion generates a hidden trait of the same name and visibility, the trait is implemented for widget builders,
/// the widget macros use this to set the property. Because it has the same name it is imported together with the property
/// function, in practice this only matters in doc links where you must use the `fn@` disambiguator.
///
/// # Attribute
///
/// The property attribute has one required argument and three optional.
///
/// #### Nest Group
///
/// The first argument is the property [`NestGroup`]. The group defines the overall nest position
/// of the property, for example, `LAYOUT` properties always wrap `FILL` properties. This is important as widgets are open and any combination
/// of properties may end-up instantiated in the same widget.
///
/// ```
/// # fn main() { }
/// use zng::prelude_wgt::*;
///
/// #[property(LAYOUT)]
/// pub fn align(child: impl UiNode, align: impl IntoVar<Align>) -> impl UiNode {
///     // ..
/// #   child
/// }
/// ```
///
/// The nest group can be tweaked, by adding or subtracting integers, in the example bellow both properties are in the `SIZE` group,
/// but `size` is always inside `max_size`.
///
/// ```
/// # fn main() { }
/// use zng::prelude_wgt::*;
///
/// #[property(SIZE+1)]
/// pub fn size(child: impl UiNode, size: impl IntoVar<Size>) -> impl UiNode {
///     // ..
/// #   child
/// }
///
/// #[property(SIZE)]
/// pub fn max_size(child: impl UiNode, size: impl IntoVar<Size>) -> impl UiNode {
///     // ..
/// #   child
/// }
/// ```
///
/// #### Default
///
/// 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.
/// 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
/// property in `when` blocks.
///
/// ```
/// # fn main() { }
/// use zng::prelude_wgt::*;
///
/// #[property(FILL, default(rgba(0, 0, 0, 0)))]
/// pub fn background_color(child: impl UiNode, color: impl IntoVar<Rgba>) -> impl UiNode {
///     // ..
/// #   child
/// }
/// ```
///
/// 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`
/// block if will only be visible when it is active.
///
/// For properties with multiple inputs the default args may be defined in a comma separated list of params, `default(dft0, ..)`.
///
/// #### Impl For
///
/// The last argument is an optional `impl(<widget-type>)`, it strongly associates
/// the property with a widget, users can set this property on the widget without needing to import the property.
///
/// Note that this makes the property have priority over all others of the same name, only a derived widget can override
/// with another strongly associated property.
///
/// Note that you can also use the [`widget_impl!`] in widget declarations to implement existing properties for a widget.
///
/// #### Capture
///
/// After the nest group and before default the `, capture, ` value indicates that the property is capture-only. This flag
/// changes how the property must be declared, the first argument is a property input and the function can have only one input,
/// no return type is allowed and the function body must be empty, unused input warnings are suppressed by the expanded code.
///
/// Capture-only properties must be captured by a widget and implemented as part of the widget's intrinsics, the reason for
/// a property function is purely to define the property signature and metadata, the capture-only property function can also
/// be used to set a property dynamically, such as in a style widget that is applied on the actual widget that captures the property.
///
/// A documentation sections explaining capture-only properties is generated for the property, it is also tagged differently in the functions list.
///
/// ```
/// # fn main() { }
/// use zng::prelude_wgt::*;
///
/// /// Children property, must be captured by panel widgets.
/// #[property(CONTEXT, capture)]
/// pub fn children(children: impl UiNodeList) { }
/// ```
///
/// # Args
///
/// The property function requires at least two args, the first is the child node and the other(s) the input values. The
/// number and type of inputs is validated at compile time, the types are limited and are identified and validated by their
/// token name, so you cannot use renamed types.
///
/// #### Child
///
/// The first function arg must be of type `impl UiNode`, it represents the child node and the property node must
/// delegate to it so that the UI tree functions correctly. The type must be an `impl` generic, a full path to [`UiNode`]
/// is allowed, but no import renames as the proc-macro attribute can only use tokens to identify the type.
///
/// #### Inputs
///
/// The second arg and optional other args define the property inputs. When a property is assigned in a widget only these inputs
/// are defined by the user, the child arg is provided by the widget builder. Property inputs are limited, and must be identifiable
/// by their token name alone. The types are validated at compile time, they must be declared using `impl` generics,
/// a full path to the generic traits is allowed, but no import renames.
///
/// #### Input Types
///
/// These are the allowed input types:
///
/// ##### `impl IntoVar<T>`
///
/// The most common type, accepts any value that can be converted [`IntoVar<T>`], usually the property defines the `T`, but it can be generic.
/// The property node must respond to var updates. The input kind is [`InputKind::Var`]. No auto-default is generated for this type, property
/// implementation should provide a default value that causes the property to behave as if it was not set.
///
/// The input can be read in `when` expressions and can be assigned in `when` blocks.
///
/// ##### `impl IntoValue<T>`
///
/// Accepts any value that can be converted [`IntoValue<T>`] that does not change, usually the property
/// defines the `T`, but it can be generic. The input kind is [`InputKind::Value`]. No auto-default is generated for this type.
///
/// The input can be read in `when` expressions, but cannot be assigned in `when` blocks.
///
/// ##### `impl UiNode`
///
/// This input accepts another [`UiNode`], the implementation must handle it like it handles the child node, delegating all methods. The
/// input kind is [`InputKind::UiNode`]. The [`NilUiNode`] is used as the default value if no other is provided.
///
/// The input cannot be read in `when` expressions, but can be assigned in `when` blocks.
///
/// ##### `impl UiNodeList`
///
/// This input accepts an [`UiNodeList`], the implementation must handle it like it handles the child node, delegating all methods. The
/// input kind is [`InputKind::UiNodeList`]. An empty list is used as the default value if no other is provided.
///
/// The input cannot be read in `when` expressions, but can be assigned in `when` blocks.
///
/// ##### `impl WidgetHandler<A>`
///
/// This input accepts any [`WidgetHandler<A>`] for the argument type `A`, usually the property defines the `A`, but it can be generic.
/// The input kind is [`InputKind::WidgetHandler`]. A no-op handler is used for the default if no other is provided.
///
/// Event handler properties usually have the `on_` name prefix. You can use the [`event_property!`] macro to generate standard event properties.
///
/// The input cannot be read in `when` expressions, but can be assigned in `when` blocks.
///
/// # Getter Properties
///
/// Most properties with var inputs are *setters*, that is the inputs affect the widget. Some properties
/// can be *getters*, detecting widget state and setting it on the *input* variable. These properties are usually named with
/// a prefix that indicates their input is actually for getting state, the prefixes `is_` and `has_` mark a property with
/// a single `bool` input that reads a widget state, the prefix `get_` and `actual_` marks a property that reads a non-boolean state from
/// the widget.
///
/// Getter properties are configured with a default read-write variable, so that they can be used in `when` expressions directly,
/// for example, `when *#is_pressed`, the `is_pressed` property has a `default(var(false))`, so it automatically initializes
/// with a read-write variable that is used in the when condition. The property attribute generates defaults automatically
/// based on the prefix, the default is `var(T::default())`, this can be overwritten just by setting the default,
/// it is not possible to declare a getter property without default.
///
/// Note that if a property is used in `when` condition without being set and without default value the when block is discarded on
/// 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())`.
///
/// # Generics
///
/// Apart from the `impl` generics of inputs and child, there is some support for named generic types, only one named generic is allowed
/// for inputs `impl IntoVar<T>`, `impl IntoValue<T>` and `impl WidgetHandler<A>`.
///
/// # Output
///
/// The property output type must be any type that implements [`UiNode`], usually an opaque type `impl UiNode` is used. The property
/// node can be anything, as long as it delegates to the child node, see [`match_node`] or [`ui_node`] about implementing a node.
///
/// Some common property patterns have helper functions, for example, to setup a context var you can use the [`with_context_var`] function.
///
/// # More Details
///
/// See [`property_id!`] and [`property_args!`] for more details about what kind of meta-code is generated for properties.
///
/// [`NestGroup`]: crate::widget::builder::NestGroup
/// [`property_id!`]: crate::widget::builder::property_id
/// [`property_args!`]: crate::widget::builder::property_args
/// [`ui_node`]: macro@ui_node
/// [`match_node`]: crate::widget::node::match_node
/// [`with_context_var`]: crate::widget::node::with_context_var
/// [`VarValue`]: crate::var::VarValue
/// [`IntoValue<T>`]: crate::var::IntoValue
/// [`IntoVar<T>`]: crate::var::IntoVar
/// [`WidgetHandler<A>`]: crate::handler::WidgetHandler
/// [`UiNode`]: crate::widget::node::UiNode
/// [`UiNodeList`]: crate::widget::node::UiNodeList
/// [`NilUiNode`]: crate::widget::node::NilUiNode
/// [`InputKind::Var`]: crate::widget::builder::InputKind::Var
/// [`InputKind::Value`]: crate::widget::builder::InputKind::Value
/// [`InputKind::UiNode`]: crate::widget::builder::InputKind::UiNode
/// [`InputKind::UiNodeList`]: crate::widget::builder::InputKind::UiNodeList
/// [`InputKind::WidgetHandler`]: crate::widget::builder::InputKind::WidgetHandler
/// [`event_property!`]: crate::event::event_property
///
/// <script>
/// // hide re-exported docs
/// let me = document.currentScript;
/// document.addEventListener("DOMContentLoaded", function() {
///     while(me.nextElementSibling !== null) {
///         me.nextElementSibling.remove();
///     }
/// });
/// </script>
pub use zng_app::widget::property;

/// Expands an impl block into an [`UiNode`] trait implementation.
///
/// Missing [`UiNode`] methods are generated by this macro. The generation is configured in the macro arguments.
/// The arguments can be a single keyword, a delegate or an entire struct declaration.
///
/// The general idea is you implement only the methods required by your node and configure this macro to generate the methods
/// that are just boilerplate UI tree propagation, and in [new node](#new-node) mode var and event handlers can be inited automatically
/// as well.
///
/// # Delegate to single `impl UiNode`
///
/// If your node contains a single child node, you can configure the attribute
/// to delegate the method calls for the child node.
///
/// ```
/// # fn main() { }
/// use zng::prelude_wgt::*;
///
/// struct MyNode<C> {
///     child: C
/// }
/// #[ui_node(delegate = &mut self.child)]
/// impl<C: UiNode> UiNode for MyNode<C> { }
/// ```
///
/// If the child node is in a field named `child` you can use this shorthand to the same effect:
///
/// ```
/// # fn main() { }
/// # use zng::prelude_wgt::*;
/// # struct MyNode<C> { child: C }
/// #[ui_node(child)]
/// impl<C: UiNode> UiNode for MyNode<C> { }
/// ```
///
/// The generated code simply calls the same [`UiNode`] method in the child.
///
/// # Delegate to a `impl UiNodeList`
///
/// If your node contains multiple children nodes in a type that implements [`UiNodeList`],
/// you can configure the attribute to delegate to the equivalent list methods.
///
/// ```
/// # fn main() { }
/// use zng::prelude_wgt::*;
///
/// struct MyNode<L> {
///     children: L
/// }
/// #[ui_node(delegate_list = &mut self.children)]
/// impl<L: UiNodeList> UiNode for MyNode<L> { }
/// ```
///
/// If the children list is a member named `children` you can use this shorthand to the same effect:
///
/// ```
/// # fn main() { }
/// # use zng::prelude_wgt::*;
/// # struct MyNode<L> { children: L }
/// #[ui_node(children)]
/// impl<L: UiNodeList> UiNode for MyNode<L> { }
/// ```
///
/// The generated code simply calls the equivalent [`UiNodeList`] method in the list.
/// That is the same method name with the `_all` prefix. So `UiNode::init` maps to `UiNodeList::init_all` and so on.
///
/// ## Don't Delegate
///
/// If your node does not have any child nodes you can configure the attribute to generate empty missing methods.
///
/// ```
/// # fn main() { }
/// # use zng::prelude_wgt::*;
/// # struct MyNode { }
/// #[ui_node(none)]
/// impl UiNode for MyNode { }
/// ```
///
/// The generated [`measure`] and [`layout`] code returns the fill size.
///
/// The other generated methods are empty.
///
/// # Validation
///
/// If delegation is configured but no delegation occurs in the manually implemented methods
/// you get the error ``"auto impl delegates call to `{}` but this manual impl does not"``.
///
/// To disable this error use `#[allow_(zng::missing_delegate)]` in the method or in the `impl` block. The
/// error is also not shown if the method body contains a call to the [`todo!()`] macro.
///
/// The [`measure`] method is an exception to this and will not show the error, its ideal implementation
/// is one where the entire sub-tree is skipped from the computation.
///
/// # Mixing Methods
///
/// You can use the same `impl` block to define [`UiNode`] methods and
/// associated methods by using this attribute in a `impl` block without trait. The [`UiNode`]
/// methods must be tagged with the `#[UiNode]` pseudo-attribute.
///
/// ```
/// # fn main() { }
/// # use zng::prelude_wgt::*;
/// # struct MyNode { child: BoxedUiNode }
/// #[ui_node(child)]
/// impl MyNode {
///     fn do_the_thing(&mut self) {
///         // ..
///     }
///
///     #[UiNode]
///     fn init(&mut self) {
///         self.child.init();
///         self.do_the_thing();
///     }
///
///     #[UiNode]
///     fn update(&mut self, updates: &WidgetUpdates) {
///         self.child.update(updates);
///         self.do_the_thing();
///     }
/// }
/// ```
///
/// The above code expands to two `impl` blocks, one with the associated method and the other with
/// the [`UiNode`] implementation.
///
/// This is particularly useful for nodes that have a large amount of generic constraints, you just type them once.
///
/// # New Node
///
/// In all the usage seen so far you must declare the `struct` type and the generic bounds to
/// make it work in the `impl` block, and any var or event in it needs to be subscribed manually. You can
/// avoid this extra boilerplate by declaring the node `struct` as an arg for the macro.
///
/// ```
/// # fn main() { }
/// # use zng::prelude_wgt::*;
/// fn my_widget_node(child: impl UiNode, number: impl IntoVar<u32>) -> impl UiNode {
///     #[ui_node(struct MyNode {
///         child: impl UiNode,
///         #[var] number: impl Var<u32>,
///     })]
///     impl UiNode for MyNode {
///         fn update(&mut self, updates: &WidgetUpdates) {
///             self.child.update(updates);
///             if let Some(n) = self.number.get_new() {
///                 println!("new number: {n}");
///             }
///         }
///     }
///     MyNode {
///         child,
///         number: number.into_var(),
///     }
/// }
/// ```
///
/// In the example above the `MyNode` struct is declared with two generic params: `T_child` and `T_var`, the unimplemented
/// node methods are delegated to `child` because of the name, and the `number` var is subscribed automatically because of
/// the `#[var]` pseudo attribute.
///
/// Note that you can also use [`node::match_node`] to declare *anonymous* nodes, most of the properties are implemented using
/// this node instead of the `#[ui_node]` macro.
///
/// #### Generics
///
/// You can declare named generics in the `struct`, those are copied to the implement block, you can also have members with type
/// `impl Trait`, a named generic is generated for these, the generated name is `T_member`. You can use named generics in the `impl`
/// generics the same way as you would in a function.
///
/// #### Impl Block
///
/// The impl block cannot have any generics, they are added automatically, the `UiNode for` part is optional, like in the delegating
/// mode, if you omit the trait you must annotate each node method with the `#[UiNode]` pseudo attribute.
///
/// #### Delegation
///
/// Delegation is limited to members named `child` or `children`, there is no way to declare a custom delegation in *new node*
/// mode. If no specially named member is present the `none` delegation is used.
///
/// #### Subscription
///
/// You can mark members with the `#[var]` or `#[event]` pseudo attributes to generate initialization code that subscribes the var or
/// event to the [`WIDGET`] context. The init code is placed in a method with signature `fn auto_subs(&mut self)`,
/// if you manually implement the `init` node method you must call `self.auto_subs();` in it, a compile time error is emitted if the call is missing.
///
/// #### Limitations
///
/// The new node type must be private, you cannot set visibility modifiers. The struct cannot have any attribute set on it, but you can
/// have attributes in members, the `#[cfg]` attribute is copied to generated generics. The `impl Trait` auto-generics only works for
/// the entire type of a generic, you cannot declare a type `Vec<impl Debug>` for example.
///
/// [`UiNode`]: crate::widget::node::UiNode
/// [`UiNodeList`]: crate::widget::node::UiNodeList
/// [`measure`]: crate::widget::node::UiNode::measure
/// [`layout`]: crate::widget::node::UiNode::layout
/// [`render`]: crate::widget::node::UiNode::render
/// [`WIDGET`]: crate::widget::WIDGET
///
/// <script>
/// // hide re-exported docs
/// let me = document.currentScript;
/// document.addEventListener("DOMContentLoaded", function() {
///     while(me.nextElementSibling !== null) {
///         me.nextElementSibling.remove();
///     }
/// });
/// </script>
pub use zng_app::widget::ui_node;