use crate::prelude::*;
use crate::ui::canvas::frame::cell::Cell;
use crate::ui::canvas::frame::cursor::Cursor;
use crate::ui::canvas::internal::iframe::Iframe;
use geo::point;
use std::ops::Range;
pub mod cell;
pub mod cursor;
#[cfg(test)]
mod cursor_tests;
#[derive(Debug, Clone)]
pub struct Frame {
iframe: Iframe,
cursor: Cursor,
}
impl Frame {
pub fn new(size: U16Size, cursor: Cursor) -> Self {
Frame {
iframe: Iframe::new(size),
cursor,
}
}
pub fn pos2range(&self, pos: U16Pos, n: usize) -> Range<usize> {
self.iframe.pos2range(pos, n)
}
pub fn idx2range(&self, index: usize, n: usize) -> Range<usize> {
self.iframe.idx2range(index, n)
}
pub fn xy2idx(&self, x: usize, y: usize) -> usize {
self.iframe.xy2idx(x, y)
}
pub fn pos2idx(&self, pos: U16Pos) -> usize {
self.iframe.pos2idx(pos)
}
pub fn idx2xy(&self, index: usize) -> (usize, usize) {
self.iframe.idx2xy(index)
}
pub fn idx2pos(&self, index: usize) -> U16Pos {
let (x, y) = self.idx2xy(index);
point!(x: x as u16, y: y as u16)
}
pub fn size(&self) -> U16Size {
self.iframe.size()
}
pub fn zero_sized(&self) -> bool {
self.iframe.zero_sized()
}
pub fn set_size(&mut self, size: U16Size) -> U16Size {
self.iframe.set_size(size)
}
pub fn contains_index(&self, index: usize) -> bool {
self.iframe.contains_index(index)
}
pub fn contains_range(&self, range: &Range<usize>) -> bool {
self.iframe.contains_range(range)
}
pub fn get_cell(&self, pos: U16Pos) -> &Cell {
self.iframe.get_cell(pos)
}
pub fn try_get_cell(&self, pos: U16Pos) -> Option<&Cell> {
self.iframe.try_get_cell(pos)
}
pub fn set_cell(&mut self, pos: U16Pos, cell: Cell) -> Cell {
self.iframe.set_cell(pos, cell)
}
pub fn try_set_cell(&mut self, pos: U16Pos, cell: Cell) -> Option<Cell> {
self.iframe.try_set_cell(pos, cell)
}
pub fn set_empty_cell(&mut self, pos: U16Pos) -> Cell {
self.iframe.set_empty_cell(pos)
}
pub fn try_set_empty_cell(&mut self, pos: U16Pos) -> Option<Cell> {
self.iframe.try_set_empty_cell(pos)
}
pub fn get_cells(&self) -> &Vec<Cell> {
self.iframe.get_cells()
}
pub fn get_cells_at(&self, pos: U16Pos, n: usize) -> &[Cell] {
self.iframe.get_cells_at(pos, n)
}
pub fn try_get_cells_at(&self, pos: U16Pos, n: usize) -> Option<&[Cell]> {
self.iframe.try_get_cells_at(pos, n)
}
pub fn set_cells_at(&mut self, pos: U16Pos, cells: Vec<Cell>) -> Vec<Cell> {
self.iframe.set_cells_at(pos, cells)
}
pub fn try_set_cells_at(
&mut self,
pos: U16Pos,
cells: Vec<Cell>,
) -> Option<Vec<Cell>> {
self.iframe.try_set_cells_at(pos, cells)
}
pub fn set_empty_cells_at(&mut self, pos: U16Pos, n: usize) -> Vec<Cell> {
self.iframe.set_empty_cells_at(pos, n)
}
pub fn try_set_empty_cells_at(
&mut self,
pos: U16Pos,
n: usize,
) -> Option<Vec<Cell>> {
self.iframe.try_set_empty_cells_at(pos, n)
}
pub fn dirty_rows(&self) -> &Vec<bool> {
self.iframe.dirty_rows()
}
pub fn reset_dirty_rows(&mut self) {
self.iframe.reset_dirty_rows()
}
pub fn cursor(&self) -> &Cursor {
&self.cursor
}
pub fn set_cursor(&mut self, cursor: Cursor) {
self.cursor = cursor;
}
}
#[cfg(test)]
use compact_str::CompactString;
impl Frame {
#[cfg(test)]
pub fn raw_symbols(&self) -> Vec<Vec<CompactString>> {
self.iframe.raw_symbols()
}
#[cfg(test)]
pub fn raw_symbols_with_placeholder(&self) -> Vec<Vec<CompactString>> {
self.iframe.raw_symbols_with_placeholder()
}
}