rat-fps

Crates.iorat-fps
lib.rsrat-fps
version0.1.1
sourcesrc
created_at2024-11-28 20:35:08.153323
updated_at2024-11-28 20:59:29.797156
descriptionWidget to show FPS in ratatui
homepage
repository
max_upload_size
id1464980
size23,206
Brian Orwe (Borwe)

documentation

README

RAT-FPS

Description:

A Widget for use with Ratatui to display FPS

Example Usage:

use std::{error::Error, time::Duration};

use rat_fps::FPS;
use ratatui::crossterm::{self, event::{Event, KeyCode, KeyEvent}};

fn main() -> Result<(), Box<dyn Error>> {
    let mut term = ratatui::init();
    let mut keep_running = true;
    let mut fps = FPS::new()?;

    while keep_running {
        term.draw(|f|{
            //render the fps
            f.render_widget(&mut fps, f.area());
        })?;

        //wait roughly to enable rpughly atleast 60fps if possible, 
        // note what you do after the poll might reduce fps if not fast enough,
        // in such cases it is adviced to have a higher wait for fps,
        //roughly 30+ above expected
        if crossterm::event::poll(Duration::from_millis(fps.wait_for_fps(60)?))? {
            if let Event::Key(KeyEvent{ 
                code: KeyCode::Char('q'), ..}) = crossterm::event::read()? {
                keep_running = false;
            }
        }
    }

    ratatui::restore();
    Ok(())
}
Commit count: 0

cargo fmt