From bcb3d751bfc5cc10dc7c526f890b43f793a367cf Mon Sep 17 00:00:00 2001 From: Florian Dehau Date: Thu, 27 Oct 2016 12:35:26 +0200 Subject: [PATCH] Rename buffer methods --- src/buffer.rs | 16 +++++++++------- src/widgets/barchart.rs | 12 ++++++------ src/widgets/block.rs | 8 ++++---- src/widgets/gauge.rs | 2 +- src/widgets/sparkline.rs | 10 +++++----- src/widgets/text.rs | 2 +- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 0426abdc..50512e58 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -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(&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 { diff --git a/src/widgets/barchart.rs b/src/widgets/barchart.rs index 7fd5a6dd..3c481965 100644 --- a/src/widgets/barchart.rs +++ b/src/widgets/barchart.rs @@ -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 { diff --git a/src/widgets/block.rs b/src/widgets/block.rs index f725479b..23eb5659 100644 --- a/src/widgets/block.rs +++ b/src/widgets/block.rs @@ -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); } } diff --git a/src/widgets/gauge.rs b/src/widgets/gauge.rs index 4b420d7e..9f514e83 100644 --- a/src/widgets/gauge.rs +++ b/src/widgets/gauge.rs @@ -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); } } } diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs index 6672edf5..ee672b87 100644 --- a/src/widgets/sparkline.rs +++ b/src/widgets/sparkline.rs @@ -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; diff --git a/src/widgets/text.rs b/src/widgets/text.rs index 03461b2d..510bb0ba 100644 --- a/src/widgets/text.rs +++ b/src/widgets/text.rs @@ -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; }