Crafter.CppDOM/examples/InteractiveElement/README.md

44 lines
1 KiB
Markdown
Raw Permalink Normal View History

2025-11-09 22:43:52 +01:00
# 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++
2025-11-09 23:07:31 +01:00
- Demonstrates the event listener framework for attaching callbacks
- Illustrates how to respond to user interactions
2025-11-09 22:43:52 +01:00
## 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");
2025-11-09 23:07:31 +01:00
button.AddClickListener([]() {
HtmlElement output("output");
output.SetInnerHTML("Button was clicked!");
});
2025-11-09 22:43:52 +01:00
return 0;
}
```
2025-11-09 23:07:31 +01:00
## 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.