Show current mode in title row
This may be later isolated to debug builds
This commit is contained in:
parent
713dc8c2de
commit
b9ade066e7
1 changed files with 23 additions and 5 deletions
|
|
@ -30,6 +30,8 @@ use crate::action::Action;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct FpsCounter {
|
pub struct FpsCounter {
|
||||||
|
mode: String,
|
||||||
|
|
||||||
last_tick_update: Instant,
|
last_tick_update: Instant,
|
||||||
tick_count: u32,
|
tick_count: u32,
|
||||||
ticks_per_second: f64,
|
ticks_per_second: f64,
|
||||||
|
|
@ -49,6 +51,7 @@ impl FpsCounter {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
mode: String::from(""),
|
||||||
last_tick_update: Instant::now(),
|
last_tick_update: Instant::now(),
|
||||||
tick_count: 0,
|
tick_count: 0,
|
||||||
ticks_per_second: 0.0,
|
ticks_per_second: 0.0,
|
||||||
|
|
@ -88,29 +91,44 @@ impl FpsCounter {
|
||||||
impl Component for FpsCounter {
|
impl Component for FpsCounter {
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
match action {
|
match action {
|
||||||
Action::Tick => self.app_tick()?,
|
Action::SetMode(mode) => {
|
||||||
|
self.mode = format!("{:?}", mode);
|
||||||
|
}
|
||||||
Action::Render => self.render_tick()?,
|
Action::Render => self.render_tick()?,
|
||||||
|
Action::Tick => self.app_tick()?,
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
let [column, _] =
|
|
||||||
Layout::horizontal([Constraint::Min(1), Constraint::Length(2)]).areas(area);
|
|
||||||
let [_, row, _] = Layout::vertical([
|
let [_, row, _] = Layout::vertical([
|
||||||
Constraint::Length(1),
|
Constraint::Length(1),
|
||||||
Constraint::Length(1),
|
Constraint::Length(1),
|
||||||
Constraint::Min(0),
|
Constraint::Min(0),
|
||||||
])
|
])
|
||||||
.areas(column);
|
.areas(area);
|
||||||
|
let [_, left, right, _] = Layout::horizontal([
|
||||||
|
Constraint::Length(2),
|
||||||
|
Constraint::Min(1),
|
||||||
|
Constraint::Min(1),
|
||||||
|
Constraint::Length(2),
|
||||||
|
])
|
||||||
|
.areas(row);
|
||||||
|
|
||||||
|
// Debug
|
||||||
|
let span = Span::styled(format!("Mode: {}", &self.mode), Style::new().dim());
|
||||||
|
let paragraph = Paragraph::new(span).left_aligned();
|
||||||
|
frame.render_widget(paragraph, left);
|
||||||
|
|
||||||
|
// FPS
|
||||||
let message = format!(
|
let message = format!(
|
||||||
"{:.2} ticks/sec, {:.2} FPS",
|
"{:.2} ticks/sec, {:.2} FPS",
|
||||||
self.ticks_per_second, self.frames_per_second
|
self.ticks_per_second, self.frames_per_second
|
||||||
);
|
);
|
||||||
let span = Span::styled(message, Style::new().dim());
|
let span = Span::styled(message, Style::new().dim());
|
||||||
let paragraph = Paragraph::new(span).right_aligned();
|
let paragraph = Paragraph::new(span).right_aligned();
|
||||||
frame.render_widget(paragraph, row);
|
frame.render_widget(paragraph, right);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue