Skip to content

Commit d187d18

Browse files
committed
wip
1 parent 63a952a commit d187d18

File tree

8 files changed

+55
-61
lines changed

8 files changed

+55
-61
lines changed

src/vaev-engine/layout/values.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@ export struct Resolver {
328328
}
329329

330330
template <typename T, typename... Args>
331-
Resolved<T> resolve(CalcValue<T> const& calc, Args... args) {
331+
Resolved<T> resolve(Calc<T> const& calc, Args... args) {
332332
auto resolveUnion = Visitor{
333333
[&](T const& v) {
334334
return resolve(v, args...);
335335
},
336-
[&](CalcValue<T>::Leaf const& v) {
336+
[&](Calc<T>::Leaf const& v) {
337337
return resolve<T>(*v, args...);
338338
},
339339
[&](Number const& v)
@@ -344,16 +344,16 @@ export struct Resolver {
344344
};
345345

346346
return calc.visit(Visitor{
347-
[&](typename CalcValue<T>::Value const& v) {
347+
[&](typename Calc<T>::Value const& v) {
348348
return v.visit(resolveUnion);
349349
},
350-
[&](typename CalcValue<T>::Unary const& u) {
350+
[&](typename Calc<T>::Unary const& u) {
351351
return _resolveUnary<T>(
352352
u.op,
353353
u.val.visit(resolveUnion)
354354
);
355355
},
356-
[&](typename CalcValue<T>::Binary const& b) {
356+
[&](typename Calc<T>::Binary const& b) {
357357
return _resolveInfix<T>(
358358
b.op,
359359
b.lhs.visit(resolveUnion),
@@ -399,7 +399,7 @@ export Au resolve(Tree const& tree, Box const& box, FontSize const& value) {
399399
}
400400

401401
export template <typename T, typename... Args>
402-
auto resolve(Tree const& tree, Box const& box, CalcValue<T> const& value, Args... args) -> Resolved<T> {
402+
auto resolve(Tree const& tree, Box const& box, Calc<T> const& value, Args... args) -> Resolved<T> {
403403
return Resolver::from(tree, box).resolve(value, args...);
404404
}
405405

src/vaev-engine/style/props.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ export struct BorderBottomWidthProp {
812812
}
813813

814814
Res<> parse(Cursor<Css::Sst>& c) {
815-
value = try$(parseValue<CalcValue<Length>>(c));
815+
value = try$(parseValue<Calc<Length>>(c));
816816
return Ok();
817817
}
818818
};
@@ -982,7 +982,7 @@ export struct BorderRadius {
982982

983983
static constexpr Str name() { return "border-radius"; }
984984

985-
static Math::Radii<Calc<Length>>> initial() { return {CalcValue<PercentOr<Length>(Length{})}; }
985+
static Math::Radii<Calc<Length>>> initial() { return {Calc<Length>(Length{})}; }
986986

987987
void apply(SpecifiedValues& c) const {
988988
c.borders.cow().radii = value;
@@ -1014,7 +1014,7 @@ export struct BorderTopProp {
10141014

10151015
Res<> parse(Cursor<Css::Sst>& c) {
10161016
while (not c.ended()) {
1017-
auto width = parseValue<CalcValue<Length>>(c);
1017+
auto width = parseValue<Calc<Length>>(c);
10181018
if (width) {
10191019
value.width = width.unwrap();
10201020
continue;
@@ -1055,7 +1055,7 @@ export struct BorderRightProp {
10551055

10561056
Res<> parse(Cursor<Css::Sst>& c) {
10571057
while (not c.ended()) {
1058-
auto width = parseValue<CalcValue<Length>>(c);
1058+
auto width = parseValue<Calc<Length>>(c);
10591059
if (width) {
10601060
value.width = width.unwrap();
10611061
continue;
@@ -1096,7 +1096,7 @@ export struct BorderBottomProp {
10961096

10971097
Res<> parse(Cursor<Css::Sst>& c) {
10981098
while (not c.ended()) {
1099-
auto width = parseValue<CalcValue<Length>>(c);
1099+
auto width = parseValue<Calc<Length>>(c);
11001100
if (width) {
11011101
value.width = width.unwrap();
11021102
continue;
@@ -1137,7 +1137,7 @@ export struct BorderLeftProp {
11371137

11381138
Res<> parse(Cursor<Css::Sst>& c) {
11391139
while (not c.ended()) {
1140-
auto width = parseValue<CalcValue<Length>>(c);
1140+
auto width = parseValue<Calc<Length>>(c);
11411141
if (width) {
11421142
value.width = width.unwrap();
11431143
continue;
@@ -2199,7 +2199,7 @@ export struct OutlineProp {
21992199
Res<> parse(Cursor<Css::Sst>& c) {
22002200
bool styleSet = false;
22012201
while (not c.ended()) {
2202-
auto width = parseValue<CalcValue<Length>>(c);
2202+
auto width = parseValue<Calc<Length>>(c);
22032203
if (width) {
22042204
value.width = width.unwrap();
22052205
continue;
@@ -2302,7 +2302,7 @@ export struct OutlineColorProp {
23022302

23032303
// https://drafts.csswg.org/css-ui/#outline-offset
23042304
export struct OutlineOffsetProp {
2305-
CalcValue<Length> value = initial();
2305+
Calc<Length> value = initial();
23062306

23072307
static Str name() { return "outline-offset"; }
23082308

@@ -2312,12 +2312,12 @@ export struct OutlineOffsetProp {
23122312
c.outline.cow().offset = value;
23132313
}
23142314

2315-
static CalcValue<Length> load(SpecifiedValues const& c) {
2315+
static Calc<Length> load(SpecifiedValues const& c) {
23162316
return c.outline->offset;
23172317
}
23182318

23192319
Res<> parse(Cursor<Css::Sst>& c) {
2320-
value = try$(parseValue<CalcValue<Length>>(c));
2320+
value = try$(parseValue<Calc<Length>>(c));
23212321
return Ok();
23222322
}
23232323
};

src/vaev-engine/values/background.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ export struct BackgroundPosition {
5858
vertical(Percent{0}) {
5959
}
6060

61-
constexpr BackgroundPosition(Calc<Length>> horizontal, CalcValue<PercentOr<Length> vertical)
61+
constexpr BackgroundPosition(Calc<Length> horizontal, Calc<Length> vertical)
6262
: horizontalAnchor(Keywords::LEFT), horizontal(horizontal), verticalAnchor(Keywords::TOP), vertical(vertical) {
6363
}
6464

65-
constexpr BackgroundPosition(HorizontalAnchor horizontalAnchor, Calc<Length>> horizontal, VerticalAnchor verticalAnchor, CalcValue<PercentOr<Length> vertical)
65+
constexpr BackgroundPosition(HorizontalAnchor horizontalAnchor, Calc<Length> horizontal, VerticalAnchor verticalAnchor, Calc<Length> vertical)
6666
: horizontalAnchor(horizontalAnchor), horizontal(horizontal), verticalAnchor(verticalAnchor), vertical(vertical) {
6767
}
6868

src/vaev-engine/values/calc.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import :css;
1010
import :values.base;
1111
import :values.length;
1212
import :values.primitives;
13+
import :values.percent;
1314

1415
using namespace Karm;
1516

@@ -32,11 +33,12 @@ export enum struct CalcOp {
3233
// 10. Mathematical Expressions
3334
// https://drafts.csswg.org/css-values/#math
3435
export template <typename T>
35-
struct CalcValue {
36-
using Leaf = Box<CalcValue<T>>;
36+
struct Calc {
37+
using Leaf = Box<Calc>;
3738

3839
using Value = Union<
3940
T,
41+
Percent,
4042
Leaf,
4143
Number>;
4244

@@ -58,23 +60,23 @@ struct CalcValue {
5860

5961
Inner _inner;
6062

61-
constexpr CalcValue()
62-
: CalcValue(T{}) {
63+
constexpr Calc()
64+
: Calc(T{}) {
6365
}
6466

65-
constexpr CalcValue(Meta::Convertible<T> auto val)
67+
constexpr Calc(Meta::Convertible<T> auto val)
6668
: _inner(Value{T{val}}) {
6769
}
6870

69-
constexpr CalcValue(Value val)
71+
constexpr Calc(Value val)
7072
: _inner(val) {
7173
}
7274

73-
constexpr CalcValue(CalcOp op, Value val)
75+
constexpr Calc(CalcOp op, Value val)
7476
: _inner(makeBox<Unary>(op, val)) {
7577
}
7678

77-
constexpr CalcValue(CalcOp op, Value lhs, Value rhs)
79+
constexpr Calc(CalcOp op, Value lhs, Value rhs)
7880
: _inner(makeBox<Binary>(op, lhs, rhs)) {
7981
}
8082

@@ -108,8 +110,8 @@ struct CalcValue {
108110
};
109111

110112
export template <typename T>
111-
struct ValueParser<CalcValue<T>> {
112-
static Res<CalcValue<T>> parse(Cursor<Css::Sst>& c) {
113+
struct ValueParser<Calc<T>> {
114+
static Res<Calc<T>> parse(Cursor<Css::Sst>& c) {
113115
if (c.ended())
114116
return Error::invalidData("unexpected end of input");
115117

@@ -123,13 +125,13 @@ struct ValueParser<CalcValue<T>> {
123125

124126
auto op = parseOp(content);
125127
if (not op)
126-
return Ok(CalcValue<T>{lhs});
128+
return Ok(Calc<T>{lhs});
127129

128130
if (content.peek() == Css::Token::WHITESPACE) {
129131
content.next();
130132
}
131133
auto rhs = try$(parseVal(content));
132-
return Ok(CalcValue<T>{op.unwrap(), lhs, rhs});
134+
return Ok(Calc<T>{op.unwrap(), lhs, rhs});
133135
}
134136
}
135137

@@ -161,7 +163,7 @@ struct ValueParser<CalcValue<T>> {
161163
return Error::invalidData("unexpected operator");
162164
}
163165

164-
static Res<typename CalcValue<T>::Value> parseVal(Cursor<Css::Sst>& c) {
166+
static Res<typename Calc<T>::Value> parseVal(Cursor<Css::Sst>& c) {
165167
if (c.ended())
166168
return Error::invalidData("unexpected end of input");
167169

src/vaev-engine/values/line-width.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export using LineWidth = Union<
2525
Keywords::Thin,
2626
Keywords::Medium,
2727
Keywords::Thick,
28-
CalcValue<Length>>;
28+
Calc<Length>>;
2929

3030
export template <>
3131
struct ValueParser<LineWidth> {
@@ -46,7 +46,7 @@ struct ValueParser<LineWidth> {
4646
return Ok(Keywords::THICK);
4747
}
4848

49-
return Ok(try$(parseValue<CalcValue<Length>>(c)));
49+
return Ok(try$(parseValue<Calc<Length>>(c)));
5050
}
5151
};
5252

src/vaev-engine/values/outline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Vaev {
1111
// https://drafts.csswg.org/css-ui/#outline
1212
export struct Outline {
1313
LineWidth width = Keywords::MEDIUM;
14-
CalcValue<Length> offset = 0_au;
14+
Calc<Length> offset = 0_au;
1515
Union<Keywords::Auto, Gfx::BorderStyle> style = Gfx::BorderStyle::NONE;
1616
Union<Keywords::Auto, Color> color = Keywords::AUTO;
1717

src/vaev-engine/values/percent.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ struct ValueParser<Percent> {
3232
}
3333
};
3434

35-
export template <typename T>
36-
using PercentOr = Union<Percent, T>;
37-
38-
export template <typename T>
39-
struct _Resolved<PercentOr<T>> {
40-
using Type = Resolved<T>;
41-
};
42-
4335
} // namespace Vaev
4436

4537
export template <>

0 commit comments

Comments
 (0)