refactor: remove typed-builder (#1181)

This commit is contained in:
Clement Tsang 2023-06-02 00:53:38 -04:00 committed by GitHub
parent 87a793f501
commit 852e2e86c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 54 deletions

12
Cargo.lock generated
View File

@ -176,7 +176,6 @@ dependencies = [
"thiserror", "thiserror",
"time", "time",
"toml_edit", "toml_edit",
"typed-builder",
"unicode-segmentation", "unicode-segmentation",
"unicode-width", "unicode-width",
"windows", "windows",
@ -1276,17 +1275,6 @@ dependencies = [
"winnow", "winnow",
] ]
[[package]]
name = "typed-builder"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64cba322cb9b7bc6ca048de49e83918223f35e7a86311267013afff257004870"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.16.0" version = "1.16.0"

View File

@ -102,7 +102,6 @@ thiserror = "1.0.40"
time = { version = "0.3.21", features = ["formatting", "macros"] } time = { version = "0.3.21", features = ["formatting", "macros"] }
toml_edit = { version = "0.19.10", features = ["serde"] } toml_edit = { version = "0.19.10", features = ["serde"] }
tui = { version = "0.21.0", package = "ratatui" } tui = { version = "0.21.0", package = "ratatui" }
typed-builder = "0.14.0"
unicode-segmentation = "1.10.1" unicode-segmentation = "1.10.1"
unicode-width = "0.1.10" unicode-width = "0.1.10"

View File

@ -1,7 +1,5 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use typed_builder::*;
use crate::constants::DEFAULT_WIDGET_ID; use crate::constants::DEFAULT_WIDGET_ID;
use crate::error::{BottomError, Result}; use crate::error::{BottomError, Result};
@ -675,32 +673,23 @@ impl BottomLayout {
BottomLayout { BottomLayout {
total_row_height_ratio: 3, total_row_height_ratio: 3,
rows: vec![ rows: vec![
BottomRow::builder() BottomRow::new(vec![BottomCol::new(vec![
.canvas_handle_height(true) BottomColRow::new(vec![cpu]).canvas_handle_height(true)
.children(vec![BottomCol::new(vec![ ])
BottomColRow::new(vec![cpu]).canvas_handle_height(true) .canvas_handle_width(true)])
]) .canvas_handle_height(true),
.canvas_handle_width(true)]) BottomRow::new(vec![BottomCol::new(vec![BottomColRow::new(vec![
.build(), mem, net,
BottomRow::builder() ])
.canvas_handle_height(true) .canvas_handle_height(true)])
.children(vec![BottomCol::new(vec![BottomColRow::new(vec![ .canvas_handle_width(true)])
mem, net, .canvas_handle_height(true),
]) BottomRow::new(vec![BottomCol::new(vec![
.canvas_handle_height(true)]) BottomColRow::new(vec![table]).canvas_handle_height(true)
.canvas_handle_width(true)]) ])
.build(), .canvas_handle_width(true)])
BottomRow::builder() .canvas_handle_height(true),
.canvas_handle_height(true) BottomRow::new(table_widgets).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(),
], ],
} }
} }
@ -729,23 +718,47 @@ impl BottomLayout {
// } // }
/// Represents a single row in the layout. /// Represents a single row in the layout.
#[derive(Clone, Debug, TypedBuilder)] #[derive(Clone, Debug)]
pub struct BottomRow { pub struct BottomRow {
pub children: Vec<BottomCol>, pub children: Vec<BottomCol>,
#[builder(default = 1)]
pub total_col_ratio: u32, pub total_col_ratio: u32,
#[builder(default = 1)]
pub row_height_ratio: u32, pub row_height_ratio: u32,
#[builder(default = false)]
pub canvas_handle_height: bool, pub canvas_handle_height: bool,
#[builder(default = false)]
pub flex_grow: bool, 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 /// 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 /// 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). /// a widget, as per the config, for simplicity's sake).

View File

@ -218,11 +218,9 @@ impl Row {
} }
} }
Ok(BottomRow::builder() Ok(BottomRow::new(children)
.total_col_ratio(total_col_ratio) .total_col_ratio(total_col_ratio)
.row_height_ratio(row_ratio) .row_height_ratio(row_ratio))
.children(children)
.build())
} }
} }