summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Verevkin <maxxverrr@gmail.com>2022-04-03 21:02:39 +0300
committerMax Verevkin <maxxverrr@gmail.com>2022-04-03 21:04:38 +0300
commit6ab71396f028f6945d2e7554b65c64de146d7e87 (patch)
treedd9c1bc1499c989a4988a64757a1b4da400494b2 /src
parent54aa8c4d3616f9bc9d62784180fddc092e4673ae (diff)
downloadi3bar-mango-6ab71396f028f6945d2e7554b65c64de146d7e87.tar.gz
a little cleanup
Diffstat (limited to 'src')
-rw-r--r--src/main.rs29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index 0fc92fa..85d61d8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::derive_ord_xor_partial_ord)]
+
#[macro_use]
extern crate log;
@@ -628,14 +630,12 @@ fn render_blocks(
// Progressively switch to short mode
if offset_left + blocks_width > full_width {
let mut heap = BinaryHeap::new();
- for (name, delta) in &deltas {
- heap.push((*delta as i32, *name));
- }
- while let Some((_, to_switch)) = heap.pop() {
- let d = *deltas.get(to_switch).unwrap();
- if d <= 0.0 {
- break;
+ for (name, delta) in deltas {
+ if delta > 0.0 {
+ heap.push((OrdFloat(delta), name));
}
+ }
+ while let Some((OrdFloat(delta), to_switch)) = heap.pop() {
for (name, full, short) in &mut blocks_computed {
if *name == Some(to_switch) {
if let Some(short) = short {
@@ -643,7 +643,7 @@ fn render_blocks(
}
}
}
- blocks_width -= d;
+ blocks_width -= delta;
if offset_left + blocks_width <= full_width {
break;
}
@@ -684,3 +684,16 @@ fn render_blocks(
}
}
}
+
+#[derive(PartialEq, PartialOrd)]
+struct OrdFloat(f64);
+
+impl Eq for OrdFloat {}
+
+impl Ord for OrdFloat {
+ fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+ self.0
+ .partial_cmp(&other.0)
+ .unwrap_or(std::cmp::Ordering::Less)
+ }
+}