feat: textbox which takes in anime query

This commit is contained in:
Muhammad Nauman Raza 2024-05-28 15:32:03 +01:00
parent f84d0137c5
commit 49136205a2
Signed by: devraza
GPG key ID: 91EAD6081011574B

View file

@ -1,25 +1,54 @@
use ratatui::{
layout::Alignment,
prelude::*,
style::{Color, Style},
widgets::{Block, BorderType, Paragraph},
widgets::*,
Frame,
};
use crate::app::App;
/// Renders the user interface widgets.
/// Renders the user interface.
pub fn render(app: &mut App, frame: &mut Frame) {
frame.render_widget(
Paragraph::new(format!(
"This is just a placeholder."
))
.block(
Block::bordered()
.title("Template")
.title_alignment(Alignment::Center)
.border_type(BorderType::Rounded),
let chunks = Layout::default()
.direction(Direction::Vertical)
.margin(2)
.constraints(
[
Constraint::Length(1),
Constraint::Length(3),
Constraint::Min(1),
]
.as_ref(),
)
.centered(),
frame.size(),
.split(frame.size());
let mut text: Vec<Line> = vec![];
text.push(
Line::from(vec![
"Press ".into(),
"Esc".bold(),
" or ".into(),
"Ctrl+C".bold(),
" to quit, and ".into(),
"Enter".bold(),
" to submit your query.".into(),
]),
);
let help_message = Paragraph::new(text);
frame.render_widget(help_message, chunks[0]);
let width = chunks[0].width.max(3) - 3;
let scroll = app.input.visual_scroll(width as usize);
let input = Paragraph::new(app.input.value())
.style(Style::default().fg(Color::Yellow))
.scroll((0, scroll as u16))
.block(Block::default().borders(Borders::ALL).title("Search (Anime)"));
frame.render_widget(input, chunks[1]);
frame.set_cursor(
chunks[1].x
+ ((app.input.visual_cursor()).max(scroll) - scroll) as u16
+ 1,
chunks[1].y + 1,
)
}