Skip to main content

PerfOverlay

Struct PerfOverlay 

Source
pub struct PerfOverlay<'a, const N: usize = 120> { /* private fields */ }
Expand description

A bordered panel showing live FrameStats.

An NNNfps MM.Mms minMM.M maxMM.M <backend> readout, any extra caller-supplied metric rows (VSync state, resolution, render backend details, …), and a scrolling frame-time Sparkline.

The richer counterpart to DefaultPerfRenderer: composed entirely from existing widgets (Panel, Text, Sparkline), it draws through Surface like every other widget in this crate, so it already works on every backend. Hand it to PerfOverlayApp::with_closure as a closure to use it instead of the built-in renderer:

use retroglyph_core::app::{App, Flow, Frame};
use retroglyph_core::backend::{Backend, Headless};
use retroglyph_core::grid::Size;
use retroglyph_core::terminal::Terminal;
use retroglyph_ui::{PerfOverlay, PerfOverlayApp, Widget};

struct MyGame;
impl<B: Backend> App<B> for MyGame {
    fn update(&mut self, _term: &mut Terminal<B>, frame: &Frame) -> Flow {
        if frame.frame >= 1 { Flow::Exit } else { Flow::Continue }
    }
}

let term = Terminal::new(Headless::new(60, 12));
let app = PerfOverlayApp::with_closure(MyGame, "software", |stats, backend, area, surface| {
    PerfOverlay::new(stats)
        .backend(backend)
        .metrics(&[("res", "1920x1080"), ("vsync", "on")])
        .render(&mut surface.scope(area));
})
.size(Size::new(34, 8));
retroglyph_core::app::run_blocking(term, app).expect("run_blocking");

N must match the FrameStats window it’s built from; this crate’s PerfOverlayApp always uses 120 samples (FRAME_HISTORY), the default here too.

§As an AnimatedWidget

This type is read-only: it borrows an already-updated FrameStats (new(stats)), which is exactly what Widget rendering wants but is the wrong shape for AnimatedWidget, whose state: &mut FrameStats argument needs to record into the same data a draw call reads – an immutable borrow baked into self and a mutable one for state can’t coexist. Use AnimatedPerfOverlay instead for a call site that owns one FrameStats field and wants to record and draw in a single call, with no PerfOverlayApp decorator wrapping the app.

Rows beyond the panel’s available interior height are silently dropped: the readout row draws first, then one row per metrics entry, then the sparkline, each only if there’s still room, so a caller that under-sizes the area loses the least important rows first rather than panicking or overflowing the border.

Implementations§

Source§

impl<'a, const N: usize> PerfOverlay<'a, N>

Source

pub fn new(stats: &'a FrameStats<N>) -> Self

A perf overlay reading stats, titled "perf", with no backend label and no extra metrics, styled from Theme::DARK (as if PerfOverlay::theme had been called).

Source

pub const fn backend(self, backend: &'a str) -> Self

Sets the backend label appended to the readout row (e.g. "crossterm", "software"). Omitted entirely if left empty (the default).

Source

pub const fn title(self, title: &'a str) -> Self

Sets the panel’s title. Defaults to "perf".

Source

pub const fn metrics(self, metrics: &'a [(&'a str, &'a str)]) -> Self

Sets extra (label, value) metric rows drawn below the readout: resolution, VSync state, render backend details, or anything else an app wants visible. Defaults to none.

Source

pub const fn text_style(self, style: Style) -> Self

Sets the readout/metric text’s style. Defaults to Theme::DARK’s fg role.

Source

pub const fn sparkline_style(self, style: Style) -> Self

Sets the frame-time sparkline’s bar color (every bar, uniformly; see Sparkline::style).

Defaults to a fixed accent color, not Sparkline’s own green-to-red ramp: the sparkline scrolls, so “tallest bar in the visible window” isn’t the same thing as “a slow frame”: the same absolute frame time reads as short one moment and tall the next as the window’s own max shifts. A ramp keyed to that relative height would tell a story the data doesn’t support; one fixed color makes height the only signal, which is the honest one.

Source

pub fn theme(self, theme: Theme) -> Self

Applies theme’s named roles: border_style/fill_style map the same way as Panel::theme, and text_style becomes theme.fg on theme.panel_bg.

Call before any manual style override you want to keep.

Trait Implementations§

Source§

impl<'a, const N: usize> Clone for PerfOverlay<'a, N>

Source§

fn clone(&self) -> PerfOverlay<'a, N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, const N: usize> Debug for PerfOverlay<'a, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Widget for PerfOverlay<'_, N>

Source§

fn render(&self, surface: &mut Surface<'_>)

Draw this widget into surface, filling surface.area(). Read more
Source§

impl<'a, const N: usize> Copy for PerfOverlay<'a, N>

Auto Trait Implementations§

§

impl<'a, const N: usize> Freeze for PerfOverlay<'a, N>

§

impl<'a, const N: usize> RefUnwindSafe for PerfOverlay<'a, N>

§

impl<'a, const N: usize> Send for PerfOverlay<'a, N>

§

impl<'a, const N: usize> Sync for PerfOverlay<'a, N>

§

impl<'a, const N: usize> Unpin for PerfOverlay<'a, N>

§

impl<'a, const N: usize> UnsafeUnpin for PerfOverlay<'a, N>

§

impl<'a, const N: usize> UnwindSafe for PerfOverlay<'a, N>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<C> WithAlpha for C
where C: Copy,

§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see [AlphaFirst]).
§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see [AlphaLast]).