Skip to main content

AnimatedPerfOverlay

Struct AnimatedPerfOverlay 

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

PerfOverlay’s AnimatedWidget counterpart.

The same readout, extra metric rows, and frame-time sparkline, but reading its FrameStats from state at render time instead of borrowing one up front.

PerfOverlay::new takes stats: &'a FrameStats<N>, which Widget rendering (a pure read of already-current data) wants but AnimatedWidget::render can’t offer: its state: &mut FrameStats<N> needs to record a fresh sample into the same data a draw call then reads, and an immutable borrow baked into self can’t coexist with a mutable one passed as state in the same call. AnimatedPerfOverlay holds no stats reference of its own, only the same backend/title/metrics/style knobs PerfOverlay has, so there’s nothing to alias.

Replaces routing a Duration through PerfOverlayApp just to reach this widget: an app that owns one FrameStats field can record into it and draw in a single call, no decorator wrapping the app at all. PerfOverlayApp remains the right choice for an app that also wants its toggle-key handling, mode cycling, and event draining done generically, across any wrapped App. This is only for the (now unblocked) case that doesn’t need any of that.

§Examples

use retroglyph_core::app::{App, Flow, Frame};
use retroglyph_core::backend::{Backend, Headless};
use retroglyph_core::frames::FrameStats;
use retroglyph_core::grid::Rect;
use retroglyph_core::terminal::Terminal;
use retroglyph_ui::{AnimatedPerfOverlay, AnimatedWidget};

struct MyGame {
    stats: FrameStats,
}

impl<B: Backend> App<B> for MyGame {
    fn update(&mut self, term: &mut Terminal<B>, frame: &Frame) -> Flow {
        let area = Rect::new(0, 0, 34, 8);
        let mut surface = term.surface();
        AnimatedPerfOverlay::new()
            .backend("software")
            .render(&mut surface.scope(area), &mut self.stats, frame);
        if frame.frame >= 1 { Flow::Exit } else { Flow::Continue }
    }
}

let term = Terminal::new(Headless::new(60, 12));
let app = MyGame { stats: FrameStats::new() };
retroglyph_core::app::run_blocking(term, app).expect("run_blocking");

Implementations§

Source§

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

Source

pub fn new() -> Self

An animated perf overlay titled "perf", with no backend label and no extra metrics: the same defaults as PerfOverlay::new, styled from Theme::DARK (as if AnimatedPerfOverlay::theme had been called). N must match the FrameStats window this is driven by; the default, 120, matches PerfOverlay’s and FrameStats’s own defaults.

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Trait Implementations§

Source§

impl<const N: usize> AnimatedWidget for AnimatedPerfOverlay<'_, N>

Source§

fn render( &self, surface: &mut Surface<'_>, state: &mut Self::State, frame: &Frame, )

Records a sample into state via FrameStats::record, then draws PerfOverlay::new built from the result (plus this type’s own backend/title/metrics/style knobs), both in one call, so there’s exactly one place, not two independently ordered ones, where the stats window advances.

Source§

type State = FrameStats<N>

The externally owned, time-evolving state this widget reads and/or updates while rendering, e.g. crate::ScrollState.
Source§

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

Source§

fn clone(&self) -> AnimatedPerfOverlay<'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 AnimatedPerfOverlay<'a, N>

Source§

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

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

impl<const N: usize> Default for AnimatedPerfOverlay<'_, N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<'a, const N: usize> UnwindSafe for AnimatedPerfOverlay<'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]).