7#include <Ultralight/detail/Css.h>
65 enum class Unit : uint8_t {
90 UL_CSS_CONSTEVAL
Length(
const char (&s)[N]) {
91 const detail::TrackValue t = detail::ResolveTrack(s, N - 1,
false);
92 if (t.status != detail::CssStatus::Ok) {
93 if (std::is_constant_evaluated())
94 detail::RaiseCssError(t.status);
133 const detail::TrackValue t = detail::ResolveTrack(text, length,
false);
134 if (t.status != detail::CssStatus::Ok)
157 constexpr double value()
const {
return value_; }
176 constexpr bool invalid()
const {
return invalid_; }
185 bool invalid_ =
false;
224 constexpr explicit Flex(
double factor) : value_(factor) {}
233 UL_CSS_CONSTEVAL
Flex(
const char (&s)[N]) {
234 const detail::CssNumber num = detail::ParseCssNumber(s, N - 1);
235 const detail::CssStatus status
236 = (num.status != detail::CssStatus::Ok)
238 : (num.unit == detail::CssUnit::Fr ? detail::CssStatus::Ok
239 : detail::CssStatus::ExpectedFr);
240 if (status != detail::CssStatus::Ok) {
241 if (std::is_constant_evaluated())
242 detail::RaiseCssError(status);
254 static constexpr Flex Fr(
double factor) {
return Flex(factor); }
268 static constexpr bool TryParse(
const char* text,
size_t length,
Flex& out) {
269 const detail::CssNumber num = detail::ParseCssNumber(text, length);
270 if (num.status != detail::CssStatus::Ok || num.unit != detail::CssUnit::Fr)
272 out =
Flex(num.value);
293 constexpr double value()
const {
return value_; }
299 constexpr bool invalid()
const {
return invalid_; }
305 bool invalid_ =
false;
397 : value_(length.
value()),
417 UL_CSS_CONSTEVAL
Size(
const char (&s)[N]) {
418 const detail::TrackValue t = detail::ResolveTrack(s, N - 1,
true);
419 if (t.status != detail::CssStatus::Ok) {
420 if (std::is_constant_evaluated())
421 detail::RaiseCssError(t.status);
461 static constexpr bool TryParse(
const char* text,
size_t length,
Size& out) {
462 const detail::TrackValue t = detail::ResolveTrack(text, length,
true);
463 if (t.status != detail::CssStatus::Ok)
488 constexpr double value()
const {
return value_; }
504 constexpr bool invalid()
const {
return invalid_; }
513 bool invalid_ =
false;
A share of a container's free space distributed among siblings.
Definition Length.h:214
static constexpr Flex Fr(double factor)
Create a flex factor.
Definition Length.h:254
constexpr Flex(double factor)
Create a flex factor from a computed number.
Definition Length.h:224
constexpr double value() const
Get the flex factor.
Definition Length.h:293
static constexpr bool TryParse(const char *text, size_t length, Flex &out)
Parse a runtime string with the same rules as the literal form (only the fr form is accepted).
Definition Length.h:268
static bool TryParse(const String &text, Flex &out)
Parse a runtime string with the same rules as the literal form.
Definition Length.h:285
UL_CSS_CONSTEVAL Flex(const char(&s)[N])
Create a Flex from a CSS string literal, parsed and validated at compile time.
Definition Length.h:233
constexpr bool invalid() const
Whether or not this value came from a malformed literal on a compiler where literal validation degrad...
Definition Length.h:299
friend constexpr bool operator==(const Flex &, const Flex &)=default
A distance or size constraint in an AppCore layout.
Definition Length.h:60
Unit
The unit of a Length.
Definition Length.h:65
@ Default
Unset: the receiving field's default applies.
Definition Length.h:66
@ Percent
A percentage of the parent container's content box (inside its padding).
Definition Length.h:68
@ Px
Logical pixels.
Definition Length.h:67
constexpr Length()=default
Create an unset Length (the receiving field's default applies).
static constexpr Length Px(double value)
Create a Length in logical pixels.
Definition Length.h:112
UL_CSS_CONSTEVAL Length(const char(&s)[N])
Create a Length from a CSS string literal, parsed and validated at compile time.
Definition Length.h:90
constexpr Length(double px)
Create a Length in logical pixels (implicit, a bare number means px).
Definition Length.h:79
constexpr double value() const
Get the numeric value (px or percent points, per unit()).
Definition Length.h:157
static bool TryParse(const String &text, Length &out)
Parse a runtime string with the same rules as the literal form.
Definition Length.h:149
static constexpr Length Pct(double value)
Create a percentage Length.
Definition Length.h:119
static constexpr bool TryParse(const char *text, size_t length, Length &out)
Parse a runtime string with the same rules as the literal form.
Definition Length.h:132
constexpr Length(Flex)=delete
Length does not accept fr units– a flex factor is not a distance.
constexpr bool invalid() const
Whether or not this value came from a malformed literal on a compiler where literal validation degrad...
Definition Length.h:176
constexpr bool is_set() const
Whether or not this value was explicitly set (shorthand for unit() != Unit::Default).
Definition Length.h:167
friend constexpr bool operator==(const Length &, const Length &)=default
constexpr Unit unit() const
Get the unit.
Definition Length.h:162
constexpr Size()=default
Create an unset Size (the receiving field's default applies).
Unit
The unit of a Size.
Definition Length.h:376
@ Default
Unset: the receiving field's default applies.
Definition Length.h:377
@ Percent
A percentage of the container's free space along the axis.
Definition Length.h:379
@ Px
Logical pixels.
Definition Length.h:378
@ Fr
A flex factor (share of the remaining free space).
Definition Length.h:380
constexpr double value() const
Get the numeric value (px, percent points, or flex factor, per unit()).
Definition Length.h:488
static constexpr bool TryParse(const char *text, size_t length, Size &out)
Parse a runtime string with the same rules as the literal form.
Definition Length.h:461
static bool TryParse(const String &text, Size &out)
Parse a runtime string with the same rules as the literal form.
Definition Length.h:480
friend constexpr bool operator==(const Size &, const Size &)=default
constexpr Size(Length length)
Create a Size from a Length (implicit, px stays px and percent stays percent).
Definition Length.h:396
static constexpr Size Px(double value)
Create a Size in logical pixels.
Definition Length.h:434
static constexpr Size Pct(double value)
Create a percent-of-free-space Size.
Definition Length.h:441
constexpr bool invalid() const
Whether or not this value came from a malformed literal on a compiler where literal validation degrad...
Definition Length.h:504
constexpr bool is_set() const
Whether or not this value was explicitly set (shorthand for unit() != Unit::Default).
Definition Length.h:498
static constexpr Size Fr(double value)
Create a flex-factor Size.
Definition Length.h:448
constexpr Size(double px)
Create a Size in logical pixels (implicit, a bare number means px).
Definition Length.h:391
UL_CSS_CONSTEVAL Size(const char(&s)[N])
Create a Size from a CSS string literal, parsed and validated at compile time.
Definition Length.h:417
constexpr Size(Flex flex)
Create a Size from a flex factor (implicit).
Definition Length.h:406
constexpr Unit unit() const
Get the unit.
Definition Length.h:493
A null-terminated UTF-8 string container.
Definition String8.h:17
char * data()
Get raw UTF-8 data.
Definition String8.h:53
size_t length() const
Get length in bytes (not including null terminator).
Definition String8.h:59
Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
Definition String.h:31
String8 & utf8()
Get native UTF-8 string.
Definition String.h:109
Root namespace for every public Ultralight type, function, and enumeration.
@ Default
The platform's usual corners for this kind of window.
Definition Window.h:138