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

Holds global state of an SVG document, such as the root element, id-to-element mapping, and the document size. More...

#include "donner/svg/components/DocumentContext.h"

Public Member Functions

 DocumentContext (InternalCtorTag ctorTag, SVGDocument &document, Registry &registry)
 Internal constructor, creates a context on the given SVGDocument.
 
SVGDocumentdocument () const
 Get the SVGDocument instance.
 
Entity getEntityById (const RcString &id) const
 Get the entity with the given ID, using the internal id-to-entity mapping.
 

Public Attributes

std::optional< Vector2icanvasSize
 Current canvas size, if set. Equivalent to the window size, which controls how the SVG contents are rendered.
 
Entity rootEntity = entt::null
 Root entity of the document, which contains the "<svg>" element.
 

Friends

class ::donner::svg::SVGDocument
 

Detailed Description

Holds global state of an SVG document, such as the root element, id-to-element mapping, and the document size.

One instance of this class is created per SVG document.

Access the document context via the Registry::ctx API:

DocumentContext& context = registry.ctx().get<DocumentContext>();
Entity foo = context.getEntityById("foo");
Holds global state of an SVG document, such as the root element, id-to-element mapping,...
Definition DocumentContext.h:44
Entity getEntityById(const RcString &id) const
Get the entity with the given ID, using the internal id-to-entity mapping.
Definition DocumentContext.h:83
entt::entity Entity
Entity type for the SVG Registry, a std::uint32_t alias.
Definition Registry.h:16

Constructor & Destructor Documentation

◆ DocumentContext()

donner::svg::components::DocumentContext::DocumentContext ( InternalCtorTag ctorTag,
SVGDocument & document,
Registry & registry )
explicit

Internal constructor, creates a context on the given SVGDocument.

To use this class, access it via the Registry::ctx API.

DocumentContext& context = registry.ctx().get<DocumentContext>();
Parameters
ctorTagInternal tag to allow construction.
documentThe SVG document.
registryUnderlying registry for the document.

Member Function Documentation

◆ getEntityById()

Entity donner::svg::components::DocumentContext::getEntityById ( const RcString & id) const
inline

Get the entity with the given ID, using the internal id-to-entity mapping.

If multiple elements have the same id, the first one that was created will be returned.

Parameters
idID to find the entity for.

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