|
Ultralight C++ API 2.0.0
|
#include <AppCore/layout/Length.h>
A distance or size constraint in an AppCore layout.
You use Length to set container padding and gap, or to define minimum and maximum size constraints on panels and containers.
Numbers and CSS string literals convert to Length automatically, so you can write values directly in layout options.
This example sets a row's spacing and constrains a child panel:
A Length is measured in one of two units:
Length doesn't accept flex units– a flex factor isn't a distance, and passing "fr" or a Flex produces a compile error.
String literals and runtime strings follow the same rules as Size (see Size).
The default constructor creates an unset Length, which leaves the receiving field's default in effect:
Public Types | |
| enum class | Unit : uint8_t { Default = 0 , Px , Percent } |
| The unit of a Length. More... | |
Static Public Member Functions | |
| static constexpr Length | Px (double value) |
| Create a Length in logical pixels. | |
| static constexpr Length | Pct (double value) |
| Create a percentage Length. | |
| static constexpr bool | TryParse (const char *text, size_t length, Length &out) |
| Parse a runtime string with the same rules as the literal form. | |
| static bool | TryParse (const String &text, Length &out) |
| Parse a runtime string with the same rules as the literal form. | |
Public Member Functions | |
| constexpr | Length ()=default |
| Create an unset Length (the receiving field's default applies). | |
| constexpr | Length (double px) |
| Create a Length in logical pixels (implicit, a bare number means px). | |
| template<size_t N> | |
| UL_CSS_CONSTEVAL | Length (const char(&s)[N]) |
| Create a Length from a CSS string literal, parsed and validated at compile time. | |
| constexpr | Length (Flex)=delete |
| Length does not accept fr units– a flex factor is not a distance. | |
| constexpr double | value () const |
| Get the numeric value (px or percent points, per unit()). | |
| constexpr Unit | unit () const |
| Get the unit. | |
| constexpr bool | is_set () const |
| Whether or not this value was explicitly set (shorthand for unit() != Unit::Default). | |
| constexpr bool | invalid () const |
| Whether or not this value came from a malformed literal on a compiler where literal validation degrades to a runtime flag. | |
Friends | |
| constexpr bool | operator== (const Length &, const Length &)=default |
|
strong |
The unit of a Length.
| Enumerator | |
|---|---|
| Default | Unset: the receiving field's default applies. |
| Px | Logical pixels. |
| Percent | A percentage of the parent container's content box (inside its padding). |
|
constexprdefault |
Create an unset Length (the receiving field's default applies).
|
inlineconstexpr |
Create a Length in logical pixels (implicit, a bare number means px).
|
inline |
Create a Length from a CSS string literal, parsed and validated at compile time.
Accepted forms are a number with px, a number with %, and a bare number (logical pixels). Any other format produces a compile error that explains the issue.
|
constexprdelete |
|
inlineconstexpr |
Whether or not this value came from a malformed literal on a compiler where literal validation degrades to a runtime flag.
|
inlineconstexpr |
Whether or not this value was explicitly set (shorthand for unit() != Unit::Default).
|
inlinestaticconstexpr |
Create a percentage Length.
| value | The percentage, in percent points (50 means 50%). |
|
inlinestaticconstexpr |
Create a Length in logical pixels.
| value | The distance, in logical pixels. |
|
inlinestaticconstexpr |
Parse a runtime string with the same rules as the literal form.
| text | UTF-8 text to parse. |
| length | Byte length of text. |
| out | Receives the parsed value on success (left unchanged on failure). |
Parse a runtime string with the same rules as the literal form.
| text | The text to parse. |
| out | Receives the parsed value on success (left unchanged on failure). |
|
inlineconstexpr |
Get the unit.
Unit::Default means unset (the field's default applies).
|
inlineconstexpr |
Get the numeric value (px or percent points, per unit()).
Zero when unset.