wip: header+column widths

This commit is contained in:
Jack Wills
2022-07-22 19:38:19 +00:00
parent d14744b378
commit 96ca208197
6 changed files with 430 additions and 170 deletions
+30 -7
View File
@@ -1,6 +1,8 @@
use std::{collections::HashMap, fmt};
use tui::layout::{Constraint, Rect};
use crate::app_data::Header;
#[derive(Debug, PartialEq, std::hash::Hash, std::cmp::Eq, Clone, Copy)]
pub enum SelectablePanel {
Containers,
@@ -165,7 +167,8 @@ pub struct GuiState {
// Think this should be a BMapTree, so can define order when iterating over potential intersects
// Is an issue if two panels are in the same space, sush as a smaller panel embedded, yet infront of, a larger panel
// If a BMapTree think it would mean have to implement ordering for SelectablePanel
area_map: HashMap<SelectablePanel, Rect>,
panel_map: HashMap<SelectablePanel, Rect>,
heading_map: HashMap<Header, Rect>,
loading_icon: Loading,
// Should be a vec, each time loading add a new to the vec, and reset remove from vec
// for for if is_loading just check if vec is empty or not
@@ -179,7 +182,8 @@ impl GuiState {
/// Generate a default gui_state
pub fn default() -> Self {
Self {
area_map: HashMap::new(),
panel_map: HashMap::new(),
heading_map: HashMap::new(),
loading_icon: Loading::One,
selected_panel: SelectablePanel::Containers,
show_help: false,
@@ -190,13 +194,13 @@ impl GuiState {
/// clear panels hash map, so on resize can fix the sizes for mouse clicks
pub fn clear_area_map(&mut self) {
self.area_map.clear();
self.panel_map.clear();
}
/// Check if a given Rect (a clicked area of 1x1), interacts with any known panels
pub fn rect_insersects(&mut self, rect: Rect) {
pub fn panel_intersect(&mut self, rect: Rect) {
if let Some(data) = self
.area_map
.panel_map
.iter()
.filter(|i| i.1.intersects(rect))
.collect::<Vec<_>>()
@@ -206,9 +210,28 @@ impl GuiState {
}
}
/// Check if a given Rect (a clicked area of 1x1), interacts with any known panels
pub fn header_intersect(&mut self, rect: Rect) -> Option<Header> {
self.heading_map
.iter()
.filter(|i| i.1.intersects(rect))
.collect::<Vec<_>>()
.get(0)
.map(|data| data.0.to_owned())
}
/// Insert selectable gui panel into area map
pub fn insert_into_area_map(&mut self, panel: SelectablePanel, area: Rect) {
self.area_map.entry(panel).or_insert(area);
/// 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);
}
/// Change to next selectable panel