ui/CellBuffer: change row_iter() bounds to Range
Writing a range x..y is more ergonomic than (x, y+ 1)master
parent
651fda1467
commit
b401b64f35
|
@ -157,7 +157,7 @@ impl ListingTrait for CompactListing {
|
|||
|
||||
let (upper_left, bottom_right) = area;
|
||||
change_colors(grid, area, fg_color, bg_color);
|
||||
let mut x = get_x(upper_left)
|
||||
let x = get_x(upper_left)
|
||||
+ self.data_columns.widths[0]
|
||||
+ self.data_columns.widths[1]
|
||||
+ self.data_columns.widths[2]
|
||||
|
@ -172,9 +172,8 @@ impl ListingTrait for CompactListing {
|
|||
pos_dec(self.data_columns.columns[3].size(), (1, 1)),
|
||||
),
|
||||
);
|
||||
for _ in 0..self.data_columns.widths[3] {
|
||||
grid[(x, get_y(upper_left))].set_bg(bg_color);
|
||||
x += 1;
|
||||
for c in grid.row_iter(x..(self.data_columns.widths[3] + x), get_y(upper_left)) {
|
||||
grid[c].set_bg(bg_color);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -280,9 +279,10 @@ impl ListingTrait for CompactListing {
|
|||
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])
|
||||
|
@ -290,7 +290,7 @@ impl ListingTrait for CompactListing {
|
|||
.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];
|
||||
remainder.saturating_sub(min_col_width + self.data_columns.widths[3]);
|
||||
self.data_columns.widths[2] = min_col_width;
|
||||
}
|
||||
}
|
||||
|
@ -980,7 +980,7 @@ impl CompactListing {
|
|||
((0, idx), (min_width.0, idx)),
|
||||
None,
|
||||
);
|
||||
for c in columns[0].row_iter((x, min_width.0.saturating_sub(1)), idx) {
|
||||
for c in columns[0].row_iter(x..min_width.0, idx) {
|
||||
columns[0][c].set_bg(bg_color);
|
||||
}
|
||||
let (x, _) = write_string_to_grid(
|
||||
|
@ -992,7 +992,7 @@ impl CompactListing {
|
|||
((0, idx), (min_width.1.saturating_sub(1), idx)),
|
||||
None,
|
||||
);
|
||||
for c in columns[1].row_iter((x, min_width.1.saturating_sub(1)), idx) {
|
||||
for c in columns[1].row_iter(x..min_width.1, idx) {
|
||||
columns[1][c].set_bg(bg_color);
|
||||
}
|
||||
let (x, _) = write_string_to_grid(
|
||||
|
@ -1004,7 +1004,7 @@ impl CompactListing {
|
|||
((0, idx), (min_width.2, idx)),
|
||||
None,
|
||||
);
|
||||
for c in columns[2].row_iter((x, min_width.2.saturating_sub(1)), idx) {
|
||||
for c in columns[2].row_iter(x..min_width.2, idx) {
|
||||
columns[2][c].set_bg(bg_color);
|
||||
}
|
||||
let (x, _) = write_string_to_grid(
|
||||
|
@ -1016,7 +1016,7 @@ impl CompactListing {
|
|||
((0, idx), (min_width.3, idx)),
|
||||
None,
|
||||
);
|
||||
for c in columns[3].row_iter((x, min_width.3.saturating_sub(1)), idx) {
|
||||
for c in columns[3].row_iter(x..min_width.3, idx) {
|
||||
columns[3][c].set_bg(bg_color);
|
||||
}
|
||||
let (x, _) = write_string_to_grid(
|
||||
|
@ -1040,25 +1040,25 @@ impl CompactListing {
|
|||
((x + 1, idx), (min_width.4, idx)),
|
||||
None,
|
||||
);
|
||||
for c in columns[4].row_iter((x, x), idx) {
|
||||
for c in columns[4].row_iter(x..(x + 1), idx) {
|
||||
columns[4][c].set_bg(color);
|
||||
}
|
||||
for c in columns[4].row_iter((_x, _x), idx) {
|
||||
for c in columns[4].row_iter(_x..(_x + 1), idx) {
|
||||
columns[4][c].set_bg(color);
|
||||
columns[4][c].set_keep_bg(true);
|
||||
}
|
||||
for c in columns[4].row_iter((x + 1, _x), idx) {
|
||||
for c in columns[4].row_iter((x + 1)..(_x + 1), idx) {
|
||||
columns[4][c].set_keep_fg(true);
|
||||
columns[4][c].set_keep_bg(true);
|
||||
}
|
||||
for c in columns[4].row_iter((x, x), idx) {
|
||||
for c in columns[4].row_iter(x..(x + 1), idx) {
|
||||
columns[4][c].set_keep_bg(true);
|
||||
}
|
||||
x = _x + 1;
|
||||
}
|
||||
x
|
||||
};
|
||||
for c in columns[4].row_iter((x, min_width.4.saturating_sub(1)), idx) {
|
||||
for c in columns[4].row_iter(x..min_width.4, idx) {
|
||||
columns[4][c].set_ch(' ');
|
||||
columns[4][c].set_bg(bg_color);
|
||||
}
|
||||
|
|
|
@ -1000,7 +1000,7 @@ impl ConversationsListing {
|
|||
((0, 3 * idx), (width - 1, 3 * idx)),
|
||||
None,
|
||||
);
|
||||
for c in self.content.row_iter((x, x + 3), 3 * idx) {
|
||||
for c in self.content.row_iter(x..(x + 4), 3 * idx) {
|
||||
self.content[c].set_bg(bg_color);
|
||||
}
|
||||
/* draw subject */
|
||||
|
@ -1025,25 +1025,25 @@ impl ConversationsListing {
|
|||
((x + 1, 3 * idx), (width - 1, 3 * idx)),
|
||||
None,
|
||||
);
|
||||
for c in self.content.row_iter((x, x), 3 * idx) {
|
||||
for c in self.content.row_iter(x..(x + 1), 3 * idx) {
|
||||
self.content[c].set_bg(color);
|
||||
}
|
||||
for c in self.content.row_iter((_x, _x), 3 * idx) {
|
||||
for c in self.content.row_iter(_x..(_x + 1), 3 * idx) {
|
||||
self.content[c].set_bg(color);
|
||||
self.content[c].set_keep_bg(true);
|
||||
}
|
||||
for c in self.content.row_iter((x + 1, _x), 3 * idx) {
|
||||
for c in self.content.row_iter(x + 1..(_x + 1), 3 * idx) {
|
||||
self.content[c].set_keep_fg(true);
|
||||
self.content[c].set_keep_bg(true);
|
||||
}
|
||||
for c in self.content.row_iter((x, x), 3 * idx) {
|
||||
for c in self.content.row_iter(x..(x + 1), 3 * idx) {
|
||||
self.content[c].set_keep_bg(true);
|
||||
}
|
||||
x = _x + 1;
|
||||
}
|
||||
x
|
||||
};
|
||||
for c in self.content.row_iter((x, width.saturating_sub(1)), 3 * idx) {
|
||||
for c in self.content.row_iter(x..width, 3 * idx) {
|
||||
self.content[c].set_ch(' ');
|
||||
self.content[c].set_bg(bg_color);
|
||||
}
|
||||
|
@ -1057,7 +1057,7 @@ impl ConversationsListing {
|
|||
((0, 3 * idx + 1), (width - 1, 3 * idx + 1)),
|
||||
None,
|
||||
);
|
||||
for c in self.content.row_iter((x, x + 4), 3 * idx + 1) {
|
||||
for c in self.content.row_iter(x..(x + 5), 3 * idx + 1) {
|
||||
self.content[c].set_ch('▁');
|
||||
self.content[c].set_bg(bg_color);
|
||||
}
|
||||
|
@ -1072,17 +1072,11 @@ impl ConversationsListing {
|
|||
None,
|
||||
);
|
||||
|
||||
for c in self
|
||||
.content
|
||||
.row_iter((x, width.saturating_sub(1)), 3 * idx + 1)
|
||||
{
|
||||
for c in self.content.row_iter(x..width, 3 * idx + 1) {
|
||||
self.content[c].set_ch('▁');
|
||||
self.content[c].set_bg(bg_color);
|
||||
}
|
||||
for c in self
|
||||
.content
|
||||
.row_iter((0, width.saturating_sub(1)), 3 * idx + 2)
|
||||
{
|
||||
for c in self.content.row_iter(0..width, 3 * idx + 2) {
|
||||
self.content[c].set_ch('▓');
|
||||
self.content[c].set_fg(padding_fg);
|
||||
self.content[c].set_bg(bg_color);
|
||||
|
@ -1131,7 +1125,7 @@ impl Component for ConversationsListing {
|
|||
area,
|
||||
Some(get_x(upper_left)),
|
||||
);
|
||||
for c in grid.row_iter((x, get_x(bottom_right)), y) {
|
||||
for c in grid.row_iter(x..(get_x(bottom_right) + 1), y) {
|
||||
grid[c] = Cell::default();
|
||||
}
|
||||
clear_area(grid, ((x, y), set_y(bottom_right, y)));
|
||||
|
|
|
@ -161,10 +161,7 @@ impl ListingTrait for PlainListing {
|
|||
pos_dec(self.data_columns.columns[3].size(), (1, 1)),
|
||||
),
|
||||
);
|
||||
for c in grid.row_iter(
|
||||
(x, x + self.data_columns.widths[3].saturating_sub(1)),
|
||||
get_y(upper_left),
|
||||
) {
|
||||
for c in grid.row_iter(x..(x + self.data_columns.widths[3]), get_y(upper_left)) {
|
||||
grid[c].set_bg(bg_color);
|
||||
}
|
||||
return;
|
||||
|
@ -338,14 +335,11 @@ impl ListingTrait for PlainListing {
|
|||
bg_color,
|
||||
);
|
||||
for c in grid.row_iter(
|
||||
(
|
||||
flag_x,
|
||||
std::cmp::min(
|
||||
flag_x
|
||||
..std::cmp::min(
|
||||
get_x(bottom_right),
|
||||
flag_x + 2 + self.data_columns.widths[3],
|
||||
)
|
||||
.saturating_sub(1),
|
||||
),
|
||||
),
|
||||
get_y(upper_left) + r,
|
||||
) {
|
||||
grid[c].set_bg(bg_color);
|
||||
|
@ -775,7 +769,7 @@ impl PlainListing {
|
|||
((0, idx), (min_width.0, idx)),
|
||||
None,
|
||||
);
|
||||
for c in columns[0].row_iter((x, min_width.0.saturating_sub(1)), idx) {
|
||||
for c in columns[0].row_iter(x..min_width.0, idx) {
|
||||
columns[0][c].set_bg(bg_color);
|
||||
}
|
||||
let (x, _) = write_string_to_grid(
|
||||
|
@ -787,7 +781,7 @@ impl PlainListing {
|
|||
((0, idx), (min_width.1, idx)),
|
||||
None,
|
||||
);
|
||||
for c in columns[1].row_iter((x, min_width.1.saturating_sub(1)), idx) {
|
||||
for c in columns[1].row_iter(x..min_width.1, idx) {
|
||||
columns[1][c].set_bg(bg_color);
|
||||
}
|
||||
let (x, _) = write_string_to_grid(
|
||||
|
@ -799,7 +793,7 @@ impl PlainListing {
|
|||
((0, idx), (min_width.2, idx)),
|
||||
None,
|
||||
);
|
||||
for c in columns[2].row_iter((x, min_width.2.saturating_sub(1)), idx) {
|
||||
for c in columns[2].row_iter(x..min_width.2, idx) {
|
||||
columns[2][c].set_bg(bg_color);
|
||||
}
|
||||
let (x, _) = write_string_to_grid(
|
||||
|
@ -811,7 +805,7 @@ impl PlainListing {
|
|||
((0, idx), (min_width.3, idx)),
|
||||
None,
|
||||
);
|
||||
for c in columns[3].row_iter((x, min_width.3.saturating_sub(1)), idx) {
|
||||
for c in columns[3].row_iter(x..min_width.3, idx) {
|
||||
columns[3][c].set_bg(bg_color);
|
||||
}
|
||||
let (x, _) = write_string_to_grid(
|
||||
|
@ -835,25 +829,25 @@ impl PlainListing {
|
|||
((x + 1, idx), (min_width.4, idx)),
|
||||
None,
|
||||
);
|
||||
for c in columns[4].row_iter((x, x), idx) {
|
||||
for c in columns[4].row_iter(x..(x + 1), idx) {
|
||||
columns[4][c].set_bg(color);
|
||||
}
|
||||
for c in columns[4].row_iter((_x, _x), idx) {
|
||||
for c in columns[4].row_iter(_x..(_x + 1), idx) {
|
||||
columns[4][c].set_bg(color);
|
||||
columns[4][c].set_keep_bg(true);
|
||||
}
|
||||
for c in columns[4].row_iter((x + 1, _x), idx) {
|
||||
for c in columns[4].row_iter((x + 1)..(_x + 1), idx) {
|
||||
columns[4][c].set_keep_fg(true);
|
||||
columns[4][c].set_keep_bg(true);
|
||||
}
|
||||
for c in columns[4].row_iter((x, x), idx) {
|
||||
for c in columns[4].row_iter(x..(x + 1), idx) {
|
||||
columns[4][c].set_keep_bg(true);
|
||||
}
|
||||
x = _x + 1;
|
||||
}
|
||||
x
|
||||
};
|
||||
for c in columns[4].row_iter((x, min_width.4.saturating_sub(1)), idx) {
|
||||
for c in columns[4].row_iter(x..min_width.4, idx) {
|
||||
columns[4][c].set_bg(bg_color);
|
||||
}
|
||||
if context.accounts[self.cursor_pos.0]
|
||||
|
|
|
@ -355,12 +355,12 @@ impl CellBuffer {
|
|||
}
|
||||
|
||||
/// See `RowIterator` documentation.
|
||||
pub fn row_iter(&self, bounds: (usize, usize), row: usize) -> RowIterator {
|
||||
pub fn row_iter(&self, bounds: std::ops::Range<usize>, row: usize) -> RowIterator {
|
||||
if row < self.rows {
|
||||
RowIterator {
|
||||
row,
|
||||
col: std::cmp::min(self.cols.saturating_sub(1), bounds.0)
|
||||
..(std::cmp::min(self.cols, bounds.1 + 1)),
|
||||
col: std::cmp::min(self.cols.saturating_sub(1), bounds.start)
|
||||
..(std::cmp::min(self.cols, bounds.end)),
|
||||
}
|
||||
} else {
|
||||
RowIterator { row, col: 0..0 }
|
||||
|
@ -1871,7 +1871,7 @@ pub mod ansi {
|
|||
/// `BoundsIterator` which iterates each row.
|
||||
/// ```norun
|
||||
/// for c in grid.row_iter(
|
||||
/// (x, x + 10),
|
||||
/// x..(x + 11),
|
||||
/// 0,
|
||||
/// ) {
|
||||
/// grid[c].set_ch('w');
|
||||
|
|
Loading…
Reference in New Issue