diff options
| author | lukeflo | 2024-12-15 13:21:42 +0100 |
|---|---|---|
| committer | lukeflo | 2024-12-23 21:03:19 +0100 |
| commit | a6fca1fcf164142d84d09242b9d95a1da0b2d2d9 (patch) | |
| tree | 08cae1f39342d5d81bb2d51554a62676899ef70e /src/tui | |
| parent | b892bc9a66e65cb73901d719c83768face67941d (diff) | |
| download | bibiman-a6fca1fcf164142d84d09242b9d95a1da0b2d2d9.tar.gz bibiman-a6fca1fcf164142d84d09242b9d95a1da0b2d2d9.zip | |
use input struct, place cursor at pos
Diffstat (limited to 'src/tui')
| -rw-r--r-- | src/tui/popup.rs | 4 | ||||
| -rw-r--r-- | src/tui/ui.rs | 41 |
2 files changed, 24 insertions, 21 deletions
diff --git a/src/tui/popup.rs b/src/tui/popup.rs index 9b91801..afe0cfc 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -40,8 +40,8 @@ pub struct PopupArea { pub popup_scroll_pos: u16, pub popup_list: Vec<String>, pub popup_state: ListState, - pub add_entry_input: String, - pub add_entry_cursor_position: usize, + // pub add_entry_input: String, + // pub add_entry_cursor_position: usize, } impl PopupArea { 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, |
