operator
| -rw-r--r-- | src/cell.rs | 41 | ||||
| -rw-r--r-- | src/lib.rs | 8 |
2 files changed, 44 insertions, 5 deletions
diff --git a/src/cell.rs b/src/cell.rs index 319e19a..9a7ea08 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -5,6 +5,20 @@ pub struct Style { // one of [Style::BOLD].. pub flags: u8, } +impl Style { + pub fn basic(self, c: char) -> Cell { + Cell { + style: self, + letter: Some(c), + } + } + pub fn empty(self) -> Cell { + Cell { + style: self, + letter: None, + } + } +} impl Default for Style { fn default() -> Self { @@ -18,7 +32,7 @@ impl Default for Style { use std::default::Default::default; use std::fmt::Debug; -use std::ops::BitOrAssign; +use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign}; impl Style { pub const BOLD: u8 = 1; pub const DIM: u8 = 1 << 1; @@ -31,17 +45,42 @@ pub struct Cell { pub style: Style, pub letter: Option<char>, } + impl Debug for Cell { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.letter.unwrap_or(' ')) } } +impl BitOr<u8> for Style { + type Output = Self; + + fn bitor(self, rhs: u8) -> Self::Output { + Self { + flags: self.flags | rhs, + ..self + } + } +} impl BitOrAssign<(u8, [u8; 3])> for Style { fn bitor_assign(&mut self, (f, c): (u8, [u8; 3])) { self.flags |= f; self.color = c; } } +impl BitAnd<(u8, [u8; 3])> for Style { + type Output = Style; + fn bitand(mut self, (flags, bg): (u8, [u8; 3])) -> Self::Output { + self.flags |= flags; + self.bg = bg; + self + } +} +impl BitAndAssign<(u8, [u8; 3])> for Style { + fn bitand_assign(&mut self, rhs: (u8, [u8; 3])) { + *self = *self & rhs; + } +} + impl Cell { pub fn basic(c: char) -> Self { Self { @@ -33,10 +33,10 @@ use umath::FF32; pub use crate::cell::Cell; use crate::cell::Style; pub struct Fonts<'a, 'b, 'c, 'd> { - regular: F<'a>, - bold: F<'b>, - italic: F<'c>, - bold_italic: F<'d>, + pub regular: F<'a>, + pub bold: F<'b>, + pub italic: F<'c>, + pub bold_italic: F<'d>, cache: LruCache<(u8, FF32, u16), swash::scale::image::Image>, scx: ShapeContext, |