summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--.github/workflows/ci.yml2
-rw-r--r--Cargo.lock150
-rw-r--r--Cargo.toml3
-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
-rw-r--r--tests/integration/arg_tests.rs (renamed from tests/arg_tests.rs)56
-rw-r--r--tests/integration/invalid_config_tests.rs (renamed from tests/invalid_config_tests.rs)88
-rw-r--r--tests/integration/layout_management_tests.rs (renamed from tests/layout_management_tests.rs)0
-rw-r--r--tests/integration/layout_movement_tests.rs (renamed from tests/layout_movement_tests.rs)0
-rw-r--r--tests/integration/main.rs11
-rw-r--r--tests/integration/util.rs144
-rw-r--r--tests/integration/valid_config_tests.rs69
-rw-r--r--tests/util.rs76
-rw-r--r--tests/valid_configs/all_proc.toml22
-rw-r--r--tests/valid_configs/cpu_doughnut.toml29
-rw-r--r--tests/valid_configs/empty_config.toml (renamed from tests/empty_config.toml)0
-rw-r--r--tests/valid_configs/many_proc.toml22
19 files changed, 724 insertions, 412 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bff02a44..07d78d56 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -236,7 +236,7 @@ jobs:
target: "aarch64-linux-android",
cross: true,
rust: stable,
- cross-version: "git:d6511b7b166c18640f81b8f6a74d9eef380f7ded",
+ cross-version: "git:cabfc3b02d1edec03869fabdabf6a7f8b0519160",
no-default-features: true,
}
diff --git a/Cargo.lock b/Cargo.lock
index 30e79e1a..f7f171f9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -176,6 +176,7 @@ dependencies = [
"log",
"mach2",
"nvml-wrapper",
+ "portable-pty",
"predicates",
"ratatui",
"regex",
@@ -352,7 +353,7 @@ dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
- "memoffset",
+ "memoffset 0.9.0",
]
[[package]]
@@ -477,6 +478,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
+name = "downcast-rs"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
+
+[[package]]
name = "either"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -607,6 +614,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8"
[[package]]
+name = "ioctl-rs"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f7970510895cee30b3e9128319f2cefd4bde883a39f38baa279567ba3a7eb97d"
+dependencies = [
+ "libc",
+]
+
+[[package]]
name = "itertools"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -640,6 +656,12 @@ dependencies = [
]
[[package]]
+name = "lazy_static"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
+
+[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -720,6 +742,15 @@ checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
name = "memoffset"
+version = "0.6.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "memoffset"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
@@ -750,6 +781,20 @@ dependencies = [
[[package]]
name = "nix"
+version = "0.25.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4"
+dependencies = [
+ "autocfg",
+ "bitflags 1.3.2",
+ "cfg-if",
+ "libc",
+ "memoffset 0.6.5",
+ "pin-utils",
+]
+
+[[package]]
+name = "nix"
version = "0.26.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
@@ -877,6 +922,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
+name = "pin-utils"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
+
+[[package]]
+name = "portable-pty"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "806ee80c2a03dbe1a9fb9534f8d19e4c0546b790cde8fd1fea9d6390644cb0be"
+dependencies = [
+ "anyhow",
+ "bitflags 1.3.2",
+ "downcast-rs",
+ "filedescriptor",
+ "lazy_static",
+ "libc",
+ "log",
+ "nix 0.25.1",
+ "serial",
+ "shared_library",
+ "shell-words",
+ "winapi",
+ "winreg",
+]
+
+[[package]]
name = "powerfmt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1112,6 +1184,64 @@ dependencies = [
]
[[package]]
+name = "serial"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1237a96570fc377c13baa1b88c7589ab66edced652e43ffb17088f003db3e86"
+dependencies = [
+ "serial-core",
+ "serial-unix",
+ "serial-windows",
+]
+
+[[package]]
+name = "serial-core"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f46209b345401737ae2125fe5b19a77acce90cd53e1658cda928e4fe9a64581"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "serial-unix"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f03fbca4c9d866e24a459cbca71283f545a37f8e3e002ad8c70593871453cab7"
+dependencies = [
+ "ioctl-rs",
+ "libc",
+ "serial-core",
+ "termios",
+]
+
+[[package]]
+name = "serial-windows"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "15c6d3b776267a75d31bbdfd5d36c0ca051251caafc285827052bc53bcdc8162"
+dependencies = [
+ "libc",
+ "serial-core",
+]
+
+[[package]]
+name = "shared_library"
+version = "0.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11"
+dependencies = [
+ "lazy_static",
+ "libc",
+]
+
+[[package]]
+name = "shell-words"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
+
+[[package]]
name = "signal-hook"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1276,6 +1406,15 @@ dependencies = [
]
[[package]]
+name = "termios"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d5d9cf598a6d7ce700a4e6a9199da127e6819a61e64b68609683cc9a01b5683a"
+dependencies = [
+ "libc",
+]
+
+[[package]]
name = "termtree"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1617,6 +1756,15 @@ dependencies = [
]
[[package]]
+name = "winreg"
+version = "0.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
name = "wrapcenum-derive"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 39a0cfce..45805ddc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -135,6 +135,9 @@ cargo-husky = { version = "1.5.0", default-features = false, features = [
] }
predicates = "3.0.3"
+[target.'cfg(all(target_arch = "x86_64", target_os = "linux"))'.dev-dependencies]
+portable-pty = "0.8.1"
+
[build-dependencies]
clap = { version = "4.4.14", features = ["default", "cargo", "wrap_help"] }
clap_complete = "4.4.6"
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
}