use super::Cell;
#[allow(unused)]
use super::{region::Region, Buffer};
use crate::{
style::Style,
utils::geometry::{Axis, Position, Size},
};
pub trait Draw {
fn set_option_cell(&mut self, position: Position, cell: Option<Cell>) -> bool;
fn clear(&mut self) {
let Size { width, height } = self.size();
for x in 0..width {
for y in 0..height {
self.set_option_cell(Position { x, y }, None);
}
}
}
fn set_cell(&mut self, position: Position, cell: Cell) -> bool {
self.set_option_cell(position, Some(cell))
}
fn unset_cell(&mut self, position: Position) -> bool {
self.set_option_cell(position, None)
}
fn set_char(&mut self, position: Position, chr: char, style: Style) -> bool {
self.set_cell(position, Cell { chr: Some(chr), style })
}
fn write_string(&mut self, axis: Axis, mut position: Position, string: &str, style: Style) {
for chr in string.chars() {
if !self.set_cell(position, Cell { chr: Some(chr), style }) {
return;
}
match axis {
Axis::Horizontal => position.x += 1,
Axis::Vertical => position.y += 1,
}
}
}
fn repeat_char(&mut self, axis: Axis, mut position: Position, chr: char, style: Style, n: u16) {
for _ in 0..n {
if !self.set_cell(position, Cell { chr: Some(chr), style }) {
return;
}
match axis {
Axis::Horizontal => position.x += 1,
Axis::Vertical => position.y += 1,
}
}
}
#[must_use]
fn size(&self) -> Size;
}