working keydown
This commit is contained in:
parent
7350ce0bea
commit
6210e9c99b
12 changed files with 975 additions and 401 deletions
|
|
@ -7,8 +7,6 @@ HtmlElement* input = new HtmlElement("textInput");
|
|||
HtmlElement* output = new HtmlElement("output");
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
// Click event
|
||||
button->AddClickListener([&]() {
|
||||
output->SetInnerHTML("Button was clicked!");
|
||||
|
|
|
|||
63
examples/EnhancedEventHandling/main.cpp
Normal file
63
examples/EnhancedEventHandling/main.cpp
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import Crafter.CppDOM;
|
||||
using namespace Crafter;
|
||||
import std;
|
||||
|
||||
HtmlElement* body = new HtmlElement("body", "<div id='container'>"
|
||||
"<h1>Enhanced Event Handling Demo</h1>"
|
||||
"<button id='clickButton'>Click Me!</button>"
|
||||
"<button id='mouseButton'>Mouse Events</button>"
|
||||
"<input type='text' id='keyInput' placeholder='Press keys here'>"
|
||||
"<input type='text' id='changeInput' placeholder='Change me'>"
|
||||
"<div id='output'></div>"
|
||||
"</div>");
|
||||
HtmlElement* clickButton = new HtmlElement("clickButton");
|
||||
HtmlElement* mouseButton = new HtmlElement("mouseButton");
|
||||
HtmlElement* keyInput = new HtmlElement("keyInput");
|
||||
HtmlElement* changeInput = new HtmlElement("changeInput");
|
||||
HtmlElement* output = new HtmlElement("output");
|
||||
|
||||
int main(){
|
||||
// Click event - simple handler
|
||||
clickButton->AddClickListener([&]() {
|
||||
output->SetInnerHTML("<p>Simple click event triggered!</p>");
|
||||
});
|
||||
|
||||
// Mouse events with position data
|
||||
// mouseButton->AddMouseMoveListener([&](MouseEvent event) {
|
||||
// output->SetInnerHTML("<p>Mouse moved to: (" + std::to_string(event.clientX) + ", " + std::to_string(event.clientY) + ")</p>");
|
||||
// });
|
||||
|
||||
// Keyboard events with rich data
|
||||
keyInput->AddKeyDownListener([&](KeyboardEvent event) {
|
||||
std::string keyInfo = std::format("<p>Key pressed: {}</p>", event.key);
|
||||
if (event.ctrlKey) keyInfo += "<p>Ctrl key pressed</p>";
|
||||
if (event.shiftKey) keyInfo += "<p>Shift key pressed</p>";
|
||||
if (event.altKey) keyInfo += "<p>Alt key pressed</p>";
|
||||
output->SetInnerHTML(keyInfo);
|
||||
});
|
||||
|
||||
// // Input event with data
|
||||
// keyInput->AddInputListener([&](InputEvent event) {
|
||||
// output->SetInnerHTML(std::format("<p>Input data: {} (composing: {})</p>", event.data, event.isComposing));
|
||||
// });
|
||||
|
||||
// Change event with value
|
||||
changeInput->AddChangeListener([&](ChangeEvent event) {
|
||||
output->SetInnerHTML("<p>Input value changed to: '" + event.value + "'</p>");
|
||||
});
|
||||
|
||||
// Context menu with position
|
||||
mouseButton->AddContextMenuListener([&](MouseEvent event) {
|
||||
output->SetInnerHTML("<p>Context menu at: (" + std::to_string(event.clientX) + ", " + std::to_string(event.clientY) + ")</p>");
|
||||
});
|
||||
|
||||
// Resize event
|
||||
body->AddResizeListener([&](ResizeEvent event) {
|
||||
output->SetInnerHTML("<p>Window resized to: " + std::to_string(event.width) + "x" + std::to_string(event.height) + "</p>");
|
||||
});
|
||||
|
||||
// Scroll event
|
||||
body->AddScrollListener([&](ScrollEvent event) {
|
||||
output->SetInnerHTML("<p>Scrolled to: (" + std::to_string(event.scrollX) + ", " + std::to_string(event.scrollY) + ")</p>");
|
||||
});
|
||||
}
|
||||
17
examples/EnhancedEventHandling/project.json
Normal file
17
examples/EnhancedEventHandling/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/EnhancedEventHandling/run.sh
Executable file
1
examples/EnhancedEventHandling/run.sh
Executable file
|
|
@ -0,0 +1 @@
|
|||
caddy file-server --listen :8080 --root bin/executable
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import Crafter.CppDOM;
|
||||
using namespace Crafter::CppDOM::Bindings;
|
||||
using namespace Crafter::CppDOMBindings;
|
||||
|
||||
int main(){
|
||||
void* body = GetElementById("body");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue