Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/asklar/cppwinrtbuilders
Provides builder-style helpers for WinRT objects
https://github.com/asklar/cppwinrtbuilders
Last synced: 4 days ago
JSON representation
Provides builder-style helpers for WinRT objects
- Host: GitHub
- URL: https://github.com/asklar/cppwinrtbuilders
- Owner: asklar
- License: mit
- Created: 2022-07-17T05:14:47.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-06T23:20:35.000Z (9 months ago)
- Last Synced: 2024-08-30T12:59:33.891Z (about 1 month ago)
- Language: C#
- Size: 215 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# CppWinRT.Builders
Add-on NuGet package to generate C++ builder-style helpers for WinRT objects.
### Motivation
In C++/WinRT, setters are implemented as method calls that return `void`.
This means that creating a button from code looks like:```cpp
auto button = Controls::Button();
button.Height(40);
button.Width(200);
button.Content(winrt::box_value(L"Hello"));
```This can get repetitive, and some developers prefer a more fluent style.
*CppWinRT.Builders* enables you to write this instead:```cpp
#include
auto button = Controls::builders::Button()
.Height(40)
.Width(200)
.Content(winrt::box_value(L"Hello"));
```Collections (such as types that derive from `IVector` and `IMap`) can also be initialized via C++ initializer lists:
```cpp
auto sp = Controls::builders::StackPanel{}
.Children({
Controls::builders::Button{}
.Height(40)
.Width(200)
.Content(winrt::box_value(L"Hello")),
Controls::builders::Button{}
.Height(40)
.Width(200)
.Content(winrt::box_value(L"world")),
})
.Resources({
{ winrt::box_value(L"SomeKey"), winrt::box_value(42) }
})
.Background(Media::SolidColorBrush{ Windows::UI::Colors::AliceBlue() })
.Padding(ThicknessHelper::FromUniformLength(8))
.Orientation(Controls::Orientation::Horizontal);
```### Formatters
The tool in this package also generates string formatters for enums.
To use:
```cpp
#include// ...
auto visibility = Visibility::Collapsed;
std::wcout << visibility << std::endl; // prints "Collapsed"
```