zng_wgt_inspector/
lib.rs

1#![doc(html_favicon_url = "https://zng-ui.github.io/res/zng-logo-icon.png")]
2#![doc(html_logo_url = "https://zng-ui.github.io/res/zng-logo.png")]
3//!
4//! Inspector, debug crash handler and debug properties.
5//!
6//! # Crate
7//!
8#![doc = include_str!(concat!("../", std::env!("CARGO_PKG_README")))]
9#![warn(unused_extern_crates)]
10#![warn(missing_docs)]
11
12zng_wgt::enable_widget_macros!();
13
14use zng_wgt::{ICONS, prelude::*};
15
16pub mod crash_handler;
17pub mod debug;
18
19mod live;
20
21#[cfg(feature = "live")]
22pub use crate::live::data_model::{INSPECTOR, InspectedInfo, InspectedTree, InspectedWidget, InspectorWatcherBuilder, WeakInspectedTree};
23
24command! {
25    /// Represent the window **inspect** action.
26    pub static INSPECT_CMD = {
27        l10n!: "inspector",
28        name: "Debug Inspector",
29        info: "Inspect the window",
30        shortcut: [shortcut!(CTRL | SHIFT + 'I'), shortcut!(F12)],
31        icon: wgt_fn!(|_| ICONS.get(["inspector", "screen-search-desktop"])),
32    };
33}
34
35/// Setup the inspector for the window.
36#[property(WIDGET)]
37pub fn inspector(child: impl IntoUiNode, inspector: impl IntoUiNode) -> UiNode {
38    match_node(ui_vec![child, inspector], move |c, op| match op {
39        UiNodeOp::Measure { wm, desired_size } => {
40            c.delegated();
41            let children = c.node_impl::<UiVec>();
42            *desired_size = children[0].measure(wm);
43            LAYOUT.with_constraints(PxConstraints2d::new_exact_size(*desired_size), || {
44                let _ = children[1].measure(wm);
45            });
46        }
47        UiNodeOp::Layout { wl, final_size } => {
48            c.delegated();
49            let children = c.node_impl::<UiVec>();
50            *final_size = children[0].layout(wl);
51            LAYOUT.with_constraints(PxConstraints2d::new_exact_size(*final_size), || {
52                let _ = children[1].layout(wl);
53            });
54        }
55        _ => {}
56    })
57}
58
59#[cfg(feature = "live")]
60/// Live interactive inspector.
61///
62/// Can be set on a window using the [`inspector`](fn@inspector) property.
63/// Note that the main `APP.defaults()` already sets this for all windows when
64/// the `"inspector"` feature is enabled.
65pub fn live_inspector(can_inspect: impl IntoVar<bool>) -> UiNode {
66    live::inspect_node(can_inspect)
67}