Integrate table_value into table (#90)

* integrate table_value into table

* remove wrap

* remove wrap and alignment
pull/91/head
Takayuki Maeda 3 years ago committed by GitHub
parent 241cf9136e
commit 1ffb2c36c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -401,9 +401,18 @@ impl TableComponent {
impl DrawableComponent for TableComponent { impl DrawableComponent for TableComponent {
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, area: Rect, focused: bool) -> Result<()> { fn draw<B: Backend>(&mut self, f: &mut Frame<B>, area: Rect, focused: bool) -> Result<()> {
let layout = Layout::default() let chunks = Layout::default()
.vertical_margin(1)
.horizontal_margin(1)
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints(vec![Constraint::Length(3), Constraint::Length(5)]) .constraints(
[
Constraint::Length(2),
Constraint::Min(1),
Constraint::Length(2),
]
.as_ref(),
)
.split(area); .split(area);
f.render_widget( f.render_widget(
@ -415,16 +424,9 @@ impl DrawableComponent for TableComponent {
} else { } else {
Style::default().fg(Color::DarkGray) Style::default().fg(Color::DarkGray)
}), }),
layout[1], area,
); );
let chunks = Layout::default()
.vertical_margin(1)
.horizontal_margin(1)
.direction(Direction::Vertical)
.constraints([Constraint::Min(1), Constraint::Length(2)].as_ref())
.split(layout[1]);
self.selected_row.selected().map_or_else( self.selected_row.selected().map_or_else(
|| { || {
self.scroll.reset(); self.scroll.reset();
@ -433,14 +435,11 @@ impl DrawableComponent for TableComponent {
self.scroll.update( self.scroll.update(
selection, selection,
self.rows.len(), self.rows.len(),
layout[1].height.saturating_sub(2) as usize, chunks[1].height.saturating_sub(2) as usize,
); );
}, },
); );
TableValueComponent::new(self.selected_cells().unwrap_or_default())
.draw(f, layout[0], focused)?;
let block = Block::default().borders(Borders::NONE); let block = Block::default().borders(Borders::NONE);
let (selected_column_index, headers, rows, constraints) = let (selected_column_index, headers, rows, constraints) =
self.calculate_cell_widths(block.inner(chunks[0]).width); self.calculate_cell_widths(block.inner(chunks[0]).width);
@ -485,7 +484,7 @@ impl DrawableComponent for TableComponent {
let mut state = self.selected_row.clone(); let mut state = self.selected_row.clone();
f.render_stateful_widget( f.render_stateful_widget(
table, table,
chunks[0], chunks[1],
if let Some((_, y)) = self.selection_area_corner { if let Some((_, y)) = self.selection_area_corner {
state.select(Some(y)); state.select(Some(y));
&mut state &mut state
@ -494,6 +493,9 @@ impl DrawableComponent for TableComponent {
}, },
); );
TableValueComponent::new(self.selected_cells().unwrap_or_default())
.draw(f, chunks[0], focused)?;
TableStatusComponent::new( TableStatusComponent::new(
if self.rows.is_empty() { if self.rows.is_empty() {
None None
@ -507,9 +509,9 @@ impl DrawableComponent for TableComponent {
}, },
self.table.as_ref().map(|t| t.1.clone()), self.table.as_ref().map(|t| t.1.clone()),
) )
.draw(f, chunks[1], focused)?; .draw(f, chunks[2], focused)?;
self.scroll.draw(f, chunks[0]); self.scroll.draw(f, chunks[1]);
Ok(()) Ok(())
} }
} }

@ -8,7 +8,7 @@ use tui::{
layout::Rect, layout::Rect,
style::{Color, Style}, style::{Color, Style},
text::{Span, Spans}, text::{Span, Spans},
widgets::{Block, Borders, Paragraph, Wrap}, widgets::{Block, Borders, Paragraph},
Frame, Frame,
}; };
@ -64,8 +64,7 @@ impl DrawableComponent for TableStatusComponent {
Style::default() Style::default()
} else { } else {
Style::default().fg(Color::DarkGray) Style::default().fg(Color::DarkGray)
})) }));
.wrap(Wrap { trim: true });
f.render_widget(status, area); f.render_widget(status, area);
Ok(()) Ok(())
} }

@ -4,10 +4,9 @@ use crate::event::Key;
use anyhow::Result; use anyhow::Result;
use tui::{ use tui::{
backend::Backend, backend::Backend,
layout::{Alignment, Rect}, layout::Rect,
style::{Color, Modifier, Style}, style::{Color, Style},
text::Span, widgets::{Block, Borders, Paragraph},
widgets::{Block, Borders, Paragraph, Wrap},
Frame, Frame,
}; };
@ -24,22 +23,12 @@ impl TableValueComponent {
impl DrawableComponent for TableValueComponent { impl DrawableComponent for TableValueComponent {
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, area: Rect, focused: bool) -> Result<()> { fn draw<B: Backend>(&mut self, f: &mut Frame<B>, area: Rect, focused: bool) -> Result<()> {
let paragraph = Paragraph::new(self.value.clone()) let paragraph = Paragraph::new(self.value.clone())
.block( .block(Block::default().borders(Borders::BOTTOM))
Block::default()
.borders(Borders::ALL)
.style(Style::default())
.title(Span::styled(
"Value",
Style::default().add_modifier(Modifier::BOLD),
)),
)
.style(if focused { .style(if focused {
Style::default() Style::default()
} else { } else {
Style::default().fg(Color::DarkGray) Style::default().fg(Color::DarkGray)
}) });
.alignment(Alignment::Left)
.wrap(Wrap { trim: true });
f.render_widget(paragraph, area); f.render_widget(paragraph, area);
Ok(()) Ok(())
} }

Loading…
Cancel
Save