ofxDOM
A DOM Level 3 Events implementation for openFrameworks.
ofx::DOM::Element Class Reference

A class representing a DOM Element. More...

#include <Element.h>

Inheritance diagram for ofx::DOM::Element:
ofx::DOM::EventTarget< Element > ofx::DOM::Document

Public Member Functions

 Element (float x, float y, float width, float height)
 Construct a new Element with the given parameters. More...
 
 Element (const std::string &id, float x, float y, float width, float height)
 Construct a new Element with the given parameters. More...
 
virtual ~Element ()
 Destroy the Element.
 
template<typename ElementType >
ElementType * addChild (std::unique_ptr< ElementType > element)
 Take ownership of the passed std::unique_ptr<Element>. More...
 
template<typename ElementType , typename... Args>
ElementType * addChild (Args &&...args)
 Create a child using a templated Element type. More...
 
std::unique_ptr< ElementremoveChild (Element *element)
 Release ownership of a child Element. More...
 
void moveToFront ()
 Move this Element in front of all of its siblings.
 
void moveForward ()
 Move this Element in front of its next sibling.
 
void moveToBack ()
 Move this Element in back of all of its siblings.
 
void moveBackward ()
 Move this Element in back of its next sibling.
 
void moveChildToIndex (Element *element, std::size_t index)
 Move the given Element to the the given index. More...
 
void moveChildToFront (Element *element)
 Move the given Element in front of all of its siblings. More...
 
void moveChildForward (Element *element)
 Move the given Element in front of its next sibling. More...
 
void moveChildToBack (Element *element)
 Move the given Element in back of all of its siblings. More...
 
void moveChildBackward (Element *element)
 Move the given Element in back of its next sibling. More...
 
bool isChild (Element *element) const
 Determine if the given Element is a child of this Element. More...
 
bool isSibling (Element *element) const
 Determine if the given Element is a sibling of this Element. More...
 
std::size_t numSiblings () const
 
std::vector< Element * > siblings ()
 
template<typename ElementType >
std::vector< ElementType * > siblings ()
 Get a list of siblings of a given Element or Element subclass. More...
 
bool isParent (Element *element) const
 Determine if the given Element is the parent of this Element. More...
 
std::size_t numChildren () const
 
std::vector< Element * > children ()
 Get a list of pointers to the child elements. More...
 
template<typename ElementType >
std::vector< ElementType * > children ()
 Get a list of pointers to the child elements. More...
 
bool hasParent () const
 Determine if this Element has a parent Element. More...
 
ElementfindFirstChildById (const std::string &id)
 Find this Element's first child by its id. More...
 
std::vector< Element * > findChildrenById (const std::string &id)
 Find all of this Element's matching the given id. More...
 
Elementparent ()
 Get a pointer to the parent. More...
 
const Elementparent () const
 Get a pointer to the parent. More...
 
Documentdocument ()
 Get a pointer to the parent Document. More...
 
const Documentdocument () const
 Get a pointer to the parent Document. More...
 
template<typename LayoutType , typename... Args>
LayoutType * createLayout (Args &&...args)
 Create a Layout using a templated Layout type. More...
 
template<typename LayoutType >
LayoutType * setLayout (std::unique_ptr< LayoutType > layout)
 Take ownership of the passed std::unique_ptr<Layout>. More...
 
std::unique_ptr< LayoutremoveLayout ()
 Release ownership of the Layout. More...
 
Layoutlayout ()
 Get a pointer to the associated Layout. More...
 
virtual bool hitTest (const Position &parentPosition) const
 Perform a hit test on the Element. More...
 
virtual bool childHitTest (const Position &localPosition) const
 Perform a hit test on a child Element. More...
 
Position localToScreen (const Position &localPosition) const
 Convert the local coordinates to screen coordinates. More...
 
Position screenToLocal (const Position &screenPosition) const
 Convert the screen coordinates to local coordinates. More...
 
Position parentToScreen (const Position &parentPosition) const
 Convert the parent coordinates to screen coordinates. More...
 
Position screenToParent (const Position &screenPosition) const
 Convert the screen coordinates to parent coordinates. More...
 
void setPosition (float x, float y)
 Set the position of the Element in its parent coordinates. More...
 
void setPosition (const Position &position)
 Set the position of the Element in its parent coordinates. More...
 
Position getPosition () const
 Get the position of the Element in its parent coordinates. More...
 
