#[cfg(feature = "derive")]
use serde::{Deserialize, Serialize};
mod pixelbuffer;
mod viewport;
pub mod camera;
pub mod events;
pub mod render;
pub mod widgets;
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
pub struct Pixel {
pub glyph: char,
pub pos: ScreenPos,
pub fg_color: Option<Color>,
pub bg_color: Option<Color>,
}
impl Pixel {
pub fn new(
glyph: char,
pos: ScreenPos,
fg_color: Option<Color>,
bg_color: Option<Color>,
) -> Self {
Self { glyph, pos, fg_color, bg_color }
}
pub fn white(c: char, pos: ScreenPos) -> Self {
Self::new(c, pos, None, None)
}
}
pub use camera::Camera;
pub use crossterm::style::{Color, Colored};
pub use crossterm::terminal::size as term_size;
pub use crossterm::ErrorKind as CrosstermError;
pub use pixelbuffer::PixelBuffer;
pub use render::{Renderer, StdoutTarget};
pub use viewport::Viewport;
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
pub struct ScreenPos {
pub x: u16,
pub y: u16,
}
impl ScreenPos {
pub fn new(x: u16, y: u16) -> Self {
Self { x, y }
}
pub fn zero() -> Self {
Self::new(0, 0)
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
pub struct WorldPos {
pub x: i64,
pub y: i64,
}
impl WorldPos {
pub fn new(x: i64, y: i64) -> Self {
Self { x, y }
}
pub fn zero() -> Self {
Self::new(0, 0)
}
}
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
pub struct ScreenRect {
pub origin: ScreenPos,
pub size: ScreenSize,
}
impl ScreenRect {
pub fn new(origin: ScreenPos, size: ScreenSize) -> Self {
Self { origin, size }
}
}
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
pub struct WorldRect {
pub origin: WorldPos,
pub size: WorldSize,
}
impl WorldRect {
pub fn new(origin: WorldPos, size: WorldSize) -> Self {
Self { origin, size }
}
pub fn min_x(&self) -> i64 {
self.origin.x
}
pub fn min_y(&self) -> i64 {
self.origin.y
}
pub fn max_x(&self) -> i64 {
self.origin.x + self.size.width
}
pub fn max_y(&self) -> i64 {
self.origin.y + self.size.height
}
}
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
pub struct ScreenSize {
pub width: u16,
pub height: u16,
}
impl ScreenSize {
pub fn new(width: u16, height: u16) -> Self {
Self { width, height }
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
pub struct WorldSize {
pub width: i64,
pub height: i64,
}
impl WorldSize {
pub fn new(width: i64, height: i64) -> Self {
Self { width, height }
}
}