Skip to main content

Module gizmo

Module gizmo 

Source
Expand description

The debug view’s data (ADR-0085): what a screen hands in to be drawn over the running game (Gizmos, each in a Channel with a GizmoRole), one frame’s list of them (Gizmos), and which channels are on (DebugView, on Ctx::debug_view).

A screen hands its gizmos in from Screen::debug_draw, from &self and the context alone, so looking changes nothing. A channel’s helper asks Gizmos::channel_on first and skips the work when it is off:

use shuyi_ui::debug::gizmo::{Channel, Gizmo, GizmoRole, Gizmos};
use shuyi_ui::frame::Rect;

const BOXES: Channel = Channel::new("boxes", "Hit boxes");

fn boxes(hits: &[Rect], out: &mut Gizmos) {
    if !out.channel_on(BOXES) {
        return;
    }
    for &rect in hits {
        out.push(BOXES, GizmoRole::Solid, Gizmo::Rect { rect });
    }
}

let mut out = Gizmos::with_on(["boxes"]);
boxes(&[Rect::new(8, 16, 8, 8)], &mut out);
assert_eq!(out.len(), 1);
assert_eq!(out.offered(), [BOXES]);

Re-exports§

pub use crate::frame::gizmo::GizmoRole;

Structs§

Channel
A kind of thing the debug view shows, turned on and off as one from the debug menu: a stable snake_case id (grid, collision), which is what is saved, and a label for the menu.
DebugView
Which channels of the debug view are on, and which the running screens have offered (Ctx::debug_view). None is on at first. Turned on from the debug menu, which saves the choice (Ctx::set_debug_channel); a shipped build never reads or writes it.
Drawn
A gizmo handed in, with its channel and role.
Gizmos
What one frame hands in: the gizmos of the channels that are on, in the order they were pushed, and every channel offered, on or off. It knows the frame’s pixels (frame), so a helper can keep its gizmos on it.

Enums§

Gizmo
A shape the debug view draws over the frame, in console pixels, like the frame’s items. Its colour comes from its role (GizmoRole::color), never from the screen.