summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2024-01-15 04:19:18 -0500
committerGitHub <noreply@github.com>2024-01-15 04:19:18 -0500
commitdd66ae774ca9a93a2c1bd471e3b1ba2075044f15 (patch)
tree8c6c76195150944da8a42b7131b65acb8f78918c /src
parentf093902aef3954bef79fa348c46e1bf3949675cf (diff)
refactor: simplify some config -> constraints code (#1383)
* refactor: simplify some config -> constraints code * iteratively progress... * update bcr; this might need testing since I removed some old proc code * widget side * fix battery * fix widget tests with bandaid for now The issue was that the calculations assume a certain ratio for CPU legends. * add some tests * bump up * fix proc drawing issues So with the proc widget in certain places, there would be a panic during constraint determination. Looks like back when I wrote this I made some gross assumptions about certain things. In particular, the problem here was that the search added an additional "one" height, so that needs to be accounted for after we removed the "doubling" code. * tests * fix tests * reorganize tests * clippy * fix cross tests not working * fix builds for android
Diffstat (limited to 'src')
-rw-r--r--src/app/layout_manager.rs273
-rw-r--r--src/canvas.rs91
-rw-r--r--src/options.rs16
-rw-r--r--src/options/config/layout.rs84
4 files changed, 224 insertions, 240 deletions
diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs
index ca353f52..e7904c9a 100644
--- a/src/app/layout_manager.rs
+++ b/src/app/layout_manager.rs
@@ -66,20 +66,20 @@ impl BottomLayout {
col_row_mapping.insert(
(
widget_width * 100 / col_row.total_widget_ratio,
- (widget_width + widget.width_ratio) * 100
+ (widget_width + widget.constraint.ratio()) * 100
/ col_row.total_widget_ratio,
),
widget.widget_id,
);
}
}
- widget_width += widget.width_ratio;
+ widget_width += widget.constraint.ratio();
}
if is_valid_col_row {
col_mapping.insert(
(
col_row_height * 100 / col.total_col_row_ratio,
- (col_row_height + col_row.col_row_height_ratio) * 100
+ (col_row_height + col_row.constraint.ratio()) * 100
/ col.total_col_row_ratio,
),
(col.total_col_row_ratio, col_row_mapping),
@@ -87,31 +87,31 @@ impl BottomLayout {
is_valid_col = true;
}
- col_row_height += col_row.col_row_height_ratio;
+ col_row_height += col_row.constraint.ratio();
}
if is_valid_col {
row_mapping.insert(
(
row_width * 100 / row.total_col_ratio,
- (row_width + col.col_width_ratio) * 100 / row.total_col_ratio,
+ (row_width + col.constraint.ratio()) * 100 / row.total_col_ratio,
),
(row.total_col_ratio, col_mapping),
);
is_valid_row = true;
}
- row_width += col.col_width_ratio;
+ row_width += col.constraint.ratio();
}
if is_valid_row {
layout_mapping.insert(
(
total_height * 100 / self.total_row_height_ratio,
- (total_height + row.row_height_ratio) * 100 / self.total_row_height_ratio,
+ (total_height + row.constraint.ratio()) * 100 / self.total_row_height_ratio,
),
(self.total_row_height_ratio, row_mapping),
);
}
- total_height += row.row_height_ratio;
+ total_height += row.constraint.ratio();
}
// Now pass through a second time; this time we want to build up
@@ -121,20 +121,20 @@ impl BottomLayout {
let mut col_cursor = 0;
let row_height_percentage_start = height_cursor * 100 / self.total_row_height_ratio;
let row_height_percentage_end =
- (height_cursor + row.row_height_ratio) * 100 / self.total_row_height_ratio;
+ (height_cursor + row.constraint.ratio()) * 100 / self.total_row_height_ratio;
for col in &mut row.children {
let mut col_row_cursor = 0;
let col_width_percentage_start = col_cursor * 100 / row.total_col_ratio;
let col_width_percentage_end =
- (col_cursor + col.col_width_ratio) * 100 / row.total_col_ratio;
+ (col_cursor + col.constraint.ratio()) * 100 / row.total_col_ratio;
for col_row in &mut col.children {
let mut widget_cursor = 0;
let col_row_height_percentage_start =
col_row_cursor * 100 / col.total_col_row_ratio;
let col_row_height_percentage_end =
- (col_row_cursor + col_row.col_row_height_ratio) * 100
+ (col_row_cursor + col_row.constraint.ratio()) * 100
/ col.total_col_row_ratio;
let col_row_children_len = col_row.children.len();
@@ -147,7 +147,8 @@ impl BottomLayout {
let widget_width_percentage_start =
widget_cursor * 100 / col_row.total_widget_ratio;
let widget_width_percentage_end =
- (widget_cursor + widget.width_ratio) * 100 / col_row.total_widget_ratio;
+ (widget_cursor + widget.constraint.ratio()) * 100
+ / col_row.total_widget_ratio;
if let Some(current_row) = layout_mapping
.get(&(row_height_percentage_start, row_height_percentage_end))
@@ -523,91 +524,85 @@ impl BottomLayout {
}
}
}
- widget_cursor += widget.width_ratio;
+ widget_cursor += widget.constraint.ratio();
}
- col_row_cursor += col_row.col_row_height_ratio;
+ col_row_cursor += col_row.constraint.ratio();
}
- col_cursor += col.col_width_ratio;
+ col_cursor += col.constraint.ratio();
}
- height_cursor += row.row_height_ratio;
+ height_cursor += row.constraint.ratio();
}
}
pub fn init_basic_default(use_battery: bool) -> Self {
let table_widgets = if use_battery {
let disk_widget = BottomWidget::new(BottomWidgetType::Disk, 4)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(100))
.left_neighbour(Some(8))
.right_neighbour(Some(DEFAULT_WIDGET_ID + 2));
let proc_sort = BottomWidget::new(BottomWidgetType::ProcSort, DEFAULT_WIDGET_ID + 2)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(100))
.down_neighbour(Some(DEFAULT_WIDGET_ID + 1))
.left_neighbour(Some(4))
.right_neighbour(Some(DEFAULT_WIDGET_ID))
- .width_ratio(1)
+ .ratio(1)
.parent_reflector(Some((WidgetDirection::Right, 2)));
let proc = BottomWidget::new(BottomWidgetType::Proc, DEFAULT_WIDGET_ID)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(100))
.down_neighbour(Some(DEFAULT_WIDGET_ID + 1))
.left_neighbour(Some(DEFAULT_WIDGET_ID + 2))
.right_neighbour(Some(7))
- .width_ratio(2);
+ .ratio(2);
let proc_search =
BottomWidget::new(BottomWidgetType::ProcSearch, DEFAULT_WIDGET_ID + 1)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(DEFAULT_WIDGET_ID))
.left_neighbour(Some(4))
.right_neighbour(Some(7))
.parent_reflector(Some((WidgetDirection::Up, 1)));
let temp = BottomWidget::new(BottomWidgetType::Temp, 7)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(100))
.left_neighbour(Some(DEFAULT_WIDGET_ID))
.right_neighbour(Some(8));
let battery = BottomWidget::new(BottomWidgetType::Battery, 8)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(100))
.left_neighbour(Some(7))
.right_neighbour(Some(4));
vec![
- BottomCol::new(vec![
- BottomColRow::new(vec![disk_widget]).canvas_handle_height(true)
- ])
- .canvas_handle_width(true),
+ BottomCol::new(vec![BottomColRow::new(vec![disk_widget]).canvas_handled()])
+ .canvas_handled(),
BottomCol::new(vec![
BottomColRow::new(vec![proc_sort, proc])
- .canvas_handle_height(true)
+ .canvas_handled()
.total_widget_ratio(3),
- BottomColRow::new(vec![proc_search]).canvas_handle_height(true),
- ])
- .canvas_handle_width(true),
- BottomCol::new(vec![
- BottomColRow::new(vec![temp]).canvas_handle_height(true)
+ BottomColRow::new(vec![proc_search]).canvas_handled(),
])
- .canvas_handle_width(true),
- BottomCol::new(vec![
- BottomColRow::new(vec![battery]).canvas_handle_height(true)
- ])
- .canvas_handle_width(true),
+ .canvas_handled(),
+ BottomCol::new(vec![BottomColRow::new(vec![temp]).canvas_handled()])
+ .canvas_handled(),
+ BottomCol::new(vec![BottomColRow::new(vec![battery]).canvas_handled()])
+ .canvas_handled(),
]
} else {
let disk = BottomWidget::new(BottomWidgetType::Disk, 4)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(100))
.left_neighbour(Some(7))
.right_neighbour(Some(DEFAULT_WIDGET_ID + 2));
let proc_sort = BottomWidget::new(BottomWidgetType::ProcSort, DEFAULT_WIDGET_ID + 2)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(100))
.down_neighbour(Some(DEFAULT_WIDGET_ID + 1))
.left_neighbour(Some(4))
@@ -615,7 +610,7 @@ impl BottomLayout {
.parent_reflector(Some((WidgetDirection::Right, 2)));
let proc = BottomWidget::new(BottomWidgetType::Proc, DEFAULT_WIDGET_ID)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(100))
.down_neighbour(Some(DEFAULT_WIDGET_ID + 1))
.left_neighbour(Some(DEFAULT_WIDGET_ID + 2))
@@ -623,110 +618,111 @@ impl BottomLayout {
let proc_search =
BottomWidget::new(BottomWidgetType::ProcSearch, DEFAULT_WIDGET_ID + 1)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(DEFAULT_WIDGET_ID))
.left_neighbour(Some(4))
.right_neighbour(Some(7))
.parent_reflector(Some((WidgetDirection::Up, 1)));
let temp = BottomWidget::new(BottomWidgetType::Temp, 7)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(100))
.left_neighbour(Some(DEFAULT_WIDGET_ID))
.right_neighbour(Some(4));
vec![
+ BottomCol::new(vec![BottomColRow::new(vec![disk]).canvas_handled()])
+ .canvas_handled(),
BottomCol::new(vec![
- BottomColRow::new(vec![disk]).canvas_handle_height(true)
- ])
- .canvas_handle_width(true),
- BottomCol::new(vec![
- BottomColRow::new(vec![proc_sort, proc]).canvas_handle_height(true),
- BottomColRow::new(vec![proc_search]).canvas_handle_height(true),
+ BottomColRow::new(vec![proc_sort, proc]).canvas_handled(),
+ BottomColRow::new(vec![proc_search]).canvas_handled(),
])
- .canvas_handle_width(true),
- BottomCol::new(vec![
- BottomColRow::new(vec![temp]).canvas_handle_height(true)
- ])
- .canvas_handle_width(true),
+ .canvas_handled(),
+ BottomCol::new(vec![BottomColRow::new(vec![temp]).canvas_handled()])
+ .canvas_handled(),
]
};
let cpu = BottomWidget::new(BottomWidgetType::BasicCpu, 1)
- .canvas_handle_width(true)
+ .canvas_handled()
.down_neighbour(Some(2));
let mem = BottomWidget::new(BottomWidgetType::BasicMem, 2)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(1))
.down_neighbour(Some(100))
.right_neighbour(Some(3));
let net = BottomWidget::new(BottomWidgetType::BasicNet, 3)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(1))
.down_neighbour(Some(100))
.left_neighbour(Some(2));
let table = BottomWidget::new(BottomWidgetType::BasicTables, 100)
- .canvas_handle_width(true)
+ .canvas_handled()
.up_neighbour(Some(2));
BottomLayout {
total_row_height_ratio: 3,
rows: vec![
BottomRow::new(vec![BottomCol::new(vec![
- BottomColRow::new(vec![cpu]).canvas_handle_height(true)
+ BottomColRow::new(vec![cpu]).canvas_handled()
])
- .canvas_handle_width(true)])
- .canvas_handle_height(true),
+ .canvas_handled()])
+ .canvas_handled(),
BottomRow::new(vec![BottomCol::new(vec![BottomColRow::new(vec![
mem, net,
])
- .canvas_handle_height(true)])
- .canvas_handle_width(true)])
- .canvas_handle_height(true),
+ .canvas_handled()])
+ .canvas_handled()])
+ .canvas_handled(),
BottomRow::new(vec![BottomCol::new(vec![
- BottomColRow::new(vec![table]).canvas_handle_height(true)
+ BottomColRow::new(vec![table]).canvas_handled()
])
- .canvas_handle_width(true)])
- .canvas_handle_height(true),
- BottomRow::new(table_widgets).canvas_handle_height(true),
+ .canvas_handled()])
+ .canvas_handled(),
+ BottomRow::new(table_widgets).canvas_handled(),
],
}
}
}
-// pub enum BottomLayoutNode {
-// Container(BottomContainer),
-// Widget(BottomWidget),
-// }
-
-// pub struct BottomContainer {
-// children: Vec<BottomLayoutNode>,
-// root_ratio: u32,
-// growth_type: BottomLayoutNodeSizing,
-// }
+#[derive(Clone, Debug)]
+pub enum IntermediaryConstraint {
+ PartialRatio(u32),
+ CanvasHandled { ratio: Option<u32> },
+ Grow { minimum: Option<u32> },
+}
-// pub enum BottomContainerType {
-// Row,
-// Col,
-// }
+impl Default for IntermediaryConstraint {
+ fn default() -> Self {
+ IntermediaryConstraint::PartialRatio(1)
+ }
+}
-// pub enum BottomLayoutNodeSizing {
-// Ratio(u32),
-// CanvasHandles,
-// FlexGrow,
-// }
+impl IntermediaryConstraint {
+ pub fn ratio(&self) -> u32 {
+ match self {
+ IntermediaryConstraint::PartialRatio(val) => *val,
+ IntermediaryConstraint::Grow { minimum } => match minimum {
+ Some(val) => *val,
+ None => 1,
+ },
+ IntermediaryConstraint::CanvasHandled { ratio } => match ratio {
+ Some(val) => *val,
+ None => 1,
+ },
+ }
+ }
+}
/// Represents a single row in the layout.
#[derive(Clone, Debug)]
pub struct BottomRow {
pub children: Vec<BottomCol>,
pub total_col_ratio: u32,
- pub row_height_ratio: u32,
- pub canvas_handle_height: bool,
- pub flex_grow: bool,
+ pub constraint: IntermediaryConstraint,
}
impl BottomRow {
@@ -734,9 +730,7 @@ impl BottomRow {
Self {
children,
total_col_ratio: 1,
- row_height_ratio: 1,
- canvas_handle_height: false,
- flex_grow: false,
+ constraint: IntermediaryConstraint::default(),
}
}
@@ -745,18 +739,18 @@ impl BottomRow {
self
}
- pub fn row_height_ratio(mut self, row_height_ratio: u32) -> Self {
- self.row_height_ratio = row_height_ratio;
+ pub fn ratio(mut self, row_height_ratio: u32) -> Self {
+ self.constraint = IntermediaryConstraint::PartialRatio(row_height_ratio);
self
}
- pub fn canvas_handle_height(mut self, canvas_handle_height: bool) -> Self {
- self.canvas_handle_height = canvas_handle_height;
+ pub fn canvas_handled(mut self) -> Self {
+ self.constraint = IntermediaryConstraint::CanvasHandled { ratio: None };
self
}
- pub fn flex_grow(mut self, flex_grow: bool) -> Self {
- self.flex_grow = flex_grow;
+ pub fn grow(mut self, minimum: Option<u32>) -> Self {
+ self.constraint = IntermediaryConstraint::Grow { minimum };
self
}
}
@@ -768,9 +762,7 @@ impl BottomRow {
pub struct BottomCol {
pub children: Vec<BottomColRow>,
pub total_col_row_ratio: u32,
- pub col_width_ratio: u32,
- pub canvas_handle_width: bool,
- pub flex_grow: bool,
+ pub constraint: IntermediaryConstraint,
}
impl BottomCol {
@@ -778,9 +770,7 @@ impl BottomCol {
Self {
children,
total_col_row_ratio: 1,
- col_width_ratio: 1,
- canvas_handle_width: false,
- flex_grow: false,
+ constraint: IntermediaryConstraint::default(),
}
}
@@ -789,18 +779,18 @@ impl BottomCol {
self
}
- pub fn col_width_ratio(mut self, col_width_ratio: u32) -> Self {
- self.col_width_ratio = col_width_ratio;
+ pub fn ratio(mut self, col_width_ratio: u32) -> Self {
+ self.constraint = IntermediaryConstraint::PartialRatio(col_width_ratio);
self
}
- pub fn canvas_handle_width(mut self, canvas_handle_width: bool) -> Self {
- self.canvas_handle_width = canvas_handle_width;
+ pub fn canvas_handled(mut self) -> Self {
+ self.constraint = IntermediaryConstraint::CanvasHandled { ratio: None };
self
}
- pub fn flex_grow(mut self, flex_grow: bool) -> Self {
- self.flex_grow = flex_grow;
+ pub fn grow(mut self, minimum: Option<u32>) -> Self {
+ self.constraint = IntermediaryConstraint::Grow { minimum };
self
}
}
@@ -809,9 +799,7 @@ impl BottomCol {
pub struct BottomColRow {
pub children: Vec<BottomWidget>,
pub total_widget_ratio: u32,
- pub col_row_height_ratio: u32,
- pub canvas_handle_height: bool,
- pub flex_grow: bool,
+ pub constraint: IntermediaryConstraint,
}
impl BottomColRow {
@@ -819,9 +807,7 @@ impl BottomColRow {
Self {
children,
total_widget_ratio: 1,
- col_row_height_ratio: 1,
- canvas_handle_height: false,
- flex_grow: false,
+ constraint: IntermediaryConstraint::default(),
}
}
@@ -830,18 +816,18 @@ impl BottomColRow {
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;
+ pub fn ratio(mut self, col_row_height_ratio: u32) -> Self {
+ self.constraint = IntermediaryConstraint::PartialRatio(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;
+ pub fn canvas_handled(mut self) -> Self {
+ self.constraint = IntermediaryConstraint::CanvasHandled { ratio: None };
self
}
- pub(crate) fn flex_grow(mut self, flex_grow: bool) -> Self {
- self.flex_grow = flex_grow;
+ pub fn grow(mut self, minimum: Option<u32>) -> Self {
+ self.constraint = IntermediaryConstraint::Grow { minimum };
self
}
}
@@ -872,18 +858,12 @@ impl WidgetDirection {
pub struct BottomWidget {
pub widget_type: BottomWidgetType,
pub widget_id: u64,
- pub width_ratio: u32,
+ pub constraint: IntermediaryConstraint,
pub left_neighbour: Option<u64>,
pub right_neighbour: Option<u64>,
pub up_neighbour: Option<u64>,
pub down_neighbour: Option<u64>,
- /// If set to true, the canvas will override any ratios.
- pub canvas_handle_width: bool,
-
- /// Whether we want this widget to take up all available room (and ignore any ratios).
- pub flex_grow: bool,
-
/// The value is the direction to bounce, as well as the parent offset.
pub parent_reflector: Option<(WidgetDirection, u64)>,
@@ -899,24 +879,17 @@ impl BottomWidget {
Self {
widget_type,
widget_id,
- width_ratio: 1,
+ constraint: IntermediaryConstraint::default(),
left_neighbour: None,
right_neighbour: None,
up_neighbour: None,
down_neighbour: None,
- canvas_handle_width: false,
- flex_grow: false,
parent_reflector: None,
top_left_corner: None,
bottom_right_corner: None,
}
}
- pub(crate) fn width_ratio(mut self, width_ratio: u32) -> Self {
- self.width_ratio = width_ratio;
- self
- }
-
pub(crate) fn left_neighbour(mut self, left_neighbour: Option<u64>) -> Self {
self.left_neighbour = left_neighbour;
self
@@ -937,13 +910,23 @@ impl BottomWidget {
self
}
- pub(crate) fn canvas_handle_width(mut self, canvas_handle_width: bool) -> Self {
- self.canvas_handle_width = canvas_handle_width;
+ pub(crate) fn ratio(mut self, width_ratio: u32) -> Self {
+ self.constraint = IntermediaryConstraint::PartialRatio(width_ratio);
self
}
- pub(crate) fn flex_grow(mut self, flex_grow: bool) -> Self {
- self.flex_grow = flex_grow;
+ pub fn canvas_handled(mut self) -> Self {
+ self.constraint = IntermediaryConstraint::CanvasHandled { ratio: None };
+ self
+ }
+
+ pub fn canvas_with_ratio(mut self, ratio: u32) -> Self {
+ self.constraint = IntermediaryConstraint::CanvasHandled { ratio: Some(ratio) };
+ self
+ }
+
+ pub fn grow(mut self, minimum: Option<u32>) -> Self {
+ self.constraint = IntermediaryConstraint::Grow { minimum };
self
}
@@ -1038,6 +1021,8 @@ Supported widget names:
+--------------------------+
| batt, battery |
+--------------------------+
+| empty |
++--------------------------+
",
)))
}
@@ -1060,6 +1045,8 @@ Supported widget names:
+--------------------------+
| disk |
+--------------------------+
+| empty |
++--------------------------+
",
)))
}
diff --git a/src/canvas.rs b/src/canvas.rs
index 3a02803b..0f3e7202 100644
--- a/src/canvas.rs
+++ b/src/canvas.rs
@@ -18,7 +18,7 @@ use tui::{
use crate::{
app::{
- layout_manager::{BottomColRow, BottomLayout, BottomWidgetType},
+ layout_manager::{BottomColRow, BottomLayout, BottomWidgetType, IntermediaryConstraint},
App,
},
constants::*,
@@ -80,7 +80,7 @@ pub enum LayoutConstraint {
}
impl Painter {
- pub fn init(widget_layout: BottomLayout, styling: CanvasStyling) -> anyhow::Result<Self> {
+ pub fn init(layout: BottomLayout, styling: CanvasStyling) -> anyhow::Result<Self> {
// Now for modularity; we have to also initialize the base layouts!
// We want to do this ONCE and reuse; after this we can just construct
// based on the console size.
@@ -90,56 +90,69 @@ impl Painter {
let mut col_row_constraints = Vec::new();
let mut layout_constraints = Vec::new();
- widget_layout.rows.iter().for_each(|row| {
- if row.canvas_handle_height {
- row_constraints.push(LayoutConstraint::CanvasHandled);
- } else {
- row_constraints.push(LayoutConstraint::Ratio(
- row.row_height_ratio,
- widget_layout.total_row_height_ratio,
- ));
+ layout.rows.iter().for_each(|row| {
+ match row.constraint {
+ IntermediaryConstraint::PartialRatio(val) => {
+ row_constraints
+ .push(LayoutConstraint::Ratio(val, layout.total_row_height_ratio));
+ }
+ IntermediaryConstraint::CanvasHandled { .. } => {
+ row_constraints.push(LayoutConstraint::CanvasHandled);
+ }
+ IntermediaryConstraint::Grow { .. } => {
+ row_constraints.push(LayoutConstraint::Grow);
+ }
}
let mut new_col_constraints = Vec::new();
let mut new_widget_constraints = Vec::new();
let mut new_col_row_constraints = Vec::new();
row.children.iter().for_each(|col| {
- if col.canvas_handle_width {
- new_col_constraints.push(LayoutConstraint::CanvasHandled);
- } else {
- new_col_constraints.push(LayoutConstraint::Ratio(
- col.col_width_ratio,
- row.total_col_ratio,
- ));
+ match col.constraint {
+ IntermediaryConstraint::PartialRatio(val) => {
+ new_col_constraints.push(LayoutConstraint::Ratio(val, row.total_col_ratio));
+ }
+ IntermediaryConstraint::CanvasHandled { .. } => {
+ new_col_constraints.push(LayoutConstraint::CanvasHandled);
+ }
+ IntermediaryConstraint::Grow { .. } => {
+ new_col_constraints.push(LayoutConstraint::Grow);
+ }
}
let mut new_new_col_row_constraints = Vec::new();
let mut new_new_widget_constraints = Vec::new();
col.children.iter().for_each(|col_row| {
- if col_row.canvas_handle_height {
- new_new_col_row_constraints.push(LayoutConstraint::CanvasHandled);
- } else if col_row.flex_grow {
- new_new_col_row_constraints.push(LayoutConstraint::Grow);
- } else {
- new_new_col_row_constraints.push(LayoutConstraint::Ratio(
- col_row.col_row_height_ratio,
- col.total_col_row_ratio,
- ));
+ match col_row.constraint {
+ IntermediaryConstraint::PartialRatio(val) => {
+ new_new_col_row_constraints
+ .push(LayoutConstraint::Ratio(val, col.total_col_row_ratio));
+ }
+ IntermediaryConstraint::CanvasHandled { .. } => {
+ new_new_col_row_constraints.push(LayoutConstraint::CanvasHandled);
+ }
+ IntermediaryConstraint::Grow { .. } => {
+ new_new_col_row_constraints.push(LayoutConstraint::Grow);
+ }
}
let mut new_new_new_widget_constraints = Vec::new();
- col_row.children.iter().for_each(|widget| {
- if widget.canvas_handle_width {
- new_new_new_widget_constraints.push(LayoutConstraint::CanvasHandled);
- } else if widget.flex_grow {
- new_new_new_widget_constraints.push(LayoutConstraint::Grow);
- } else {
- new_new_new_widget_constraints.push(LayoutConstraint::Ratio(
- widget.width_ratio,
- col_row.total_widget_ratio,
- ));
- }
- });
+ col_row
+ .children
+ .iter()
+ .for_each(|widget| match widget.constraint {
+ IntermediaryConstraint::PartialRatio(val) => {
+ new_new_new_widget_constraints
+ .push(LayoutConstraint::Ratio(val, col_row.total_widget_ratio));
+ }
+ IntermediaryConstraint::CanvasHandled { .. } => {
+ new_new_new_widget_constraints
+ .push(LayoutConstraint::CanvasHandled);
+ }
+ IntermediaryConstraint::Grow { .. } => {
+ new_new_new_widget_constraints.push(LayoutConstraint::Grow);
+ }
+ });
new_new_widget_constraints.push(new_new_new_widget_constraints);
});
new_col_row_constraints.push(new_new_col_row_constraints);
@@ -158,7 +171,7 @@ impl Painter {
col_constraints,
col_row_constraints,
layout_constraints,
- widget_layout,
+ widget_layout: layout,
derived_widget_draw_locs: Vec::default(),
};
diff --git a/src/options.rs b/src/options.rs
index 86d44e75..95c780f6 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -747,14 +747,6 @@ fn get_default_widget_and_count(
fn get_use_battery(matches: &ArgMatches, config: &Config) -> bool {
#[cfg(feature = "battery")]
{
- if matches.get_flag("battery") {
- return true;
- } else if let Some(flags) = &config.flags {
- if let Some(battery) = flags.battery {
- return battery;
- }
- }
-
if let Ok(battery_manager) = Manager::new() {
if let Ok(batteries) = battery_manager.batteries() {
if batteries.count() == 0 {
@@ -762,6 +754,14 @@ fn get_use_battery(matches: &ArgMatches, config: &Config) -> bool {
}
}
}
+
+ if matches.get_flag("battery") {
+ return true;
+ } else if let Some(flags) = &config.flags {
+ if let Some(battery) = flags.battery {
+ return battery;
+ }
+ }
}
false
diff --git a/src/options/config/layout.rs b/src/options/config/layout.rs
index 4b3e587a..45c2a0ab 100644
--- a/src/options/config/layout.rs
+++ b/src/options/config/layout.rs
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use crate::{app::layout_manager::*, error::Result};
-/// Represents a row. This has a length of some sort (optional) and a vector
+/// Represents a row. This has a length of some sort (optional) and a vector
/// of children.
#[derive(Clone, Deserialize, Debug, Serialize)]
#[serde(rename = "row")]
@@ -19,21 +19,15 @@ fn new_cpu(left_legend: bool, iter_id: &mut u64) -> BottomColRow {
if left_legend {
BottomColRow::new(vec![
BottomWidget::new(BottomWidgetType::CpuLegend, legend_id)
- .width_ratio(3)
- .canvas_handle_width(true)
+ .canvas_with_ratio(3)
.parent_reflector(Some((WidgetDirection::Right, 1))),
- BottomWidget::new(BottomWidgetType::Cpu, cpu_id)
- .width_ratio(17)
- .flex_grow(true),
+ BottomWidget::new(BottomWidgetType::Cpu, cpu_id).grow(Some(17)),
])
} else {
BottomColRow::new(vec![
- BottomWidget::new(BottomWidgetType::Cpu, cpu_id)
- .width_ratio(17)
- .flex_grow(true),
+ BottomWidget::new(BottomWidgetType::Cpu, cpu_id).grow(Some(17)),
BottomWidget::new(BottomWidgetType::CpuLegend, legend_id)
- .width_ratio(3)
- .canvas_handle_width(true)
+ .canvas_with_ratio(3)
.parent_reflector(Some((WidgetDirection::Left, 1))),
])
}
@@ -42,13 +36,12 @@ fn new_cpu(left_legend: bool, iter_id: &mut u64) -> BottomColRow {
fn new_proc_sort(sort_id: u64) -> BottomWidget {
BottomWidget::new(BottomWidgetType::ProcSort, sort_id)
- .canvas_handle_width(true)
+ .canvas_handled()
.parent_reflector(Some((WidgetDirection::Right, 2)))
- .width_ratio(1)
}
fn new_proc(proc_id: u64) -> BottomWidget {
- BottomWidget::new(BottomWidgetType::Proc, proc_id).width_ratio(2)
+ BottomWidget::new(BottomWidgetType::Proc, proc_id).ratio(2)
}
fn new_proc_search(search_id: u64) -> BottomWidget {
@@ -99,7 +92,7 @@ impl Row {
children.push(match widget_type {
BottomWidgetType::Cpu => {
BottomCol::new(vec![new_cpu(left_legend, iter_id)])
- .col_width_ratio(width_ratio)
+ .ratio(width_ratio)
}
BottomWidgetType::Proc => {
let proc_id = *iter_id;
@@ -110,34 +103,31 @@ impl Row {
new_proc_sort(*iter_id),
new_proc(proc_id),
])
- .total_widget_ratio(3)
- .flex_grow(true),
+ .grow(None)
+ .total_widget_ratio(3),
BottomColRow::new(vec![new_proc_search(proc_search_id)])
- .canvas_handle_height(true),
+ .canvas_handled(),
])
.total_col_row_ratio(2)
- .col_width_ratio(width_ratio)
+ .ratio(width_ratio)
}
_ => BottomCol::new(vec![BottomColRow::new(vec![BottomWidget::new(
widget_type,
*iter_id,
)])])
- .col_width_ratio(width_ratio),
+ .ratio(width_ratio),
});
}
RowChildren::Col { ratio, child } => {
let col_width_ratio = ratio.unwrap_or(1);
total_col_ratio += col_width_ratio;
let mut total_col_row_ratio = 0;
- let mut contains_proc = false;
let mut col_row_children: Vec<BottomColRow> = Vec::new();
for widget in child {