Skip to content

Commit

Permalink
The block is now not needed anymore - we can just own simple props
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 5, 2019
1 parent f59b32d commit 42fb0cc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 185 deletions.
14 changes: 6 additions & 8 deletions src/interactive/widgets/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use tui::{
buffer::Buffer,
layout::Rect,
style::{Color, Style},
widgets::{Borders, Text},
widgets::{Block, Borders, Text},
};
use tui_react::{fill_background_to_right, BlockProps, ReactList, ReactListProps};
use tui_react::{fill_background_to_right, ReactList, ReactListProps};

pub struct ReactEntriesProps<'a> {
pub tree: &'a Tree,
Expand Down Expand Up @@ -58,12 +58,10 @@ impl ReactEntries {
p => p,
};
let title = format!(" {} ", title);
let block = BlockProps {
borders: Borders::ALL,
border_style: *border_style,
title: Some(&title),
..Default::default()
};
let block = Block::default()
.title(&title)
.border_style(*border_style)
.borders(Borders::ALL);
let entry_in_view = selected.map(|selected| {
entries
.iter()
Expand Down
3 changes: 2 additions & 1 deletion tui-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ refernces in your state, it's probably not suitable for most.

Instead, any struct can implement `render` methods or functions, and freely write into the terminal.
That way, one can leverage everything Rust has to offer, which allows stateful components which
work in your favor.
work in your favor. Thus, this crate does away with 'one size fits all' render implementations,
greatly adding to flexibility.

State that one wants within the component for instance could be the scoll location. Alternatively,
one can configure windows by altering their public state.
Expand Down
165 changes: 0 additions & 165 deletions tui-react/src/block.rs

This file was deleted.

2 changes: 0 additions & 2 deletions tui-react/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod block;
mod list;
mod terminal;

pub use block::*;
pub use list::*;
pub use terminal::*;
16 changes: 7 additions & 9 deletions tui-react/src/list.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use super::BlockProps;
use std::borrow::Borrow;
use std::iter::repeat;
use tui::{
buffer::Buffer,
layout::Rect,
widgets::{Paragraph, Text, Widget},
widgets::{Block, Paragraph, Text, Widget},
};

pub fn fill_background_to_right(mut s: String, entire_width: u16) -> String {
Expand Down Expand Up @@ -38,31 +36,31 @@ impl ReactList {

#[derive(Default)]
pub struct ReactListProps<'b> {
pub block: Option<BlockProps<'b>>,
pub block: Option<Block<'b>>,
pub entry_in_view: Option<usize>,
}

impl ReactList {
pub fn render<'a, 't>(
&mut self,
props: impl Borrow<ReactListProps<'a>>,
props: ReactListProps<'a>,
items: impl IntoIterator<Item = Vec<Text<'t>>>,
area: Rect,
buf: &mut Buffer,
) {
let ReactListProps {
block,
entry_in_view,
} = props.borrow();
} = props;

let list_area = match block {
Some(b) => {
b.render(area, buf);
Some(mut b) => {
b.draw(area, buf);
b.inner(area)
}
None => area,
};
self.offset = self.list_offset_for(*entry_in_view, list_area.height as usize);
self.offset = self.list_offset_for(entry_in_view, list_area.height as usize);

if list_area.width < 1 || list_area.height < 1 {
return;
Expand Down

0 comments on commit 42fb0cc

Please sign in to comment.