From 58d08d36ae6a2c6efbf175247bb096fae6629eb1 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Fri, 23 Jul 2021 18:10:17 +0900 Subject: Simplify ui/menu.rs --- helix-term/src/ui/menu.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'helix-term/src/ui') diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index 8681e5b1..dc3bbf7f 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -233,16 +233,16 @@ impl Component for Menu { let max_lens = self.options.iter().fold(vec![0; n], |mut acc, option| { let row = option.row(); // maintain max for each column - for (i, cell) in row.cells.iter().enumerate() { + for (acc, cell) in acc.iter_mut().zip(row.cells.iter()) { let width = cell.content.width(); - if width > acc[i] { - acc[i] = width; + if width > *acc { + *acc = width; } } acc }); - let len = (max_lens.iter().sum::()) + n + 1; // +1: reserve some space for scrollbar + let len = max_lens.iter().sum::() + n + 1; // +1: reserve some space for scrollbar let width = len.min(viewport.0 as usize); self.widths = max_lens @@ -250,9 +250,7 @@ impl Component for Menu { .map(|len| Constraint::Length(len as u16)) .collect(); - const MAX: usize = 10; - let height = std::cmp::min(self.options.len(), MAX); - let height = std::cmp::min(height, viewport.1 as usize); + let height = self.options.len().min(10).min(viewport.1 as usize); self.size = (width as u16, height as u16); -- cgit v1.2.3-70-g09d2