Crafter.CppDOM/examples/InteractiveElement/README.md
2025-11-09 23:07:31 +01:00

1 KiB

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

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

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.