Skip to content

Commit

Permalink
Entries is now ReactEntries :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 5, 2019
1 parent 3aa9b01 commit ae679ed
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
25 changes: 17 additions & 8 deletions src/interactive/widgets/entries.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
use crate::interactive::{DisplayOptions, EntryDataBundle};
use dua::traverse::{Tree, TreeIndex};
use itertools::Itertools;
use std::path::Path;
use std::{borrow::Borrow, path::Path};
use tui::{
buffer::Buffer,
layout::Rect,
style::{Color, Style},
widgets::{Borders, Text, Widget},
widgets::{Borders, Text},
};
use tui_react::{fill_background_to_right, BlockProps, ReactList, ReactListProps};

pub struct Entries<'a> {
pub struct ReactEntriesProps<'a> {
pub tree: &'a Tree,
pub root: TreeIndex,
pub display: DisplayOptions,
pub selected: Option<TreeIndex>,
pub entries: &'a [EntryDataBundle],
pub border_style: Style,
pub is_focussed: bool,
}

#[derive(Default, Clone)]
pub struct ReactEntries {
pub list: ReactList,
}

impl<'a, 'b> Widget for Entries<'a> {
fn draw(&mut self, area: Rect, buf: &mut Buffer) {
let Self {
impl ReactEntries {
pub fn render<'a>(
&mut self,
props: impl Borrow<ReactEntriesProps<'a>>,
area: Rect,
buf: &mut Buffer,
) {
let ReactEntriesProps {
tree,
root,
display,
entries,
selected,
border_style,
is_focussed,
list,
} = self;
} = props.borrow();
let list = &mut self.list;

let is_top = |node_idx| {
tree.neighbors_directed(node_idx, petgraph::Incoming)
.next()
Expand Down
15 changes: 9 additions & 6 deletions src/interactive/widgets/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::interactive::{
widgets::{Entries, Header, ReactFooter, ReactFooterProps, ReactHelpPane, ReactHelpPaneProps},
widgets::{
Header, ReactEntries, ReactEntriesProps, ReactFooter, ReactFooterProps, ReactHelpPane,
ReactHelpPaneProps,
},
FocussedPane, TerminalApp,
};
use dua::traverse::Traversal;
Expand All @@ -11,11 +14,12 @@ use tui::{
style::Modifier,
widgets::Widget,
};
use tui_react::{ReactList, ToplevelComponent};
use tui_react::ToplevelComponent;

#[derive(Default, Clone)] // TODO: remove clone derive
pub struct ReactMainWindow {
pub help_pane: Option<ReactHelpPane>,
pub entries_pane: ReactEntries,
}

impl<'a, 'b> ToplevelComponent for ReactMainWindow {
Expand Down Expand Up @@ -71,7 +75,7 @@ impl<'a, 'b> ToplevelComponent for ReactMainWindow {
};

Header.draw(header_area, buf);
Entries {
let props = ReactEntriesProps {
tree: &tree,
root: state.root,
display: *display,
Expand All @@ -83,9 +87,8 @@ impl<'a, 'b> ToplevelComponent for ReactMainWindow {
} else {
false
},
list: ReactList::default(),
}
.draw(entries_area, buf);
};
self.entries_pane.render(props, entries_area, buf);

if let Some((help_area, pane)) = help_pane {
let props = ReactHelpPaneProps {
Expand Down
7 changes: 2 additions & 5 deletions tui-react/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Derived from TUI-rs, license: MIT, Copyright (c) 2016 Florian Dehau
use super::ToplevelComponent;
use std::borrow::Borrow;
use std::marker::PhantomData;
use tui::{
Expand Down Expand Up @@ -71,10 +70,8 @@ impl<'a> BlockProps<'a> {
}
}

impl<'a, T> ToplevelComponent for Block<'a, T> {
type Props = BlockProps<'a>;

fn render(&mut self, props: impl Borrow<Self::Props>, area: Rect, buf: &mut Buffer) {
impl<'a, T> Block<'a, T> {
fn render(&self, props: impl Borrow<BlockProps<'a>>, area: Rect, buf: &mut Buffer) {
if area.width < 2 || area.height < 2 {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion tui-react/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn fill_background_to_right(mut s: String, entire_width: u16) -> String {
}
}

#[derive(Default)] // TODO: remove Clone derive
#[derive(Default, Clone)] // TODO: remove Clone derive
pub struct ReactList {
/// The index at which the list last started. Used for scrolling
offset: usize,
Expand Down

0 comments on commit ae679ed

Please sign in to comment.