docs
Loading...
Searching...
No Matches
CssValue

#include <Ultralight/dom/StyleValue.h>

Overview

Compile-time wrapper for CSS string literals assigned to element styles.

CssValue wraps CSS string literals assigned to inline styles, which the library parses when written. It checks the literal at compile time to catch mistyped numbers and units before your code runs.

String literals convert to CssValue on their own when assigned to style properties:

hud.style.width = "50%"; // a number: checked when you compile
hud.style.margin = "0 auto"; // other CSS: parsed when it's written
hud.style.fontSize = "12pt"; // a unit StyleValue doesn't have: parsed when it's written
// hud.style.width = "50pxx"; // a typo: compile error

Strings Built at Run Time

Style properties provide a separate overload for dynamic values, parsing the CSS text when it's written.

Wrap a char array filled at run time in std::string_view so the compiler doesn't treat the buffer as a string literal and fail to compile:

char text[16];
std::snprintf(text, sizeof(text), "%dpx", bar_width);
hud.style.width = std::string_view(text);
constexpr const char * text() const
Get the literal's text as written (null-terminated).
Definition StyleValue.h:383
Note
On older MSVC toolsets (before Visual Studio 2026), a mistyped literal causes a compile error only in a constant expression. In ordinary style writes, it's ignored when written.
See also
dom::StyleValue, dom::Element::style

Public Types

enum class  Kind : uint8_t { Passthrough = 0 , Numeric }
 How the literal is written– either parsed as a number at compile time (Numeric) or passed to the library's CSS parser as text (Passthrough). More...

Public Member Functions

template<size_t N>
UL_CSS_CONSTEVAL CssValue (const char(&s)[N])
 Capture a string literal and parse it at compile time.
constexpr Kind kind () const
 Get how the literal is written (see Kind).
constexpr double value () const
 Get the parsed number (only meaningful when kind() is Kind::Numeric).
constexpr StyleUnit unit () const
 Get the parsed unit (only meaningful when kind() is Kind::Numeric).
constexpr const char * text () const
 Get the literal's text as written (null-terminated).
constexpr size_t length () const
 Get the literal's length in bytes.

Member Enumeration Documentation

◆ Kind

enum class Kind : uint8_t
strong

How the literal is written– either parsed as a number at compile time (Numeric) or passed to the library's CSS parser as text (Passthrough).

Enumerator
Passthrough 
Numeric 

Constructor & Destructor Documentation

◆ CssValue()

template<size_t N>
UL_CSS_CONSTEVAL CssValue ( const char(&) s[N])
inline

Capture a string literal and parse it at compile time.

Parameters
sThe string literal.

Member Function Documentation

◆ kind()

Kind kind ( ) const
inlineconstexpr

Get how the literal is written (see Kind).

◆ length()

size_t length ( ) const
inlineconstexpr

Get the literal's length in bytes.

◆ text()

const char * text ( ) const
inlineconstexpr

Get the literal's text as written (null-terminated).

◆ unit()

StyleUnit unit ( ) const
inlineconstexpr

Get the parsed unit (only meaningful when kind() is Kind::Numeric).

◆ value()

double value ( ) const
inlineconstexpr

Get the parsed number (only meaningful when kind() is Kind::Numeric).


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