Crafter.CppDOM/README.md

64 lines
2 KiB
Markdown
Raw Normal View History

2025-01-02 02:48:44 +01:00
# About
![alt text](https://github.com/Catcrafts/Crafter.Web/blob/master/hello.png?raw=true)
2025-02-03 22:51:18 +01:00
Crafter.Web is a C++ library that exposes the browser DOM api's to C++ WebAssembly.
2025-01-02 02:48:44 +01:00
# How to use
2025-02-21 03:52:46 +01:00
Please view the samples folder, this is a snippit from the HelloElement sample:
```cpp
import Crafter.CppDOM;
using namespace Crafter::CppDOM;
int main(){
HtmlElement body("body");
body.SetInnerHTML("Hello World!");
}
```
You can also view the wiki for more detailed information.
2025-01-02 02:48:44 +01:00
It is highly recommended to use this with [Crafter.WebBuild](https://github.com/Catcrafts/Crafter.WebBuild), but it is not strictly required if the same way of injecting the env is followed. The following instructions will be for Crafter.WebBuild.
## Quickstart
create a ``project.json`` in an empty folder, open it in your preferred text editor.
Create a basic project file, that describes your web project.
```JSON
{
"name": "sample-project",
"configurations": [
{
"name": "debug",
"standard": "c++26",
"source_files": ["main"],
"module_files": [],
"build_dir": "./build",
"output_dir": "./bin",
"optimization_level": "0",
"target": "wasm32-unknown-wasi",
"type": "executable",
"dependencies": [
{
2025-02-03 22:51:18 +01:00
"path":"https://github.com/Catcrafts/Crafter.CppDOM.git",
2025-01-02 02:48:44 +01:00
"configuration":"debug"
}
]
}
]
}
2025-02-21 03:53:03 +01:00
```
2025-02-21 03:52:46 +01:00
2025-01-02 02:48:44 +01:00
Save and close the file, create a ``main.cpp``
```cpp
2025-02-12 22:22:06 +01:00
import Crafter.CppDOM;
2025-02-12 23:06:56 +01:00
using namespace Crafter::CppDOM;
2025-01-02 02:48:44 +01:00
2025-02-12 22:22:06 +01:00
int main(){
2025-02-12 23:06:56 +01:00
HtmlElement body("body");
body.SetInnerHTML("Hello World!");
2025-01-02 02:48:44 +01:00
}
```
2025-02-21 03:52:46 +01:00
2025-02-12 22:22:06 +01:00
Save and close, then run ``crafter-webbuild serve -c debug``. Now you can open the browser at ``http://localhost:8080/`` and ``Hello World!`` will appear in the browser.
2025-02-12 23:06:56 +01:00
This sample can also be viewed in the [HelloElement sample](https://github.com/Catcrafts/Crafter.CppDOM/tree/master/samples/HelloElement)