mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-23 13:45:12 +02:00
refactor: remove TypedBuilder for col row (#1158)
This commit is contained in:
parent
f541947a59
commit
a1a48bc647
@ -538,9 +538,7 @@ impl BottomLayout {
|
||||
vec![
|
||||
BottomCol::builder()
|
||||
.canvas_handle_width(true)
|
||||
.children(vec![BottomColRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![BottomWidget::builder()
|
||||
.children(vec![BottomColRow::new(vec![BottomWidget::builder()
|
||||
.canvas_handle_width(true)
|
||||
.widget_type(BottomWidgetType::Disk)
|
||||
.widget_id(4)
|
||||
@ -548,15 +546,12 @@ impl BottomLayout {
|
||||
.left_neighbour(Some(8))
|
||||
.right_neighbour(Some(DEFAULT_WIDGET_ID + 2))
|
||||
.build()])
|
||||
.build()])
|
||||
.canvas_handle_height(true)])
|
||||
.build(),
|
||||
BottomCol::builder()
|
||||
.canvas_handle_width(true)
|
||||
.children(vec![
|
||||
BottomColRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.total_widget_ratio(3)
|
||||
.children(vec![
|
||||
BottomColRow::new(vec![
|
||||
BottomWidget::builder()
|
||||
.canvas_handle_width(true)
|
||||
.widget_type(BottomWidgetType::ProcSort)
|
||||
@ -579,10 +574,9 @@ impl BottomLayout {
|
||||
.width_ratio(2)
|
||||
.build(),
|
||||
])
|
||||
.build(),
|
||||
BottomColRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![BottomWidget::builder()
|
||||
.total_widget_ratio(3),
|
||||
BottomColRow::new(vec![BottomWidget::builder()
|
||||
.canvas_handle_width(true)
|
||||
.widget_type(BottomWidgetType::ProcSearch)
|
||||
.widget_id(DEFAULT_WIDGET_ID + 1)
|
||||
@ -591,14 +585,12 @@ impl BottomLayout {
|
||||
.right_neighbour(Some(7))
|
||||
.parent_reflector(Some((WidgetDirection::Up, 1)))
|
||||
.build()])
|
||||
.build(),
|
||||
.canvas_handle_height(true),
|
||||
])
|
||||
.build(),
|
||||
BottomCol::builder()
|
||||
.canvas_handle_width(true)
|
||||
.children(vec![BottomColRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![BottomWidget::builder()
|
||||
.children(vec![BottomColRow::new(vec![BottomWidget::builder()
|
||||
.canvas_handle_width(true)
|
||||
.widget_type(BottomWidgetType::Temp)
|
||||
.widget_id(7)
|
||||
@ -606,13 +598,11 @@ impl BottomLayout {
|
||||
.left_neighbour(Some(DEFAULT_WIDGET_ID))
|
||||
.right_neighbour(Some(8))
|
||||
.build()])
|
||||
.build()])
|
||||
.canvas_handle_height(true)])
|
||||
.build(),
|
||||
BottomCol::builder()
|
||||
.canvas_handle_width(true)
|
||||
.children(vec![BottomColRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![BottomWidget::builder()
|
||||
.children(vec![BottomColRow::new(vec![BottomWidget::builder()
|
||||
.canvas_handle_width(true)
|
||||
.widget_type(BottomWidgetType::Battery)
|
||||
.widget_id(8)
|
||||
@ -620,16 +610,14 @@ impl BottomLayout {
|
||||
.left_neighbour(Some(7))
|
||||
.right_neighbour(Some(4))
|
||||
.build()])
|
||||
.build()])
|
||||
.canvas_handle_height(true)])
|
||||
.build(),
|
||||
]
|
||||
} else {
|
||||
vec![
|
||||
BottomCol::builder()
|
||||
.canvas_handle_width(true)
|
||||
.children(vec![BottomColRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![BottomWidget::builder()
|
||||
.children(vec![BottomColRow::new(vec![BottomWidget::builder()
|
||||
.canvas_handle_width(true)
|
||||
.widget_type(BottomWidgetType::Disk)
|
||||
.widget_id(4)
|
||||
@ -637,14 +625,12 @@ impl BottomLayout {
|
||||
.left_neighbour(Some(7))
|
||||
.right_neighbour(Some(DEFAULT_WIDGET_ID + 2))
|
||||
.build()])
|
||||
.build()])
|
||||
.canvas_handle_height(true)])
|
||||
.build(),
|
||||
BottomCol::builder()
|
||||
.canvas_handle_width(true)
|
||||
.children(vec![
|
||||
BottomColRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![
|
||||
BottomColRow::new(vec![
|
||||
BottomWidget::builder()
|
||||
.canvas_handle_width(true)
|
||||
.widget_type(BottomWidgetType::ProcSort)
|
||||
@ -665,10 +651,8 @@ impl BottomLayout {
|
||||
.right_neighbour(Some(7))
|
||||
.build(),
|
||||
])
|
||||
.build(),
|
||||
BottomColRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![BottomWidget::builder()
|
||||
.canvas_handle_height(true),
|
||||
BottomColRow::new(vec![BottomWidget::builder()
|
||||
.canvas_handle_width(true)
|
||||
.widget_type(BottomWidgetType::ProcSearch)
|
||||
.widget_id(DEFAULT_WIDGET_ID + 1)
|
||||
@ -677,14 +661,12 @@ impl BottomLayout {
|
||||
.right_neighbour(Some(7))
|
||||
.parent_reflector(Some((WidgetDirection::Up, 1)))
|
||||
.build()])
|
||||
.build(),
|
||||
.canvas_handle_height(true),
|
||||
])
|
||||
.build(),
|
||||
BottomCol::builder()
|
||||
.canvas_handle_width(true)
|
||||
.children(vec![BottomColRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![BottomWidget::builder()
|
||||
.children(vec![BottomColRow::new(vec![BottomWidget::builder()
|
||||
.canvas_handle_width(true)
|
||||
.widget_type(BottomWidgetType::Temp)
|
||||
.widget_id(7)
|
||||
@ -692,7 +674,7 @@ impl BottomLayout {
|
||||
.left_neighbour(Some(DEFAULT_WIDGET_ID))
|
||||
.right_neighbour(Some(4))
|
||||
.build()])
|
||||
.build()])
|
||||
.canvas_handle_height(true)])
|
||||
.build(),
|
||||
]
|
||||
};
|
||||
@ -704,24 +686,20 @@ impl BottomLayout {
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![BottomCol::builder()
|
||||
.canvas_handle_width(true)
|
||||
.children(vec![BottomColRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![BottomWidget::builder()
|
||||
.children(vec![BottomColRow::new(vec![BottomWidget::builder()
|
||||
.canvas_handle_width(true)
|
||||
.widget_type(BottomWidgetType::BasicCpu)
|
||||
.widget_id(1)
|
||||
.down_neighbour(Some(2))
|
||||
.build()])
|
||||
.build()])
|
||||
.canvas_handle_height(true)])
|
||||
.build()])
|
||||
.build(),
|
||||
BottomRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![BottomCol::builder()
|
||||
.canvas_handle_width(true)
|
||||
.children(vec![BottomColRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![
|
||||
.children(vec![BottomColRow::new(vec![
|
||||
BottomWidget::builder()
|
||||
.canvas_handle_width(true)
|
||||
.widget_type(BottomWidgetType::BasicMem)
|
||||
@ -739,22 +717,20 @@ impl BottomLayout {
|
||||
.left_neighbour(Some(2))
|
||||
.build(),
|
||||
])
|
||||
.build()])
|
||||
.canvas_handle_height(true)])
|
||||
.build()])
|
||||
.build(),
|
||||
BottomRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![BottomCol::builder()
|
||||
.canvas_handle_width(true)
|
||||
.children(vec![BottomColRow::builder()
|
||||
.canvas_handle_height(true)
|
||||
.children(vec![BottomWidget::builder()
|
||||
.children(vec![BottomColRow::new(vec![BottomWidget::builder()
|
||||
.canvas_handle_width(true)
|
||||
.widget_type(BottomWidgetType::BasicTables)
|
||||
.widget_id(100)
|
||||
.up_neighbour(Some(2))
|
||||
.build()])
|
||||
.build()])
|
||||
.canvas_handle_height(true)])
|
||||
.build()])
|
||||
.build(),
|
||||
BottomRow::builder()
|
||||
@ -804,23 +780,47 @@ pub struct BottomCol {
|
||||
pub flex_grow: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Debug, TypedBuilder)]
|
||||
#[derive(Clone, Default, Debug)]
|
||||
pub struct BottomColRow {
|
||||
pub children: Vec<BottomWidget>,
|
||||
|
||||
#[builder(default = 1)]
|
||||
pub total_widget_ratio: u32,
|
||||
|
||||
#[builder(default = 1)]
|
||||
pub col_row_height_ratio: u32,
|
||||
|
||||
#[builder(default = false)]
|
||||
pub canvas_handle_height: bool,
|
||||
|
||||
#[builder(default = false)]
|
||||
pub flex_grow: bool,
|
||||
}
|
||||
|
||||
impl BottomColRow {
|
||||
pub(crate) fn new(children: Vec<BottomWidget>) -> Self {
|
||||
Self {
|
||||
children,
|
||||
total_widget_ratio: 1,
|
||||
col_row_height_ratio: 1,
|
||||
canvas_handle_height: false,
|
||||
flex_grow: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn total_widget_ratio(mut self, total_widget_ratio: u32) -> Self {
|
||||
self.total_widget_ratio = total_widget_ratio;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn col_row_height_ratio(mut self, col_row_height_ratio: u32) -> Self {
|
||||
self.col_row_height_ratio = col_row_height_ratio;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn canvas_handle_height(mut self, canvas_handle_height: bool) -> Self {
|
||||
self.canvas_handle_height = canvas_handle_height;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn flex_grow(mut self, flex_grow: bool) -> Self {
|
||||
self.flex_grow = flex_grow;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum WidgetDirection {
|
||||
Left,
|
||||
|
@ -59,18 +59,13 @@ impl Row {
|
||||
BottomCol::builder()
|
||||
.col_width_ratio(width_ratio)
|
||||
.children(if left_legend {
|
||||
vec![BottomColRow::builder()
|
||||
.total_widget_ratio(20)
|
||||
.children(vec![
|
||||
vec![BottomColRow::new(vec![
|
||||
BottomWidget::builder()
|
||||
.width_ratio(3)
|
||||
.widget_type(BottomWidgetType::CpuLegend)
|
||||
.widget_id(*iter_id)
|
||||
.canvas_handle_width(true)
|
||||
.parent_reflector(Some((
|
||||
WidgetDirection::Right,
|
||||
1,
|
||||
)))
|
||||
.parent_reflector(Some((WidgetDirection::Right, 1)))
|
||||
.build(),
|
||||
BottomWidget::builder()
|
||||
.width_ratio(17)
|
||||
@ -79,11 +74,9 @@ impl Row {
|
||||
.flex_grow(true)
|
||||
.build(),
|
||||
])
|
||||
.build()]
|
||||
.total_widget_ratio(20)]
|
||||
} else {
|
||||
vec![BottomColRow::builder()
|
||||
.total_widget_ratio(20)
|
||||
.children(vec![
|
||||
vec![BottomColRow::new(vec![
|
||||
BottomWidget::builder()
|
||||
.width_ratio(17)
|
||||
.widget_type(BottomWidgetType::Cpu)
|
||||
@ -95,13 +88,10 @@ impl Row {
|
||||
.widget_type(BottomWidgetType::CpuLegend)
|
||||
.widget_id(*iter_id)
|
||||
.canvas_handle_width(true)
|
||||
.parent_reflector(Some((
|
||||
WidgetDirection::Left,
|
||||
1,
|
||||
)))
|
||||
.parent_reflector(Some((WidgetDirection::Left, 1)))
|
||||
.build(),
|
||||
])
|
||||
.build()]
|
||||
.total_widget_ratio(20)]
|
||||
})
|
||||
.build()
|
||||
}
|
||||
@ -113,16 +103,12 @@ impl Row {
|
||||
.total_col_row_ratio(2)
|
||||
.col_width_ratio(width_ratio)
|
||||
.children(vec![
|
||||
BottomColRow::builder()
|
||||
.children(vec![
|
||||
BottomColRow::new(vec![
|
||||
BottomWidget::builder()
|
||||
.widget_type(BottomWidgetType::ProcSort)
|
||||
.widget_id(*iter_id)
|
||||
.canvas_handle_width(true)
|
||||
.parent_reflector(Some((
|
||||
WidgetDirection::Right,
|
||||
2,
|
||||
)))
|
||||
.parent_reflector(Some((WidgetDirection::Right, 2)))
|
||||
.width_ratio(1)
|
||||
.build(),
|
||||
BottomWidget::builder()
|
||||
@ -132,27 +118,22 @@ impl Row {
|
||||
.build(),
|
||||
])
|
||||
.total_widget_ratio(3)
|
||||
.flex_grow(true)
|
||||
.build(),
|
||||
BottomColRow::builder()
|
||||
.children(vec![BottomWidget::builder()
|
||||
.flex_grow(true),
|
||||
BottomColRow::new(vec![BottomWidget::builder()
|
||||
.widget_type(BottomWidgetType::ProcSearch)
|
||||
.widget_id(proc_search_id)
|
||||
.parent_reflector(Some((WidgetDirection::Up, 1)))
|
||||
.build()])
|
||||
.canvas_handle_height(true)
|
||||
.build(),
|
||||
.canvas_handle_height(true),
|
||||
])
|
||||
.build()
|
||||
}
|
||||
_ => BottomCol::builder()
|
||||
.col_width_ratio(width_ratio)
|
||||
.children(vec![BottomColRow::builder()
|
||||
.children(vec![BottomWidget::builder()
|
||||
.children(vec![BottomColRow::new(vec![BottomWidget::builder()
|
||||
.widget_type(widget_type)
|
||||
.widget_id(*iter_id)
|
||||
.build()])
|
||||
.build()])
|
||||
.build()])])
|
||||
.build(),
|
||||
});
|
||||
}
|
||||
@ -194,10 +175,7 @@ impl Row {
|
||||
*iter_id += 1;
|
||||
if left_legend {
|
||||
col_row_children.push(
|
||||
BottomColRow::builder()
|
||||
.col_row_height_ratio(col_row_height_ratio)
|
||||
.total_widget_ratio(20)
|
||||
.children(vec![
|
||||
BottomColRow::new(vec![
|
||||
BottomWidget::builder()
|
||||
.width_ratio(3)
|
||||
.widget_type(BottomWidgetType::CpuLegend)
|
||||
@ -215,14 +193,12 @@ impl Row {
|
||||
.flex_grow(true)
|
||||
.build(),
|
||||
])
|
||||
.build(),
|
||||
.col_row_height_ratio(col_row_height_ratio)
|
||||
.total_widget_ratio(20),
|
||||
);
|
||||
} else {
|
||||
col_row_children.push(
|
||||
BottomColRow::builder()
|
||||
.col_row_height_ratio(col_row_height_ratio)
|
||||
.total_widget_ratio(20)
|
||||
.children(vec![
|
||||
BottomColRow::new(vec![
|
||||
BottomWidget::builder()
|
||||
.width_ratio(17)
|
||||
.widget_type(BottomWidgetType::Cpu)
|
||||
@ -240,7 +216,8 @@ impl Row {
|
||||
)))
|
||||
.build(),
|
||||
])
|
||||
.build(),
|
||||
.col_row_height_ratio(col_row_height_ratio)
|
||||
.total_widget_ratio(20),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -250,16 +227,12 @@ impl Row {
|
||||
let proc_search_id = *iter_id + 1;
|
||||
*iter_id += 2;
|
||||
col_row_children.push(
|
||||
BottomColRow::builder()
|
||||
.children(vec![
|
||||
BottomColRow::new(vec![
|
||||
BottomWidget::builder()
|
||||
.widget_type(BottomWidgetType::ProcSort)
|
||||
.widget_id(*iter_id)
|
||||
.canvas_handle_width(true)
|
||||
.parent_reflector(Some((
|
||||
WidgetDirection::Right,
|
||||
2,
|
||||
)))
|
||||
.parent_reflector(Some((WidgetDirection::Right, 2)))
|
||||
.width_ratio(1)
|
||||
.build(),
|
||||
BottomWidget::builder()
|
||||
@ -269,29 +242,24 @@ impl Row {
|
||||
.build(),
|
||||
])
|
||||
.col_row_height_ratio(col_row_height_ratio)
|
||||
.total_widget_ratio(3)
|
||||
.build(),
|
||||
.total_widget_ratio(3),
|
||||
);
|
||||
col_row_children.push(
|
||||
BottomColRow::builder()
|
||||
.col_row_height_ratio(col_row_height_ratio)
|
||||
.children(vec![BottomWidget::builder()
|
||||
BottomColRow::new(vec![BottomWidget::builder()
|
||||
.widget_type(BottomWidgetType::ProcSearch)
|
||||
.widget_id(proc_search_id)
|
||||
.parent_reflector(Some((WidgetDirection::Up, 1)))
|
||||
.build()])
|
||||
.canvas_handle_height(true)
|
||||
.build(),
|
||||
.col_row_height_ratio(col_row_height_ratio),
|
||||
);
|
||||
}
|
||||
_ => col_row_children.push(
|
||||
BottomColRow::builder()
|
||||
.col_row_height_ratio(col_row_height_ratio)
|
||||
.children(vec![BottomWidget::builder()
|
||||
BottomColRow::new(vec![BottomWidget::builder()
|
||||
.widget_type(widget_type)
|
||||
.widget_id(*iter_id)
|
||||
.build()])
|
||||
.build(),
|
||||
.col_row_height_ratio(col_row_height_ratio),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user