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>
impl<'a, const N: usize> AnimatedPerfOverlay<'a, N>
Sourcepub fn new() -> Self
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.
Sourcepub const fn backend(self, backend: &'a str) -> Self
pub const fn backend(self, backend: &'a str) -> Self
See PerfOverlay::backend.
Sourcepub const fn title(self, title: &'a str) -> Self
pub const fn title(self, title: &'a str) -> Self
See PerfOverlay::title.
Sourcepub const fn metrics(self, metrics: &'a [(&'a str, &'a str)]) -> Self
pub const fn metrics(self, metrics: &'a [(&'a str, &'a str)]) -> Self
See PerfOverlay::metrics.
Sourcepub const fn text_style(self, style: Style) -> Self
pub const fn text_style(self, style: Style) -> Self
Sourcepub const fn sparkline_style(self, style: Style) -> Self
pub const fn sparkline_style(self, style: Style) -> Self
Sourcepub fn theme(self, theme: Theme) -> Self
pub fn theme(self, theme: Theme) -> Self
See PerfOverlay::theme.
Trait Implementations§
Source§impl<const N: usize> AnimatedWidget for AnimatedPerfOverlay<'_, N>
impl<const N: usize> AnimatedWidget for AnimatedPerfOverlay<'_, N>
Source§fn render(
&self,
surface: &mut Surface<'_>,
state: &mut Self::State,
frame: &Frame,
)
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>
type State = FrameStats<N>
crate::ScrollState.Source§impl<'a, const N: usize> Clone for AnimatedPerfOverlay<'a, N>
impl<'a, const N: usize> Clone for AnimatedPerfOverlay<'a, N>
Source§fn clone(&self) -> AnimatedPerfOverlay<'a, N>
fn clone(&self) -> AnimatedPerfOverlay<'a, N>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a, const N: usize> Debug for AnimatedPerfOverlay<'a, N>
impl<'a, const N: usize> Debug for AnimatedPerfOverlay<'a, N>
Source§impl<const N: usize> Default for AnimatedPerfOverlay<'_, N>
impl<const N: usize> Default for AnimatedPerfOverlay<'_, N>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).