Readable Fullscreen Modals for Stats, Standings/Bracket, and History
This commit is contained in:
parent
39ea6c0c0a
commit
dcdd06c8c3
5 changed files with 179 additions and 45 deletions
|
|
@ -2,10 +2,10 @@ use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
|||
use ratatui::prelude::*;
|
||||
use ratatui::widgets::{Block, Borders, Clear, List, ListItem, Paragraph};
|
||||
|
||||
use crate::app::{App, CreateDraft};
|
||||
use crate::app::{App, CreateDraft, OverlayModal};
|
||||
use crate::data::TEAMS;
|
||||
|
||||
pub fn render(f: &mut Frame<'_>, area: Rect, app: &App, draft: &CreateDraft) {
|
||||
pub fn render_create(f: &mut Frame<'_>, area: Rect, app: &App, draft: &CreateDraft) {
|
||||
let popup = centered_rect(70, 70, area);
|
||||
f.render_widget(Clear, popup);
|
||||
|
||||
|
|
@ -59,6 +59,82 @@ pub fn render(f: &mut Frame<'_>, area: Rect, app: &App, draft: &CreateDraft) {
|
|||
f.render_widget(help, inner[2]);
|
||||
}
|
||||
|
||||
pub fn render_overlay(f: &mut Frame<'_>, area: Rect, app: &App, modal: OverlayModal) {
|
||||
let popup = centered_rect(90, 86, area);
|
||||
f.render_widget(Clear, popup);
|
||||
|
||||
let frame = Block::default()
|
||||
.title(modal.title())
|
||||
.borders(Borders::ALL)
|
||||
.style(Style::default().fg(Color::White).bg(Color::Black));
|
||||
f.render_widget(frame, popup);
|
||||
|
||||
let inner = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(1)
|
||||
.constraints([
|
||||
Constraint::Length(1),
|
||||
Constraint::Min(4),
|
||||
Constraint::Length(1),
|
||||
])
|
||||
.split(popup);
|
||||
|
||||
let Some(inst) = app.selected_instance() else {
|
||||
f.render_widget(Paragraph::new("No selected instance"), inner[1]);
|
||||
return;
|
||||
};
|
||||
|
||||
let all_lines: Vec<String> = match modal {
|
||||
OverlayModal::Stats => {
|
||||
if inst.stats_lines.is_empty() {
|
||||
vec!["No stats available yet. Start a simulation first.".to_string()]
|
||||
} else {
|
||||
inst.stats_lines.clone()
|
||||
}
|
||||
}
|
||||
OverlayModal::Competition => {
|
||||
if inst.competition_lines.is_empty() {
|
||||
vec!["No standings/bracket available for this simulation yet.".to_string()]
|
||||
} else {
|
||||
inst.competition_lines.clone()
|
||||
}
|
||||
}
|
||||
OverlayModal::History => {
|
||||
if inst.history_lines.is_empty() {
|
||||
vec!["No history entries yet.".to_string()]
|
||||
} else {
|
||||
inst.history_lines.clone()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let viewport = (inner[1].height as usize).saturating_sub(2).max(1);
|
||||
let max_start = all_lines.len().saturating_sub(viewport);
|
||||
let start = app.overlay_scroll.min(max_start);
|
||||
let end = (start + viewport).min(all_lines.len());
|
||||
let visible = &all_lines[start..end];
|
||||
let items: Vec<ListItem> = visible
|
||||
.iter()
|
||||
.map(|line| ListItem::new(line.clone()))
|
||||
.collect();
|
||||
|
||||
let top = Paragraph::new(format!(
|
||||
"sim-{} [{}] lines {}-{} / {}",
|
||||
inst.id,
|
||||
inst.sim_type.as_str(),
|
||||
start + 1,
|
||||
end,
|
||||
all_lines.len()
|
||||
));
|
||||
f.render_widget(top, inner[0]);
|
||||
|
||||
let list = List::new(items).block(Block::default().borders(Borders::ALL));
|
||||
f.render_widget(list, inner[1]);
|
||||
|
||||
let help = Paragraph::new("j/k or up/down to scroll, Esc or q to close");
|
||||
f.render_widget(help, inner[2]);
|
||||
}
|
||||
|
||||
fn centered_rect(percent_x: u16, percent_y: u16, area: Rect) -> Rect {
|
||||
let vertical = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue