Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::svg::SVGRectElement Class Reference

DOM object for the "<rect>" element. More...

#include "donner/svg/SVGRectElement.h"

Inheritance diagram for donner::svg::SVGRectElement:
[legend]
Collaboration diagram for donner::svg::SVGRectElement:
[legend]

Public Member Functions

void setX (Lengthd value)
 Set the top-left X coordinate.
 
void setY (Lengthd value)
 Set the top-left Y coordinate.
 
void setWidth (Lengthd value)
 Set the width dimension.
 
void setHeight (Lengthd value)
 Set the height dimension.
 
void setRx (std::optional< Lengthd > value)
 Set the horizontal radius, along the X axis, for rounded corners.
 
void setRy (std::optional< Lengthd > value)
 Set the vertical radius, along the Y axis, for rounded corners.
 
Lengthd x () const
 Get the top-left X coordinate.
 
Lengthd y () const
 Get the top-left Y coordinate.
 
Lengthd width () const
 Get the width dimension.
 
Lengthd height () const
 Get the height dimension.
 
std::optional< Lengthdrx () const
 Get the horizontal radius, along the X axis, for rounded corners.
 
std::optional< Lengthdry () const
 Get the vertical radius, along the Y axis, for rounded corners.
 
Lengthd computedX () const
 Get the computed top-left X coordinate.
 
Lengthd computedY () const
 Get the computed top-left Y coordinate.
 
Lengthd computedWidth () const
 Get the computed width dimension.
 
Lengthd computedHeight () const
 Get the computed height dimension.
 
Lengthd computedRx () const
 Get the computed horizontal radius, along the X axis, for rounded corners.
 
Lengthd computedRy () const
 Get the computed vertical radius, along the Y axis, for rounded corners.
 
std::optional< PathSplinecomputedSpline () const
 Get the computed path of this rectangle, including rounded corners (if any).
 
- Public Member Functions inherited from donner::svg::SVGGeometryElement
double computedPathLength () const
 Get the length of the path in user units. To override this value for stroke-dasharray and other path-offset-relative values, use setPathLength.
 
std::optional< double > pathLength () const
 Get the path length override, if set. To get the computed path length, use computedPathLength().
 
void setPathLength (std::optional< double > value)
 Set the path length override.
 
std::optional< PathSplinecomputedSpline () const
 Get the path spline, computed by converting this shape's path to a spline.
 
std::optional< BoxdworldBounds () const
 Get the bounding box of the element, in world coordinates.
 
- Public Member Functions inherited from donner::svg::SVGGraphicsElement
Transformd transform () const
 Get the 2d transformation for this element, element-from-parent.
 
void setTransform (const Transformd &transform)
 Set the 2d transformation for this element, element-from-parent. This is a no-op if the transform is identity.
 
Transformd elementFromWorld () const
 Get the absolute element-from-world transform for this element.
 
- Public Member Functions inherited from donner::svg::SVGElement
 SVGElement (const SVGElement &other)
 Create another reference to the same SVGElement.
 
 SVGElement (SVGElement &&other) noexcept
 Move constructor.
 
 ~SVGElement () noexcept=default
 Destructor.
 
SVGElementoperator= (const SVGElement &other)
 Create another reference to the same SVGElement.
 
SVGElementoperator= (SVGElement &&other) noexcept
 Move assignment operator.
 
ElementType type () const
 Get the ElementType for known XML element types.
 
XMLQualifiedNameRef tagName () const
 Get the XML tag name string for this element.
 
bool isKnownType () const
 Returns true if this is a known element type, returns false if this is an SVGUnknownElement.
 
Entity entity () const
 Get the underlying Entity, for advanced use-cases that require direct access to the ECS.
 
RcString id () const
 Get the element id, the value of the "id" attribute.
 
void setId (std::string_view id)
 Set the element id, the value of the "id" attribute.
 
RcString className () const
 Get the element class name, the value of the "class" attribute.
 
void setClassName (std::string_view name)
 Set the element class name, the value of the "class" attribute.
 
void setStyle (std::string_view style)
 Set the element style, the value of the "style" attribute.
 
base::parser::ParseResult< bool > trySetPresentationAttribute (std::string_view name, std::string_view value)
 Set the value of a presentation attribute, such as "fill" or "stroke".
 
bool hasAttribute (const XMLQualifiedNameRef &name) const
 Returns true if the element has an attribute with the given name.
 
