Skip to content

Commit 7b2fb0d

Browse files
authored
Support OptionsGroup widgets (#135)
1 parent 2622ebf commit 7b2fb0d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include <implot.h>
2727
#include <sofa/helper/map.h>
28+
#include <sofa/helper/OptionsGroup.h>
29+
2830

2931
namespace sofaimgui
3032
{
@@ -480,6 +482,31 @@ void DataWidget<std::map<std::string, type::vector<float> > >::showWidget(MyData
480482
showWidgetT(data);
481483
}
482484

485+
/***********************************************************************************************************************
486+
* OptionsGroup
487+
**********************************************************************************************************************/
488+
489+
template<>
490+
void DataWidget<helper::OptionsGroup>::showWidget(MyData& data)
491+
{
492+
const auto& label = data.getName();
493+
const auto id = data.getName() + data.getOwner()->getPathName();
494+
495+
const auto& optionsGroup = data.getValue();
496+
int selectedOption = static_cast<int>(optionsGroup.getSelectedId());
497+
498+
std::unique_ptr<const char*[]> charArray(new const char*[optionsGroup.size()]);
499+
for (unsigned int i = 0; i < optionsGroup.size(); ++i)
500+
{
501+
charArray[i] = optionsGroup[i].c_str();
502+
}
503+
504+
if (ImGui::Combo((label + "##" + id).c_str(), &selectedOption, charArray.get(), static_cast<int>(optionsGroup.size())))
505+
{
506+
helper::WriteAccessor(data)->setSelectedItem(selectedOption);
507+
}
508+
}
509+
483510
/***********************************************************************************************************************
484511
* Factory
485512
**********************************************************************************************************************/
@@ -539,4 +566,6 @@ const bool dw_vector_tri = DataWidgetFactory::Add<type::vector<topology::Triangl
539566
const bool dw_map_vectorf = DataWidgetFactory::Add<std::map<std::string, type::vector<float> > >();
540567
const bool dw_map_vectord = DataWidgetFactory::Add<std::map<std::string, type::vector<double> > >();
541568

569+
const bool dw_optionsGroup = DataWidgetFactory::Add<helper::OptionsGroup>();
570+
542571
}

0 commit comments

Comments
 (0)