ui: use BoundsIterator in clear_area

memfd
Manos Pitsidianakis 2019-12-06 12:33:19 +02:00
parent 9d8d3e09f4
commit c431fb6dff
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 12 additions and 10 deletions

View File

@ -252,17 +252,19 @@ impl ListingTrait for PlainListing {
let remainder = width
.saturating_sub(self.data_columns.widths[0])
.saturating_sub(self.data_columns.widths[1])
- 4;
.saturating_sub(4);
self.data_columns.widths[2] = remainder / 6;
self.data_columns.widths[4] = (2 * remainder) / 3 - self.data_columns.widths[3];
self.data_columns.widths[4] =
((2 * remainder) / 3).saturating_sub(self.data_columns.widths[3]);
} else {
let remainder = width
.saturating_sub(self.data_columns.widths[0])
.saturating_sub(self.data_columns.widths[1])
.saturating_sub(8);
if min_col_width + self.data_columns.widths[4] > remainder {
self.data_columns.widths[4] =
remainder - min_col_width - self.data_columns.widths[3];
self.data_columns.widths[4] = remainder
.saturating_sub(min_col_width)
.saturating_sub(self.data_columns.widths[3]);
self.data_columns.widths[2] = min_col_width;
}
}

View File

@ -363,10 +363,10 @@ impl CellBuffer {
pub fn bounds_iter(&self, area: Area) -> BoundsIterator {
BoundsIterator {
rows: std::cmp::min(self.rows.saturating_sub(1), get_y(upper_left!(area)))
..(std::cmp::min(self.rows, get_y(bottom_right!(area))) + 1),
..(std::cmp::min(self.rows, get_y(bottom_right!(area)) + 1)),
cols: (
std::cmp::min(self.cols.saturating_sub(1), get_x(upper_left!(area))),
std::cmp::min(self.cols.saturating_sub(1), get_x(bottom_right!(area))),
std::cmp::min(self.cols, get_x(bottom_right!(area)) + 1),
),
}
}
@ -1043,9 +1043,9 @@ pub fn clear_area(grid: &mut CellBuffer, area: Area) {
}
let upper_left = upper_left!(area);
let bottom_right = bottom_right!(area);
for y in get_y(upper_left)..=get_y(bottom_right) {
for x in get_x(upper_left)..=get_x(bottom_right) {
grid[(x, y)] = Cell::default();
for row in grid.bounds_iter(area) {
for c in row {
grid[c] = Cell::default();
}
}
}
@ -1325,7 +1325,7 @@ impl Iterator for BoundsIterator {
if let Some(next_row) = self.rows.next() {
Some(RowIterator {
row: next_row,
col: self.cols.0..(self.cols.1 + 1),
col: self.cols.0..self.cols.1,
})
} else {
None