Skip to content

Commit

Permalink
ui: use BoundsIterator in clear_area
Browse files Browse the repository at this point in the history
  • Loading branch information
epilys committed Dec 6, 2019
1 parent 9d8d3e0 commit c431fb6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions ui/src/components/mail/listing/plain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
12 changes: 6 additions & 6 deletions ui/src/terminal/cells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
}
}
Expand Down Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c431fb6

Please sign in to comment.