float getX () const
 Get the X position of the Element in its parent coordinates. More...
 
float getY () const
 Get the Y position of the Element in its parent coordinates. More...
 
Position getScreenPosition () const
 Get the Position of the Element in screen coordinates. More...
 
float getScreenX () const
 Get the X position of the Element in screen coordinates. More...
 
float getScreenY () const
 Get the Y position of the Element in screen coordinates. More...
 
void setSize (float width, float height)
 Set the size of the Element. More...
 
Size getSize () const
 Get the Size of the Element. More...
 
float getWidth () const
 Get the width of the Element. More...
 
float getHeight () const
 Get the height of the Element. More...
 
Geometry getGeometry () const
 Get the geometry of the Element in its parent coordinates. More...
 
void setGeometry (const Geometry &geometry)
 Set the geometry of the Element in its parent coordinates. More...
 
Geometry getChildGeometry () const
 Get the bounding box representing all child elements. More...
 
Geometry getTotalGeometry () const
 Get the bounding box representing the union of the child geometry and the element geometry. More...
 
std::string getId () const
 Get the id of this Element. More...
 
void setId (const std::string &id)
 Set the id of the Element. More...
 
bool hasAttribute (const std::string &name) const
 Determine of the Element has an attribute with the given name. More...
 
template<typename AnyType >
AnyType getAttribute (const std::string &key, bool inherit=false) const
 Get a named attribute via its key. More...
 
void setAttribute (const std::string &name, const Any &value)
 Set a value for a named attribute. More...
 
void clearAttribute (const std::string &name)
 Clear a named attribute. More...
 
void setPointerCapture (std::size_t id)
 Request that the parent Document capture the given pointer id. More...
 
void releasePointerCapture (std::size_t id)
 Release a captured pointer with the given id. More...
 
bool isEnabled () const
 
void setEnabled (bool enabled)
 Enable or disable this Element. More...
 
bool isHidden () const
 
void setHidden (bool hidden)
 Hide or show this Element. More...
 
bool isLocked () const
 
void setLocked (bool locked)
 Lock or unlock a this Element. More...
 
- Public Member Functions inherited from ofx::DOM::EventTarget< Element >
 EventTarget ()
 Create an EventTarget.
 
virtual ~EventTarget ()
 Destroy the EventTarget.
 
