use crate::css::Css;
use crate::data_type::{Color, Length, LengthPercentage};
use crate::keyword::{
TextAlign, TextDecorationLine, TextDecorationStyle, TextOverflow, TextTransform, VerticalAlign,
WhiteSpace, WordBreak, WordWrap,
};
impl Css {
pub fn text_align(self, v: TextAlign) -> Self {
self.push("text-align", v)
}
pub fn text_decoration_line(self, v: TextDecorationLine) -> Self {
self.push("text-decoration-line", v)
}
pub fn text_decoration_style(self, v: TextDecorationStyle) -> Self {
self.push("text-decoration-style", v)
}
pub fn text_decoration_color(self, v: Color) -> Self {
self.push("text-decoration-color", v)
}
pub fn text_decoration_thickness(self, v: Length) -> Self {
self.push("text-decoration-thickness", v)
}
pub fn text_overflow(self, v: TextOverflow) -> Self {
self.push("text-overflow", v)
}
pub fn text_transform(self, v: TextTransform) -> Self {
self.push("text-transform", v)
}
pub fn text_indent(self, v: impl Into<LengthPercentage>) -> Self {
self.push("text-indent", v.into())
}
pub fn vertical_align(self, v: VerticalAlign) -> Self {
self.push("vertical-align", v)
}
pub fn white_space(self, v: WhiteSpace) -> Self {
self.push("white-space", v)
}
pub fn word_break(self, v: WordBreak) -> Self {
self.push("word-break", v)
}
pub fn word_wrap(self, v: WordWrap) -> Self {
self.push("word-wrap", v)
}
pub fn overflow_wrap(self, v: WordWrap) -> Self {
self.push("overflow-wrap", v)
}
pub fn webkit_line_clamp(self, v: u32) -> Self {
self.push_raw("-webkit-line-clamp", v.to_string())
}
pub fn text_stroke_width(self, v: Length) -> Self {
self.push("text-stroke-width", v)
}
pub fn text_stroke_color(self, v: Color) -> Self {
self.push("text-stroke-color", v)
}
}
#[cfg(test)]
mod tests {
use crate::data_type::{Color, NamedColor};
use crate::ext::*;
use crate::keyword::*;
use crate::Css;
#[test]
fn text_align_keywords() {
let s = Css::new().text_align(TextAlign::Center);
assert_eq!(s.to_string(), "text-align: center;");
}
#[test]
fn text_decoration_set() {
let s = Css::new()
.text_decoration_line(TextDecorationLine::Underline)
.text_decoration_style(TextDecorationStyle::Wavy)
.text_decoration_color(Color::Named(NamedColor::Red))
.text_decoration_thickness(2.px());
assert_eq!(
s.to_string(),
"text-decoration-line: underline; text-decoration-style: wavy; text-decoration-color: red; text-decoration-thickness: 2px;"
);
}
#[test]
fn text_overflow_and_transform() {
let s = Css::new()
.text_overflow(TextOverflow::Ellipsis)
.text_transform(TextTransform::Uppercase);
assert_eq!(
s.to_string(),
"text-overflow: ellipsis; text-transform: uppercase;"
);
}
#[test]
fn text_indent_value() {
let s = Css::new().text_indent(px(20));
assert_eq!(s.to_string(), "text-indent: 20px;");
}
#[test]
fn vertical_align_keywords() {
let s = Css::new().vertical_align(VerticalAlign::Middle);
assert_eq!(s.to_string(), "vertical-align: middle;");
}
#[test]
fn whitespace_word_handling() {
let s = Css::new()
.white_space(WhiteSpace::Nowrap)
.word_break(WordBreak::BreakAll)
.word_wrap(WordWrap::BreakWord)
.overflow_wrap(WordWrap::Normal);
assert_eq!(
s.to_string(),
"white-space: nowrap; word-break: break-all; word-wrap: break-word; overflow-wrap: normal;"
);
}
#[test]
fn webkit_line_clamp_count() {
let s = Css::new().webkit_line_clamp(2);
assert_eq!(s.to_string(), "-webkit-line-clamp: 2;");
}
#[test]
fn text_stroke_set() {
let s = Css::new()
.text_stroke_width(1.px())
.text_stroke_color(Color::hex(0x000000));
assert_eq!(
s.to_string(),
"text-stroke-width: 1px; text-stroke-color: rgb(0, 0, 0);"
);
}
}