Skip to content

Commit

Permalink
It shows that making the stateless GUI work with list scrolling... ne…
Browse files Browse the repository at this point in the history
…eds state

Either we keep the GUI elements around and let them handle it, or the
main app has additional update calls to compute what it has to.
  • Loading branch information
Sebastian Thiel committed Jun 4, 2019
1 parent 1ff799e commit 92c636c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/interactive/app.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use super::widgets::{DisplayState, MainWindow};
use crate::{path_of, sorted_entries, traverse::Traversal, ByteFormat, WalkOptions, WalkResult};
use crate::{
interactive::widgets::{DisplayState, MainWindow},
path_of, sorted_entries,
traverse::Traversal,
ByteFormat, WalkOptions, WalkResult,
};
use failure::Error;
use itertools::Itertools;
use petgraph::Direction;
use std::{io, path::PathBuf};
use termion::input::{Keys, TermReadEventsAndRaw};
use tui::widgets::Widget;
use tui::{backend::Backend, Terminal};
use tui::{backend::Backend, widgets::Widget, Terminal};

/// Options to configure how we display things
#[derive(Clone, Copy)]
Expand Down Expand Up @@ -159,9 +162,10 @@ impl TerminalApp {
let full_screen = f.size();
let state = DisplayState {
root: traversal.root_index,
selected: None,
sorting: Default::default(),
message: Some("-> scanning <-".into()),
selected: None,
entries_list_start: 0,
};
MainWindow {
traversal,
Expand All @@ -181,9 +185,10 @@ impl TerminalApp {
Ok(TerminalApp {
state: DisplayState {
root,
selected,
sorting,
message: None,
selected,
entries_list_start: 0,
},
display: display_options,
traversal,
Expand Down
2 changes: 2 additions & 0 deletions src/interactive/widgets/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Entries<'a> {
pub display: DisplayOptions,
pub sorting: SortMode,
pub selected: Option<TreeIndex>,
pub list_start: usize,
}

impl<'a> Widget for Entries<'a> {
Expand All @@ -28,6 +29,7 @@ impl<'a> Widget for Entries<'a> {
display,
sorting,
selected,
list_start: _,
} = self;
let is_top = |node_idx| {
tree.neighbors_directed(node_idx, petgraph::Incoming)
Expand Down
2 changes: 2 additions & 0 deletions src/interactive/widgets/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl Default for SortMode {
pub struct DisplayState {
pub root: TreeIndex,
pub selected: Option<TreeIndex>,
pub entries_list_start: usize,
pub sorting: SortMode,
pub message: Option<String>,
}
Expand Down Expand Up @@ -70,6 +71,7 @@ impl<'a, 'b, 'c> Widget for MainWindow<'a, 'b> {
display: *display,
sorting: state.sorting,
selected: state.selected,
list_start: state.entries_list_start,
}
.draw(entries, buf);

Expand Down

0 comments on commit 92c636c

Please sign in to comment.