Ceral+ImGui Archiver block

Hi all,

I just wrote a small block that links Cinder-Cereal and Cinder-ImGui. It basically gets the data generated by cereal and instead of outputting it to a json/xml/bin file, it builds a couple ImGui controls.

link: GitHub - Hperigo/Cinder-CerealImGui: Bridge between ImGui and Cereal

If you have an object and a serialize function like this:

struct Simple{
    float mFloat = 3.14;
    int   mInt = 42;
    ci::vec2 mVec2 {10, 20};
    
    ci::Color mColor{ 1.0f, 1.0f, 0.0f };
    ci::ColorA mColorAlpha{ 0.0f, 0.0f, 1.0f, 0.5 };
    
    glm::quat mRotation;
    
    std::string mString = "hello world";
};

namespace cereal{
    template<class Archive>
    void serialize(Archive& archive, Simple& simple ){

        archive(
                CEREAL_NVP_("Name", simple.mString),
                simple.mFloat,
                simple.mInt,
                CEREAL_NVP_("position", simple.mVec2),
                CEREAL_NVP_("rotation", simple.mRotation),
                
                CEREAL_NVP_("color", simple.mColor),
            CEREAL_NVP_("colorA", simple.mColorAlpha) );
    }
}

all you need to do in the draw method is call the ImGuiArchive:

Simple simpleObject;

cereal::ImGuiArchive uiArchive;
uiArchive(simpleObject);

and you get a window with these controls:

image

You can also add some options for each element:

    cereal::ImGuiArchive uiAr;
    uiAr.setOption("position", cereal::ImGuiArchive::Options().setMinMax(-10, 10) );
    uiAr.setOption("rotation", cereal::ImGuiArchive::Options().setStep(0.001f) );
    uiAr.setOption("color", cereal::ImGuiArchive::Options().setSpacing(10) );
    uiAr.setOption("2", cereal::ImGuiArchive::Options().setHidden(true) );
    uiAr(simpleObject);

My guess is that if you see yourself using it with very complex objects it’s best to keep things separate (cereal and imgui). But for small things and tests it’s nice to have everything in one go.

some notes:

  1. glm::quat are converted to Euler angles, and back again ( not sure if it’s the best idea)
  2. supported types: int, float, vec2, vec3, Color, ColorA, glm::quat, std::string
  3. imGui names are generated by the CEREAL_NVP_ or the current draw count if no name is provided
  4. if you don’t use CEREAL_NVP_ with vec2, vec3, Color, etc… ImGui will draw each dimension as an float slider ( ColorA creates four sliders, not that nice color widget )
8 Likes