moved block for mod_list out of app
This commit is contained in:
@@ -21,7 +21,9 @@ pub fn run(root_config: &mut RootConfig) -> anyhow::Result<()> {
|
||||
#[derive(Debug)]
|
||||
struct App<'a> {
|
||||
root_config: &'a mut RootConfig,
|
||||
|
||||
exit: bool,
|
||||
active_modal: bool,
|
||||
|
||||
mod_list_state: TableState,
|
||||
selected_instance: Option<String>,
|
||||
@@ -37,6 +39,7 @@ impl<'a> App<'a> {
|
||||
mod_list_state: state,
|
||||
selected_instance: None,
|
||||
exit: false,
|
||||
active_modal: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,16 +158,7 @@ impl<'a> Widget for &mut App<'a> {
|
||||
|
||||
InstanceSelect::new(self.selected_instance.clone()).render(chunks[0], buf);
|
||||
|
||||
let list_block = Block::default()
|
||||
.title("Mod list")
|
||||
.borders(Borders::ALL)
|
||||
.style(Style::default());
|
||||
|
||||
ModList::new(self.root_config).block(list_block).render(
|
||||
chunks[1],
|
||||
buf,
|
||||
&mut self.mod_list_state,
|
||||
);
|
||||
ModList::new(self.root_config).render(chunks[1], buf, &mut self.mod_list_state);
|
||||
|
||||
StatusBar.render(chunks[2], buf);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Constraint, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
widgets::{Block, Cell, Row, StatefulWidget, Table, TableState},
|
||||
widgets::{Block, Borders, Cell, Row, StatefulWidget, Table, TableState},
|
||||
};
|
||||
|
||||
use crate::types::{ModConfig, RootConfig};
|
||||
@@ -16,7 +16,6 @@ pub struct ListItem<'a> {
|
||||
#[derive(Debug)]
|
||||
pub struct ModList<'a> {
|
||||
items: Vec<ListItem<'a>>,
|
||||
block: Option<Block<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> ModList<'a> {
|
||||
@@ -31,12 +30,7 @@ impl<'a> ModList<'a> {
|
||||
.collect();
|
||||
|
||||
items.sort_by_key(|item| item.id);
|
||||
Self { items, block: None }
|
||||
}
|
||||
|
||||
pub fn block(mut self, block: Block<'a>) -> Self {
|
||||
self.block = Some(block);
|
||||
self
|
||||
Self { items }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +38,11 @@ impl<'a> StatefulWidget for ModList<'a> {
|
||||
type State = TableState;
|
||||
|
||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
|
||||
let block = Block::default()
|
||||
.title("Mod list")
|
||||
.borders(Borders::ALL)
|
||||
.style(Style::default());
|
||||
|
||||
let rows: Vec<Row> = self
|
||||
.items
|
||||
.iter()
|
||||
@@ -62,13 +61,9 @@ impl<'a> StatefulWidget for ModList<'a> {
|
||||
.bg(Color::DarkGray)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.block(block)
|
||||
.highlight_symbol(">> ");
|
||||
|
||||
let table = match self.block {
|
||||
Some(b) => table.block(b),
|
||||
None => table,
|
||||
};
|
||||
|
||||
StatefulWidget::render(table, area, buf, state);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user