rebrand to CppDOM
This commit is contained in:
parent
8245a90e2f
commit
258192b195
9 changed files with 10 additions and 238 deletions
|
|
@ -22,9 +22,7 @@ module;
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
export module Crafter.Web;
|
export module Crafter.CppDOM;
|
||||||
export import :HtmlElement;
|
|
||||||
export import :Canvas;
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void __cxa_allocate_exception() {
|
void __cxa_allocate_exception() {
|
||||||
|
|
@ -38,13 +36,13 @@ extern "C" {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export namespace Crafter::Web::Bindings {
|
export namespace Crafter::CppDOM::Bindings {
|
||||||
__attribute__((import_module("env"), import_name("setInnerHTML"))) void SetInnerHTML(const char* id, std::size_t idLenght, const char* html, std::size_t htmlLenght);
|
__attribute__((import_module("env"), import_name("setInnerHTML"))) void SetInnerHTML(const char* id, std::size_t idLenght, const char* html, std::size_t htmlLenght);
|
||||||
__attribute__((import_module("env"), import_name("strokeRect"))) void StrokeRect(std::uint64_t id, std::uint32_t x, std::uint32_t y, std::uint32_t width, std::uint32_t height, const char* color, std::size_t colorLenght);
|
// __attribute__((import_module("env"), import_name("strokeRect"))) void StrokeRect(std::uint64_t id, std::uint32_t x, std::uint32_t y, std::uint32_t width, std::uint32_t height, const char* color, std::size_t colorLenght);
|
||||||
__attribute__((import_module("env"), import_name("putImageData"))) void PutImageData(std::uint64_t id, Crafter::Web::Pixel* buffer, std::uint32_t width, std::uint32_t height);
|
// __attribute__((import_module("env"), import_name("putImageData"))) void PutImageData(std::uint64_t id, Crafter::Web::Pixel* buffer, std::uint32_t width, std::uint32_t height);
|
||||||
__attribute__((import_module("env"), import_name("fetch"))) void Fetch(void* obj, const char* url, std::size_t urlCallback, char* buffer, void (*listener)(void* obj, std::uint32_t, char*));
|
// __attribute__((import_module("env"), import_name("fetch"))) void Fetch(void* obj, const char* url, std::size_t urlCallback, char* buffer, void (*listener)(void* obj, std::uint32_t, char*));
|
||||||
__attribute__((import_module("env"), import_name("setTimeout"))) void SetTimeout(void* obj, std::uint32_t time, void (*listener)(void* obj));
|
// __attribute__((import_module("env"), import_name("setTimeout"))) void SetTimeout(void* obj, std::uint32_t time, void (*listener)(void* obj));
|
||||||
__attribute__((import_module("env"), import_name("draw"))) void Draw(std::uint64_t id, std::uint32_t x, std::uint32_t y, const char* text, std::uint32_t textLenght);
|
// __attribute__((import_module("env"), import_name("draw"))) void Draw(std::uint64_t id, std::uint32_t x, std::uint32_t y, const char* text, std::uint32_t textLenght);
|
||||||
//__attribute__((import_module("env"), import_name("addEventListener"))) void AddEventListener(std::string id, std::string eventId, void (*listener)(void));
|
//__attribute__((import_module("env"), import_name("addEventListener"))) void AddEventListener(std::string id, std::string eventId, void (*listener)(void));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
Crafter.Web
|
|
||||||
Copyright (C) 2024 Catcrafts
|
|
||||||
Catcrafts.net
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
module;
|
|
||||||
#include <string>
|
|
||||||
#include <format>
|
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <cstdint>
|
|
||||||
module Crafter.Web;
|
|
||||||
using namespace Crafter::Web;
|
|
||||||
|
|
||||||
Canvas::Canvas(std::uint32_t width, std::uint32_t height, std::string value, std::unordered_map<std::string, std::string> style, std::vector<HtmlElement*> children , std::unordered_map<std::string, std::string> attributes) : HtmlElement("canvas", value, style, children, attributes), width(width), height(height) {
|
|
||||||
this->attributes.insert({"width",std::to_string(width)});
|
|
||||||
this->attributes.insert({"height",std::to_string(height)});
|
|
||||||
}
|
|
||||||
|
|
||||||
void Canvas::DrawRect(std::uint32_t x, std::uint32_t y, std::uint32_t width, std::uint32_t height, std::string color) {
|
|
||||||
Crafter::Web::Bindings::StrokeRect(id, x, y, width, height, color.c_str(), color.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Canvas::SetBuffer(Pixel* buffer) {
|
|
||||||
Crafter::Web::Bindings::PutImageData(id, buffer, width, height);
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
/*
|
|
||||||
Crafter.Web
|
|
||||||
Copyright (C) 2024 Catcrafts
|
|
||||||
Catcrafts.net
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
module;
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <cstdint>
|
|
||||||
export module Crafter.Web:Canvas;
|
|
||||||
import :HtmlElement;
|
|
||||||
|
|
||||||
export namespace Crafter::Web {
|
|
||||||
|
|
||||||
struct Pixel {
|
|
||||||
std::uint8_t r;
|
|
||||||
std::uint8_t g;
|
|
||||||
std::uint8_t b;
|
|
||||||
std::uint8_t a;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Canvas : public Crafter::Web::HtmlElement {
|
|
||||||
public:
|
|
||||||
std::uint32_t width;
|
|
||||||
std::uint32_t height;
|
|
||||||
Canvas(std::uint32_t width, std::uint32_t height, std::string value = "", std::unordered_map<std::string, std::string> style = {}, std::vector<HtmlElement*> children = {}, std::unordered_map<std::string, std::string> attributes = {});
|
|
||||||
void DrawRect(std::uint32_t x, std::uint32_t y, std::uint32_t width, std::uint32_t height, std::string color);
|
|
||||||
void SetBuffer(Pixel* buffer);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
/*
|
|
||||||
Crafter.Web
|
|
||||||
Copyright (C) 2024 Catcrafts
|
|
||||||
Catcrafts.net
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
module;
|
|
||||||
#include <string>
|
|
||||||
#include <format>
|
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <cstdint>
|
|
||||||
module Crafter.Web;
|
|
||||||
using namespace Crafter::Web;
|
|
||||||
|
|
||||||
HtmlElement::HtmlElement(std::string tag, std::string value, std::unordered_map<std::string, std::string> style, std::vector<HtmlElement*> children, std::unordered_map<std::string, std::string> attributes) : id(idCounter++), tag(tag), children(children), style(style), value(value), attributes(attributes) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string HtmlElement::Render() const {
|
|
||||||
std::string childrenRendered;
|
|
||||||
for(HtmlElement* child : children){
|
|
||||||
childrenRendered+=child->Render();
|
|
||||||
}
|
|
||||||
std::string styleRender;
|
|
||||||
for(const auto& [key, value] : style){
|
|
||||||
styleRender+=std::format("{}:{};",key,value);
|
|
||||||
}
|
|
||||||
std::string attributesRender;
|
|
||||||
for(const auto& [key, value] : attributes){
|
|
||||||
attributesRender+=std::format("{}=\"{}\"",key,value);
|
|
||||||
}
|
|
||||||
return std::format("<{} id=\"{}\" style=\"{}\" {}>{}{}</{}>",tag, id, styleRender, attributesRender, value, childrenRendered, tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HtmlElement::RenderAsRoot() const {
|
|
||||||
const std::string render = Render();
|
|
||||||
const char id[] = "body";
|
|
||||||
Crafter::Web::Bindings::SetInnerHTML(id, sizeof(id)-1, render.c_str(), render.size()-1);
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
Crafter.Web
|
|
||||||
Copyright (C) 2024 Catcrafts
|
|
||||||
Catcrafts.net
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 3.0 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
module;
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <cstdint>
|
|
||||||
export module Crafter.Web:HtmlElement;
|
|
||||||
|
|
||||||
export namespace Crafter::Web {
|
|
||||||
class HtmlElement {
|
|
||||||
public:
|
|
||||||
inline static std::uint64_t idCounter = 0;
|
|
||||||
std::uint64_t id;
|
|
||||||
std::string tag;
|
|
||||||
std::string value;
|
|
||||||
std::unordered_map<std::string, std::string> style;
|
|
||||||
std::vector<HtmlElement*> children;
|
|
||||||
std::unordered_map<std::string, std::string> attributes;
|
|
||||||
HtmlElement(std::string tag, std::string value = "", std::unordered_map<std::string, std::string> style = {}, std::vector<HtmlElement*> children = {}, std::unordered_map<std::string, std::string> attributes = {});
|
|
||||||
std::string Render() const;
|
|
||||||
void RenderAsRoot() const;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -4,9 +4,9 @@
|
||||||
{
|
{
|
||||||
"name": "base",
|
"name": "base",
|
||||||
"standard": "c++26",
|
"standard": "c++26",
|
||||||
"source_files": ["Crafter.Web-HtmlElement", "Crafter.Web-Canvas"],
|
"source_files": [],
|
||||||
"module_files": ["Crafter.Web-Canvas", "Crafter.Web-HtmlElement", "Crafter.Web"],
|
"module_files": ["Crafter.CppDOM"],
|
||||||
"additional_files": ["Crafter.Web.js"],
|
"additional_files": ["Crafter.CppDOM.js"],
|
||||||
"build_dir": "./build",
|
"build_dir": "./build",
|
||||||
"output_dir": "./bin",
|
"output_dir": "./bin",
|
||||||
"type":"library",
|
"type":"library",
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import Crafter.Web;
|
|
||||||
using namespace Crafter::Web;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
HtmlElement root("div", "", {}, {
|
|
||||||
HtmlElement("h1", "HELLO FROM C++"),
|
|
||||||
HtmlElement("h1", "blue text", {{"color","blue"}}),
|
|
||||||
HtmlElement("h1", "", {{"display","flex"}, {"justify-content","space-between"}}, {
|
|
||||||
HtmlElement("div", "c++"),
|
|
||||||
HtmlElement("div", "webdev"),
|
|
||||||
HtmlElement("div", "is"),
|
|
||||||
HtmlElement("div", "awesome")
|
|
||||||
}),
|
|
||||||
HtmlElement("img", "", {}, {}, {{"src","https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/ISO_C%2B%2B_Logo.svg/1822px-ISO_C%2B%2B_Logo.svg.png"},{"width","200"}}),
|
|
||||||
});
|
|
||||||
root.RenderAsRoot();
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
"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": [
|
|
||||||
{
|
|
||||||
"path":"../project.json",
|
|
||||||
"configuration":"debug"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue