C++ bindings for browser DOM api's
Find a file
2025-11-10 22:06:27 +01:00
additional style 2025-11-10 22:06:27 +01:00
examples style 2025-11-10 22:06:27 +01:00
implementations style 2025-11-10 22:06:27 +01:00
interfaces style 2025-11-10 22:06:27 +01:00
.gitignore added HtmlElement class 2025-02-12 23:06:56 +01:00
hello.png Initial commit 2025-01-02 02:48:44 +01:00
LICENSE Initial commit 2025-01-02 02:48:44 +01:00
project.json split 2025-11-10 21:52:23 +01:00
README.md style 2025-11-10 22:06:27 +01:00

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 once
  • SetProperty(const std::string_view property, const std::string_view value) - Sets a single CSS property
  • AddClass(const std::string_view className) - Adds a CSS class to the element
  • RemoveClass(const std::string_view className) - Removes a CSS class from the element
  • ToggleClass(const std::string_view className) - Toggles a CSS class on the element
  • HasClass(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

  1. Type Safety: Compile-time checking of method names and parameters
  2. Performance: More efficient than constructing HTML strings
  3. Maintainability: Clear separation between content and styling logic
  4. Flexibility: Support for both inline styles and CSS classes
  5. Developer Experience: Intuitive API similar to JavaScript DOM

Examples

Check the examples directory for usage demonstrations:

  • HelloWorld - Basic usage
  • HelloElement - Creating and manipulating elements
  • InteractiveElement - Interactive elements with event handling
  • AllEventHandling - Complete event handling example
  • StyleExample - Demonstrates new styling features