Skip to content

Commit

Permalink
Support OptionsGroup widgets (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbilger authored Oct 23, 2024
1 parent 2622ebf commit 7b2fb0d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include <implot.h>
#include <sofa/helper/map.h>
#include <sofa/helper/OptionsGroup.h>


namespace sofaimgui
{
Expand Down Expand Up @@ -480,6 +482,31 @@ void DataWidget<std::map<std::string, type::vector<float> > >::showWidget(MyData
showWidgetT(data);
}

/***********************************************************************************************************************
* OptionsGroup
**********************************************************************************************************************/

template<>
void DataWidget<helper::OptionsGroup>::showWidget(MyData& data)
{
const auto& label = data.getName();
const auto id = data.getName() + data.getOwner()->getPathName();

const auto& optionsGroup = data.getValue();
int selectedOption = static_cast<int>(optionsGroup.getSelectedId());

std::unique_ptr<const char*[]> charArray(new const char*[optionsGroup.size()]);
for (unsigned int i = 0; i < optionsGroup.size(); ++i)
{
charArray[i] = optionsGroup[i].c_str();
}

if (ImGui::Combo((label + "##" + id).c_str(), &selectedOption, charArray.get(), static_cast<int>(optionsGroup.size())))
{
helper::WriteAccessor(data)->setSelectedItem(selectedOption);
}
}

/***********************************************************************************************************************
* Factory
**********************************************************************************************************************/
Expand Down Expand Up @@ -539,4 +566,6 @@ const bool dw_vector_tri = DataWidgetFactory::Add<type::vector<topology::Triangl
const bool dw_map_vectorf = DataWidgetFactory::Add<std::map<std::string, type::vector<float> > >();
const bool dw_map_vectord = DataWidgetFactory::Add<std::map<std::string, type::vector<double> > >();

const bool dw_optionsGroup = DataWidgetFactory::Add<helper::OptionsGroup>();

}

0 comments on commit 7b2fb0d

Please sign in to comment.