diff options
| author | lukeflo | 2024-09-27 23:48:46 +0200 |
|---|---|---|
| committer | lukeflo | 2024-09-27 23:48:46 +0200 |
| commit | a13f63f34272889239d1e0fcd37f9c4fb5ec983a (patch) | |
| tree | e060e7cd863abef68aeaa7553394d902d0c87e74 /src/frontend/ui.rs | |
| parent | 3e86e1d11fa06dedde78621c3e0503a7492ad05e (diff) | |
| download | bibiman-a13f63f34272889239d1e0fcd37f9c4fb5ec983a.tar.gz bibiman-a13f63f34272889239d1e0fcd37f9c4fb5ec983a.zip | |
implement scroll action for info box
Diffstat (limited to 'src/frontend/ui.rs')
| -rw-r--r-- | src/frontend/ui.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/frontend/ui.rs b/src/frontend/ui.rs index 8d5dcd8..5413194 100644 --- a/src/frontend/ui.rs +++ b/src/frontend/ui.rs @@ -229,12 +229,32 @@ impl App { .bg(Color::Black) .padding(Padding::horizontal(1)); + // INFO: '.line_count' method only possible with unstable-rendered-line-info feature -> API might change: https://github.com/ratatui/ratatui/issues/293#ref-pullrequest-2027056434 + let box_height = Paragraph::new(info.clone()) + .block(block.clone()) + .wrap(Wrap { trim: false }) + .line_count(area.width); + // Make sure to allow scroll only if text is larger than the rendered area and stop scrolling when last line is reached + let scroll_height = { + if self.scroll_info == 0 { + self.scroll_info + } else if area.height > box_height as u16 { + self.scroll_info = 0; + self.scroll_info + } else if self.scroll_info > (box_height as u16 + 1 - area.height) { + self.scroll_info = box_height as u16 + 1 - area.height; + self.scroll_info + } else { + self.scroll_info + } + }; + // We can now render the item info Paragraph::new(info) .block(block) // .fg(TEXT_FG_COLOR) .wrap(Wrap { trim: false }) - .scroll((self.scroll_info, 0)) + .scroll((scroll_height, 0)) .render(area, buf); } |
