src/render/pages/global.rs
50 lines · 1693 bytes
1use crate::{app::{pages::global::GlobalItem, app::App}, traits::RenderItem};
2use tui::{
3 backend::Backend,
4 layout::{Alignment, Rect},
5 style::{Color, Style},
6 // style::{Color, Style},
7 widgets::{Block, BorderType, Borders, Paragraph},
8 Frame,
9};
10
11impl GlobalItem {
12 pub fn render_item<B: Backend>(
13 &self,
14 frame: &mut Frame<B>,
15 rect: Rect,
16 selected: bool,
17 hover: bool,
18 message: &Option<String>,
19 ) {
20 match self {
21 GlobalItem::SearchBar(search) => {
22 let style = Style::default().fg(if selected {
23 Color::LightBlue
24 } else if hover {
25 Color::LightRed
26 } else {
27 Color::Reset
28 });
29 let block = Block::default()
30 .border_type(BorderType::Rounded)
31 .borders(Borders::ALL)
32 .style(style)
33 .title("Search YouTube")
34 .title_alignment(Alignment::Center);
35 let paragraph = Paragraph::new(search.clone()).block(block);
36 frame.render_widget(paragraph, rect);
37 }
38 GlobalItem::MessageBar => {
39 // let color = Color::LightYellow;
40 let block = Block::default()
41 .border_type(BorderType::Rounded)
42 .borders(Borders::ALL);
43 let paragraph =
44 Paragraph::new(message.clone().unwrap_or(String::from("All good :)")))
45 .block(block);
46 frame.render_widget(paragraph, rect);
47 }
48 }
49 }
50}