use core::fmt;
use crate::to_css::ToCss;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum TextAlign {
Left,
Right,
Center,
Start,
End,
}
impl ToCss for TextAlign {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
TextAlign::Left => "left",
TextAlign::Right => "right",
TextAlign::Center => "center",
TextAlign::Start => "start",
TextAlign::End => "end",
})
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum TextDecorationLine {
None,
Underline,
Overline,
LineThrough,
}
impl ToCss for TextDecorationLine {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
TextDecorationLine::None => "none",
TextDecorationLine::Underline => "underline",
TextDecorationLine::Overline => "overline",
TextDecorationLine::LineThrough => "line-through",
})
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum TextDecorationStyle {
Solid,
Double,
Dotted,
Dashed,
Wavy,
}
impl ToCss for TextDecorationStyle {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
TextDecorationStyle::Solid => "solid",
TextDecorationStyle::Double => "double",
TextDecorationStyle::Dotted => "dotted",
TextDecorationStyle::Dashed => "dashed",
TextDecorationStyle::Wavy => "wavy",
})
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum TextOverflow {
Clip,
Ellipsis,
}
impl ToCss for TextOverflow {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
TextOverflow::Clip => "clip",
TextOverflow::Ellipsis => "ellipsis",
})
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum TextTransform {
None,
Uppercase,
Lowercase,
Capitalize,
}
impl ToCss for TextTransform {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
TextTransform::None => "none",
TextTransform::Uppercase => "uppercase",
TextTransform::Lowercase => "lowercase",
TextTransform::Capitalize => "capitalize",
})
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum VerticalAlign {
Baseline,
Top,
Middle,
Bottom,
Super,
Sub,
}
impl ToCss for VerticalAlign {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
VerticalAlign::Baseline => "baseline",
VerticalAlign::Top => "top",
VerticalAlign::Middle => "middle",
VerticalAlign::Bottom => "bottom",
VerticalAlign::Super => "super",
VerticalAlign::Sub => "sub",
})
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum Direction {
Ltr,
Rtl,
}
impl ToCss for Direction {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
Direction::Ltr => "ltr",
Direction::Rtl => "rtl",
})
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum WhiteSpace {
Normal,
Nowrap,
Pre,
PreWrap,
PreLine,
}
impl ToCss for WhiteSpace {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
WhiteSpace::Normal => "normal",
WhiteSpace::Nowrap => "nowrap",
WhiteSpace::Pre => "pre",
WhiteSpace::PreWrap => "pre-wrap",
WhiteSpace::PreLine => "pre-line",
})
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum WordBreak {
Normal,
BreakAll,
KeepAll,
}
impl ToCss for WordBreak {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
WordBreak::Normal => "normal",
WordBreak::BreakAll => "break-all",
WordBreak::KeepAll => "keep-all",
})
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum WordWrap {
Normal,
BreakWord,
}
impl ToCss for WordWrap {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
WordWrap::Normal => "normal",
WordWrap::BreakWord => "break-word",
})
}
}
#[cfg(test)]
mod tests {
use super::*;
macro_rules! assert_keyword_set {
($cases:expr) => {
for (k, expected) in $cases {
assert_eq!(k.to_css_string(), expected);
}
};
}
#[test]
fn text_align_all() {
assert_keyword_set!([
(TextAlign::Left, "left"),
(TextAlign::Right, "right"),
(TextAlign::Center, "center"),
(TextAlign::Start, "start"),
(TextAlign::End, "end"),
]);
}
#[test]
fn text_decoration_line_all() {
assert_keyword_set!([
(TextDecorationLine::None, "none"),
(TextDecorationLine::Underline, "underline"),
(TextDecorationLine::Overline, "overline"),
(TextDecorationLine::LineThrough, "line-through"),
]);
}
#[test]
fn text_decoration_style_all() {
assert_keyword_set!([
(TextDecorationStyle::Solid, "solid"),
(TextDecorationStyle::Double, "double"),
(TextDecorationStyle::Dotted, "dotted"),
(TextDecorationStyle::Dashed, "dashed"),
(TextDecorationStyle::Wavy, "wavy"),
]);
}
#[test]
fn text_overflow_all() {
assert_keyword_set!([
(TextOverflow::Clip, "clip"),
(TextOverflow::Ellipsis, "ellipsis"),
]);
}
#[test]
fn text_transform_all() {
assert_keyword_set!([
(TextTransform::None, "none"),
(TextTransform::Uppercase, "uppercase"),
(TextTransform::Lowercase, "lowercase"),
(TextTransform::Capitalize, "capitalize"),
]);
}
#[test]
fn vertical_align_all() {
assert_keyword_set!([
(VerticalAlign::Baseline, "baseline"),
(VerticalAlign::Top, "top"),
(VerticalAlign::Middle, "middle"),
(VerticalAlign::Bottom, "bottom"),
(VerticalAlign::Super, "super"),
(VerticalAlign::Sub, "sub"),
]);
}
#[test]
fn direction_all() {
assert_keyword_set!([(Direction::Ltr, "ltr"), (Direction::Rtl, "rtl")]);
}
#[test]
fn white_space_all() {
assert_keyword_set!([
(WhiteSpace::Normal, "normal"),
(WhiteSpace::Nowrap, "nowrap"),
(WhiteSpace::Pre, "pre"),
(WhiteSpace::PreWrap, "pre-wrap"),
(WhiteSpace::PreLine, "pre-line"),
]);
}
#[test]
fn word_break_all() {
assert_keyword_set!([
(WordBreak::Normal, "normal"),
(WordBreak::BreakAll, "break-all"),
(WordBreak::KeepAll, "keep-all"),
]);
}
#[test]
fn word_wrap_all() {
assert_keyword_set!([
(WordWrap::Normal, "normal"),
(WordWrap::BreakWord, "break-word"),
]);
}
}