Skip to main content

PerfOverlayApp

Struct PerfOverlayApp 

Source
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>

Source

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>
where F: FnMut(&FrameStats<FRAME_HISTORY>, &str, Rect, &mut Surface<'_>),

Source

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>

Source

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.

Source

pub fn cycle_with<F>(self, size: Size, renderer: F) -> Self
where F: FnMut(&FrameStats<FRAME_HISTORY>, &str, Rect, &mut Surface<'_>) + 'static,

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn stats(&self) -> &FrameStats<FRAME_HISTORY>

The frame-time statistics fed by every update call so far.

Source

pub const fn is_visible(&self) -> bool

Whether the overlay currently renders: true for Compact or Full, false for Off. See mode to distinguish Compact from Full.

Source

pub const fn mode(&self) -> PerfOverlayMode

The overlay’s current PerfOverlayMode.

Source

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.

Source

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.

Source

pub const fn inner(&self) -> &A

A shared reference to the wrapped app.

Source

pub const fn inner_mut(&mut self) -> &mut A

A mutable reference to the wrapped app.

Source

pub fn into_inner(self) -> A

Unwraps this overlay, discarding its accumulated FrameStats and returning the wrapped app.

Trait Implementations§

Source§

impl<B, A, R> App<B> for PerfOverlayApp<A, R>
where B: Backend, A: App<B>, R: PerfRenderer,

Source§

fn update(&mut self, term: &mut Terminal<B>, frame: &Frame) -> Flow

Advance and render one frame. Read more

Auto Trait Implementations§

§

impl<A, R> Freeze for PerfOverlayApp<A, R>
where A: Freeze, R: Freeze,

§

impl<A, R = DefaultPerfRenderer> !RefUnwindSafe for PerfOverlayApp<A, R>

§

impl<A, R = DefaultPerfRenderer> !Send for PerfOverlayApp<A, R>

§

impl<A, R = DefaultPerfRenderer> !Sync for PerfOverlayApp<A, R>

§

impl<A, R> Unpin for PerfOverlayApp<A, R>
where A: Unpin, R: Unpin,

§

impl<A, R> UnsafeUnpin for PerfOverlayApp<A, R>
where A: UnsafeUnpin, R: UnsafeUnpin,

§

impl<A, R = DefaultPerfRenderer> !UnwindSafe for PerfOverlayApp<A, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.