diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2022-10-16 03:10:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-16 03:10:30 -0400 |
commit | b879c36588cd45ae382e152804e9421a5e8b9dd6 (patch) | |
tree | c56dcab3fc39299783cd6ce5ebc679afda029949 /src/app | |
parent | c0a5fd15b26ed9e6ceefd633cccd6102207666fa (diff) |
refactor: move some state code around (#839)
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/layout_manager.rs | 4 | ||||
-rw-r--r-- | src/app/states.rs | 38 | ||||
-rw-r--r-- | src/app/widgets.rs | 9 | ||||
-rw-r--r-- | src/app/widgets/battery_widget.rs | 5 | ||||
-rw-r--r-- | src/app/widgets/mem_graph.rs | 15 | ||||
-rw-r--r-- | src/app/widgets/net_graph.rs | 15 |
6 files changed, 50 insertions, 36 deletions
diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs index 9148ab5b..916a3d5b 100644 --- a/src/app/layout_manager.rs +++ b/src/app/layout_manager.rs @@ -872,11 +872,11 @@ pub struct BottomWidget { #[builder(default = None)] pub parent_reflector: Option<(WidgetDirection, u64)>, - /// Top left corner when drawn, for mouse click detection. (x, y) + /// Top left corner when drawn, for mouse click detection. (x, y) #[builder(default = None)] pub top_left_corner: Option<(u16, u16)>, - /// Bottom right corner when drawn, for mouse click detection. (x, y) + /// Bottom right corner when drawn, for mouse click detection. (x, y) #[builder(default = None)] pub bottom_right_corner: Option<(u16, u16)>, } diff --git a/src/app/states.rs b/src/app/states.rs index a1465640..dcecc15a 100644 --- a/src/app/states.rs +++ b/src/app/states.rs @@ -7,7 +7,10 @@ use crate::{ constants, }; -use super::widgets::{CpuWidgetState, DiskTableWidget, ProcWidget, TempWidgetState}; +use super::widgets::{ + BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState, + ProcWidget, TempWidgetState, +}; #[derive(Debug)] pub enum ScrollDirection { @@ -140,20 +143,6 @@ impl ProcState { } } -pub struct NetWidgetState { - pub current_display_time: u64, - pub autohide_timer: Option<Instant>, -} - -impl NetWidgetState { - pub fn init(current_display_time: u64, autohide_timer: Option<Instant>) -> Self { - NetWidgetState { - current_display_time, - autohide_timer, - } - } -} - pub struct NetState { pub force_update: Option<u64>, pub widget_states: HashMap<u64, NetWidgetState>, @@ -198,19 +187,6 @@ impl CpuState { } } -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>, @@ -281,12 +257,6 @@ pub struct BasicTableWidgetState { 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>, } diff --git a/src/app/widgets.rs b/src/app/widgets.rs index 6bdb0e55..2a00fa38 100644 --- a/src/app/widgets.rs +++ b/src/app/widgets.rs @@ -11,3 +11,12 @@ pub use disk_table::*; pub mod cpu_graph; pub use cpu_graph::*; + +pub mod net_graph; +pub use net_graph::*; + +pub mod mem_graph; +pub use mem_graph::*; + +pub mod battery_widget; +pub use battery_widget::*; diff --git a/src/app/widgets/battery_widget.rs b/src/app/widgets/battery_widget.rs new file mode 100644 index 00000000..68bbca79 --- /dev/null +++ b/src/app/widgets/battery_widget.rs @@ -0,0 +1,5 @@ +#[derive(Default)] +pub struct BatteryWidgetState { + pub currently_selected_battery_index: usize, + pub tab_click_locs: Option<Vec<((u16, u16), (u16, u16))>>, +} diff --git a/src/app/widgets/mem_graph.rs b/src/app/widgets/mem_graph.rs new file mode 100644 index 00000000..a86bd02a --- /dev/null +++ b/src/app/widgets/mem_graph.rs @@ -0,0 +1,15 @@ +use std::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, + } + } +} diff --git a/src/app/widgets/net_graph.rs b/src/app/widgets/net_graph.rs new file mode 100644 index 00000000..e3526210 --- /dev/null +++ b/src/app/widgets/net_graph.rs @@ -0,0 +1,15 @@ +use std::time::Instant; + +pub struct NetWidgetState { + pub current_display_time: u64, + pub autohide_timer: Option<Instant>, +} + +impl NetWidgetState { + pub fn init(current_display_time: u64, autohide_timer: Option<Instant>) -> Self { + NetWidgetState { + current_display_time, + autohide_timer, + } + } +} |