click event
This commit is contained in:
parent
e35b7302cb
commit
f40afe684a
13 changed files with 151 additions and 20 deletions
39
examples/InteractiveElement/README.md
Normal file
39
examples/InteractiveElement/README.md
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# 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 framework for attaching event listeners
|
||||
- Illustrates the planned callback mechanism for event handling
|
||||
|
||||
## Usage
|
||||
|
||||
The library now provides the foundation for interactive web applications:
|
||||
|
||||
```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.AddEventListener("click");
|
||||
|
||||
// Future: button.OnClick([]() {
|
||||
// HtmlElement output("output");
|
||||
// output.SetInnerHTML("Button was clicked!");
|
||||
// });
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
Note: The full callback mechanism requires additional infrastructure to properly bridge between JavaScript events and C++ callbacks. This implementation provides the framework for future development.
|
||||
16
examples/InteractiveElement/main.cpp
Normal file
16
examples/InteractiveElement/main.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import Crafter.CppDOM;
|
||||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
HtmlElement body("body","<h1>Interactive Element Demo</h1>"
|
||||
"<button id='myButton'>Click Me!</button>"
|
||||
"<p id='output'>Click the button above</p>");
|
||||
HtmlElement* button = new HtmlElement("myButton"); //prevent destruction
|
||||
|
||||
|
||||
int main() {
|
||||
button->AddClickListener([](){
|
||||
auto output = HtmlElement("output");
|
||||
output.SetInnerHTML("Button was clicked!");
|
||||
});
|
||||
}
|
||||
17
examples/InteractiveElement/project.json
Normal file
17
examples/InteractiveElement/project.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "main",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "executable",
|
||||
"implementations": ["main"],
|
||||
"target": "wasm32-wasi",
|
||||
"debug" : true,
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-debug"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
1
examples/InteractiveElement/run.sh
Executable file
1
examples/InteractiveElement/run.sh
Executable file
|
|
@ -0,0 +1 @@
|
|||
caddy file-server --listen :8080 --root bin/executable
|
||||
Loading…
Add table
Add a link
Reference in a new issue