C++ bindings for browser DOM api's
| additional | ||
| examples | ||
| implementations | ||
| interfaces | ||
| .gitignore | ||
| hello.png | ||
| LICENSE | ||
| project.json | ||
| README.md | ||
Crafter.CppDOM
A C++ DOM library for web applications that allows you to manipulate HTML elements directly from C++.
New Styling Features
This library now supports comprehensive styling capabilities beyond just inline HTML:
Style Methods
SetStyle(const std::string_view style)- Sets multiple CSS properties at onceSetProperty(const std::string_view property, const std::string_view value)- Sets a single CSS propertyAddClass(const std::string_view className)- Adds a CSS class to the elementRemoveClass(const std::string_view className)- Removes a CSS class from the elementToggleClass(const std::string_view className)- Toggles a CSS class on the elementHasClass(const std::string_view className)- Checks if the element has a specific CSS class
Example Usage
HtmlElement div("myDiv");
// Set multiple styles at once
div.SetStyle("color: blue; font-size: 20px; background-color: lightgray;");
// Set individual properties
div.SetProperty("border", "2px solid red");
div.SetProperty("padding", "10px");
// Work with CSS classes
div.AddClass("highlight");
div.AddClass("container");
div.ToggleClass("active");
bool isActive = div.HasClass("active");
div.RemoveClass("highlight");
Benefits
- Type Safety: Compile-time checking of method names and parameters
- Performance: More efficient than constructing HTML strings
- Maintainability: Clear separation between content and styling logic
- Flexibility: Support for both inline styles and CSS classes
- Developer Experience: Intuitive API similar to JavaScript DOM
Examples
Check the examples directory for usage demonstrations:
HelloWorld- Basic usageHelloElement- Creating and manipulating elementsInteractiveElement- Interactive elements with event handlingAllEventHandling- Complete event handling exampleStyleExample- Demonstrates new styling features