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
// Copyright 2026 Joseph Anthony Abbott III
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Developer tools for the Nadir engine: an immediate-mode debug UI, a
//! stats overlay ([`Stats`]), a profiler with Chrome trace export
//! ([`Profiler`]), an inspector of the world's entities ([`Inspector`]) and
//! a console of commands ([`Console`]). The debug drawing and the time
//! controls are the engine's, in nadir_engine's `dev` (roadmap M7.6).
//! They are for development builds only: a
//! game depends on this crate behind its `dev` feature, and
//! `cargo xtask release-no-dev` checks that a release does not.
//!
//! # The debug UI
//!
//! A [`DebugUi`] keeps what lasts from frame to frame. Each frame,
//! [`DebugUi::frame`] takes that frame's events from a [`DebugInput`], code
//! fills windows with [`Frame::window`] and their widgets through a
//! [`Ui`], each widget answering what was done to it (a [`Response`]), and
//! [`Frame::finish`] pushes what they draw into the frame's
//! `RenderFrame::ui`, after the game's UI and in front of it.
//!
//! - **Input:** the engine feeds a [`DebugInput`] with the window's events
//! (nadir_engine's `dev`); a test feeds it its own. A frame takes at most one
//! press and one release of the left button, so that a click is judged
//! where it was pressed and where it was released.
//! - **Identity:** a widget is the hash of its scope's identity and its
//! text, or its explicit ID after `##`: `"Pause (3)##pause"`.
//! - **Hot and active:** the widget under the pointer is hot; the one the
//! button went down on is active until it goes up, and a click is a
//! release over the widget that was pressed.
//! - **Capture:** [`DebugUi::wants_mouse`] and [`DebugUi::wants_keyboard`]
//! tell the game to leave the mouse or the keys alone, and
//! [`DebugUi::is_over`] whether a point is over a window.
//! - **Places:** each window's place is kept as data
//! ([`DebugUi::places`], [`DebugUi::set_place`]); the engine saves it.
//! - **Text:** measured by [`TextMetrics`]: [`FontMetrics`] for a `Font`.
//!
//! # The tools
//!
//! Each fills a window it is given. [`Stats::show`] shows the last frame's
//! numbers, which the engine copies in. A [`Profiler`] keeps the last
//! [`PROFILER_FRAMES`] frames, each with the scopes
//! `nadir_core::profile::take_frame` collected, and the GPU's time over
//! its drawing once the engine reads it back ([`GpuTiming`],
//! [`Profiler::set_gpu`]): [`Profiler::show`] draws their processor and GPU
//! times as graphs and the scopes of the frame clicked as a tree, and
//! [`Profiler::trace_json`] writes them as Chrome trace event JSON, with a
//! track of the GPU's passes, which Perfetto UI opens. An [`Inspector`]
//! lists a `nadir-ecs` world's entities and edits the components of the one
//! clicked, by the types of the world's `nadir-scene` `TypeRegistry`,
//! through their reflection: [`Inspector::show`] fills its window, and
//! [`Inspector::prefab`] writes the entity as a prefab when its
//! [`InspectorResponse`] asks. A [`Console`] is a command line over a log:
//! commands registered by their usage, a line checked against it and handed
//! back with its [`Args`] to run ([`Console::show`], [`Console::run_line`]),
//! with history and Tab completion, and the engine's log records added by
//! the caller ([`Console::log_record`]).
//!
//! ```
//! use nadir_core::{GenIndex, Handle, Key, MouseButton, Rect, UVec2, Vec2};
//! use nadir_debug::{DebugInput, DebugUi, TextMetrics};
//! use nadir_render::UiList;
//!
//! /// A font of 8 units a line, each character 6 wide.
//! struct Mono;
//! impl TextMetrics for Mono {
//! fn line_height(&self) -> f32 {
//! 8.0
//! }
//! fn caret_x(&self, text: &str, byte: usize) -> f32 {
//! 6.0 * text[..byte].chars().count() as f32
//! }
//! }
//!
//! fn handle<T>(index: u32) -> Handle<T> {
//! Handle::new(GenIndex::new(index, std::num::NonZeroU32::MIN))
//! }
//! let mut ui = DebugUi::new(handle(0), Mono, handle(1));
//! let mut input = DebugInput::new();
//! let mut paused = false;
//! let mut name = String::from("hero");
//! let mut renamed = false;
//! let mut out = UiList::new();
//! let output = UVec2::new(640, 360);
//! for _ in 0..2 {
//! // A click on the checkbox, in the second frame, where the first drew it.
//! let mut frame = ui.frame(&mut input, output, output);
//! frame.window("Tools", Rect::new(Vec2::ZERO, Vec2::new(200.0, 120.0)), |ui| {
//! ui.checkbox("Paused", &mut paused);
//! // Enter in the field, once it has the keyboard.
//! renamed |= ui.text_input("Name", &mut name).submitted;
//! });
//! frame.finish(&mut out);
//! input.pointer_moved(Vec2::new(8.0, 18.0));
//! input.button(MouseButton::Left, true);
//! input.button(MouseButton::Left, false);
//! }
//! assert!(paused && !renamed);
//! assert!(!ui.wants_keyboard());
//! # let _ = Key::Enter;
//! ```
// The README's examples are compiled as doc tests too.
;
pub use ;
pub use DebugInput;
pub use ;
pub use ;
pub use ;
pub use Stats;
pub use Style;
pub use ;
pub use ;