Skip to content

Commit

Permalink
The first version of list scrolling... works but funnily :D
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 3, 2019
1 parent 85726c7 commit 6e21175
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/interactive/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
traverse::{Traversal, Tree, TreeIndex},
ByteFormat,
};
use itertools::Itertools;
use std::path::Path;
use tui::layout::{Constraint, Direction, Layout};
use tui::style::{Color, Style};
Expand Down Expand Up @@ -151,7 +152,21 @@ impl<'a> Widget for Entries<'a> {
};
let title = format!(" {} ", title);
let block = Block::default().borders(Borders::ALL).title(&title);
List::new(entries.iter().map(|(node_idx, w)| {
let offset = match selected {
Some(selected) => {
let pos = entries
.iter()
.find_position(|(idx, _)| *idx == *selected)
.map(|(idx, _)| idx)
.unwrap_or(0);
match block.inner(area).height as usize {
h if pos >= h => pos - h + 1,
_ => 0,
}
}
None => 0,
};
List::new(entries.iter().skip(offset).map(|(node_idx, w)| {
let style = match selected {
Some(idx) if *idx == *node_idx => Style {
fg: Color::Black,
Expand Down

0 comments on commit 6e21175

Please sign in to comment.