use crate::style::Color;
#[derive(Clone, Debug, Default, PartialEq)]
pub struct RunFont {
pub bold: bool,
pub italic: bool,
pub underline: Option<String>,
pub strike: bool,
pub size: Option<f64>,
pub color: Option<Color>,
pub name: Option<String>,
pub vert_align: Option<String>,
}
impl RunFont {
pub fn is_empty(&self) -> bool {
!self.bold
&& !self.italic
&& self.underline.is_none()
&& !self.strike
&& self.size.is_none()
&& self.color.is_none()
&& self.name.is_none()
&& self.vert_align.is_none()
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct TextRun {
pub text: String,
pub font: Option<RunFont>,
}
impl TextRun {
pub fn plain<S: Into<String>>(text: S) -> Self {
TextRun {
text: text.into(),
font: None,
}
}
pub fn formatted<S: Into<String>>(text: S, font: RunFont) -> Self {
TextRun {
text: text.into(),
font: Some(font),
}
}
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct RichText {
pub runs: Vec<TextRun>,
}
impl RichText {
pub fn new(runs: Vec<TextRun>) -> Self {
RichText { runs }
}
pub fn plain(&self) -> String {
self.runs.iter().map(|r| r.text.as_str()).collect()
}
pub fn is_empty(&self) -> bool {
self.runs.is_empty()
}
}