docs
Loading...
Searching...
No Matches
Flex

#include <AppCore/layout/Length.h>

Overview

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:

Size wide = Flex(2); // twice the share of a 1fr sibling
Size same = "2fr"; // the literal form
constexpr Flex(double factor)
Create a flex factor from a computed number.
Definition Length.h:224
Fixed, percentage, and flexible sizes for panels and containers.
Definition Length.h:371

Distinguishing Shares from Distances

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).

See also
Size, 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

Constructor & Destructor Documentation

◆ Flex() [1/2]

Flex ( double factor)
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.

Parameters
factorThe share of free space, relative to the sibling flex factors.

◆ Flex() [2/2]

template<size_t N>
UL_CSS_CONSTEVAL Flex ( const char(&) s[N])
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.

Member Function Documentation

◆ Fr()

constexpr Flex Fr ( double factor)
inlinestaticconstexpr

Create a flex factor.

Parameters
factorThe share of free space, relative to the sibling flex factors.

◆ invalid()

bool invalid ( ) const
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()).

◆ TryParse() [1/2]

constexpr bool TryParse ( const char * text,
size_t length,
Flex & out )
inlinestaticconstexpr

Parse a runtime string with the same rules as the literal form (only the fr form is accepted).

Parameters
textUTF-8 text to parse.
lengthByte length of text.
outReceives the parsed value on success (left unchanged on failure).
Returns
Returns whether or not the text parsed as a valid Flex.

◆ TryParse() [2/2]

bool TryParse ( const String & text,
Flex & out )
inlinestatic

Parse a runtime string with the same rules as the literal form.

Parameters
textThe text to parse.
outReceives the parsed value on success (left unchanged on failure).
Returns
Returns whether or not the text parsed as a valid Flex.

◆ value()

double value ( ) const
inlineconstexpr

Get the flex factor.

◆ operator==

bool operator== ( const Flex & ,
const Flex &  )
friend

The documentation for this class was generated from the following file: