From a6fca1fcf164142d84d09242b9d95a1da0b2d2d9 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sun, 15 Dec 2024 13:21:42 +0100 Subject: use input struct, place cursor at pos --- src/tui/ui.rs | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src/tui/ui.rs') diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 8d7498a..e3fddfd 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -198,37 +198,39 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { .border_style(Style::new().fg(Color::Indexed(args.colors.entry_color))); // Prepare the input fields - let content = vec![ - Line::from(vec![Span::styled( + let content = vec![Line::from(vec![ + Span::styled( "DOI: ", Style::new().fg(Color::Indexed(args.colors.entry_color)), - )]), - Line::from(app.bibiman.popup_area.add_entry_input.clone()), - ]; + ), + Span::raw(app.input.value().to_string().clone()), + ])]; let paragraph = Paragraph::new(content) .block(block.clone()) .style(Style::new().fg(Color::Indexed(args.colors.main_text_color))) .wrap(Wrap { trim: false }); + let doi_lines = paragraph.line_count(area.width / 2); // Calculate popup size let popup_width = area.width / 2; - let popup_height = 5; // Adjust as needed + let popup_height = doi_lines as u16; // Adjust as needed let popup_area = popup_area(area, popup_width, popup_height); // Render the popup frame.render_widget(Clear, popup_area); + render_cursor(app, frame, popup_area, 6, 2); frame.render_widget(paragraph, popup_area); - // Set the cursor position - if app.input_mode { - // Calculate cursor x and y - let input_prefix_len = "Title: ".len() as u16 + 1; // +1 for padding - let cursor_x = popup_area.x - + input_prefix_len - + app.bibiman.popup_area.add_entry_cursor_position as u16; - let cursor_y = popup_area.y + 1; // Line after 'Title: ' - frame.set_cursor_position(Position::new(cursor_x, cursor_y)); - } + // // Set the cursor position + // if app.input_mode { + // // Calculate cursor x and y + // let input_prefix_len = "Title: ".len() as u16 + 1; // +1 for padding + // let cursor_x = popup_area.x + // + input_prefix_len + // + app.bibiman.popup_area.add_entry_cursor_position as u16; + // let cursor_y = popup_area.y + 1; // Line after 'Title: ' + // frame.set_cursor_position(Position::new(cursor_x, cursor_y)); + // } } Some(PopupKind::MessageConfirm) => { let area = frame.area(); @@ -376,7 +378,7 @@ pub fn render_footer(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: Rec ])) .block(block); - render_cursor(app, frame, rect, title_lenght + 1); + render_cursor(app, frame, rect, title_lenght + 1, 1); frame.render_widget(search_string, rect); } @@ -1035,12 +1037,13 @@ pub fn render_taglist(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: Re } /// Render the cursor when in InputMode -fn render_cursor(app: &mut App, frame: &mut Frame, area: Rect, x_offset: u16) { +fn render_cursor(app: &mut App, frame: &mut Frame, area: Rect, x_offset: u16, y_offset: u16) { let scroll = app.input.visual_scroll(area.width as usize); if app.input_mode { let (x, y) = ( area.x + ((app.input.visual_cursor()).max(scroll) - scroll) as u16 + x_offset, - area.bottom().saturating_sub(1), + // area.bottom().saturating_sub(1) + y_offset, + area.bottom().saturating_sub(y_offset), ); frame.render_widget( Clear, -- cgit v1.2.3