range refactor, clippy
This commit is contained in:
parent
2a4f92c9b3
commit
0bf317dd6d
6 changed files with 35 additions and 57 deletions
|
|
@ -1,23 +1,23 @@
|
|||
use servicepoint::{CharGridMutExt, GridMut, TILE_SIZE, WindowMut};
|
||||
use servicepoint::{Bitmap, CharGrid, CharGridMutExt, TILE_SIZE, WindowMut};
|
||||
|
||||
pub type BorderPattern = [bool; TILE_SIZE];
|
||||
|
||||
pub const OUTER_BORDER: BorderPattern = [false, false, false, true, true, false, true, false];
|
||||
pub const INNER_BORDER: BorderPattern = [false, false, false, true, true, false, false, false];
|
||||
|
||||
pub fn draw_border_panel<'t, C: GridMut<char>, P: GridMut<bool>>(
|
||||
mut chars: WindowMut<'t, char, C>,
|
||||
mut bitmap: WindowMut<'t, bool, P>,
|
||||
pub fn draw_border_panel<'c, 'b>(
|
||||
mut chars: WindowMut<'c, char, CharGrid>,
|
||||
mut bitmap: WindowMut<'b, bool, Bitmap>,
|
||||
label: &str,
|
||||
border_pattern: BorderPattern,
|
||||
) -> (WindowMut<'t, char, C>, WindowMut<'t, bool, P>) {
|
||||
) -> (WindowMut<'c, char, CharGrid>, WindowMut<'b, bool, Bitmap>) {
|
||||
let tile_width = chars.width();
|
||||
let tile_height = chars.height();
|
||||
let pixel_width = bitmap.width();
|
||||
let pixel_height = bitmap.height();
|
||||
|
||||
chars
|
||||
.window_mut(2, 0, tile_width - 4, 1)
|
||||
.window_mut(2..tile_width - 2, 0..1)
|
||||
.unwrap()
|
||||
.set_row_str(0, label)
|
||||
.unwrap();
|
||||
|
|
@ -28,12 +28,11 @@ pub fn draw_border_panel<'t, C: GridMut<char>, P: GridMut<bool>>(
|
|||
let x = tile_x * TILE_SIZE + inner_x;
|
||||
let draw_top = tile_x <= 1 || tile_x >= label.chars().count() + 2;
|
||||
|
||||
for inner_y in 0..TILE_SIZE {
|
||||
let val = border_pattern[inner_y];
|
||||
for (inner_y, val) in border_pattern.iter().enumerate() {
|
||||
if draw_top {
|
||||
bitmap.set(x, inner_y, val);
|
||||
bitmap.set(x, inner_y, *val);
|
||||
}
|
||||
bitmap.set(x, pixel_height - inner_y - 1, val);
|
||||
bitmap.set(x, pixel_height - inner_y - 1, *val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -42,18 +41,16 @@ pub fn draw_border_panel<'t, C: GridMut<char>, P: GridMut<bool>>(
|
|||
for tile_y in 1..tile_height - 1 {
|
||||
for inner_y in 0..TILE_SIZE {
|
||||
let y = tile_y * TILE_SIZE + inner_y;
|
||||
for inner_x in 0..TILE_SIZE {
|
||||
let val = border_pattern[inner_x];
|
||||
|
||||
bitmap.set(inner_x, y, val);
|
||||
bitmap.set(pixel_width - inner_x - 1, y, val);
|
||||
for (inner_x, val) in border_pattern.iter().enumerate() {
|
||||
bitmap.set(inner_x, y, *val);
|
||||
bitmap.set(pixel_width - inner_x - 1, y, *val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// edges
|
||||
for pat_index in 0..TILE_SIZE {
|
||||
if !border_pattern[pat_index] {
|
||||
for (pat_index, pat_val) in border_pattern.iter().enumerate() {
|
||||
if !pat_val {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue