diff options
author | ClementTsang <cjhtsang@uwaterloo.ca> | 2021-05-23 18:51:35 -0400 |
---|---|---|
committer | ClementTsang <cjhtsang@uwaterloo.ca> | 2021-08-23 16:55:27 -0400 |
commit | f73ea0da365efa35be31379d799a2a9f07bfc38f (patch) | |
tree | d97752e0e5f0de4e936b320f8a94f7b36973aed1 /src/app | |
parent | d1e672f26329a6483608ccd61a55f1e33f9662da (diff) |
refactor: Start state refactor
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/data_harvester/cpu/heim/mod.rs | 2 | ||||
-rw-r--r-- | src/app/data_harvester/mod.rs (renamed from src/app/data_harvester.rs) | 2 | ||||
-rw-r--r-- | src/app/data_harvester/network/heim.rs | 2 | ||||
-rw-r--r-- | src/app/data_harvester/processes/linux.rs | 6 | ||||
-rw-r--r-- | src/app/filter.rs | 14 | ||||
-rw-r--r-- | src/app/widget_states/battery_state.rs | 25 | ||||
-rw-r--r-- | src/app/widget_states/cpu_state.rs | 47 | ||||
-rw-r--r-- | src/app/widget_states/disk_state.rs | 35 | ||||
-rw-r--r-- | src/app/widget_states/graph_state.rs | 1 | ||||
-rw-r--r-- | src/app/widget_states/mem_state.rs | 37 | ||||
-rw-r--r-- | src/app/widget_states/mod.rs | 125 | ||||
-rw-r--r-- | src/app/widget_states/net_state.rs | 52 | ||||
-rw-r--r-- | src/app/widget_states/process_state.rs (renamed from src/app/states.rs) | 342 | ||||
-rw-r--r-- | src/app/widget_states/table_state.rs | 1 | ||||
-rw-r--r-- | src/app/widget_states/temp_state.rs | 35 |
15 files changed, 383 insertions, 343 deletions
diff --git a/src/app/data_harvester/cpu/heim/mod.rs b/src/app/data_harvester/cpu/heim/mod.rs index 73a97b5b..6941dd0c 100644 --- a/src/app/data_harvester/cpu/heim/mod.rs +++ b/src/app/data_harvester/cpu/heim/mod.rs @@ -102,7 +102,7 @@ pub async fn get_cpu_data_list( .enumerate() .map(|(itx, (current_cpu, (past_cpu_work, past_cpu_total)))| { if let Ok(cpu_time) = current_cpu { - let present_times = convert_cpu_times(&cpu_time); + let present_times = convert_cpu_times(cpu_time); ( present_times, diff --git a/src/app/data_harvester.rs b/src/app/data_harvester/mod.rs index 5d2bebfe..32482537 100644 --- a/src/app/data_harvester.rs +++ b/src/app/data_harvester/mod.rs @@ -238,7 +238,7 @@ impl DataCollector { if let Some(battery_manager) = &self.battery_manager { if let Some(battery_list) = &mut self.battery_list { self.data.list_of_batteries = - Some(batteries::refresh_batteries(&battery_manager, battery_list)); + Some(batteries::refresh_batteries(battery_manager, battery_list)); } } diff --git a/src/app/data_harvester/network/heim.rs b/src/app/data_harvester/network/heim.rs index d18287c8..3c12fd73 100644 --- a/src/app/data_harvester/network/heim.rs +++ b/src/app/data_harvester/network/heim.rs @@ -25,7 +25,7 @@ pub async fn get_network_data( if filter.is_list_ignored { let mut ret = true; for r in &filter.list { - if r.is_match(&io.interface()) { + if r.is_match(io.interface()) { ret = false; break; } diff --git a/src/app/data_harvester/processes/linux.rs b/src/app/data_harvester/processes/linux.rs index 79c77190..87297837 100644 --- a/src/app/data_harvester/processes/linux.rs +++ b/src/app/data_harvester/processes/linux.rs @@ -137,7 +137,7 @@ fn read_proc( first_part .rsplit_once('/') .map(|(_prefix, suffix)| suffix) - .unwrap_or(&truncated_name) + .unwrap_or(truncated_name) .to_string() } else { truncated_name.to_string() @@ -155,7 +155,7 @@ fn read_proc( let process_state_char = stat.state; let process_state = ProcessStatus::from(process_state_char).to_string(); let (cpu_usage_percent, new_process_times) = get_linux_cpu_usage( - &stat, + stat, cpu_usage, cpu_fraction, prev_proc.cpu_time, @@ -258,7 +258,7 @@ pub fn get_process_data( } if let Ok((process_harvest, new_process_times)) = read_proc( - &prev_proc_details, + prev_proc_details, stat, cpu_usage, cpu_fraction, diff --git a/src/app/filter.rs b/src/app/filter.rs new file mode 100644 index 00000000..2674f74d --- /dev/null +++ b/src/app/filter.rs @@ -0,0 +1,14 @@ +#[derive(Debug, Clone)] +pub struct Filter { + pub is_list_ignored: bool, + pub list: Vec<regex::Regex>, +} + +/// For filtering out information +#[derive(Debug, Clone)] +pub struct DataFilters { + pub disk_filter: Option<Filter>, + pub mount_filter: Option<Filter>, + pub temp_filter: Option<Filter>, + pub net_filter: Option<Filter>, +} diff --git a/src/app/widget_states/battery_state.rs b/src/app/widget_states/battery_state.rs new file mode 100644 index 00000000..62f27d93 --- /dev/null +++ b/src/app/widget_states/battery_state.rs @@ -0,0 +1,25 @@ +use std::collections::HashMap; + +#[derive(Default)] +pub struct BatteryWidgetState { + pub currently_selected_battery_index: usize, + pub tab_click_locs: Option<Vec<((u16, u16), (u16, u16))>>, +} + +pub struct BatteryState { + pub widget_states: HashMap<u64, BatteryWidgetState>, +} + +impl BatteryState { + pub fn init(widget_states: HashMap<u64, BatteryWidgetState>) -> Self { + BatteryState { widget_states } + } + + pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut BatteryWidgetState> { + self.widget_states.get_mut(&widget_id) + } + + pub fn get_widget_state(&self, widget_id: u64) -> Option<&BatteryWidgetState> { + self.widget_states.get(&widget_id) + } +} diff --git a/src/app/widget_states/cpu_state.rs b/src/app/widget_states/cpu_state.rs new file mode 100644 index 00000000..c155cf84 --- /dev/null +++ b/src/app/widget_states/cpu_state.rs @@ -0,0 +1,47 @@ +use std::{collections::HashMap, time::Instant}; + +use super::{AppScrollWidgetState, CanvasTableWidthState}; + +pub struct CpuWidgetState { + pub current_display_time: u64, + pub is_legend_hidden: bool, + pub autohide_timer: Option<Instant>, + pub scroll_state: AppScrollWidgetState, + pub is_multi_graph_mode: bool, + pub table_width_state: CanvasTableWidthState, +} + +impl CpuWidgetState { + pub fn init(current_display_time: u64, autohide_timer: Option<Instant>) -> Self { + CpuWidgetState { + current_display_time, + is_legend_hidden: false, + autohide_timer, + scroll_state: AppScrollWidgetState::default(), + is_multi_graph_mode: false, + table_width_state: CanvasTableWidthState::default(), + } + } +} + +pub struct CpuState { + pub force_update: Option<u64>, + pub widget_states: HashMap<u64, CpuWidgetState>, +} + +impl CpuState { + pub fn init(widget_states: HashMap<u64, CpuWidgetState>) -> Self { + CpuState { + force_update: None, + widget_states, + } + } + + pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut CpuWidgetState> { + self.widget_states.get_mut(&widget_id) + } + + pub fn get_widget_state(&self, widget_id: u64) -> Option<&CpuWidgetState> { + self.widget_states.get(&widget_id) + } +} diff --git a/src/app/widget_states/disk_state.rs b/src/app/widget_states/disk_state.rs new file mode 100644 index 00000000..8528668c --- /dev/null +++ b/src/app/widget_states/disk_state.rs @@ -0,0 +1,35 @@ +use std::collections::HashMap; + +use super::{AppScrollWidgetState, CanvasTableWidthState}; + +pub struct DiskWidgetState { + pub scroll_state: AppScrollWidgetState, + pub table_width_state: CanvasTableWidthState, +} + +impl DiskWidgetState { + pub fn init() -> Self { + DiskWidgetState { + scroll_state: AppScrollWidgetState::default(), + table_width_state: CanvasTableWidthState::default(), + } + } +} + +pub struct DiskState { + pub widget_states: HashMap<u64, DiskWidgetState>, +} + +impl DiskState { + pub fn init(widget_states: HashMap<u64, DiskWidgetState>) -> Self { + DiskState { widget_states } + } + + pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut DiskWidgetState> { + self.widget_states.get_mut(&widget_id) + } + + pub fn get_widget_state(&self, widget_id: u64) -> Option<&DiskWidgetState> { + self.widget_states.get(&widget_id) + } +} diff --git a/src/app/widget_states/graph_state.rs b/src/app/widget_states/graph_state.rs new file mode 100644 index 00000000..6f3b55d4 --- /dev/null +++ b/src/app/widget_states/graph_state.rs @@ -0,0 +1 @@ +//! States for a graph widget. diff --git a/src/app/widget_states/mem_state.rs b/src/app/widget_states/mem_state.rs new file mode 100644 index 00000000..1e6ce5f7 --- /dev/null +++ b/src/app/widget_states/mem_state.rs @@ -0,0 +1,37 @@ +use std::{collections::HashMap, time::Instant}; + +pub struct MemWidgetState { + pub current_display_time: u64, + pub autohide_timer: Option<Instant>, +} + +impl MemWidgetState { + pub fn init(current_display_time: u64, autohide_timer: Option<Instant>) -> Self { + MemWidgetState { + current_display_time, + autohide_timer, + } + } +} + +pub struct MemState { + pub force_update: Option<u64>, + pub widget_states: HashMap<u64, MemWidgetState>, +} + +impl MemState { + pub fn init(widget_states: HashMap<u64, MemWidgetState>) -> Self { + MemState { + force_update: None, + widget_states, + } + } + + pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut MemWidgetState> { + self.widget_states.get_mut(&widget_id) + } + + pub fn get_widget_state(&self, widget_id: u64) -> Option<&MemWidgetState> { + self.widget_states.get(&widget_id) + } +} diff --git a/src/app/widget_states/mod.rs b/src/app/widget_states/mod.rs new file mode 100644 index 00000000..dc6c02e7 --- /dev/null +++ b/src/app/widget_states/mod.rs @@ -0,0 +1,125 @@ +use std::time::Instant; + +use tui::widgets::TableState; + +use crate::{app::layout_manager::BottomWidgetType, constants}; + +pub mod process_state; +pub use process_state::*; + +pub mod net_state; +pub use net_state::*; + +pub mod mem_state; +pub use mem_state::*; + +pub mod cpu_state; +pub use cpu_state::*; + +pub mod disk_state; +pub use disk_state::*; + +pub mod battery_state; +pub use battery_state::*; + +pub mod temp_state; +pub use temp_state::*; + +#[derive(Debug)] +pub enum ScrollDirection { + // UP means scrolling up --- this usually DECREMENTS + Up, + // DOWN means scrolling down --- this usually INCREMENTS + Down, +} + +impl Default for ScrollDirection { + fn default() -> Self { + ScrollDirection::Down + } +} + +#[derive(Debug)] +pub enum CursorDirection { + Left, + Right, +} + +/// AppScrollWidgetState deals with fields for a scrollable app's current state. +#[derive(Default)] +pub struct AppScrollWidgetState { + pub current_scroll_position: usize, + pub previous_scroll_position: usize, + pub scroll_direction: ScrollDirection, + pub table_state: TableState, +} + +#[derive(PartialEq)] +pub enum KillSignal { + Cancel, + Kill(usize), +} + +impl Default for KillSignal { + #[cfg(target_family = "unix")] + fn default() -> Self { + KillSignal::Kill(15) + } + #[cfg(target_os = "windows")] + fn default() -> Self { + KillSignal::Kill(1) + } +} + +#[derive(Default)] +pub struct AppDeleteDialogState { + pub is_showing_dd: bool, + pub selected_signal: KillSignal, + /// tl x, tl y, br x, br y, index/signal + pub button_positions: Vec<(u16, u16, u16, u16, usize)>, + pub keyboard_signal_select: usize, + pub last_number_press: Option<Instant>, + pub scroll_pos: usize, +} + +pub struct AppHelpDialogState { + pub is_showing_help: bool, + pub scroll_state: ParagraphScrollState, + pub index_shortcuts: Vec<u16>, +} + +impl Default for AppHelpDialogState { + fn default() -> Self { + AppHelpDialogState { + is_showing_help: false, + scroll_state: ParagraphScrollState::default(), + index_shortcuts: vec![0; constants::HELP_TEXT.len()], + } + } +} + +/// Meant for canvas operations involving table column widths. +#[derive(Default)] +pub struct CanvasTableWidthState { + pub desired_column_widths: Vec<u16>, + pub calculated_column_widths: Vec<u16>, +} + +pub struct BasicTableWidgetState { + // Since this is intended (currently) to only be used for ONE widget, that's + // how it's going to be written. If we want to allow for multiple of these, + // then we can expand outwards with a normal BasicTableState and a hashmap + pub currently_displayed_widget_type: BottomWidgetType, + pub currently_displayed_widget_id: u64, + pub widget_id: i64, + pub left_tlc: Option<(u16, u16)>, + pub left_brc: Option<(u16, u16)>, + pub right_tlc: Option<(u16, u16)>, + pub right_brc: Option<(u16, u16)>, +} + +#[derive(Default)] +pub struct ParagraphScrollState { + pub current_scroll_index: u16, + pub max_scroll_index: u16, +} diff --git a/src/app/widget_states/net_state.rs b/src/app/widget_states/net_state.rs new file mode 100644 index 00000000..85c1281e --- /dev/null +++ b/src/app/widget_states/net_state.rs @@ -0,0 +1,52 @@ +use std::{collections::HashMap, time::Instant}; + +pub struct NetWidgetState { + pub current_display_time: u64, + pub autohide_timer: Option<Instant>, + // pub draw_max_range_cache: f64, + // pub draw_labels_cache: Vec<String>, + // pub draw_time_start_cache: f64, + // TODO: Re-enable these when we move net details state-side! + // pub unit_type: DataUnitTypes, + // pub scale_type: AxisScaling, +} + +impl NetWidgetState { + pub fn init( + current_display_time: u64, + autohide_timer: Option<Instant>, + // unit_type: DataUnitTypes, + // scale_type: AxisScaling, + ) -> Self { + NetWidgetState { + current_display_time, + autohide_timer, + // draw_max_range_cache: 0.0, + // draw_labels_cache: vec![], + // draw_time_start_cache: 0.0, + // unit_type, + // scale_type, + } + } +} +pub struct NetState { + pub force_update: Option<u64>, + pub widget_states: HashMap<u64, NetWidgetState>, +} + +impl NetState { + pub fn init(widget_states: HashMap<u64, NetWidgetState>) -> Self { + NetState { + force_update: None, + widget_states, + } + } + + pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut NetWidgetState> { + self.widget_states.get_mut(&widget_id) + } + + pub fn get_widget_state(&self, widget_id: u64) -> Option<&NetWidgetState> { + self.widget_states.get(&widget_id) + } +} diff --git a/src/app/states.rs b/src/app/widget_states/process_state.rs index 28d1323b..dedc7b83 100644 --- a/src/app/states.rs +++ b/src/app/widget_states/process_state.rs @@ -1,88 +1,16 @@ -use std::{collections::HashMap, time::Instant}; +use std::collections::HashMap; use unicode_segmentation::GraphemeCursor; use tui::widgets::TableState; use crate::{ - app::{layout_manager::BottomWidgetType, query::*}, - constants, + app::query::*, data_harvester::processes::{self, ProcessSorting}, }; use ProcessSorting::*; -#[derive(Debug)] -pub enum ScrollDirection { - // UP means scrolling up --- this usually DECREMENTS - Up, - // DOWN means scrolling down --- this usually INCREMENTS - Down, -} - -impl Default for ScrollDirection { - fn default() -> Self { - ScrollDirection::Down - } -} - -#[derive(Debug)] -pub enum CursorDirection { - Left, - Right, -} - -/// AppScrollWidgetState deals with fields for a scrollable app's current state. -#[derive(Default)] -pub struct AppScrollWidgetState { - pub current_scroll_position: usize, - pub previous_scroll_position: usize, - pub scroll_direction: ScrollDirection, - pub table_state: TableState, -} - -#[derive(PartialEq)] -pub enum KillSignal { - Cancel, - Kill(usize), -} - -impl Default for KillSignal { - #[cfg(target_family = "unix")] - fn default() -> Self { - KillSignal::Kill(15) - } - #[cfg(target_os = "windows")] - fn default() -> Self { - KillSignal::Kill(1) - } -} - -#[derive(Default)] -pub struct AppDeleteDialogState { - pub is_showing_dd: bool, - pub selected_signal: KillSignal, - /// tl x, tl y, br x, br y, index/signal - pub button_positions: Vec<(u16, u16, u16, u16, usize)>, - pub keyboard_signal_select: usize, - pub last_number_press: Option<Instant>, - pub scroll_pos: usize, -} - -pub struct AppHelpDialogState { - pub is_showing_help: bool, - pub scroll_state: ParagraphScrollState, - pub index_shortcuts: Vec<u16>, -} - -impl Default for AppHelpDialogState { - fn default() -> Self { - AppHelpDialogState { - is_showing_help: false, - scroll_state: ParagraphScrollState::default(), - index_shortcuts: vec![0; constants::HELP_TEXT.len()], - } - } -} +use super::{AppScrollWidgetState, CanvasTableWidthState, CursorDirection, ScrollDirection}; /// AppSearchState deals with generic searching (I might do this in the future). pub struct AppSearchState { @@ -131,13 +59,6 @@ impl AppSearchState { } } -/// Meant for canvas operations involving table column widths. -#[derive(Default)] -pub struct CanvasTableWidthState { - pub desired_column_widths: Vec<u16>, - pub calculated_column_widths: Vec<u16>, -} - /// ProcessSearchState only deals with process' search's current settings and state. pub struct ProcessSearchState { pub search_state: AppSearchState, @@ -383,7 +304,7 @@ impl ProcColumn { self.ordered_columns .iter() .filter_map(|column_type| { - if let Some(col_map) = self.column_mapping.get(&column_type) { + if let Some(col_map) = self.column_mapping.get(column_type) { if col_map.enabled { Some(1) } else { @@ -429,7 +350,7 @@ impl ProcColumn { self.ordered_columns .iter() .filter_map(|column_type| { - let mapping = self.column_mapping.get(&column_type).unwrap(); + let mapping = self.column_mapping.get(column_type).unwrap(); let mut command_str = String::default(); if let Some(command) = mapping.shortcut { command_str = format!("({})", command); @@ -685,256 +606,3 @@ impl ProcState { self.widget_states.get(&widget_id) } } - -pub struct NetWidgetState { - pub current_display_time: u64, - pub autohide_timer: Option<Instant>, - // pub draw_max_range_cache: f64, - // pub draw_labels_cache: Vec<String>, - // pub draw_time_start_cache: f64, - // TODO: Re-enable these when we move net details state-side! - // pub unit_type: DataUnitTypes, - // pub scale_type: AxisScaling, -} - -impl NetWidgetState { - pub fn init( - current_display_time: u64, - autohide_timer: Option<Instant>, - // unit_type: DataUnitTypes, - // scale_type: AxisScaling, - ) -> Self { - NetWidgetState { - current_display_time, - autohide_timer, - // draw_max_range_cache: 0.0, - // draw_labels_cache: vec![], - // draw_time_start_cache: 0.0, - // unit_type, - // scale_type, - } - } -} - -pub struct NetState { - pub force_update: Option<u64>, - pub widget_states: HashMap<u64, NetWidgetState>, -} - -impl NetState { - pub fn init(widget_states: HashMap<u64, NetWidgetState>) -> Self { - NetState { - force_update: None, - widget_states, - } - } - - pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut NetWidgetState> { - self.widget_states.get_mut(&widget_id) - } - - pub fn get_widget_state(&self, widget_id: u64) -> Option<&NetWidgetState> { - self.widget_states.get(&widget_id) - } -} - -pub struct CpuWidgetState { - pub current_display_time: u64, - pub is_legend_hidden: bool, - pub autohide_timer: Option<Instant>, - pub scroll_state: AppScrollWidgetState, - pub is_multi_graph_mode: bool, - pub table_width_state: CanvasTableWidthState, -} - -impl CpuWidgetState { - pub fn init(current_display_time: u64, autohide_timer: Option<Instant>) -> Self { - CpuWidgetState { - current_display_time, - is_legend_hidden: false, - autohide_timer, - scroll_state: AppScrollWidgetState::default(), - is_multi_graph_mode: false, - table_width_state: CanvasTableWidthState::default(), - } - } -} - -pub struct CpuState { - pub force_update: Option<u64>, - pub widget_states: HashMap<u64, CpuWidgetState>, -} - -impl CpuState { - pub fn init(widget_states: HashMap<u64, CpuWidgetState>) -> Self { - CpuState { - force_update: None, - widget_states, - } - } - - pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut CpuWidgetState> { - self.widget_states.get_mut(&widget_id) - } - - pub fn get_widget_state(&self, widget_id: u64) -> Option<&CpuWidgetState> { - self.widget_states.get(&widget_id) - } -} - -pub struct MemWidgetState { - pub current_display_time: u64, - pub autohide_timer: Option<Instant>, -} - -impl MemWidgetState { - pub fn init(current_display_time: u64, autohide_timer: Option<Instant>) -> Self { - MemWidgetState { - current_display_time, - autohide_timer, - } - } -} -pub struct MemState { - pub force_update: Option<u64>, - pub widget_states: HashMap<u64, MemWidgetState>, -} - -impl MemState { - pub fn init(widget_states: HashMap<u64, MemWidgetState>) -> Self { - MemState { - force_update: None, - widget_states, - } - } - - pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut MemWidgetState> { - self.widget_states.get_mut(&widget_id) - } - - pub fn get_widget_state(&self, widget_id: u64) -> Option<&MemWidgetState> { - self.widget_states.get(&widget_id) - } -} - -pub struct TempWidgetState { - pub scroll_state: AppScrollWidgetState, - pub table_width_state: CanvasTableWidthState, -} - -impl TempWidgetState { - pub fn init() -> Self { - TempWidgetState { - scroll_state: AppScrollWidgetState::default(), - table_width_state: CanvasTableWidthState::default(), - } - } -} - -pub struct TempState { - pub widget_states: HashMap<u64, TempWidgetState>, -} - -impl TempState { - pub fn init(widget_states: HashMap<u64, TempWidgetState>) -> Self { - TempState { widget_states } - } - - pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut TempWidgetState> { - self.widget_states.get_mut(&widget_id) - } - - pub fn get_widget_state(&self, widget_id: u64) -> Option<&TempWidgetState> { - self.widget_states.get(&widget_id) - } -} - -pub struct DiskWidgetState { - pub scroll_state: AppScrollWidgetState, - pub table_width_state: CanvasTableWidthState, -} - -impl DiskWidgetState { - pub fn init() -> Self { - DiskWidgetState { - scroll_state: AppScrollWidgetState::default(), - table_width_state: CanvasTableWidthState::default(), - } - } -} - -pub struct DiskState { - pub widget_states: HashMap<u64, DiskWidgetState>, -} - -impl DiskState { - pub fn init(widget_states: HashMap<u64, DiskWidgetState>) -> Self { - DiskState { widget_states } - } - - pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut DiskWidgetState> { - self.widget_states.get_mut(&widget_id) - } - - pub fn get_widget_state(&self, widget_id: u64) -> Option<&DiskWidgetState> { - self.widget_states.get(&widget_id) - } -} -pub struct BasicTableWidgetState { - // Since this is intended (currently) to only be used for ONE widget, that's - // how it's going to be written. If we want to allow for multiple of these, - // then we can expand outwards with a normal BasicTableState and a hashmap - pub currently_displayed_widget_type: BottomWidgetType, - pub currently_displayed_widget_id: u64, - pub widget_id: i64, - pub left_tlc: Option<(u16, u16)>, - pub left_brc: Option<(u16, u16)>, - pub right_tlc: Option<(u16, u16)>, - pub right_brc: Option<(u16, u16)>, -} - -#[derive(Default)] -pub struct BatteryWidgetState { - pub currently_selected_battery_index: usize, - pub tab_click_locs: Option<Vec<((u16, u16), (u16, u16))>>, -} - -pub struct BatteryState { - pub widget_states: HashMap<u64, BatteryWidgetState>, -} - -impl BatteryState { - pub fn init(widget_states: HashMap<u64, BatteryWidgetState>) -> Self { - BatteryState { widget_states } - } - - pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut BatteryWidgetState> { - self.widget_states.get_mut(&widget_id) - } - - pub fn get_widget_state(&self, widget_id: u64) -> Option<&BatteryWidgetState> { - self.widget_states.get(&widget_id) - } -} - -#[derive(Default)] -pub struct ParagraphScrollState { - pub current_scroll_index: u16, - pub max_scroll_index: u16, -} - -#[derive(Default)] -pub struct ConfigState { - pub current_category_index: usize, - pub category_list: Vec<ConfigCategory>, -} - -#[derive(Default)] -pub struct ConfigCategory { - pub category_name: &'static str, - pub options_list: Vec<ConfigOption>, -} - -pub struct ConfigOption { - pub set_function: Box<dyn Fn() -> anyhow::Result<()>>, -} diff --git a/src/app/widget_states/table_state.rs b/src/app/widget_states/table_state.rs new file mode 100644 index 00000000..2e57e8f1 --- /dev/null +++ b/src/app/widget_states/table_state.rs @@ -0,0 +1 @@ +//! States for a table widget. diff --git a/src/app/widget_states/temp_state.rs b/src/app/widget_states/temp_state.rs new file mode 100644 index 00000000..e8bd73f4 --- /dev/null +++ b/src/app/widget_states/temp_state.rs @@ -0,0 +1,35 @@ +use std::collections::HashMap; + +use super::{AppScrollWidgetState, CanvasTableWidthState}; + +pub struct TempWidgetState { + pub scroll_state: AppScrollWidgetState, + pub table_width_state: CanvasTableWidthState, +} + +impl TempWidgetState { + pub fn init() -> Self { + TempWidgetState { + scroll_state: AppScrollWidgetState::default(), + table_width_state: CanvasTableWidthState::default(), + } + } +} + +pub struct TempState { + pub widget_states: HashMap<u64, TempWidgetState>, +} + +impl TempState { + pub fn init(widget_states: HashMap<u64, TempWidgetState>) -> Self { + TempState { widget_states } + } + + pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut TempWidgetState> { + self.widget_states.get_mut(&widget_id) + } + + pub fn get_widget_state(&self, widget_id: u64) -> Option<&TempWidgetState> { + self.widget_states.get(&widget_id) + } +} |