integrate table_value into table

pull/90/head
Takayuki Maeda 3 years ago
parent 241cf9136e
commit 0a3e69a6c8

@ -401,9 +401,18 @@ impl TableComponent {
impl DrawableComponent for TableComponent {
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)
.constraints(vec![Constraint::Length(3), Constraint::Length(5)])
.constraints(
[
Constraint::Length(2),
Constraint::Min(1),
Constraint::Length(2),
]
.as_ref(),
)
.split(area);
f.render_widget(
@ -415,16 +424,9 @@ impl DrawableComponent for TableComponent {
} else {
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.scroll.reset();
@ -433,14 +435,11 @@ impl DrawableComponent for TableComponent {
self.scroll.update(
selection,
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 (selected_column_index, headers, rows, constraints) =
self.calculate_cell_widths(block.inner(chunks[0]).width);
@ -485,7 +484,7 @@ impl DrawableComponent for TableComponent {
let mut state = self.selected_row.clone();
f.render_stateful_widget(
table,
chunks[0],
chunks[1],
if let Some((_, y)) = self.selection_area_corner {
state.select(Some(y));
&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(
if self.rows.is_empty() {
None
@ -507,9 +509,9 @@ impl DrawableComponent for TableComponent {
},
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(())
}
}

@ -5,8 +5,7 @@ use anyhow::Result;
use tui::{
backend::Backend,
layout::{Alignment, Rect},
style::{Color, Modifier, Style},
text::Span,
style::{Color, Style},
widgets::{Block, Borders, Paragraph, Wrap},
Frame,
};
@ -24,15 +23,7 @@ impl TableValueComponent {
impl DrawableComponent for TableValueComponent {
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, area: Rect, focused: bool) -> Result<()> {
let paragraph = Paragraph::new(self.value.clone())
.block(
Block::default()
.borders(Borders::ALL)
.style(Style::default())
.title(Span::styled(
"Value",
Style::default().add_modifier(Modifier::BOLD),
)),
)
.block(Block::default().borders(Borders::BOTTOM))
.style(if focused {
Style::default()
} else {

Loading…
Cancel
Save