Skip to content

alexcui03/libmvvm

Repository files navigation

libmvvm

Model-View-ViewModel (MVVM) support library for modern C++.

This library is header-only, and it is recommended to use CMake.

Requirements

  • 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

Usage

Build examples with CMake:

mkdir build && cd build
cmake ..
cmake --build .

Example

#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
}

Reference

About

Model-View-ViewModel (MVVM) support library for modern C++.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors