Add tabs to the cockpit
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Isaac Mills 2025-07-20 00:44:28 -06:00
parent 852fba7b05
commit 6cac22c9d8
Signed by: fnmain
GPG key ID: B67D7410F33A0F61
4 changed files with 73 additions and 7 deletions

View file

@ -2,13 +2,17 @@
use ratzilla::ratatui;
use ratatui::{
layout::{Constraint, Direction, Layout},
style::{Color, Stylize},
widgets::{Block, Borders, Paragraph},
widgets::{Block, Borders, Paragraph, Tabs},
Frame,
};
use web_time::Instant;
#[derive(Default)]
pub struct App {}
pub struct App {
transition_instant: Instant,
selected_tab: usize,
}
const SPLASH: &str = r#"
!~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -37,14 +41,55 @@ YJJJJJJJJJ????????????77777777777!!!!!!!!!!!~~~~~~
YJJJJJJJJJJJ???????????77777777777!!!!!!!!!!!~~~~~
"#;
const TABS: [&'static str; 3] = ["Whatzahoozits", "Thingamajigs", "Doohickeys"];
impl App {
pub fn new() -> Self {
Self {
transition_instant: Instant::now(),
selected_tab: 0,
}
}
pub fn draw(&mut self, frame: &mut Frame) {
let layout = Layout::new(
Direction::Vertical,
[Constraint::Length(3), Constraint::Min(0)],
)
.split(frame.area());
frame.render_widget(
Tabs::new(TABS)
.select(self.selected_tab)
.fg(Color::Rgb(226, 190, 89))
.bg(Color::Black)
.block(Block::new().borders(Borders::all()).title("Coming soon")),
layout[0],
);
frame.render_widget(
Paragraph::new(SPLASH)
.alignment(ratatui::layout::Alignment::Center)
.fg(Color::Rgb(226, 190, 89))
.block(Block::new().borders(Borders::all()).title("Coming soon")),
frame.area(),
.bg(Color::Black)
.block(Block::new().borders(Borders::all())),
layout[1],
);
}
pub fn next_tab(&mut self) {
self.transition_instant = Instant::now();
if self.selected_tab == TABS.len() - 1 {
self.selected_tab = 0;
} else {
self.selected_tab += 1;
}
}
pub fn prev_tab(&mut self) {
self.transition_instant = Instant::now();
if self.selected_tab == 0 {
self.selected_tab = TABS.len() - 1;
} else {
self.selected_tab -= 1;
}
}
}