diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2023-06-02 00:53:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-02 00:53:38 -0400 |
commit | 852e2e86c7230cb339c7d0482d596194dbb59415 (patch) | |
tree | 93cc8f5f6909487e3fe5f5b958846f715f64455f /src/app | |
parent | 87a793f50176d29565268ef176248b2bb736d9b7 (diff) |
refactor: remove typed-builder (#1181)
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/layout_manager.rs | 87 |
1 files changed, 50 insertions, 37 deletions
diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs index 1f692e9b..4e7d3b0e 100644 --- a/src/app/layout_manager.rs +++ b/src/app/layout_manager.rs @@ -1,7 +1,5 @@ use std::collections::BTreeMap; -use typed_builder::*; - use crate::constants::DEFAULT_WIDGET_ID; use crate::error::{BottomError, Result}; @@ -675,32 +673,23 @@ impl BottomLayout { BottomLayout { total_row_height_ratio: 3, rows: vec![ - BottomRow::builder() - .canvas_handle_height(true) - .children(vec![BottomCol::new(vec![ - BottomColRow::new(vec![cpu]).canvas_handle_height(true) - ]) - .canvas_handle_width(true)]) - .build(), - BottomRow::builder() - .canvas_handle_height(true) - .children(vec![BottomCol::new(vec![BottomColRow::new(vec![ - mem, net, - ]) - .canvas_handle_height(true)]) - .canvas_handle_width(true)]) - .build(), - BottomRow::builder() - .canvas_handle_height(true) - .children(vec![BottomCol::new(vec![ - BottomColRow::new(vec![table]).canvas_handle_height(true) - ]) - .canvas_handle_width(true)]) - .build(), - BottomRow::builder() - .canvas_handle_height(true) - .children(table_widgets) - .build(), + BottomRow::new(vec![BottomCol::new(vec![ + BottomColRow::new(vec![cpu]).canvas_handle_height(true) + ]) + .canvas_handle_width(true)]) + .canvas_handle_height(true), + BottomRow::new(vec![BottomCol::new(vec![BottomColRow::new(vec![ + mem, net, + ]) + .canvas_handle_height(true)]) + .canvas_handle_width(true)]) + .canvas_handle_height(true), + BottomRow::new(vec![BottomCol::new(vec![ + BottomColRow::new(vec![table]).canvas_handle_height(true) + ]) + .canvas_handle_width(true)]) + .canvas_handle_height(true), + BottomRow::new(table_widgets).canvas_handle_height(true), ], } } @@ -729,23 +718,47 @@ impl BottomLayout { // } /// Represents a single row in the layout. -#[derive(Clone, Debug, TypedBuilder)] +#[derive(Clone, Debug)] pub struct BottomRow { pub children: Vec<BottomCol>, - - #[builder(default = 1)] pub total_col_ratio: u32, - - #[builder(default = 1)] pub row_height_ratio: u32, - - #[builder(default = false)] pub canvas_handle_height: bool, - - #[builder(default = false)] pub flex_grow: bool, } +impl BottomRow { + pub fn new(children: Vec<BottomCol>) -> Self { + Self { + children, + total_col_ratio: 1, + row_height_ratio: 1, + canvas_handle_height: false, + flex_grow: false, + } + } + + pub fn total_col_ratio(mut self, total_col_ratio: u32) -> Self { + self.total_col_ratio = total_col_ratio; + self + } + + pub fn row_height_ratio(mut self, row_height_ratio: u32) -> Self { + self.row_height_ratio = row_height_ratio; + self + } + + pub fn canvas_handle_height(mut self, canvas_handle_height: bool) -> Self { + self.canvas_handle_height = canvas_handle_height; + self + } + + pub fn flex_grow(mut self, flex_grow: bool) -> Self { + self.flex_grow = flex_grow; + self + } +} + /// Represents a single column in the layout. We assume that even if the column /// contains only ONE element, it is still a column (rather than either a col or /// a widget, as per the config, for simplicity's sake). |