use crate::components::linescore::LineScore;
use crate::state::app_state::HomeOrAway;
use tui::{
buffer::Buffer,
layout::{Constraint, Rect},
style::{Color, Modifier, Style},
widgets::{Block, Borders, Row, Table, Widget},
};
pub struct LineScoreWidget<'a> {
pub active: HomeOrAway,
pub linescore: &'a LineScore,
}
impl Widget for LineScoreWidget<'_> {
fn render(self, area: Rect, buf: &mut Buffer) {
let width = match self.linescore.mini {
true => 3,
false => 5,
};
let mut widths = vec![Constraint::Length(width); self.linescore.header.len()];
widths[0] = Constraint::Length(6);
widths[self.linescore.header.len() - 4] = Constraint::Length(width + 1);
let header = Row::new(self.linescore.header.clone())
.height(1)
.style(Style::default().add_modifier(Modifier::BOLD | Modifier::UNDERLINED));
let t = Table::new(
vec![
Row::new(self.linescore.away.create_score_vec(self.active)),
Row::new(self.linescore.home.create_score_vec(self.active)),
],
widths.as_slice(),
)
.column_spacing(0)
.style(Style::default().fg(Color::White))
.header(header)
.block(Block::default().borders(Borders::NONE));
Widget::render(t, area, buf);
}
}