use rustty::{Size, HasSize, Pos, HasPosition};
use rustty::{Cell, CellAccessor};
use core::{
Alignable,
HorizontalAlign,
VerticalAlign,
Widget,
Frame,
Painter
};
pub struct Canvas {
frame: Frame
}
impl Canvas {
pub fn new(cols: usize, rows: usize) -> Canvas {
Canvas {
frame: Frame::new(cols, rows)
}
}
pub fn size(&self) -> Size {
self.frame.size()
}
pub fn cellvec(&self) -> &Vec<Cell> {
self.frame.cellvec()
}
pub fn cellvec_mut(&mut self) -> &mut Vec<Cell> {
self.frame.cellvec_mut()
}
pub fn clear(&mut self, blank: Cell) {
self.frame.clear(blank);
}
pub fn pos_to_index(&self, x: usize, y: usize) -> Option<usize> {
self.frame.pos_to_index(x, y)
}
pub fn get(&self, x: usize, y: usize) -> Option<&Cell> {
self.frame.get(x, y)
}
pub fn get_mut(&mut self, x: usize, y: usize) -> Option<&mut Cell> {
self.frame.get_mut(x, y)
}
pub fn origin(&self) -> Pos {
self.frame.origin()
}
pub fn set_origin(&mut self, new_origin: Pos) {
self.frame.set_origin(new_origin);
}
}
impl Widget for Canvas {
fn draw(&mut self, parent: &mut CellAccessor) {
self.frame.draw_into(parent);
}
fn pack(&mut self, parent: &HasSize, halign: HorizontalAlign, valign: VerticalAlign,
margin: (usize, usize)) {
self.frame.align(parent, halign, valign, margin);
}
fn resize(&mut self, new_size: Size) {
self.frame.resize(new_size);
}
fn draw_box(&mut self) {
self.frame.draw_box();
}
fn frame(&self) -> &Frame {
&self.frame
}
fn frame_mut(&mut self) -> &mut Frame {
&mut self.frame
}
}