New CSS value system#196
Conversation
| // FIXME: Remove | ||
| export constexpr Au THIN_VALUE = 1_au; | ||
| export constexpr Au MEDIUM_VALUE = 3_au; | ||
| export constexpr Au THICK_VALUE = 5_au; |
| // 6. MARK: Distance Units: the <length> type | ||
| // https://drafts.csswg.org/css-values/#lengths | ||
|
|
||
| // export using Px = Distinct<f64, struct _PxTag>; |
| Px snapped() { | ||
| // 1. Assert: len is non-negative. | ||
| if (value() <= 0.0f) { | ||
| panic("border snapping negative length"); | ||
| } | ||
|
|
||
| // 2. If len is an integer number of device pixels, do nothing. | ||
| if (Math::abs(value() - Math::round(value())) < Limits<f32>::EPSILON) { | ||
| return Px(Math::round(value())); | ||
| } | ||
|
|
||
| // 3. If len is greater than zero, but less than 1 device pixel, round len up to 1 device pixel. | ||
| if (value() <= 1.0f) { | ||
| return Px(1.0f); | ||
| } | ||
|
|
||
| // 4. If len is greater than 1 device pixel, round it down to the nearest integer number of device pixels. | ||
| return Px(Math::floor(value())); | ||
| } |
There was a problem hiding this comment.
- Missing const
- Name is also too generic, should be something like
snappedAsBorderWidthor something. - Good that you are doing that at value time but the layout code that did it too wasn't removed.
There was a problem hiding this comment.
Fixed the const and the naming.
I didn't see the snapping code in the layout, the length visitor of line-width only calls resolve(length)
| // FIXME: | ||
| // // https://drafts.csswg.org/mediaqueries/#typedef-mq-boolean | ||
| // export template <> | ||
| // struct _Computed<bool> : IdentityComputed<bool> {}; |
| auto operator==(Ratio const& other) const { | ||
| return Math::epsilonEq(num / deno, other.num / other.deno); | ||
| } |
There was a problem hiding this comment.
Is epsilonEq really needed here ? Also not sure it's the right sema for operator==()
There was a problem hiding this comment.
I went back to IEEE semantics since it doesn't make sense to compare aspect ratios by equality anyways.
| // FIXME: Refactor during calc refactor to look something like this: | ||
| // LengthPercentage = Length | Percent | Calc |
There was a problem hiding this comment.
Not just length you can have percentage of other stuff ;)
There was a problem hiding this comment.
I clarified the comment a bit
| export template <StrLit K> | ||
| struct ValueParser<Keyword<K>> { | ||
| struct ValueTraits<Keyword<K>> { | ||
| // FIXME: Plz remove |
There was a problem hiding this comment.
Not sure what this is trying to say
There was a problem hiding this comment.
At first I didn't want default value traits on keywords (identity computed value etc..) but I changed my mind so I removed the comment.
| .col = valueFromComputed<Gap>(computed.col) | ||
| }; | ||
| } | ||
| }; |
There was a problem hiding this comment.
It's just a computed value property group, it doesn't make sens to have all the value boilerplate, the following should be fine.
export struct GapProps {
Computed<Gap> row = Keywords::NORMAL;
Computed<Gap> col = Keywords::NORMAL;
void repr(Io::Emit& e) const {
e("(gaps {} {})", row, col);
}
};| template <> | ||
| struct ValueTraits<Keywords::Auto> : DefaultValueTraits<Keywords::Auto> { | ||
| static Res<Keywords::Auto> parse(Cursor<Css::Sst>& c) { | ||
| if (c.ended()) | ||
| return Error::invalidData("unexpected end of input"); | ||
|
|
||
| if (c->token == Css::Token::ident("auto")) { | ||
| c.next(); | ||
| return Ok(Keywords::Auto{}); | ||
| } | ||
|
|
||
| return Error::invalidData("expected keyword"); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Can't this use just the normal keyword parsing infra?
0eefb5b to
7478089
Compare
No description provided.