AeonGUI
A portable video game graphic user interface library.
Loading...
Searching...
No Matches
Element.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_ELEMENT_H
17#define AEONGUI_ELEMENT_H
18#include <cstdint>
19#include <vector>
20#include <memory>
21#include <string>
22#include <variant>
23#include "aeongui/Platform.hpp"
24#include "aeongui/AttributeMap.hpp"
25#include "aeongui/StyleSheet.hpp"
26#include "aeongui/dom/DOMString.hpp"
27#include "Node.hpp"
28
29extern "C"
30{
31 typedef struct lwc_string_s lwc_string;
32}
33namespace AeonGUI
34{
35 class Canvas;
36 namespace DOM
37 {
38 class Document;
45 class Element : public Node
46 {
47 public:
53 DLL Element ( const DOMString& aTagName, AttributeMap&& aAttributes, Node* aParent );
55 DLL virtual ~Element();
59 NodeType nodeType() const final;
63 DLL const DOMString& tagName() const;
67 DLL const DOMString& id() const;
71 const std::vector<lwc_string*>& classes() const;
75 DLL const AttributeMap& attributes() const;
80 DLL const DOMString* getAttribute ( const DOMString& aName ) const;
85 DLL void setAttribute ( const DOMString& aName, const DOMString& aValue );
89 DLL bool isHover() const;
93 DLL bool isActive() const;
97 DLL bool isFocus() const;
100 void setHover ( bool aHover );
103 void setActive ( bool aActive );
106 void setFocus ( bool aFocus );
110 DLL void ReselectCSS ( css_stylesheet* aDocumentStyleSheet = nullptr );
112 private:
113 DOMString mTagName{};
114 DOMString mId{};
115 std::vector<lwc_string*> mClasses{};
116 DLL void OnAncestorChanged() override;
117 bool mIsHover{false};
118 bool mIsActive{false};
119 bool mIsFocus{false};
120 css_stylesheet* mDocumentStyleSheet{nullptr};
121 protected:
122 AttributeMap mAttributes{};
123 StyleSheetPtr mInlineStyleSheet{};
124 SelectResultsPtr mComputedStyles{};
127 css_select_results* GetParentComputedStyles() const;
130 css_select_results* GetComputedStyles() const;
133 void ApplyChildTransformAnimations ( Canvas& aCanvas ) const;
136 void ApplyChildPaintAnimations ( Canvas& aCanvas ) const;
145 virtual void onAttributeChanged ( const DOMString& aName, const DOMString& aValue );
146 };
147 }
148}
149#endif
Platform-specific DLL import/export macros and compiler helpers.
Abstract 2D rendering surface.
Definition Canvas.hpp:40
Represents a DOM Document.
Definition Document.hpp:40
const DOMString * getAttribute(const DOMString &aName) const
Get the value of a named attribute.
Definition Element.cpp:393
const std::vector< lwc_string * > & classes() const
Get the element's CSS class list.
Definition Element.cpp:384
void setFocus(bool aFocus)
Set the :focus pseudo-class state.
Definition Element.cpp:516
NodeType nodeType() const final
Get the node type (always ELEMENT_NODE).
Definition Element.cpp:372
AttributeMap mAttributes
The element's attribute map.
Definition Element.hpp:122
StyleSheetPtr mInlineStyleSheet
Inline style parsed from the style attribute.
Definition Element.hpp:123
virtual ~Element()
Virtual destructor.
Definition Element.cpp:263
void ApplyChildPaintAnimations(Canvas &aCanvas) const
Apply child paint animation overrides to the canvas.
Definition Element.cpp:323
void ApplyChildTransformAnimations(Canvas &aCanvas) const
Apply child transform animation overrides to the canvas.
Definition Element.cpp:295
bool isHover() const
Check the :hover pseudo-class state.
Definition Element.cpp:491
bool isActive() const
Check the :active pseudo-class state.
Definition Element.cpp:496
void ReselectCSS(css_stylesheet *aDocumentStyleSheet=nullptr)
Re-run CSS selection and compose with parent styles.
Definition Element.cpp:521
const AttributeMap & attributes() const
Get the element's attribute map.
Definition Element.cpp:388
const DOMString & id() const
Get the element's ID attribute value.
Definition Element.cpp:380
virtual void onAttributeChanged(const DOMString &aName, const DOMString &aValue)
Called after an attribute is changed via setAttribute.
Definition Element.cpp:409
void setActive(bool aActive)
Set the :active pseudo-class state.
Definition Element.cpp:511
void setAttribute(const DOMString &aName, const DOMString &aValue)
Set (or add) a named attribute.
Definition Element.cpp:403
void setHover(bool aHover)
Set the :hover pseudo-class state.
Definition Element.cpp:506
css_select_results * GetParentComputedStyles() const
Get computed styles from the parent element.
Definition Element.cpp:271
css_select_results * GetComputedStyles() const
Get this element's computed styles.
Definition Element.cpp:286
Element(const DOMString &aTagName, AttributeMap &&aAttributes, Node *aParent)
Construct an element.
Definition Element.cpp:172
bool isFocus() const
Check the :focus pseudo-class state.
Definition Element.cpp:501
const DOMString & tagName() const
Get the tag name.
Definition Element.cpp:376
SelectResultsPtr mComputedStyles
Computed CSS styles for this element.
Definition Element.hpp:124
NodeType
DOM node type constants.
Definition Node.hpp:46
Node(Node *aParent=nullptr)
Construct a node with an optional parent.
Definition Node.cpp:29