added view
This commit is contained in:
parent
5517a271c7
commit
580e53d3bc
11 changed files with 68 additions and 34 deletions
26
README.md
26
README.md
|
|
@ -4,6 +4,28 @@
|
|||
|
||||
Crafter.CppDOM is a C++ library that exposes the browser DOM api's to C++ WebAssembly.
|
||||
|
||||
# HtmlElement vs HtmlElementView
|
||||
|
||||
The library provides two main classes for working with HTML elements:
|
||||
|
||||
## HtmlElementView
|
||||
`HtmlElementView` is a base class that provides read and write access to HTML element properties and methods, but does **not** own the underlying DOM element. It's designed to be used when you want to interact with existing elements in the DOM without managing their lifecycle.
|
||||
|
||||
Key characteristics:
|
||||
- Provides access to element properties and methods like `SetInnerHTML`, `SetStyle`, `AddClass`, etc.
|
||||
- Supports event handling through various `Add*Listener` methods
|
||||
- Does not delete the underlying DOM element when destroyed
|
||||
- Used when you're working with elements that already exist in the DOM
|
||||
|
||||
## HtmlElement
|
||||
`HtmlElement` is a derived class from `HtmlElementView` that adds ownership semantics. It creates a new DOM element when instantiated and properly manages its lifecycle.
|
||||
|
||||
Key characteristics:
|
||||
- Inherits all functionality from `HtmlElementView`
|
||||
- Creates and owns a new DOM element when constructed
|
||||
- Automatically deletes the DOM element when the `HtmlElement` object is destroyed
|
||||
- Used when you want to create new elements programmatically
|
||||
|
||||
# How to use
|
||||
Please view the examples folder, this is a snippit from the HelloElement example:
|
||||
|
||||
|
|
@ -12,7 +34,7 @@ import Crafter.CppDOM;
|
|||
using namespace Crafter::CppDOM;
|
||||
|
||||
int main(){
|
||||
HtmlElement body("body");
|
||||
HtmlElementView body("body");
|
||||
body.SetInnerHTML("Hello World!");
|
||||
}
|
||||
```
|
||||
|
|
@ -49,7 +71,7 @@ import Crafter.CppDOM;
|
|||
using namespace Crafter::CppDOM;
|
||||
|
||||
int main(){
|
||||
HtmlElement body("body");
|
||||
HtmlElementView body("body");
|
||||
body.SetInnerHTML("Hello World!");
|
||||
}
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue