pub struct PerfOverlayApp<A, R = DefaultPerfRenderer> { /* private fields */ }Expand description
Wraps an App with a toggleable perf overlay. See the module docs.
Implementations§
Source§impl<A> PerfOverlayApp<A, DefaultPerfRenderer>
impl<A> PerfOverlayApp<A, DefaultPerfRenderer>
Sourcepub fn new(inner: A, backend: &'static str) -> Self
pub fn new(inner: A, backend: &'static str) -> Self
Wraps inner, drawing with DefaultPerfRenderer. backend is a short label (e.g.
"crossterm", "software", "gl") shown in the readout; there is no portable way to ask
a Backend what to call itself, so every caller supplies it directly.
Source§impl<A, F> PerfOverlayApp<A, F>
impl<A, F> PerfOverlayApp<A, F>
Sourcepub fn with_closure(inner: A, backend: &'static str, renderer: F) -> Self
pub fn with_closure(inner: A, backend: &'static str, renderer: F) -> Self
Wraps inner, drawing with a plain closure instead of DefaultPerfRenderer.
Prefer this over with_renderer for a closure: writing the bound
directly as FnMut(...) here (rather than the PerfRenderer trait with_renderer
takes) is what lets Rust infer a bare closure’s parameter types from context, the same way
it does for any other Fn-bounded API: a closure passed to with_renderer needs its
parameters annotated by hand, or type inference has nothing to pin them down to.
Source§impl<A, R: PerfRenderer> PerfOverlayApp<A, R>
impl<A, R: PerfRenderer> PerfOverlayApp<A, R>
Sourcepub fn with_renderer(inner: A, backend: &'static str, renderer: R) -> Self
pub fn with_renderer(inner: A, backend: &'static str, renderer: R) -> Self
Wraps inner, drawing with a custom PerfRenderer instead of DefaultPerfRenderer.
This constructor is for a named type that implements PerfRenderer directly (there is no
stable way for a plain struct to implement FnMut itself, which is why the trait exists
at all: see the module docs). See PerfOverlayApp::with_closure for why a bare
closure should go through that constructor instead.
Defaults: visible, DEFAULT_LAYER, a 64x1 area (wide enough for
DefaultPerfRenderer’s single-row readout with a short backend label), and
default_is_toggle_key; override any of these with the chainable methods below before
the wrapped app first runs.
Sourcepub fn cycle_with<F>(self, size: Size, renderer: F) -> Self
pub fn cycle_with<F>(self, size: Size, renderer: F) -> Self
Registers a second, richer PerfRenderer (a plain closure works, the same way
with_closure does for the primary one) at PerfOverlayMode::Full,
size columns by rows, and makes it reachable: the toggle key now cycles Off -> Compact -> Full -> Off instead of just Off -> Compact -> Off.
A natural pairing is DefaultPerfRenderer (or a closure) at
Compact and PerfOverlay (a bordered
panel with a frame-time sparkline) at Full; see the module docs.
Sourcepub const fn visible(self, visible: bool) -> Self
pub const fn visible(self, visible: bool) -> Self
Sets whether the overlay starts visible: true starts at PerfOverlayMode::Compact,
false at PerfOverlayMode::Off. Defaults to true; the toggle key cycles through
every registered mode at runtime regardless; see set_mode to start
directly at PerfOverlayMode::Full instead.
Sourcepub const fn layer(self, layer: u8) -> Self
pub const fn layer(self, layer: u8) -> Self
Sets which grid layer the overlay draws on. Defaults to
DEFAULT_LAYER; raise it if the wrapped app’s own content already
reaches that layer.
Sourcepub const fn size(self, size: Size) -> Self
pub const fn size(self, size: Size) -> Self
Sets Compact’s area size, placed flush against the
top-right corner of the terminal (clamped to its actual size). Defaults to 64x1, sized
for DefaultPerfRenderer’s single-row readout; a custom PerfRenderer that draws a
panel or a sparkline at Compact needs a taller (and often wider) area: size it to fit,
or register it as the richer Full mode via
cycle_with instead, which takes its own size.
Sourcepub const fn toggle_key(self, matches: fn(&Event) -> bool) -> Self
pub const fn toggle_key(self, matches: fn(&Event) -> bool) -> Self
Overrides which events toggle the overlay’s visibility. Defaults to
default_is_toggle_key.
Sourcepub const fn stats(&self) -> &FrameStats<FRAME_HISTORY>
pub const fn stats(&self) -> &FrameStats<FRAME_HISTORY>
The frame-time statistics fed by every update call so far.
Sourcepub const fn is_visible(&self) -> bool
pub const fn is_visible(&self) -> bool
Sourcepub const fn mode(&self) -> PerfOverlayMode
pub const fn mode(&self) -> PerfOverlayMode
The overlay’s current PerfOverlayMode.
Sourcepub const fn set_mode(&mut self, mode: PerfOverlayMode)
pub const fn set_mode(&mut self, mode: PerfOverlayMode)
Sets the overlay’s PerfOverlayMode directly: the one way to mutate visibility at
runtime, including reaching Full directly rather than only
through toggle’s cycle. Setting Full without a renderer registered via
cycle_with is accepted but renders nothing (the same as Off) until
one is.
Sourcepub const fn toggle(&mut self)
pub const fn toggle(&mut self)
Advances to the next PerfOverlayMode in the cycle (Off -> Compact -> Full -> Off,
skipping Full if nothing was registered via cycle_with). The same
effect the toggle key has.
Sourcepub fn into_inner(self) -> A
pub fn into_inner(self) -> A
Unwraps this overlay, discarding its accumulated FrameStats and returning the wrapped
app.