Skip to content

Commit

Permalink
vaev-style: Simplified border parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Sep 12, 2024
1 parent 32e5d21 commit 891e933
Showing 1 changed file with 27 additions and 43 deletions.
70 changes: 27 additions & 43 deletions src/web/vaev-style/styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,44 +674,38 @@ struct BorderRadius {

// https://www.w3.org/TR/css-backgrounds-3/#border-shorthands
struct BorderProp {
Array<Border, 4> value = {};
Border value;

static constexpr Str name() { return "border"; }

void apply(Computed &c) const {
c.borders.cow().top = value[0];
c.borders.cow().bottom = value[1];
c.borders.cow().start = value[2];
c.borders.cow().end = value[3];
c.borders.cow().top = value;
c.borders.cow().bottom = value;
c.borders.cow().start = value;
c.borders.cow().end = value;
}

Res<> parse(Cursor<Css::Sst> &c) {
eatWhitespace(c);

while (not c.ended()) {
auto width = parseValue<Length>(c);
if (width) {
value[0].width = width.unwrap();
value[1].width = width.unwrap();
value[2].width = width.unwrap();
value[3].width = width.unwrap();
} else {
auto color = parseValue<Color>(c);
if (color) {
value[0].color = color.unwrap();
value[1].color = color.unwrap();
value[2].color = color.unwrap();
value[3].color = color.unwrap();
} else {
auto style = parseValue<BorderStyle>(c);
if (style) {
value[0].style = style.unwrap();
value[1].style = style.unwrap();
value[2].style = style.unwrap();
value[3].style = style.unwrap();
}
}
value.width = width.unwrap();
continue;
}

auto color = parseValue<Color>(c);
if (color) {
value.color = color.unwrap();
continue;
}

auto style = parseValue<BorderStyle>(c);
if (style) {
value.style = style.unwrap();
continue;
}

break;
}

return Ok();
Expand All @@ -720,29 +714,19 @@ struct BorderProp {

// https://www.w3.org/TR/css-backgrounds-3/#border-width
struct BorderWidthProp {
Array<Length, 4> value = {Borders::MEDIUM, Borders::MEDIUM, Borders::MEDIUM, Borders::MEDIUM};
Math::Insets<Length> value = Borders::MEDIUM;

static constexpr Str name() { return "border-width"; }

void apply(Computed &c) const {
c.borders.cow().start.width = value[0];
c.borders.cow().end.width = value[1];
c.borders.cow().top.width = value[2];
c.borders.cow().bottom.width = value[3];
c.borders.cow().start.width = value.start;
c.borders.cow().end.width = value.end;
c.borders.cow().top.width = value.top;
c.borders.cow().bottom.width = value.bottom;
}

Res<> parse(Cursor<Css::Sst> &c) {
value[0] = try$(parseValue<Length>(c));
if (c.ended()) {
value[1] = value[0];
value[2] = value[0];
value[3] = value[0];
} else {
value[1] = try$(parseValue<Length>(c));
value[2] = value[0];
value[0] = value[1];
value[3] = value[2];
}
value = try$(parseValue<Math::Insets<Length>>(c));

return Ok();
}
Expand Down

0 comments on commit 891e933

Please sign in to comment.