|
Ultralight C++ API 2.0.0
|
#include <AppCore/layout/Length.h>
A share of a container's free space distributed among siblings.
Sibling Panels and Containers divide whatever space remains along the container's axis after deducting fixed and percentage sizes, proportional to their declared flex factors.
You'll use Flex when computing a flex factor dynamically in code to pass to a Size field.
You can construct a Size from an explicit Flex factor or use its literal form:
In layout contexts, a bare number means logical pixels rather than a flex share, so the Flex() constructor is explicit. You can construct a Flex from a computed number using Flex() or Flex::Fr().
Layout fields that take a Length (such as min_size, max_size, gap, and padding) don't accept a flex share because a flex factor isn't a distance (see Length).
Static Public Member Functions | |
| static constexpr Flex | Fr (double factor) |
| Create a flex factor. | |
| 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). | |
| static bool | TryParse (const String &text, Flex &out) |
| Parse a runtime string with the same rules as the literal form. | |
Public Member Functions | |
| constexpr | Flex (double factor) |
| Create a flex factor from a computed number. | |
| template<size_t N> | |
| UL_CSS_CONSTEVAL | Flex (const char(&s)[N]) |
| Create a Flex from a CSS string literal, parsed and validated at compile time. | |
| constexpr double | value () const |
| Get the flex factor. | |
| 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 (see Length::invalid()). | |
Friends | |
| constexpr bool | operator== (const Flex &, const Flex &)=default |
|
inlineexplicitconstexpr |
Create a flex factor from a computed number.
The conversion is explicit because a bare number means logical px in layout contexts, never a flex factor.
| factor | The share of free space, relative to the sibling flex factors. |
|
inline |
Create a Flex from a CSS string literal, parsed and validated at compile time.
Only the fr form is accepted (eg, "2fr"). Any other format produces a compile error that explains the issue.
|
inlinestaticconstexpr |
Create a flex factor.
| factor | The share of free space, relative to the sibling flex factors. |
|
inlineconstexpr |
Whether or not this value came from a malformed literal on a compiler where literal validation degrades to a runtime flag (see Length::invalid()).
|
inlinestaticconstexpr |
Parse a runtime string with the same rules as the literal form (only the fr form is accepted).
| 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 flex factor.