44 lines
No EOL
1 KiB
Markdown
44 lines
No EOL
1 KiB
Markdown
# Interactive Element Example
|
|
|
|
This example demonstrates how to use DOM event handling with Crafter.CppDOM.
|
|
|
|
## Features
|
|
|
|
- Shows how to create interactive UI elements using C++
|
|
- Demonstrates the event listener framework for attaching callbacks
|
|
- Illustrates how to respond to user interactions
|
|
|
|
## Usage
|
|
|
|
```cpp
|
|
import Crafter.CppDOM;
|
|
using namespace Crafter::CppDOM;
|
|
|
|
int main(){
|
|
// Create UI elements
|
|
HtmlElement body("body");
|
|
body.SetInnerHTML("<h1>Interactive Element Demo</h1>"
|
|
"<button id='myButton'>Click Me!</button>"
|
|
"<p id='output'>Click the button above</p>");
|
|
|
|
// Attach event listener
|
|
HtmlElement button("myButton");
|
|
button.AddClickListener([]() {
|
|
HtmlElement output("output");
|
|
output.SetInnerHTML("Button was clicked!");
|
|
});
|
|
|
|
return 0;
|
|
}
|
|
```
|
|
|
|
## Building and Running
|
|
|
|
```bash
|
|
crafter-build build executable
|
|
run.sh
|
|
```
|
|
|
|
Then navigate to `http://localhost:8080/` in your browser.
|
|
|
|
If caddy is not installed, you can use your favorite static file server instead. |