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