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
#![doc(html_favicon_url = "https://raw.githubusercontent.com/zng-ui/zng/main/examples/image/res/zng-logo-icon.png")]
#![doc(html_logo_url = "https://raw.githubusercontent.com/zng-ui/zng/main/examples/image/res/zng-logo.png")]
//!
//! Inspector, debug crash handler and debug properties.
//!
//! # Crate
//!
#![doc = include_str!(concat!("../", std::env!("CARGO_PKG_README")))]
#![warn(unused_extern_crates)]
#![warn(missing_docs)]

zng_wgt::enable_widget_macros!();

use zng_wgt::{prelude::*, ICONS};

pub mod crash_handler;
pub mod debug;

#[cfg(feature = "live")]
mod live;

command! {
    /// Represent the window **inspect** action.
    pub static INSPECT_CMD = {
        l10n!: "inspector",
        name: "Debug Inspector",
        info: "Inspect the window",
        shortcut: [shortcut!(CTRL|SHIFT+'I'), shortcut!(F12)],
        icon: wgt_fn!(|_| ICONS.get(["inspector", "screen-search-desktop"])),
    };
}

/// Setup the inspector for the window.
#[property(WIDGET)]
pub fn inspector(child: impl UiNode, mut inspector: impl UiNode) -> impl UiNode {
    match_node(child, move |c, op| match op {
        UiNodeOp::Measure { wm, desired_size } => {
            *desired_size = c.measure(wm);
            LAYOUT.with_constraints(PxConstraints2d::new_exact_size(*desired_size), || {
                let _ = inspector.measure(wm);
            });
        }
        UiNodeOp::Layout { wl, final_size } => {
            *final_size = c.layout(wl);
            LAYOUT.with_constraints(PxConstraints2d::new_exact_size(*final_size), || {
                let _ = inspector.layout(wl);
            });
        }
        mut op => {
            c.op(op.reborrow());
            inspector.op(op);
        }
    })
}

#[cfg(feature = "live")]
/// Live interactive inspector.
///
/// Can be set on a window using the [`inspector`](fn@inspector) property.
/// Note that the main `APP.defaults()` already sets this for all windows when
/// the `"inspector"` feature is enabled.
pub fn live_inspector(can_inspect: impl IntoVar<bool>) -> impl UiNode {
    live::inspect_node(can_inspect)
}