Crafter.CppDOM/README.md

53 lines
1.9 KiB
Markdown
Raw Normal View History

2025-11-10 22:06:27 +01:00
# Crafter.CppDOM
2025-01-02 02:48:44 +01:00
2025-11-10 22:06:27 +01:00
A C++ DOM library for web applications that allows you to manipulate HTML elements directly from C++.
2025-01-02 02:48:44 +01:00
2025-11-10 22:06:27 +01:00
## New Styling Features
2025-01-02 02:48:44 +01:00
2025-11-10 22:06:27 +01:00
This library now supports comprehensive styling capabilities beyond just inline HTML:
2025-02-21 03:52:46 +01:00
2025-11-10 22:06:27 +01:00
### Style Methods
2025-02-21 03:52:46 +01:00
2025-11-10 22:06:27 +01:00
- `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
2025-02-21 03:52:46 +01:00
2025-01-02 02:48:44 +01:00
```cpp
2025-11-10 22:06:27 +01:00
HtmlElement div("myDiv");
2025-01-02 02:48:44 +01:00
2025-11-10 22:06:27 +01:00
// 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");
2025-01-02 02:48:44 +01:00
```
2025-02-21 03:52:46 +01:00
2025-11-10 22:06:27 +01:00
### 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
2025-02-12 22:22:06 +01:00
2025-11-10 22:06:27 +01:00
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