nadir-debug
Developer tools for Nadir: an immediate-mode debug UI of windows and widgets, drawn with the engine's own renderer and bitmap font, and fed by the window's events.
It is part of Nadir, a 2D engine for
top-down games on Windows, macOS and Linux, written in Rust with no
third-party crates. Games use it through
nadir_engine's dev feature,
which re-exports it as nadir::debug, feeds it the window's events, draws
it over the game, holds the game's input off while it has the pointer or
the keyboard, and saves its windows' places; depend on it directly to use
it on its own. It is for development builds: keep it out of releases.
Status
Version 0.4: the API will change before 1.0.
Built:
- windows that drag by their title bar, collapse, resize from a grip, scroll by the wheel or a thumb, and come to the front when pressed;
- labels, buttons, checkboxes, sliders, drags, a one-line text field, combo boxes, tree nodes, separators, line plots and color edits;
- identity by text, or by an explicit ID after
##; - what the game should leave alone: the pointer over a window or a widget held, and the keyboard while a text field has it;
- each window's place, given and taken as data for saving;
- a stats overlay of numbers the engine copies in, and a profiler of the last 300 frames: graphs of their processor time and of the GPU's time over their drawing, a frame's scopes as a tree, and a Chrome trace of them all, with a track of the GPU's passes, which Perfetto UI opens;
- an inspector of a
nadir-ecsworld: its entities, a page at a time, filtered by number and component; the components of the one clicked, each field edited throughnadir-scene's reflection; components added and removed by name, the entity despawned, or written as a prefab; - a console: a command line, with history and Tab completion, under a log of what its commands print and the records the caller adds; commands registered by a usage that names their arguments, which it checks before handing the command back to run.
Not yet: tooltips, a scroll area inside a window, copy and paste. The
debug drawing (F4) and the time controls (F5 to F7) are nadir_engine's,
under its dev feature (ADR-0064).
Usage
[]
= "0.4"
# For `Handle`, `Rect`, `Vec2` and the mouse, and for the UI list it draws into.
= "0.4"
= "0.4"
Each frame, the UI takes the frame's events, code fills its windows with widgets, and the frame is pushed into the frame's UI list. Here a test font measures the text, and a click lands on a checkbox where the frame before drew it:
use NonZeroU32;
use ;
use ;
use UiList;
/// A font of 8 units a line, each character 6 wide.
;
// The font and the white texture are the game's loaded assets; here, two
// handles that name nothing.
let mut ui = new;
let mut input = new;
let mut out = new;
let output = new;
let mut paused = false;
for _ in 0..2
assert!;
// The pointer is over the window: the game should leave the mouse alone.
assert!;
assert!;
A console hands back the command a line names, with its arguments checked
against its usage, for the caller to run; Console::show fills a window
with it, and Enter runs the line typed:
use ;
let mut console = new;
console
.register
.expect;
let mut player = ;
console.run_line;
assert_eq!;
// A line that does not fit the usage does not run.
console.run_line;
let lines: = console.lines.collect;
assert_eq!;
Documentation
- API reference: https://docs.rs/nadir-debug
- Design: https://github.com/jabbott-iii/Nadir/blob/main/docs/subsystems/debug-tools.md
- The engine: https://github.com/jabbott-iii/Nadir