std::optional< RcStringgetAttribute (const XMLQualifiedNameRef &name) const
 Get the value of an attribute, if it exists.
 
SmallVector< XMLQualifiedNameRef, 1 > findMatchingAttributes (const XMLQualifiedNameRef &matcher) const
 Find attributes matching the given name matcher.
 
void setAttribute (const XMLQualifiedNameRef &name, std::string_view value)
 Set the value of a generic XML attribute, which may be either a presentation attribute or custom user-provided attribute.
 
void removeAttribute (const XMLQualifiedNameRef &name)
 Remove an attribute, which may be either a presentation attribute or custom user-provided attribute.
 
SVGDocumentownerDocument ()
 Get the SVGDocument that holds this element.
 
std::optional< SVGElementparentElement () const
 Get this element's parent, if it exists.
 
std::optional< SVGElementfirstChild () const
 Get the first child of this element, if it exists.
 
std::optional< SVGElementlastChild () const
 Get the last child of this element, if it exists.
 
std::optional< SVGElementpreviousSibling () const
 Get the previous sibling of this element, if it exists.
 
std::optional< SVGElementnextSibling () const
 Get the next sibling of this element, if it exists.
 
SVGElement insertBefore (SVGElement newNode, std::optional< SVGElement > referenceNode)
 Insert newNode as a child, before referenceNode.
 
SVGElement appendChild (SVGElement child)
 Append child as a child of the current node.
 
SVGElement replaceChild (SVGElement newChild, SVGElement oldChild)
 Replace oldChild with newChild in the tree, removing oldChild and inserting newChild in its place.
 
SVGElement removeChild (SVGElement child)
 Remove child from this node.
 
void remove ()
 Remove this node from its parent, if it has one.
 
bool operator== (const SVGElement &other) const
 Returns true if the two SVGElement handles reference the same underlying document.
 
bool operator!= (const SVGElement &other) const
 Returns true if the two SVGElement handles reference the same underlying document.
 
template<typename Derived >
bool isa () const
 Return true if this element "is a" instance of type, if it be cast to a specific type with cast.
 
template<typename Derived >
Derived cast ()
 Cast this element to its derived type.
 
template<typename Derived >
Derived cast () const
 Cast this element to its derived type (const version).
 
template<typename Derived >
std::optional< Derived > tryCast ()
 Cast this element to its derived type, if possible.
 
template<typename Derived >
std::optional< const Derived > tryCast () const
 Cast this element to its derived type, if possible.
 
std::optional< SVGElementquerySelector (std::string_view selector)
 Find the first element in the tree that matches the given CSS selector.
 
const PropertyRegistrygetComputedStyle () const
 Get the computed CSS style of this element, after the CSS cascade.
 

Static Public Member Functions

static SVGRectElement Create (SVGDocument &document)
 Create a new "<rect>" element.
 
- Static Public Member Functions inherited from donner::svg::SVGGeometryElement
static constexpr bool IsBaseOf (ElementType type)
 Returns true if the given element type can be cast to SVGGeometryElement.
 

Static Public Attributes

static constexpr ElementType Type = ElementType::Rect
 Element type.
 
static constexpr std::string_view Tag {"rect"}
 XML tag name, "<rect>".
 

Additional Inherited Members

- Protected Member Functions inherited from donner::svg::SVGGeometryElement
 SVGGeometryElement (EntityHandle handle)
 Internal constructor to create an SVGGeometryElement from an EntityHandle.
 
void invalidate ()
 Invalidates the computed shape for this element, should be called when the shape geometry changes.
 
- Protected Member Functions inherited from donner::svg::SVGGraphicsElement
 SVGGraphicsElement (EntityHandle handle)
 Inheriting constructor to be called by derived classes. SVGGraphicsElement cannot be instantiated directly.
 
- Protected Member Functions inherited from donner::svg::SVGElement
 SVGElement (EntityHandle handle)
 Internal constructor to create an SVGElement from an EntityHandle.
 
Registryregistry () const
 Get the underlying ECS Registry, which holds all data for the document, for advanced use.
 
EntityHandle toHandle (Entity entity) const
 Convert an Entity to an EntityHandle, for advanced use.
 
- Static Protected Member Functions inherited from donner::svg::SVGElement
static EntityHandle CreateEntity (Registry &registry, const XMLQualifiedNameRef &tagName, ElementType Type)
 Create a new Entity of the given type.
 
