Fill functions now support a Color as an argument
Fill functions were modified to support Into<Rune> and From<Color> was implemented for Rune and Runes. This allows Passing a color to functions such as View::fill and View::fill_all. to set the background color.
This commit is contained in:
parent
44baee56b0
commit
3e50d269e5
10
src/runes.rs
10
src/runes.rs
|
@ -41,6 +41,16 @@ impl From<char> for Rune {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Color> for Rune {
|
||||||
|
fn from(value: Color) -> Self {
|
||||||
|
Rune {
|
||||||
|
content: Some(' '),
|
||||||
|
bg: Some(value),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Rune {
|
impl Rune {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::default()
|
Self::default()
|
||||||
|
|
18
src/view.rs
18
src/view.rs
|
@ -82,11 +82,27 @@ impl View {
|
||||||
|
|
||||||
/// Fill a region of the view with a single rune, repeating it in every
|
/// Fill a region of the view with a single rune, repeating it in every
|
||||||
/// position.
|
/// position.
|
||||||
pub fn fill<R>(&mut self, rect: R, rune: Rune)
|
pub fn fill<R, U>(&mut self, rect: R, rune: U)
|
||||||
where
|
where
|
||||||
R: Into<Rect>,
|
R: Into<Rect>,
|
||||||
|
U: Into<Rune>,
|
||||||
{
|
{
|
||||||
let rect = rect.into();
|
let rect = rect.into();
|
||||||
|
let rune = rune.into();
|
||||||
|
for y in rect.pos.y..(rect.size.height + rect.pos.y).min(self.0.len()) {
|
||||||
|
for x in rect.pos.x..(rect.size.width + rect.pos.x).min(self.0[y].len()) {
|
||||||
|
let _ = std::mem::replace(&mut self.0[y][x], rune);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fill the entire view context with a rune
|
||||||
|
pub fn fill_all<R>(&mut self, rune: R)
|
||||||
|
where
|
||||||
|
R: Into<Rune>,
|
||||||
|
{
|
||||||
|
let rune = rune.into();
|
||||||
|
let rect = Rect::new((0, 0), self.size());
|
||||||
for y in rect.pos.y..(rect.size.height + rect.pos.y).min(self.0.len()) {
|
for y in rect.pos.y..(rect.size.height + rect.pos.y).min(self.0.len()) {
|
||||||
for x in rect.pos.x..(rect.size.width + rect.pos.x).min(self.0[y].len()) {
|
for x in rect.pos.x..(rect.size.width + rect.pos.x).min(self.0[y].len()) {
|
||||||
let _ = std::mem::replace(&mut self.0[y][x], rune);
|
let _ = std::mem::replace(&mut self.0[y][x], rune);
|
||||||
|
|
Loading…
Reference in New Issue