|
|
@ -137,7 +137,7 @@ impl Buffer {
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns a Buffer with all cells initialized with the attributes of the given Cell
|
|
|
|
/// Returns a Buffer with all cells initialized with the attributes of the given Cell
|
|
|
|
pub fn filled(area: Rect, cell: &Cell) -> Buffer {
|
|
|
|
pub fn filled(area: Rect, cell: &Cell) -> Buffer {
|
|
|
|
let size = area.area() as usize;
|
|
|
|
let size = area.area();
|
|
|
|
let mut content = Vec::with_capacity(size);
|
|
|
|
let mut content = Vec::with_capacity(size);
|
|
|
|
for _ in 0..size {
|
|
|
|
for _ in 0..size {
|
|
|
|
content.push(cell.clone());
|
|
|
|
content.push(cell.clone());
|
|
|
@ -239,7 +239,7 @@ impl Buffer {
|
|
|
|
y,
|
|
|
|
y,
|
|
|
|
self.area
|
|
|
|
self.area
|
|
|
|
);
|
|
|
|
);
|
|
|
|
((y - self.area.y) * self.area.width + (x - self.area.x)) as usize
|
|
|
|
((y - self.area.y) as usize) * (self.area.width as usize) + ((x - self.area.x) as usize)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the index in the Vec<Cell> for the given global (x, y) coordinates,
|
|
|
|
/// Returns the index in the Vec<Cell> for the given global (x, y) coordinates,
|
|
|
@ -278,8 +278,8 @@ impl Buffer {
|
|
|
|
self.content.len()
|
|
|
|
self.content.len()
|
|
|
|
);
|
|
|
|
);
|
|
|
|
(
|
|
|
|
(
|
|
|
|
self.area.x + i as u16 % self.area.width,
|
|
|
|
(self.area.x as usize + (i % self.area.width as usize)) as u16,
|
|
|
|
self.area.y + i as u16 / self.area.width,
|
|
|
|
(self.area.y as usize + (i / self.area.width as usize)) as u16,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -480,7 +480,7 @@ impl Buffer {
|
|
|
|
/// Resize the buffer so that the mapped area matches the given area and that the buffer
|
|
|
|
/// Resize the buffer so that the mapped area matches the given area and that the buffer
|
|
|
|
/// length is equal to area.width * area.height
|
|
|
|
/// length is equal to area.width * area.height
|
|
|
|
pub fn resize(&mut self, area: Rect) {
|
|
|
|
pub fn resize(&mut self, area: Rect) {
|
|
|
|
let length = area.area() as usize;
|
|
|
|
let length = area.area();
|
|
|
|
if self.content.len() > length {
|
|
|
|
if self.content.len() > length {
|
|
|
|
self.content.truncate(length);
|
|
|
|
self.content.truncate(length);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -587,8 +587,8 @@ impl Buffer {
|
|
|
|
let mut to_skip: usize = 0;
|
|
|
|
let mut to_skip: usize = 0;
|
|
|
|
for (i, (current, previous)) in next_buffer.iter().zip(previous_buffer.iter()).enumerate() {
|
|
|
|
for (i, (current, previous)) in next_buffer.iter().zip(previous_buffer.iter()).enumerate() {
|
|
|
|
if (current != previous || invalidated > 0) && to_skip == 0 {
|
|
|
|
if (current != previous || invalidated > 0) && to_skip == 0 {
|
|
|
|
let x = i as u16 % width;
|
|
|
|
let x = (i % width as usize) as u16;
|
|
|
|
let y = i as u16 / width;
|
|
|
|
let y = (i / width as usize) as u16;
|
|
|
|
updates.push((x, y, &next_buffer[i]));
|
|
|
|
updates.push((x, y, &next_buffer[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|