- Protected Attributes inherited from donner::svg::SVGElement
EntityHandle handle_
 The underlying ECS Entity for this element, which holds all data.
 

Detailed Description

DOM object for the "<rect>" element.

Use the x, y, width and height attributes to specify the rectangle's position and size, and optionally round the corners with the rx and ry attributes.

<rect x="10" y="50" width="280" height="200" fill="none" stroke="black" />

x,y width height

<rect x="10" y="50" width="280" height="200" rx="50" ry="40" fill="none" stroke="black" />

rx ry

Member Function Documentation

◆ computedHeight()

Lengthd donner::svg::SVGRectElement::computedHeight ( ) const

Get the computed height dimension.

Returns
Dimension value.

◆ computedRx()

Lengthd donner::svg::SVGRectElement::computedRx ( ) const

Get the computed horizontal radius, along the X axis, for rounded corners.

Returns
Corner radius value.

◆ computedRy()

Lengthd donner::svg::SVGRectElement::computedRy ( ) const

Get the computed vertical radius, along the Y axis, for rounded corners.

Returns
Corner radius value.

◆ computedSpline()

std::optional< PathSpline > donner::svg::SVGRectElement::computedSpline ( ) const

Get the computed path of this rectangle, including rounded corners (if any).

Returns
Computed path, or std::nullopt if the element is invalid (e.g. if the width or height are zero).

◆ computedWidth()

Lengthd donner::svg::SVGRectElement::computedWidth ( ) const

Get the computed width dimension.

Returns
Dimension value.

◆ computedX()

Lengthd donner::svg::SVGRectElement::computedX ( ) const

Get the computed top-left X coordinate.

Returns
Coordinate value.

◆ computedY()

Lengthd donner::svg::SVGRectElement::computedY ( ) const

Get the computed top-left Y coordinate.

Returns
Coordinate value.

◆ Create()

SVGRectElement donner::svg::SVGRectElement::Create ( SVGDocument & document)
static

Create a new "<rect>" element.

Parameters
documentContaining document.

◆ height()

Lengthd donner::svg::SVGRectElement::height ( ) const

Get the height dimension.

Returns
Dimension value.

◆ rx()

std::optional< Lengthd > donner::svg::SVGRectElement::rx ( ) const

Get the horizontal radius, along the X axis, for rounded corners.

Returns
Corner radius value, or std::nullopt for auto. To get the computed value, use computedRx().

◆ ry()

std::optional< Lengthd > donner::svg::SVGRectElement::ry ( ) const

Get the vertical radius, along the Y axis, for rounded corners.

Returns
Corner radius value, or std::nullopt for auto. To get the computed value, use computedRy().

◆ setHeight()

void donner::svg::SVGRectElement::setHeight ( Lengthd value)

Set the height dimension.

Parameters
valueDimension value.

◆ setRx()

void donner::svg::SVGRectElement::setRx ( std::optional< Lengthd > value)

Set the horizontal radius, along the X axis, for rounded corners.

Parameters
valueCorner radius value, or std::nullopt for auto, to use the same value as ry (see "auto" on rx/ry).

◆ setRy()

void donner::svg::SVGRectElement::setRy ( std::optional< Lengthd > value)

Set the vertical radius, along the Y axis, for rounded corners.

Parameters
valueCorner radius value, or std::nullopt for auto, to use the same value as rx (see "auto" on rx/ry).

◆ setWidth()

void donner::svg::SVGRectElement::setWidth ( Lengthd value)

Set the width dimension.

Parameters
valueDimension value.

◆ setX()

void donner::svg::SVGRectElement::setX ( Lengthd value)

Set the top-left X coordinate.

Parameters
valueCoordinate value.

◆ setY()

void donner::svg::SVGRectElement::setY ( Lengthd value)

Set the top-left Y coordinate.

Parameters
valueCoordinate value.

◆ width()

Lengthd donner::svg::SVGRectElement::width ( ) const

Get the width dimension.

Returns
Dimension value.

◆ x()

Lengthd donner::svg::SVGRectElement::x ( ) const

Get the top-left X coordinate.

Returns
Coordinate value.

◆ y()

Lengthd donner::svg::SVGRectElement::y ( ) const

Get the top-left Y coordinate.

Returns
Coordinate value.

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