void addEventListener (EventType &event, void(ListenerClass::*listenerMethod)(const void *, ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP)
 
void addEventListener (EventType &event, void(ListenerClass::*listenerMethod)(ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP)
 
void addEventListener (EventType &event, bool(ListenerClass::*listenerMethod)(const void *, ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP)
 
void addEventListener (EventType &event, bool(ListenerClass::*listenerMethod)(ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP)
 
void removeEventListener (EventType &event, void(ListenerClass::*listenerMethod)(const void *, ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP)
 
void removeEventListener (EventType &event, void(ListenerClass::*listenerMethod)(ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP)
 
void removeEventListener (EventType &event, bool(ListenerClass::*listenerMethod)(const void *, ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP)
 
void removeEventListener (EventType &event, bool(ListenerClass::*listenerMethod)(ArgumentsType &), bool useCapture=false, int priority=OF_EVENT_ORDER_AFTER_APP)
 
bool dispatchEvent (EventType &event)
 Dispatch the given event. More...
 
bool handleEvent (EventArgsType &e)
 Handle the given event. More...
 
bool hasListenersForEventType (const std::string &type) const
 Determine if the EventTarget has listeners for an event. More...
 
bool isEventTypeRegistered (const std::string &type) const
 Determine if the EventTarget is registered to receive the type of events. More...
 
void registerEventType (const std::string &type, BaseDOMEvent *event)
 Register a new event type by name. More...
 
void unregisterEventType (const std::string &type)
 Unregister a new event type by name. More...
 
virtual void onSetup ()
 
virtual void onUpdate ()
 
virtual void onDraw () const
 
virtual void onExit ()
 

Protected Member Functions

void _setup (ofEventArgs &e)
 Setup method called by parent Element. More...
 
void _update (ofEventArgs &e)
 Update method called by parent Element. More...
 
void _draw (ofEventArgs &e)
 Draw method called by parent Element. More...
 
void _exit (ofEventArgs &e)
 Exit method called by parent Element. More...
 
ElementrecursiveHitTest (const Position &parentPosition)
 A recursive hit test to find a target element. More...
 
std::vector< std::unique_ptr< Element > >::iterator findChild (Element *element)
 Find a child by a raw Element pointer. More...
 
bool isPointerCaptured (std::size_t id) const
 Determine if a given pointer id is captured. More...
 
std::vector< CapturedPointer >::iterator findCapturedPointerById (std::size_t id)
 Find the given CapturePointer info by id. More...
 
std::vector< CapturedPointer >::const_iterator findCapturedPointerById (std::size_t id) const
 Find the given CapturePointer info by id. More...
 
std::vector< CapturedPointer > & capturedPointers ()
 Get a reference to the captured pointer vector. More...
 
const std::vector< CapturedPointer > & capturedPointers () const
 Get a reference to the captured pointer vector. More...
 
virtual void invalidateChildGeometry () const
 Called internally to invalidate the child geometry tree.
 
void setImplicitPointerCapture (bool implicitPointerCapture)
 Set if the pointer is implicitly captured on pointer down. More...
 
bool getImplicitPointerCapture () const
 Determine if pointer is automatically captured on pointer down. More...
 

Friends

class Layout
 The Layout class has access to all private variables.
 
class Document
 The Document class has access to all private variables.
 

Additional Inherited Members

- Public Attributes inherited from ofx::DOM::EventTarget< Element >
DOMEvent< PointerUIEventArgspointerOver
 
DOMEvent< PointerUIEventArgspointerEnter
 
DOMEvent< PointerUIEventArgspointerDown
 
DOMEvent< PointerUIEventArgspointerMove
 
DOMEvent< PointerUIEventArgspointerUp
 
DOMEvent< PointerUIEventArgspointerCancel
 
DOMEvent< PointerUIEventArgspointerOut
 
DOMEvent< PointerUIEventArgspointerLeave
 
DOMEvent< PointerUIEventArgspointerScroll
 
DOMEvent< PointerCaptureUIEventArgsgotPointerCapture
 
DOMEvent< PointerCaptureUIEventArgslostPointerCapture
 
DOMEvent< KeyboardUIEventArgskeyDown
 
DOMEvent< KeyboardUIEventArgskeyUp
 
DOMEvent< FocusEventArgsblur
 
DOMEvent< FocusEventArgsfocusIn
 
DOMEvent< FocusEventArgsfocus
 
DOMEvent< FocusEventArgsfocusOut
 
ofEvent< ElementEventArgsaddedTo
 
ofEvent< ElementEventArgsremovedFrom
 
ofEvent< ElementOrderEventArgsreordered
 
ofEvent< ElementEventArgssiblingAdded
 
ofEvent< ElementEventArgssiblingRemoved
 
ofEvent< ElementOrderEventArgssiblingReordered
 
ofEvent< ElementEventArgschildAdded
 
ofEvent< ElementEventArgschildRemoved
 
ofEvent< ElementOrderEventArgschildReordered
 
ofEvent< MoveEventArgsmove
 
ofEvent< ResizeEventArgsresize
 
ofEvent< AttributeEventArgsattributeSet
 
ofEvent< AttributeEventArgsattributeCleared
 
ofEvent< EnablerEventArgsenabled
 
ofEvent< EnablerEventArgslocked
 
ofEvent< EnablerEventArgshidden
 
- Protected Attributes inherited from ofx::DOM::EventTarget< Element >
std::unordered_map< std::string, BaseDOMEvent * > _eventRegistry
 

Detailed Description

A class representing a DOM Element.

There are several DOM coordiante systems with respect to an Element.

  1. Local Coordinates: The origin of the local coordiantes are at 0, 0 of the Element Geometry. The coordiantes of the local Geometry range from (0, 0)
  • the upper left corner to (width, height) - the lower right corner of the Element.
  1. Parent Coordinates: The (x, y) position of the Element geometry are in "Parent" Coordinates, meaning they are oriented with respect to the parent's Local Coordinates.
  2. Screen Coordinates: The screen coordinates are the coordinates (x, y) in terms of the global screen coordiantes where (0, 0) is the upper left corner of the screen / window, and (ofGetWidth(), ofGetHeight()) are the coordiantes of the lower right corner.

Constructor & Destructor Documentation

ofx::DOM::Element::Element ( float  x,
float  y,
float  width,
float  height 
)

Construct a new Element with the given parameters.

The Element will take the default id, an empty string.

Parameters
xthe X position of the Element in its parent coordinates.
ythe Y position of the Element in its parent coordinates.
widththe width of the Element.
heightthe height of the Element.
ofx::DOM::Element::Element ( const std::string &  id,
float  x,
float  y,
float  width,
float  height 
)

Construct a new Element with the given parameters.

Parameters
idThe id of the Element.
xthe X position of the Element in its parent coordinates.
ythe Y position of the Element in its parent coordinates.
widththe width of the Element.
heightthe height of the Element.

Member Function Documentation

void ofx::DOM::Element::_draw ( ofEventArgs &  e)
protected

Draw method called by parent Element.

Parameters
eThe event data.
void ofx::DOM::Element::_exit ( ofEventArgs &  e)
protected

Exit method called by parent Element.

Parameters
eThe event data.
void ofx::DOM::Element::_setup ( ofEventArgs &  e)
protected

Setup method called by parent Element.

Parameters
eThe event data.
void ofx::DOM::Element::_update ( ofEventArgs &  e)
protected

Update method called by parent Element.

Parameters
eThe event data.
template<typename ElementType >
ElementType * ofx::DOM::Element::addChild ( std::unique_ptr< ElementType >  element)

Take ownership of the passed std::unique_ptr<Element>.

This this is "sink" meaning that any child passed to this will be owned by this Node.

Parameters
elementthe rvalue reference to the child node.
Returns
A pointer to the added Element. The parent Element retains ownership of the pointer via a std::unique_ptr.
Template Parameters
ElementTypeThe Element Type.

Alert the node's siblings that they have a new sibling.

template<typename ElementType , typename... Args>
ElementType * ofx::DOM::Element::addChild ( Args &&...  args)

Create a child using a templated Element type.

To create a child Element you can use this method like:

ElementType* element = parentElement->addChild<ElementType>(arguments ...);

Template Parameters
ElementTypeThe subclass of Element that will be added.
ArgsThe variable constructor arguments for the ElementType.
Parameters
argsThe variable constructor arguments for the ElementType.
Returns
A pointer to the added Element. The parent Element retains ownership of the pointer via a std::unique_ptr.
Template Parameters
ElementTypeThe Element Type.
Argsthe ElementType constructor arguments.
std::vector< CapturedPointer > & ofx::DOM::Element::capturedPointers ( )
protected

Get a reference to the captured pointer vector.

Returns
a reference to all pointers captured by this Element.
const std::vector< CapturedPointer > & ofx::DOM::Element::capturedPointers ( ) const
protected

Get a reference to the captured pointer vector.

Returns
a reference to all pointers captured by this Element.
bool ofx::DOM::Element::childHitTest ( const Position &  localPosition) const
virtual

Perform a hit test on a child Element.

Parameters
localPositionThe Position to test in local coordinates.
Returns
true iff the local position is within the hit test region.
std::vector< Element * > ofx::DOM::Element::children ( )

Get a list of pointers to the child elements.

The parent Element retains ownership.

Returns
a list of pointers to child elements.
template<typename ElementType >
std::vector< ElementType * > ofx::DOM::Element::children ( )

Get a list of pointers to the child elements.

The parent Element retains ownership.

Returns
a list of pointers to child elements.
void ofx::DOM::Element::clearAttribute ( const std::string &  name)

Clear a named attribute.

Parameters
Thename of the attribute to clear.
template<typename LayoutType , typename... Args>
LayoutType * ofx::DOM::Element::createLayout ( Args &&...  args)

Create a Layout using a templated Layout type.

To create a Layout you can use this method like:

LayoutType* layout = parentElement->createLayout<LayoutType>(arguments ...);

Template Parameters
ElementTypeThe subclass of Element that will be added.
ArgsThe variable constructor arguments for the ElementType.
Parameters
argsThe variable constructor arguments for the ElementType.
Returns
A pointer to the added Element. The parent Element retains ownership of the pointer via a std::unique_ptr.
Template Parameters
ElementTypeThe Element Type.
Argsthe ElementType constructor arguments.
Document * ofx::DOM::Element::document ( )

Get a pointer to the parent Document.

Returns
a pointer to the parent Document, self if a Document or a nullptr.
const Document * ofx::DOM::Element::document ( ) const

Get a pointer to the parent Document.

Returns
a pointer to the parent Document, self if a Document or a nullptr.
std::vector< CapturedPointer >::iterator ofx::DOM::Element::findCapturedPointerById ( std::size_t  id)
protected

Find the given CapturePointer info by id.

Parameters
idThe pointer id to find.
Returns
An const iterator to the CapturedPointer info if found.
std::vector< CapturedPointer >::const_iterator ofx::DOM::Element::findCapturedPointerById ( std::size_t  id) const
protected

Find the given CapturePointer info by id.

Parameters
idThe pointer id to find.
Returns
An const iterator to the CapturedPointer info if found.
std::vector< std::unique_ptr< Element > >::iterator ofx::DOM::Element::findChild ( Element element)
protected

Find a child by a raw Element pointer.

Parameters
Thepointer to the child.
Returns
An iterator pointing to the matching Element or the end.
std::vector< Element * > ofx::DOM::Element::findChildrenById ( const std::string &  id)

Find all of this Element's matching the given id.

Parameters
idThe id of the child Elements to find.
Returns
a vector of pointers to child elements or an empty vector if none exist.
Element * ofx::DOM::Element::findFirstChildById ( const std::string &  id)

Find this Element's first child by its id.

Parameters
idThe id of the child Element to find.
Returns
a pointer to the first child or nullptr if no such child exists.
template<typename AnyType >
AnyType ofx::DOM::Element::getAttribute ( const std::string &  key,
bool  inherit = false 
) const

Get a named attribute via its key.

Users should check to see if the attribute exists using hasAttribute or catch the DOMException.

Exceptions
DOMExceptionif no such key.
Poco::BadCastExceptionif the types do not match.
Parameters
keyThe name of the attribute.
inheritTrue if the Element should query its ancestors for the attribute.
Returns
The value corresponding to the key, or throws an exception.
Geometry ofx::DOM::Element::getChildGeometry ( ) const

Get the bounding box representing all child elements.

Returns
the bounding box representing all child elements, or a rectangle of zero width and height at the origin if no children.
Geometry ofx::DOM::Element::getGeometry ( ) const

Get the geometry of the Element in its parent coordinates.

Returns
the Geometry of the Element in its parent coordinates.
float ofx::DOM::Element::getHeight ( ) const

Get the height of the Element.

Returns
The height of the Element.
std::string ofx::DOM::Element::getId ( ) const

Get the id of this Element.

The id is optional and an empty std::string by default.

Returns
the id of the Element.
bool ofx::DOM::Element::getImplicitPointerCapture ( ) const
protected

Determine if pointer is automatically captured on pointer down.

Returns
true iff implicit pointer capture is enabled.
Position ofx::DOM::Element::getPosition ( ) const

Get the position of the Element in its parent coordinates.

Local coordinates are defined with reference to the position of the box. The Position of this element will be in its parent's local coordinates.

Returns
The position in parent coordinates.
Position ofx::DOM::Element::getScreenPosition ( ) const

Get the Position of the Element in screen coordinates.

Returns
the Position of the Element in screen coordinates.
Todo:
Cache screen position w/ geometry.
float ofx::DOM::Element::getScreenX ( ) const

Get the X position of the Element in screen coordinates.

Returns
the X position of the Element in screen coordinates.
float ofx::DOM::Element::getScreenY ( ) const

Get the Y position of the Element in screen coordinates.

Returns
the Y position of the Element in screen coordinates.
Size ofx::DOM::Element::getSize ( ) const

Get the Size of the Element.

Returns
the Size of the Element.
Geometry ofx::DOM::Element::getTotalGeometry ( ) const

Get the bounding box representing the union of the child geometry and the element geometry.

Returns
the bounding box representing the union of the child geometry and the element geometry.
float ofx::DOM::Element::getWidth ( ) const

Get the width of the Element.

Returns
The width of the Element.
float ofx::DOM::Element::getX ( ) const

Get the X position of the Element in its parent coordinates.

Returns
the X position of the Element in its parent coordinates.
float ofx::DOM::Element::getY ( ) const

Get the Y position of the Element in its parent coordinates.

Returns
the Y position of the Element in its parent coordinates.
bool ofx::DOM::Element::hasAttribute ( const std::string &  name) const

Determine of the Element has an attribute with the given name.

Parameters
nameThe name of the Attribute to query.
Returns
true iff the Element has an attribute with the given name.
bool ofx::DOM::Element::hasParent ( ) const

Determine if this Element has a parent Element.

Returns
true if this Element has a parent Element.
bool ofx::DOM::Element::hitTest ( const Position &  parentPosition) const
virtual

Perform a hit test on the Element.

For a normal Element, the hit test will test the rectangular geometry of the Element. Subclasses can override this method for custom hit test geometry.

Parent coordinates are used because the geometry / position of the Element are in parent coordinates.

Parameters
parentPositionThe Position to test in parent coordinates.
Returns
true iff the local position is within the hit test region.
bool ofx::DOM::Element::isChild ( Element element) const

Determine if the given Element is a child of this Element.

Parameters
elementA pointer the the Element to test.
Returns
true iff the given element is a child of this Element.
bool ofx::DOM::Element::isEnabled ( ) const
Returns
true iff the Element is enabled.
bool ofx::DOM::Element::isHidden ( ) const
Returns
true iff the Element is hidden.
bool ofx::DOM::Element::isLocked ( ) const
Returns
true iff the Element is locked.
bool ofx::DOM::Element::isParent ( Element element) const

Determine if the given Element is the parent of this Element.

Parameters
elementA pointer the the Element to test.
Returns
true iff the given element is the parent of this Element.
bool ofx::DOM::Element::isPointerCaptured ( std::size_t  id) const
protected

Determine if a given pointer id is captured.

Parameters
idThe pointer id to test.
Returns
true if the given pointer id is captured.
bool ofx::DOM::Element::isSibling ( Element element) const

Determine if the given Element is a sibling of this Element.

Parameters
elementA pointer the the Element to test.
Returns
true iff the given element is a sibling of this Element.
Layout* ofx::DOM::Element::layout ( )

Get a pointer to the associated Layout.

The Element retains ownership of the pointer via a std::unique_ptr.

Returns
a pointer to the associated Layout or nullptr if there is none.
Position ofx::DOM::Element::localToScreen ( const Position &  localPosition) const

Convert the local coordinates to screen coordinates.

Local coordinates are defined with reference to the position of the box. The Position of this element will be in its parent's local coordinates.

Parameters
localPositionThe local coordinates to convert.
Returns
the position converted from local to screen coordinates.
void ofx::DOM::Element::moveChildBackward ( Element element)

Move the given Element in back of its next sibling.

Parameters
elementThe child element to move.
Exceptions
DOMException(DOMException::INVALID_STATE_ERROR)if no matching child element exists.
void ofx::DOM::Element::moveChildForward ( Element element)

Move the given Element in front of its next sibling.

Parameters
elementThe child element to move.
Exceptions
DOMException(DOMException::INVALID_STATE_ERROR)if no matching child element exists.
void ofx::DOM::Element::moveChildToBack ( Element element)

Move the given Element in back of all of its siblings.

Parameters
elementThe child element to move.
Exceptions
DOMException(DOMException::INVALID_STATE_ERROR)if no matching child element exists.
void ofx::DOM::Element::moveChildToFront ( Element element)

Move the given Element in front of all of its siblings.

Exceptions
DOMException(DOMException::INVALID_STATE_ERROR)if no matching child element exists.
void ofx::DOM::Element::moveChildToIndex ( Element element,
std::size_t  index 
)

Move the given Element to the the given index.

If the index value is greater than the number of children, the element will be moved into the last position.

Parameters
elementThe child element to move.
indexThe child index to move to.
Exceptions
DOMException(DOMException::INVALID_STATE_ERROR)if no matching child element exists.
std::size_t ofx::DOM::Element::numChildren ( ) const
Returns
the number of children.
std::size_t ofx::DOM::Element::numSiblings ( ) const
Returns
the number of siblings.
Element * ofx::DOM::Element::parent ( )

Get a pointer to the parent.

Returns
a pointer to the parent or a nullptr.
const Element * ofx::DOM::Element::parent ( ) const

Get a pointer to the parent.

Returns
a pointer to the parent or a nullptr.
Position ofx::DOM::Element::parentToScreen ( const Position &  parentPosition) const

Convert the parent coordinates to screen coordinates.

Parameters
parentPositionThe parent coordinates to convert.
Returns
the position converted from parent to screen coordinates.
Element * ofx::DOM::Element::recursiveHitTest ( const Position &  parentPosition)
protected

A recursive hit test to find a target element.

Parameters
parentPositionThe parent coordinates to test.
Returns
A pointer to the target Element or a nullptr if none found.
Todo:
Provide a seed position to speed up search?
void ofx::DOM::Element::releasePointerCapture ( std::size_t  id)

Release a captured pointer with the given id.

Usually this call is not required as the parent Document's pointer dispatching system will automatically release a pointer on the next POINTER_UP event. In some cases, the user may want to explicity release the event to fire the associated lostPointerCapture events.

Parameters
idThe pointer id to release.
std::unique_ptr< Element > ofx::DOM::Element::removeChild ( Element element)

Release ownership of a child Element.

Parameters
elementThe Element to release.
Returns
a std::unique_ptr<Element> to the child.

Alert the node's siblings that it no longer has a sibling.

std::unique_ptr<Layout> ofx::DOM::Element::removeLayout ( )

Release ownership of the Layout.

Returns
a std::unique_ptr<Layout> to the Layout or nullptr if none.
Position ofx::DOM::Element::screenToLocal ( const Position &  screenPosition) const

Convert the screen coordinates to local coordinates.

Local coordinates are defined with reference to the position of the box. The Position of this element will be in its parent's local coordinates.

Parameters
screenPositionThe screen coordinates to convert.
Returns
the position converted from screen to local coordinates.
Position ofx::DOM::Element::screenToParent ( const Position &  screenPosition) const

Convert the screen coordinates to parent coordinates.

Parameters
screenPositionThe screen coordinates to convert.
Returns
the position converted from screen to parent coordinates.
void ofx::DOM::Element::setAttribute ( const std::string &  name,
const Any value 
)

Set a value for a named attribute.

If the given attribute exists, it will be overwritten with the given value.

Parameters
nameThe name of the attribute.
valueThe new value of the attribute called name.
void ofx::DOM::Element::setEnabled ( bool  enabled)

Enable or disable this Element.

Parameters
enabledThe enabled state to set. True to enable, false to disable.
void ofx::DOM::Element::setGeometry ( const Geometry &  geometry)

Set the geometry of the Element in its parent coordinates.

Parameters
geometryThe new geometry of the Element in its parent coordinates.
void ofx::DOM::Element::setHidden ( bool  hidden)

Hide or show this Element.

Parameters
hiddenThe visible state to set. True to hide, false to show.
void ofx::DOM::Element::setId ( const std::string &  id)

Set the id of the Element.

Parameters
idThe new id of the Element.
void ofx::DOM::Element::setImplicitPointerCapture ( bool  implicitPointerCapture)
protected

Set if the pointer is implicitly captured on pointer down.

This does not enable the pointer listener, only if the pointer should be automatically captured when a listener is enabled.

Parameters
implicitPointerCaptureTrue if the pointer should be captured.
template<typename LayoutType >
LayoutType * ofx::DOM::Element::setLayout ( std::unique_ptr< LayoutType >  layout)

Take ownership of the passed std::unique_ptr<Layout>.

This this is "sink" meaning that any Layout passed to this will be owned by this Element.

Parameters
layoutthe rvalue reference to the Layout.
Returns
A pointer to the set Layout. The parent Element retains ownership of the pointer via a std::unique_ptr.
Template Parameters
LayoutTypeThe Layout Type.
void ofx::DOM::Element::setLocked ( bool  locked)

Lock or unlock a this Element.

Parameters
lockedThe locked state to set. True to lock, false to unlock.
void ofx::DOM::Element::setPointerCapture ( std::size_t  id)

Request that the parent Document capture the given pointer id.

Captured pointers send all of their revents to the capturing Element.

Parameters
idThe pointer id to capture.
void ofx::DOM::Element::setPosition ( float  x,
float  y 
)

Set the position of the Element in its parent coordinates.

Parameters
xThe new x position.
yThe new y position.
void ofx::DOM::Element::setPosition ( const Position &  position)

Set the position of the Element in its parent coordinates.

Parameters
positionThe new position.
void ofx::DOM::Element::setSize ( float  width,
float  height 
)

Set the size of the Element.

Parameters
widthThe new width of the Element.
heightThe new height of the Element.
std::vector< Element * > ofx::DOM::Element::siblings ( )
Returns
a list of pointers to sibling elements.
template<typename ElementType >
std::vector< ElementType * > ofx::DOM::Element::siblings ( )

Get a list of siblings of a given Element or Element subclass.

If the there are no siblings of the given type,

Returns
a list of pointers to sibling elements of a given type.

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