1use zng_app::widget::node::Z_INDEX;
23use crate::prelude::*;
45/// Defines the render order of a widget in a layout panel.
6///
7/// When set the widget will still update and layout according to their *logical* position in the list but
8/// they will render according to the order defined by the [`ZIndex`] value.
9///
10/// An error is logged on init if the widget is not a direct child of a Z-sorting panel.
11///
12/// [`ZIndex`]: zng_app::widget::node::ZIndex
13#[property(CONTEXT, default(ZIndex::DEFAULT))]
14pub fn z_index(child: impl UiNode, index: impl IntoVar<ZIndex>) -> impl UiNode {
15let index = index.into_var();
16let mut valid = false;
1718 match_node(child, move |_, op| match op {
19 UiNodeOp::Init => {
20 valid = Z_INDEX.set(index.get());
2122if valid {
23 WIDGET.sub_var(&index);
24 } else {
25tracing::error!(
26"property `z_index` set for `{}` but it is not the direct child of a Z-sorting panel",
27 WIDGET.trace_id()
28 );
29 }
30 }
31 UiNodeOp::Update { .. } => {
32if valid {
33if let Some(i) = index.get_new() {
34assert!(Z_INDEX.set(i));
35 }
36 }
37 }
38_ => {}
39 })
40}