use super::charview::screen_character::ScreenCharacter;
use tui::style::Style as TuiStyle;
pub use super::charview::{CharChunkMap, ViewportLocation};
pub use tui::style::{Color as GameColor, Modifier as Font};
pub use crossterm::event::KeyCode as GameEvent;
pub use super::{Message, SCREEN_HEIGHT, SCREEN_WIDTH};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Style {
pub color: Option<GameColor>,
pub background_color: Option<GameColor>,
pub font: Option<Font>,
}
impl Style {
pub fn new() -> Style {
Style {
color: None,
background_color: None,
font: None,
}
}
pub fn color(mut self, color: Option<GameColor>) -> Style {
self.color = color;
self
}
pub fn background_color(mut self, background_color: Option<GameColor>) -> Style {
self.background_color = background_color;
self
}
pub fn font(mut self, font: Option<Font>) -> Style {
self.font = font;
self
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StyledCharacter {
pub c: char,
pub style: Option<Style>,
}
impl StyledCharacter {
pub fn new(c: char) -> Self {
StyledCharacter { c, style: None }
}
pub fn character(mut self, c: char) -> Self {
self.c = c;
self
}
pub fn style(mut self, s: Style) -> Self {
self.style = Some(s);
self
}
}
impl From<char> for StyledCharacter {
fn from(c: char) -> Self {
StyledCharacter { c, style: None }
}
}
impl From<StyledCharacter> for ScreenCharacter {
fn from(styled_char: StyledCharacter) -> Self {
match styled_char.style {
Some(s) => ScreenCharacter {
c: styled_char.c,
style: Some(TuiStyle {
fg: s.color,
bg: s.background_color,
add_modifier: s.font.unwrap_or(Font::empty()),
sub_modifier: Font::empty(),
}),
},
None => ScreenCharacter {
c: styled_char.c,
style: None,
},
}
}
}
impl From<ScreenCharacter> for StyledCharacter {
fn from(screen_char: ScreenCharacter) -> Self {
match screen_char.style {
Some(s) => StyledCharacter {
c: screen_char.c,
style: Some(Style {
color: s.fg,
background_color: s.bg,
font: Some(s.add_modifier).filter(|m| *m != Font::empty()),
}),
},
None => StyledCharacter {
c: screen_char.c,
style: None,
},
}
}
}