mirror of
https://github.com/TaKO8Ki/gobang.git
synced 2021-09-19 22:32:56 +03:00
Integrate table_value into table (#90)
* integrate table_value into table * remove wrap * remove wrap and alignment
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use tui::{
|
||||
layout::Rect,
|
||||
style::{Color, Style},
|
||||
text::{Span, Spans},
|
||||
widgets::{Block, Borders, Paragraph, Wrap},
|
||||
widgets::{Block, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
|
||||
@@ -64,8 +64,7 @@ impl DrawableComponent for TableStatusComponent {
|
||||
Style::default()
|
||||
} else {
|
||||
Style::default().fg(Color::DarkGray)
|
||||
}))
|
||||
.wrap(Wrap { trim: true });
|
||||
}));
|
||||
f.render_widget(status, area);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@ use crate::event::Key;
|
||||
use anyhow::Result;
|
||||
use tui::{
|
||||
backend::Backend,
|
||||
layout::{Alignment, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
text::Span,
|
||||
widgets::{Block, Borders, Paragraph, Wrap},
|
||||
layout::Rect,
|
||||
style::{Color, Style},
|
||||
widgets::{Block, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
|
||||
@@ -24,22 +23,12 @@ 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 {
|
||||
Style::default().fg(Color::DarkGray)
|
||||
})
|
||||
.alignment(Alignment::Left)
|
||||
.wrap(Wrap { trim: true });
|
||||
});
|
||||
f.render_widget(paragraph, area);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user