refactor: dead code removed

This commit is contained in:
Jack Wills
2022-07-23 04:22:56 +00:00
parent 740c059b27
commit 3dd1c1323b
5 changed files with 28 additions and 21 deletions
-1
View File
@@ -10,7 +10,6 @@ use super::Header;
#[derive(Debug, Clone)]
pub struct StatefulList<T> {
pub state: ListState,
// todo BTreeMap
pub items: Vec<T>,
}
+5 -4
View File
@@ -20,7 +20,7 @@ use crate::{
app_error::AppError,
};
use super::gui_state::BoxLocation;
use super::gui_state::{BoxLocation, Region};
use super::{GuiState, SelectablePanel};
const NAME_TEXT: &str = r#"
@@ -48,7 +48,7 @@ fn generate_block<'a>(
gui_state: &Arc<Mutex<GuiState>>,
panel: SelectablePanel,
) -> Block<'a> {
gui_state.lock().insert_into_panel_map(panel, area);
gui_state.lock().update_map(Region::Panel(panel), area);
let mut block = Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded);
@@ -473,10 +473,11 @@ pub fn draw_heading_bar<B: Backend>(
// draw the actual header blocks
for (index, (paragraph, header, _)) in header_data.into_iter().enumerate() {
let rect = headers_section[index];
gui_state
.lock()
.insert_into_header_map(header, headers_section[index]);
f.render_widget(paragraph, headers_section[index]);
.update_map(Region::Header(header), rect);
f.render_widget(paragraph, rect);
}
}
+14 -14
View File
@@ -10,6 +10,12 @@ pub enum SelectablePanel {
Logs,
}
pub enum Region {
Panel(SelectablePanel),
Header(Header)
}
#[allow(unused)]
#[derive(Debug, Clone, Copy)]
pub enum BoxLocation {
@@ -39,7 +45,7 @@ impl BoxLocation {
}
}
// Should combine and just return a tupple?
// Should combine and just return a tuple?
pub fn get_horizontal_constraints(
&self,
blank_vertical: u16,
@@ -177,7 +183,6 @@ pub struct GuiState {
pub show_help: bool,
pub info_box_text: Option<String>,
}
impl GuiState {
/// Generate a default gui_state
pub fn default() -> Self {
@@ -220,18 +225,13 @@ impl GuiState {
.map(|data| data.0.to_owned())
}
/// Insert selectable gui panel into area map
/// Remove each time, as terminal may have been resized!
pub fn insert_into_panel_map(&mut self, panel: SelectablePanel, area: Rect) {
self.panel_map.remove(&panel);
self.panel_map.insert(panel, area);
}
/// Insert selectable gui panel into area map
/// Remove each time, as terminal may have been resized!
pub fn insert_into_header_map(&mut self, header: Header, area: Rect) {
self.heading_map.remove(&header);
self.heading_map.insert(header, area);
/// Insert, or updatem header area panel into heading_map
pub fn update_map(&mut self, region: Region, area: Rect) {
match region {
Region::Header(header) =>
self.heading_map.entry(header).and_modify(|w|*w =area).or_insert(area),
Region::Panel(panel) => self.panel_map.entry(panel).and_modify(|w|*w =area).or_insert(area),
};
}
/// Change to next selectable panel