mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 20:50:59 -05:00
Enable Gui integration of SelectionPropertys
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/selectionproperty.h>
|
||||
#include <openspace/properties/triggerproperty.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
@@ -161,6 +162,29 @@ void renderOptionProperty(Property* prop, const std::string& ownerName) {
|
||||
p->set(value);
|
||||
}
|
||||
|
||||
void renderSelectionProperty(Property* prop, const std::string& ownerName) {
|
||||
SelectionProperty* p = static_cast<SelectionProperty*>(prop);
|
||||
std::string name = p->guiName();
|
||||
|
||||
if (ImGui::CollapsingHeader((ownerName + "." + name).c_str())) {
|
||||
const std::vector<SelectionProperty::Option>& options = p->options();
|
||||
std::vector<int> newSelectedIndices;
|
||||
|
||||
std::vector<int> selectedIndices = p->value();
|
||||
|
||||
for (int i = 0; i < options.size(); ++i) {
|
||||
std::string description = options[i].description;
|
||||
bool selected = std::find(selectedIndices.begin(), selectedIndices.end(), i) != selectedIndices.end();
|
||||
ImGui::Checkbox(description.c_str(), &selected);
|
||||
|
||||
if (selected)
|
||||
newSelectedIndices.push_back(i);
|
||||
}
|
||||
|
||||
p->setValue(std::move(newSelectedIndices));
|
||||
}
|
||||
}
|
||||
|
||||
void renderIntProperty(Property* prop, const std::string& ownerName) {
|
||||
IntProperty* p = static_cast<IntProperty*>(prop);
|
||||
std::string name = p->guiName();
|
||||
@@ -405,6 +429,8 @@ void GUI::registerProperty(properties::Property* prop) {
|
||||
_optionProperty.insert(prop);
|
||||
else if (className == "TriggerProperty")
|
||||
_triggerProperty.insert(prop);
|
||||
else if (className == "SelectionProperty")
|
||||
_selectionProperty.insert(prop);
|
||||
else {
|
||||
LWARNING("Class name '" << className << "' not handled in GUI generation");
|
||||
return;
|
||||
@@ -484,6 +510,10 @@ void GUI::renderPropertyWindow() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_selectionProperty.find(prop) != _selectionProperty.end()) {
|
||||
renderSelectionProperty(prop, p.first);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user