AeonGUI
A portable video game graphic user interface library.
Loading...
Searching...
No Matches
Node.hpp
1/*
2Copyright (C) 2019,2020,2023-2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGUI_NODE_H
17#define AEONGUI_NODE_H
18#include <cstdint>
19#include <vector>
20#include <memory>
21#include <functional>
22#include <variant>
23#include "aeongui/Platform.hpp"
24#include "aeongui/AttributeMap.hpp"
25#include "aeongui/dom/EventTarget.hpp"
26
27namespace AeonGUI
28{
29 class Canvas;
30 class Document;
31 namespace DOM
32 {
39 class Node : public EventTarget
40 {
41 public:
58
61 DLL Node ( Node* aParent = nullptr );
66 DLL Node* AddNode ( std::unique_ptr<Node> aNode );
71 DLL std::unique_ptr<Node> RemoveNode ( const Node* aNode );
75 DLL void TraverseDepthFirstPreOrder ( const std::function<void ( Node& ) >& aAction );
79 DLL void TraverseDepthFirstPreOrder ( const std::function<void ( const Node& ) >& aAction ) const;
83 DLL void TraverseDepthFirstPostOrder ( const std::function<void ( Node& ) >& aAction );
87 DLL void TraverseDepthFirstPostOrder ( const std::function<void ( const Node& ) >& aAction ) const;
92 DLL void TraverseDepthFirstPreOrder ( const std::function<void ( Node& ) >& aPreamble, const std::function<void ( Node& ) >& aPostamble );
97 DLL void TraverseDepthFirstPreOrder ( const std::function<void ( const Node& ) >& aPreamble, const std::function<void ( const Node& ) >& aPostamble ) const;
103 DLL void TraverseDepthFirstPreOrder ( const std::function<void ( Node& ) >& aPreamble, const std::function<void ( Node& ) >& aPostamble, const std::function<bool ( Node& ) >& aUnaryPredicate );
109 DLL void TraverseDepthFirstPreOrder ( const std::function<void ( const Node& ) >& aPreamble, const std::function<void ( const Node& ) >& aPostamble, const std::function<bool ( const Node& ) >& aUnaryPredicate ) const;
110
114 DLL virtual void DrawStart ( Canvas& aCanvas ) const;
118 DLL virtual void DrawFinish ( Canvas& aCanvas ) const;
125 DLL virtual void OnLoad ();
132 DLL virtual void OnUnload ();
137 DLL virtual bool IsDrawEnabled() const;
138 DLL virtual ~Node();
143 DLL Node* parentNode() const;
147 DLL Node* parentElement() const;
151 virtual NodeType nodeType() const = 0;
155 const std::vector<std::unique_ptr<Node>>& childNodes() const;
157 private:
158 DLL virtual void OnAncestorChanged();
159 Node* mParent{};
160 std::vector<std::unique_ptr<Node>> mChildren{};
161 mutable std::vector<std::unique_ptr<Node>>::size_type mIterator{ 0 };
162 };
163 }
164}
165#endif
Platform-specific DLL import/export macros and compiler helpers.
Abstract 2D rendering surface.
Definition Canvas.hpp:39
Base class for objects that can receive DOM events.
Definition EventTarget.hpp:58
Base class for all nodes in the DOM tree.
Definition Node.hpp:40
void TraverseDepthFirstPreOrder(const std::function< void(const Node &) > &aPreamble, const std::function< void(const Node &) > &aPostamble) const
Traverse pre-order with pre/post callbacks (const).
void TraverseDepthFirstPostOrder(const std::function< void(Node &) > &aAction)
Traverse the tree depth-first in post-order.
virtual void DrawStart(Canvas &aCanvas) const
Begin drawing this node on the canvas.
Definition Node.cpp:38
Node * AddNode(std::unique_ptr< Node > aNode)
Add a child node.
Definition Node.cpp:198
void TraverseDepthFirstPreOrder(const std::function< void(Node &) > &aPreamble, const std::function< void(Node &) > &aPostamble, const std::function< bool(Node &) > &aUnaryPredicate)
Traverse pre-order with pre/post callbacks and a predicate filter.
virtual void DrawFinish(Canvas &aCanvas) const
Finish drawing this node on the canvas.
Definition Node.cpp:44
std::unique_ptr< Node > RemoveNode(const Node *aNode)
Remove a child node.
Definition Node.cpp:210
virtual void OnLoad()
Definition Node.cpp:50
void TraverseDepthFirstPreOrder(const std::function< void(const Node &) > &aAction) const
Traverse the tree depth-first in pre-order (const).
virtual NodeType nodeType() const =0
Get the node type.
virtual void OnUnload()
Definition Node.cpp:55
NodeType
DOM node type constants.
Definition Node.hpp:44
@ ENTITY_NODE
An Entity node (legacy).
Definition Node.hpp:50
@ ATTRIBUTE_NODE
An Attribute node (legacy).
Definition Node.hpp:46
@ CDATA_SECTION_NODE
A CDATASection node.
Definition Node.hpp:48
@ TEXT_NODE
A Text node.
Definition Node.hpp:47
@ COMMENT_NODE
A Comment node.
Definition Node.hpp:52
@ DOCUMENT_TYPE_NODE
A DocumentType node.
Definition Node.hpp:54
@ ENTITY_REFERENCE_NODE
An EntityReference node (legacy).
Definition Node.hpp:49
@ NOTATION_NODE
A Notation node (legacy).
Definition Node.hpp:56
@ PROCESSING_INSTRUCTION_NODE
A ProcessingInstruction node.
Definition Node.hpp:51
@ DOCUMENT_FRAGMENT_NODE
A DocumentFragment node.
Definition Node.hpp:55
@ DOCUMENT_NODE
A Document node.
Definition Node.hpp:53
@ ELEMENT_NODE
An Element node.
Definition Node.hpp:45
virtual bool IsDrawEnabled() const
Definition Node.cpp:33
const std::vector< std::unique_ptr< Node > > & childNodes() const
Get the list of child nodes.
Definition Node.cpp:28
Node * parentElement() const
Get the parent element (same as parentNode for elements).
Definition Node.cpp:64
Node * parentNode() const
Get the parent node.
Definition Node.cpp:60
void TraverseDepthFirstPostOrder(const std::function< void(const Node &) > &aAction) const
Traverse the tree depth-first in post-order (const).
void TraverseDepthFirstPreOrder(const std::function< void(Node &) > &aAction)
Traverse the tree depth-first in pre-order.
void TraverseDepthFirstPreOrder(const std::function< void(Node &) > &aPreamble, const std::function< void(Node &) > &aPostamble)
Traverse pre-order with separate pre and post callbacks.
Node(Node *aParent=nullptr)
Construct a node with an optional parent.
Definition Node.cpp:25
void TraverseDepthFirstPreOrder(const std::function< void(const Node &) > &aPreamble, const std::function< void(const Node &) > &aPostamble, const std::function< bool(const Node &) > &aUnaryPredicate) const
Traverse pre-order with pre/post callbacks and predicate (const).