docs
Loading...
Searching...
No Matches
CSSPropertyName.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5#pragma once
6#include <Ultralight/dom/detail/StyleNames.h>
7
8namespace ultralight {
9namespace dom {
10
11///
12/// A CSS property name checked when your code compiles (the type of dom::css).
13///
14/// An unknown name is a compile error. You'd normally write one as dom::css.
15///
16template <detail::FixedString Name>
18 static_assert(detail::IsKnownCSSProperty(detail::kCSSName<Name>),
19 "unknown CSS property name; check the spelling (custom properties start "
20 "with --)");
21
22 ///
23 /// Get the property's CSS name (null-terminated). A camelCase name comes back in CSS form
24 /// (eg, `background-color` for `backgroundColor`).
25 ///
26 static constexpr const char* name() { return detail::kCSSName<Name>.data(); }
27};
28
29///
30/// A CSS property name checked when your code compiles.
31///
32/// Use it where style access takes a property name, so a typo is a compile error instead of a
33/// write that silently does nothing:
34///
35/// ```
36/// el.style[dom::css<"background-color">] = "purple";
37/// el.style[dom::css<"backgroundColor">] = "purple"; // the same property
38/// el.style[dom::css<"--accent">] = "#ff3366";
39/// std::string size = dom::getComputedStyle(el)[dom::css<"font-size">];
40/// ```
41///
42/// Write a name in lowercase CSS form (`background-color`) or in the camelCase form JavaScript
43/// uses for it (`backgroundColor`, `cssFloat` for `float`). Prefixed legacy names (eg,
44/// `-webkit-border-radius` or `webkitBorderRadius`) work too, and any custom property name (`--`
45/// followed by at least one character) is accepted.
46///
47/// @note For a name you only know at run time, pass a string instead (eg,
48/// `el.style["background-color"]`). An unknown name then does nothing.
49///
50template <detail::FixedString Name>
51inline constexpr CSSPropertyName<Name> css {};
52
53} // namespace dom
54} // namespace ultralight
Direct C++ access to modify page elements and handle events.
constexpr CSSPropertyName< Name > css
A CSS property name checked when your code compiles.
Definition CSSPropertyName.h:51
Root namespace for every public Ultralight type, function, and enumeration.
A CSS property name checked when your code compiles (the type of dom::css).
Definition CSSPropertyName.h:17
static constexpr const char * name()
Get the property's CSS name (null-terminated).
Definition CSSPropertyName.h:26