Rename buffer methods

pull/3/head
Florian Dehau 8 years ago
parent 85bd76e17d
commit bcb3d751bf

@ -89,11 +89,6 @@ impl Buffer {
(i as u16 % self.area.width, i as u16 / self.area.width)
}
pub fn set(&mut self, x: u16, y: u16, cell: Cell) {
let i = self.index_of(x, y);
self.content[i] = cell;
}
pub fn set_symbol(&mut self, x: u16, y: u16, symbol: &str) {
let i = self.index_of(x, y);
self.content[i].symbol.clear();
@ -133,13 +128,13 @@ impl Buffer {
}
pub fn update_colors(&mut self, x: u16, y: u16, fg: Color, bg: Color) {
pub fn set_colors(&mut self, x: u16, y: u16, fg: Color, bg: Color) {
let i = self.index_of(x, y);
self.content[i].fg = fg;
self.content[i].bg = bg;
}
pub fn update_cell(&mut self, x: u16, y: u16, symbol: &str, fg: Color, bg: Color) {
pub fn set_cell(&mut self, x: u16, y: u16, symbol: &str, fg: Color, bg: Color) {
let i = self.index_of(x, y);
self.content[i].symbol.clear();
self.content[i].symbol.push_str(symbol);
@ -147,6 +142,13 @@ impl Buffer {
self.content[i].bg = bg;
}
pub fn update_cell<F>(&mut self, x: u16, y: u16, f: F)
where F: Fn(&mut Cell)
{
let i = self.index_of(x, y);
f(&mut self.content[i]);
}
pub fn resize(&mut self, area: Rect) {
let length = area.area() as usize;
if self.content.len() > length {

@ -114,12 +114,12 @@ impl<'a> Widget for BarChart<'a> {
};
for x in 0..self.bar_width {
buf.update_cell(chart_area.left() + i as u16 * (self.bar_width + self.bar_gap) +
x,
chart_area.top() + j,
symbol,
self.bar_color,
Color::Reset);
buf.set_cell(chart_area.left() + i as u16 * (self.bar_width + self.bar_gap) +
x,
chart_area.top() + j,
symbol,
self.bar_color,
Color::Reset);
}
if d.1 > 8 {

@ -85,24 +85,24 @@ impl<'a> Widget for Block<'a> {
// Sides
if self.borders.intersects(border::LEFT) {
for y in area.top()..area.bottom() {
buf.update_cell(area.left(), y, line::VERTICAL, self.border_color, self.bg);
buf.set_cell(area.left(), y, line::VERTICAL, self.border_color, self.bg);
}
}
if self.borders.intersects(border::TOP) {
for x in area.left()..area.right() {
buf.update_cell(x, area.top(), line::HORIZONTAL, self.border_color, self.bg);
buf.set_cell(x, area.top(), line::HORIZONTAL, self.border_color, self.bg);
}
}
if self.borders.intersects(border::RIGHT) {
let x = area.right() - 1;
for y in area.top()..area.bottom() {
buf.update_cell(x, y, line::VERTICAL, self.border_color, self.bg);
buf.set_cell(x, y, line::VERTICAL, self.border_color, self.bg);
}
}
if self.borders.intersects(border::BOTTOM) {
let y = area.bottom() - 1;
for x in area.left()..area.right() {
buf.update_cell(x, y, line::HORIZONTAL, self.border_color, self.bg);
buf.set_cell(x, y, line::HORIZONTAL, self.border_color, self.bg);
}
}

@ -90,7 +90,7 @@ impl<'a> Widget for Gauge<'a> {
self.background_color);
for x in gauge_area.left()..end {
buf.update_colors(x, gauge_area.top(), self.background_color, self.color);
buf.set_colors(x, gauge_area.top(), self.background_color, self.color);
}
}
}

@ -89,11 +89,11 @@ impl<'a> Widget for Sparkline<'a> {
7 => bar::SEVEN_EIGHTHS,
_ => bar::FULL,
};
buf.update_cell(spark_area.left() + i as u16,
spark_area.top() + j,
symbol,
self.color,
self.background_color);
buf.set_cell(spark_area.left() + i as u16,
spark_area.top() + j,
symbol,
self.color,
self.background_color);
if *d > 8 {
*d -= 8;

@ -182,7 +182,7 @@ impl<'a> Widget for Text<'a> {
break;
}
buf.update_cell(text_area.left() + x, text_area.top() + y, s, c, self.bg);
buf.set_cell(text_area.left() + x, text_area.top() + y, s, c, self.bg);
x += 1;
}

Loading…
Cancel
Save