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