cotis_modules_debug/lib.rs
1//! Record, replay, and isolate Cotis modules for debugging layout, UI declaration, and
2//! render pipelines.
3//!
4//! Cotis builds native UIs through a modular pipeline: UI code declares an element tree,
5//! a layout manager computes geometry, and a renderer draws the result. Running the full
6//! app stack for every investigation is slow. This crate captures intermediate artifacts
7//! as JSON so you can replay individual stages in isolation.
8//!
9//! # Three-stage debug pipeline
10//!
11//! ```text
12//! Stage 1 — Record (live app + debug wrappers)
13//! UI uses DebugInitialConfiguredParentElement / DebugOpenElement / ...
14//! → LeafedInterfaceDeclaration → interface_*.json
15//! LayoutModuleCapture wraps a LayoutManager
16//! → store_computed_layout → elements_*.json
17//!
18//! Stage 2 — Replay UI declaration (layout only, normal app)
19//! LeafedInterfaceDeclaration::load_from(...)
20//! → implements UiFn → rebuilds element tree without debug wrappers
21//!
22//! Stage 3 — Render-only (skip layout entirely)
23//! load_computed_layout(...)
24//! → CotisLayoutToRenderListPipeForGenerics::transform
25//! → renderer.draw_frame(...)
26//! ```
27//!
28//! See the `gradients_example_solid`, `gradients_example_solid_replay`, and
29//! `gradients_example_solid_render_only` examples for a complete walkthrough.
30//!
31//! # Serialization requirements
32//!
33//! This crate always depends on [`cotis`] with the `serialization` feature. Consumers must
34//! also enable serialization on the types they capture:
35//!
36//! | Stage | Serialized data | Required features / bounds |
37//! |-------|-----------------|----------------------------|
38//! | 1 — Record UI | `ConfigType`, leaf configs | `cotis/serialization`; leaf types: [`Serialize`] |
39//! | 1 — Record layout | `Vec<ElementsOutput>` | `cotis-layout/serialization` |
40//! | 2 — Replay UI | `ConfigType` + [`LeafConfigList`](serialize_targets::leaf_serialization::LeafConfigList) | `ConfigType: DeserializeOwned` |
41//! | 3 — Render-only | e.g. `RenderCommandOutput` from `cotis-layout` | `cotis-layout/serialization` |
42//!
43//! [`ElementsOutput`] must implement [`Serialize`] + [`DeserializeOwned`] for file I/O helpers
44//! in [`layout_module_debugger`].
45//!
46//! # Quick start
47//!
48//! **Record pass:**
49//!
50//! ```rust,ignore
51//! use cotis_modules_debug::declaration_debugger::debug_element_configuring::DebugInitialConfiguredParentElement;
52//! use cotis_modules_debug::layout_module_debugger::capture::LayoutModuleCapture;
53//! use cotis_modules_debug::layout_module_debugger::store_computed_layout;
54//! use cotis_modules_debug::serialize_targets::{LeafedInterfaceDeclaration, SerializedInterfaceDeclaration};
55//! use cotis_modules_debug::serialize_targets::leaf_serialization::{LeafConfigList, LeafConfigListNil};
56//!
57//! type Leafs = LeafConfigList<TextElementConfig<'static>, LeafConfigListNil>;
58//! let mut decl = LeafedInterfaceDeclaration::new(SerializedInterfaceDeclaration::new(), Leafs::new());
59//! // Wrap layout root: DebugInitialConfiguredParentElement::new(layout, &mut decl)
60//! // ... build UI ...
61//! decl.store_in(path)?;
62//! store_computed_layout(app.layout_manager().output(), path)?;
63//! ```
64//!
65//! **Replay pass (stage 2):**
66//!
67//! ```rust,ignore
68//! let decl = LeafedInterfaceDeclaration::load_from(path, Leafs::new())?;
69//! // compute_frame(&mut app, &decl) — decl implements UiFn
70//! ```
71//!
72//! **Render-only (stage 3):**
73//!
74//! ```rust,ignore
75//! use cotis_layout::layout_struct::RenderCommandOutput;
76//! use cotis_pipes::cotis_layout_pipes::CotisLayoutToRenderListPipeForGenerics;
77//!
78//! let output = load_computed_layout::<RenderCommandOutput<ExampleConfig>>(path)?;
79//! let cmds: Vec<_> = pipe.transform(output.into_iter()).collect();
80//! renderer.draw_frame(cmds.into_iter());
81//! ```
82//!
83//! # Module map
84//!
85//! - [`declaration_debugger`] — debug wrappers around [`cotis::element_configuring`] that
86//! record every `open` / `configure` / `close` into a [`LeafedInterfaceDeclaration`](serialize_targets::LeafedInterfaceDeclaration).
87//! - [`serialize_targets`] — instruction-stream types, JSON persistence, and leaf-config
88//! type-list machinery for deserialization.
89//! - [`layout_module_debugger`] — capture layout output to JSON; replay declarations through
90//! a layout manager in isolation.
91//! - [`render_module_debugger`] — replay precomputed render commands through a renderer when
92//! layout-manager init side effects are needed.
93//!
94//! [`cotis`]: https://docs.rs/cotis
95//! [`Serialize`]: serde::Serialize
96//! [`DeserializeOwned`]: serde::de::DeserializeOwned
97//! [`ElementsOutput`]: cotis::layout::LayoutManager
98
99pub mod declaration_debugger;
100
101pub mod layout_module_debugger;
102
103pub mod render_module_debugger;
104
105pub mod serialize_targets;