Holds a CSS property, which has a name and value, and integrates with inheritance to allow cascading values using the CSS model with specificity.
More...
#include "donner/svg/properties/Property.h"
|
|
using | Type = T |
| | Type of the property value.
|
|
| | Property (std::string_view name, GetInitialFn< T > getInitialFn=[]() -> std::optional< T > { return std::nullopt;}) |
| | Property constructor, which is initially unset.
|
| std::optional< T > | get () const |
| | Get the property value, without considering inheritance.
|
| T | getRequired () const |
| | Gets the value of the property, requiring that the value is not std::nullopt.
|
| const T & | getRequiredRef () const |
| | Gets a const-ref to the value, for accessing complex types without copying.
|
| void | set (std::optional< T > newValue, css::Specificity newSpecificity) |
| | Set the property to a new value at the given specificity.
|
| void | set (PropertyState newState, css::Specificity newSpecificity) |
| | Unset the current value and set the property to a specific state.
|
| void | substitute (std::optional< T > newValue) |
| | Replace the current property's value with a new value at the current specificity.
|
|
void | clear () |
| | Clear the current property's value.
|
| Property< T, kCascade > | inheritFrom (const Property< T, kCascade > &parent, PropertyInheritOptions options=PropertyInheritOptions::All) const |
| | Inherit the property from the parent element, if the parent has the property set at a higher specificity.
|
| bool | hasValue () const |
|
|
std::string_view | name |
| | Property name, such as "color".
|
|
std::optional< T > | value |
| | Property value, or std::nullopt if not set.
|
|
PropertyState | state = PropertyState::NotSet |
| | Current state of the property, such as set or inherited.
|
|
css::Specificity | specificity |
| | Specificity of the property, used for inheritance.
|
|
GetInitialFn< T > | getInitialFn |
| | Function which is called to get the initial value of the property.
|
template<typename T,
PropertyCascade kCascade = PropertyCascade::None>
struct donner::svg::Property< T, kCascade >
Holds a CSS property, which has a name and value, and integrates with inheritance to allow cascading values using the CSS model with specificity.
- Template Parameters
-
| T | The type of the property value. |
| kCascade | Determines how this property type participates in the cascade, to allow for specific property types to be excluded from inheritance. |
◆ Property()
Property constructor, which is initially unset.
- Parameters
-
| name | Name of the property, such as "color". |
| getInitialFn | Function to get the initial value of the property. |
◆ get()
Get the property value, without considering inheritance.
Returns the initial value if the property has not been set.
- Returns
- The value if it is set, or the initial value if it is not. Returns std::nullopt if the property is none.
◆ getRequired()
Gets the value of the property, requiring that the value is not std::nullopt.
- Returns
- The value.
◆ getRequiredRef()
Gets a const-ref to the value, for accessing complex types without copying.
Requires that hasValue() is true.
- Returns
- const T& Reference to the value.
◆ hasValue()
- Returns
- true if the property has any value set, including CSS built-in values.
◆ inheritFrom()
Inherit the property from the parent element, if the parent has the property set at a higher specificity.
Note that this typically inherits "backwards", taking a local property which may already have a value and then overriding it if the parent has a more specific one. This is not required, but doing so is more efficient since we don't need to keep setting the property as the child overrides each parent.
- Parameters
-
| parent | Parent property to inherit into this one. |
| options | Options to control how inheritance is performed, to conditionally disable inheritance. |
- Returns
- Property with the resolved value after inheritance.
◆ set() [1/2]
Unset the current value and set the property to a specific state.
- Parameters
-
| newState | New state to set. |
| newSpecificity | Specificity to use. |
◆ set() [2/2]
Set the property to a new value at the given specificity.
- Parameters
-
| newValue | Value to set, or std::nullopt to set to an empty value. |
| newSpecificity | Specificity to use. |
◆ substitute()
Replace the current property's value with a new value at the current specificity.
- Parameters
-
| newValue | Value to use to replace the existing one. |
The documentation for this struct was generated from the following file: