use crate::value::{Color, Unit};
use elvis_core_support::EnumStyle;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, EnumStyle)]
pub enum BorderStyle {
None,
Hidden,
Dotted,
Dashed,
Solid,
Double,
Groove,
Ridge,
Inset,
Outset,
}
impl Default for BorderStyle {
fn default() -> BorderStyle {
BorderStyle::None
}
}
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub struct BoxBorder {
pub width: Unit,
pub style: BorderStyle,
pub color: Color,
}
impl Default for BoxBorder {
fn default() -> BoxBorder {
BoxBorder {
width: Unit::None(0.0),
style: BorderStyle::None,
color: Color::Black,
}
}
}
impl ToString for BoxBorder {
fn to_string(&self) -> String {
format!(
"{} {} {}",
self.width.to_string(),
self.style.to_string(),
self.color.to_string()
)
}
}
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub struct BorderRadius {
pub top_left: Unit,
pub top_right: Unit,
pub bottom_left: Unit,
pub bottom_right: Unit,
pub second_top_left: Unit,
pub second_top_right: Unit,
pub second_bottom_left: Unit,
pub second_bottom_right: Unit,
}
impl Default for BorderRadius {
fn default() -> BorderRadius {
BorderRadius {
top_left: Unit::None(0.0),
top_right: Unit::None(0.0),
bottom_left: Unit::None(0.0),
bottom_right: Unit::None(0.0),
second_top_left: Unit::None(0.0),
second_top_right: Unit::None(0.0),
second_bottom_left: Unit::None(0.0),
second_bottom_right: Unit::None(0.0),
}
}
}
impl ToString for BorderRadius {
fn to_string(&self) -> String {
let radius = format!(
"{} {} {} {}",
self.top_left.to_string(),
self.top_right.to_string(),
self.bottom_left.to_string(),
self.bottom_right.to_string(),
);
if self.second_top_left == self.second_top_right
&& self.second_bottom_right == self.second_bottom_left
&& self.second_top_left == self.second_bottom_right
&& self.second_bottom_right == Unit::None(0.0)
{
radius
} else {
format!(
"{} / {} {} {} {}",
radius,
self.second_top_left.to_string(),
self.second_top_right.to_string(),
self.second_bottom_left.to_string(),
self.second_bottom_right.to_string(),
)
}
}
}