mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-22 12:43:16 +00:00
Rename buffer methods
This commit is contained in:
parent
85bd76e17d
commit
bcb3d751bf
6 changed files with 26 additions and 24 deletions
|
@ -89,11 +89,6 @@ impl Buffer {
|
||||||
(i as u16 % self.area.width, i as u16 / self.area.width)
|
(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) {
|
pub fn set_symbol(&mut self, x: u16, y: u16, symbol: &str) {
|
||||||
let i = self.index_of(x, y);
|
let i = self.index_of(x, y);
|
||||||
self.content[i].symbol.clear();
|
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);
|
let i = self.index_of(x, y);
|
||||||
self.content[i].fg = fg;
|
self.content[i].fg = fg;
|
||||||
self.content[i].bg = bg;
|
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);
|
let i = self.index_of(x, y);
|
||||||
self.content[i].symbol.clear();
|
self.content[i].symbol.clear();
|
||||||
self.content[i].symbol.push_str(symbol);
|
self.content[i].symbol.push_str(symbol);
|
||||||
|
@ -147,6 +142,13 @@ impl Buffer {
|
||||||
self.content[i].bg = bg;
|
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) {
|
pub fn resize(&mut self, area: Rect) {
|
||||||
let length = area.area() as usize;
|
let length = area.area() as usize;
|
||||||
if self.content.len() > length {
|
if self.content.len() > length {
|
||||||
|
|
|
@ -114,12 +114,12 @@ impl<'a> Widget for BarChart<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
for x in 0..self.bar_width {
|
for x in 0..self.bar_width {
|
||||||
buf.update_cell(chart_area.left() + i as u16 * (self.bar_width + self.bar_gap) +
|
buf.set_cell(chart_area.left() + i as u16 * (self.bar_width + self.bar_gap) +
|
||||||
x,
|
x,
|
||||||
chart_area.top() + j,
|
chart_area.top() + j,
|
||||||
symbol,
|
symbol,
|
||||||
self.bar_color,
|
self.bar_color,
|
||||||
Color::Reset);
|
Color::Reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.1 > 8 {
|
if d.1 > 8 {
|
||||||
|
|
|
@ -85,24 +85,24 @@ impl<'a> Widget for Block<'a> {
|
||||||
// Sides
|
// Sides
|
||||||
if self.borders.intersects(border::LEFT) {
|
if self.borders.intersects(border::LEFT) {
|
||||||
for y in area.top()..area.bottom() {
|
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) {
|
if self.borders.intersects(border::TOP) {
|
||||||
for x in area.left()..area.right() {
|
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) {
|
if self.borders.intersects(border::RIGHT) {
|
||||||
let x = area.right() - 1;
|
let x = area.right() - 1;
|
||||||
for y in area.top()..area.bottom() {
|
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) {
|
if self.borders.intersects(border::BOTTOM) {
|
||||||
let y = area.bottom() - 1;
|
let y = area.bottom() - 1;
|
||||||
for x in area.left()..area.right() {
|
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);
|
self.background_color);
|
||||||
|
|
||||||
for x in gauge_area.left()..end {
|
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,
|
7 => bar::SEVEN_EIGHTHS,
|
||||||
_ => bar::FULL,
|
_ => bar::FULL,
|
||||||
};
|
};
|
||||||
buf.update_cell(spark_area.left() + i as u16,
|
buf.set_cell(spark_area.left() + i as u16,
|
||||||
spark_area.top() + j,
|
spark_area.top() + j,
|
||||||
symbol,
|
symbol,
|
||||||
self.color,
|
self.color,
|
||||||
self.background_color);
|
self.background_color);
|
||||||
|
|
||||||
if *d > 8 {
|
if *d > 8 {
|
||||||
*d -= 8;
|
*d -= 8;
|
||||||
|
|
|
@ -182,7 +182,7 @@ impl<'a> Widget for Text<'a> {
|
||||||
break;
|
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;
|
x += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue