Model-View-ViewModel (MVVM) support library for modern C++.
This library is header-only, and it is recommended to use CMake.
- CMake 3.30 or newer
- g++ 16 (Not released now. You can acquire it from prebuilt package or build from source code by yourself.)
FTM (Feature-Test Macros) Requirements:
__cpp_impl_reflection__cpp_lib_define_static
Build examples with CMake:
mkdir build && cd build
cmake ..
cmake --build .
#include <iostream>
#include <mvvm/mvvm.hpp>
class ViewModel {
friend class mvvm::ObservableObject<ViewModel>;
[[=mvvm::ObservableProperty()]]
int property = -1;
[[=mvvm::ObservableProperty()]]
int another_property = -1;
public:
void OnPropertyChanging(int value) {
std::cout << "onChanging " << value << " " << property << std::endl;
}
void OnPropertyChanged(int value) {
std::cout << "onChanged " << value << " " << property << std::endl;
}
void OnAnotherPropertyChanged(int value) {
std::cout << "onChanged another " << value << " " << another_property << std::endl;
}
};
int main() {
mvvm::ObservableObject<ViewModel> view_model;
view_model->property = 10;
// onChanging 10 -1
// onChanged 10 10
view_model->another_property = 20;
// onChanged another 20 20
}