Skip to content

Commit

Permalink
style: Make outline-{color,style} less stringly typed
Browse files Browse the repository at this point in the history
  • Loading branch information
robinlinden committed Nov 24, 2023
1 parent 7ac90ad commit ebc0fd4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions style/styled_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ enum class BorderStyle {
Outset,
};

using OutlineStyle = BorderStyle;

enum class DisplayValue {
None,
Inline,
Expand Down Expand Up @@ -83,6 +85,10 @@ struct StyledNode {
} else if constexpr (T == css::PropertyId::BorderBottomStyle || T == css::PropertyId::BorderLeftStyle
|| T == css::PropertyId::BorderRightStyle || T == css::PropertyId::BorderTopStyle) {
return get_border_style_property(T);
} else if constexpr (T == css::PropertyId::OutlineStyle) {
return get_border_style_property(T);
} else if constexpr (T == css::PropertyId::OutlineColor) {
return get_color_property(T);
} else if constexpr (T == css::PropertyId::Color) {
return get_color_property(T);
} else if constexpr (T == css::PropertyId::Display) {
Expand Down
21 changes: 21 additions & 0 deletions style/styled_node_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,27 @@ int main() {
expect_property_eq<css::PropertyId::BorderTopStyle>("ridge", style::BorderStyle::Ridge);
});

etest::test("get_property, outline-style", [] {
expect_property_eq<css::PropertyId::OutlineStyle>("none", style::BorderStyle::None);
expect_property_eq<css::PropertyId::OutlineStyle>("hidden", style::BorderStyle::Hidden);
expect_property_eq<css::PropertyId::OutlineStyle>("dotted", style::BorderStyle::Dotted);
expect_property_eq<css::PropertyId::OutlineStyle>("dashed", style::BorderStyle::Dashed);
expect_property_eq<css::PropertyId::OutlineStyle>("solid", style::BorderStyle::Solid);
expect_property_eq<css::PropertyId::OutlineStyle>("double", style::BorderStyle::Double);
expect_property_eq<css::PropertyId::OutlineStyle>("groove", style::BorderStyle::Groove);
expect_property_eq<css::PropertyId::OutlineStyle>("ridge", style::BorderStyle::Ridge);
expect_property_eq<css::PropertyId::OutlineStyle>("inset", style::BorderStyle::Inset);
expect_property_eq<css::PropertyId::OutlineStyle>("outset", style::BorderStyle::Outset);
expect_property_eq<css::PropertyId::OutlineStyle>("???", style::BorderStyle::None);
});

etest::test("get_property, outline-color", [] {
expect_property_eq<css::PropertyId::Color>("rgba(1 2 3)", gfx::Color{1, 2, 3});
expect_property_eq<css::PropertyId::Color>("rgba(1 2 3 / .5)", gfx::Color{1, 2, 3, 127});
expect_property_eq<css::PropertyId::Color>("rgba(1 2 3 / -0.5)", gfx::Color{1, 2, 3, 0});
expect_property_eq<css::PropertyId::Color>("rgba(1 2 3 / 1.5)", gfx::Color{1, 2, 3, 0xFF});
});

etest::test("get_property, color", [] {
expect_property_eq<css::PropertyId::Color>("rgba(1 2 3)", gfx::Color{1, 2, 3});
expect_property_eq<css::PropertyId::Color>("rgba(1 2 3 / .5)", gfx::Color{1, 2, 3, 127});
Expand Down

0 comments on commit ebc0fd4

Please sign in to comment.