This repository has been archived on 2024-09-29. You can view files and clone it, but cannot push or open issues or pull requests.
altoku/src/ui.rs

58 lines
1.6 KiB
Rust
Raw Normal View History

2024-05-28 15:11:07 +01:00
use ratatui::{
prelude::*,
2024-05-28 15:11:07 +01:00
style::{Color, Style},
widgets::*,
2024-05-28 15:11:07 +01:00
Frame,
};
use crate::app::App;
/// Renders the user interface.
2024-05-28 15:11:07 +01:00
pub fn render(app: &mut App, frame: &mut Frame) {
let chunks = Layout::default()
.direction(Direction::Vertical)
.margin(2)
.constraints(
[
Constraint::Length(1),
Constraint::Length(3),
Constraint::Min(1),
]
.as_ref(),
2024-05-28 15:11:07 +01:00
)
.split(frame.size());
2024-05-28 15:51:15 +01:00
let text: Vec<Line> = vec![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))
2024-05-28 15:51:15 +01:00
.block(
Block::default()
.borders(Borders::ALL)
.title("Search (Anime)"),
);
frame.render_widget(input, chunks[1]);
2024-05-28 15:51:15 +01:00
frame.set_cursor(
chunks[1].x + ((app.input.visual_cursor()).max(scroll) - scroll) as u16 + 1,
chunks[1].y + 1,
2024-05-28 15:42:49 +01:00
);
let messages = Paragraph::new("Another placeholder")
.block(Block::default().borders(Borders::ALL).title("Results"));
frame.render_widget(messages, chunks[2]);
2024-05-28 15:11:07 +01:00
}