use crate::style::TextStyle;
use crate::{Color, TextWrap};
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Text {
pub content: String,
pub style: Option<TextStyle>,
}
impl Text {
pub fn new(content: impl Into<String>) -> Self {
Self {
content: content.into(),
style: None,
}
}
pub fn color(mut self, color: Color) -> Self {
self.style.get_or_insert(TextStyle::default()).color = Some(color);
self
}
pub fn background(mut self, color: Color) -> Self {
self.style.get_or_insert(TextStyle::default()).background = Some(color);
self
}
pub fn bold(mut self) -> Self {
self.style.get_or_insert(TextStyle::default()).bold = Some(true);
self
}
pub fn italic(mut self) -> Self {
self.style.get_or_insert(TextStyle::default()).italic = Some(true);
self
}
pub fn underline(mut self) -> Self {
self.style.get_or_insert(TextStyle::default()).underline = Some(true);
self
}
pub fn strikethrough(mut self) -> Self {
self.style.get_or_insert(TextStyle::default()).strikethrough = Some(true);
self
}
pub fn wrap(mut self, wrap: TextWrap) -> Self {
self.style.get_or_insert(TextStyle::default()).wrap = Some(wrap);
self
}
}
impl From<String> for Text {
fn from(content: String) -> Self {
Self::new(content)
}
}
impl From<&str> for Text {
fn from(content: &str) -> Self {
Self::new(content)
}
}