terminal_ui/ui/
ui_navigation_popup.rs

1use crate::{
2    app::{App, INDEX_NAVIGATION},
3    styles::selected_style,
4};
5use tui::{
6    backend::Backend,
7    layout::{Constraint, Direction, Layout, Rect},
8    widgets::{Block, Borders, Clear, Paragraph},
9    Frame,
10};
11
12use super::{ui_popup::centered_rect, ui_shared::display_cursor};
13
14fn draw_navigation_input<B>(f: &mut Frame<B>, app: &App, area: Rect)
15where
16    B: Backend,
17{
18    let format_regex_widget = Paragraph::new(app.input_buffers[INDEX_NAVIGATION].value())
19        .style(selected_style(app.color))
20        .block(Block::default().borders(Borders::ALL).title("Index"));
21
22    f.render_widget(format_regex_widget, area);
23    if INDEX_NAVIGATION == app.input_buffer_index {
24        display_cursor(f, area, app.input_buffers[INDEX_NAVIGATION].cursor())
25    }
26}
27
28pub fn draw_navigation_popup<B>(f: &mut Frame<B>, app: &mut App)
29where
30    B: Backend,
31{
32    let block = Block::default()
33        .title("Navigate to index")
34        .borders(Borders::ALL)
35        .border_style(selected_style(app.color));
36
37    let area = centered_rect(60, 7, f.size());
38    f.render_widget(Clear, area); //this clears out the background
39    f.render_widget(block, area);
40
41    let popup_layout = Layout::default()
42        .direction(Direction::Horizontal)
43        .constraints([Constraint::Percentage(100)].as_ref())
44        .margin(1)
45        .split(area);
46    let popup_layout = Layout::default()
47        .direction(Direction::Vertical)
48        .constraints([Constraint::Length(3)].as_ref())
49        .margin(1)
50        .split(popup_layout[0]);
51
52    draw_navigation_input(f, app, popup_layout[0]);
53}