modified: src/main_screen.rs

This commit is contained in:
Michael Wain 2025-02-10 03:06:51 +03:00
parent 0e7d9aa8d9
commit 34cf8c0a15

View File

@ -1,3 +1,4 @@
use color_eyre::owo_colors::OwoColorize;
use crossterm::event::{KeyCode, KeyEvent};
use ratatui::{buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style, Stylize}, text::{Line, Span}, widgets::{Block, Borders, Paragraph, Tabs, Widget}, Frame};
use soundcloud::sobjects::CloudPlaylists;
@ -7,18 +8,18 @@ use crate::screen::AppScreen;
#[derive(Debug, Clone)]
pub struct MainScreen {
selected_tab: u8,
selected_tab: i8,
tab_titles: Vec<String>,
pub soundcloud: Option<CloudPlaylists>
}
impl AppScreen for MainScreen {
fn handle_key_event(&mut self, key_event: KeyEvent) {
/*match key_event.code {
match key_event.code {
KeyCode::Char('l') | KeyCode::Right => self.next_tab(),
KeyCode::Char('h') | KeyCode::Left => self.previous_tab(),
_ => {}
}*/
}
}
fn render(&self, frame: &mut Frame) {
@ -46,8 +47,12 @@ impl AppScreen for MainScreen {
frame.render_widget(main_content, chunks[1]); // Render into second chunk
// Render Status Bar
let status_bar = Paragraph::new("Press 'q' to quit | Arrow keys to navigate")
.style(Style::default().fg(Color::Cyan));
let status_bar = Paragraph::new(
Line::from(
vec!["◄ ► to change tab".bold(), " | ".dark_gray(), "<F5> SAVE FS".bold(), " | ".dark_gray(), "<F6> DL".bold(), " | ".dark_gray(), "<F8> DEL".bold(), " | ".dark_gray(), "<Q> QUIT".bold()]
)
)
.centered();
frame.render_widget(status_bar, chunks[2]); // Render into third chunk
}
@ -61,13 +66,11 @@ impl MainScreen {
MainScreen { soundcloud: None, selected_tab: 0, tab_titles: vec!["YouTube".to_string(), "SoundCloud".to_string(), "Local Playlists".to_string(), "Settings".to_string()] }
}
pub fn render_title(area: Rect, buf: &mut Buffer) {
"Lyrica".bold().render(area, buf);
fn next_tab(&mut self) {
self.selected_tab = std::cmp::min(self.selected_tab+1, (self.tab_titles.len()-1).try_into().unwrap())
}
pub fn render_footer(area: Rect, buf: &mut Buffer) {
Line::raw("◄ ► to change tab | <Q> to quit")
.centered()
.render(area, buf);
fn previous_tab(&mut self) {
self.selected_tab = std::cmp::max(0, self.selected_tab-1);
}
}