diff options
| author | lukeflo | 2025-05-30 17:04:42 +0200 |
|---|---|---|
| committer | lukeflo | 2025-05-30 17:04:42 +0200 |
| commit | fbcd12fb9e215852a12e0c3f5963aa52996b26aa (patch) | |
| tree | 19f5ef411175cac554e004df3d05ed7cac1a7a7d /src/tui/ui.rs | |
| parent | 0eae6de6df392fb3b8fa9d39dde42cecff97d240 (diff) | |
| download | bibiman-fbcd12fb9e215852a12e0c3f5963aa52996b26aa.tar.gz bibiman-fbcd12fb9e215852a12e0c3f5963aa52996b26aa.zip | |
better UI for popups, some testings
Diffstat (limited to 'src/tui/ui.rs')
| -rw-r--r-- | src/tui/ui.rs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 9cbd075..a998bc7 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -279,7 +279,14 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) { .popup_area .popup_list .iter() - .map(|(mes, obj)| ListItem::from(mes.to_owned() + obj)) + .map( + |(mes, obj)| { + ListItem::from(Line::from(vec![ + Span::styled(mes, Style::new().bold()), + Span::raw(obj), + ])) + }, // ListItem::from(mes.to_owned() + obj) + ) .collect(); let title = if let Some(PopupKind::OpenRes) = app.bibiman.popup_area.popup_kind { @@ -311,7 +318,25 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) { .add_modifier(Modifier::REVERSED), ); - let popup_width = frame.area().width / 2; + // To find the longest line, we need to collect the chars of every item + // and add. + let list_widths: Vec<u16> = app + .bibiman + .popup_area + .popup_list + .iter() + .map(|(m, o)| m.chars().count() as u16 + o.chars().count() as u16) + .collect(); + + // Now take the max number for the width of the popup + let max_item = list_widths.iter().max().unwrap().to_owned(); + + // Check if the popup would exceed the terminal frame width + let popup_width = if max_item + 2 > frame.area().width - 2 { + frame.area().width - 2 + } else { + max_item + 2 + }; let popup_heigth = list.len() + 2; let popup_area = popup_area(frame.area(), popup_width, popup_heigth as u16); |
