IMGUI and boost::variant

Hey guys,

Would any of you have a code snippet using boost::variant with IMGUI?

I almost got this working, but can’t get the ImGui::DragScalar to keep my value.

int64_t *pi=boost::get<int64_t>(&prop.value);
ImGui::DragScalar(propertyIdString.c_str(), ImGuiDataType_S64, pi, drag_speed);

I’ll keep digging in the meantime


full example:

auto print =
{
std::string propertyIdString = std::to_string(prop.propertyId);

ImGui::PushItemWidth(20);
ImGui::LabelText("", “%lld”, prop.propertyId);
ImGui::SameLine();
ImGui::PopItemWidth();

if (prop.propertyType == “Int”)
{
const float drag_speed = 0.2f;

int64_t *pi = boost::get<int64_t>(&prop.value);
ImGui::DragScalar(propertyIdString.c_str(), ImGuiDataType_S64, pi, drag_speed);

ImGui::SameLine();
ShowHelpMarker(“An integer property.”);
}
// else if (prop.propertyType == “Float”)
// {
// }
};

std::for_each(m_properties.begin(), m_properties.end(), print);

Problem resolved.
Was missing reference to the lambda.

    auto print = [](__unused YouiNexusEditor::property &prop)
{
    std::string propertyIdString = std::to_string(prop.propertyId);

    ImGui::PushItemWidth(20);
    ImGui::LabelText("", "%lld", prop.propertyId);
    ImGui::SameLine();
    ImGui::PopItemWidth();

    if (prop.propertyType == "Int")
    {
        const float drag_speed = 1.0;

        int64_t &pi = boost::get<int64_t>(prop.value);
        ImGui::DragScalar(propertyIdString.c_str(), ImGuiDataType_S64, &pi, drag_speed);

        ImGui::SameLine();
        ShowHelpMarker("An integer property.");
    }
};

std::for_each(m_properties.begin(), m_properties.end(), print);
1 Like