Sorted editor component dropdown and made it always be fully expanded to show as many components as possible

This commit is contained in:
2016-01-27 17:07:48 +01:00
parent 788407b709
commit 4b7613a659
2 changed files with 10 additions and 1 deletions
+2
View File
@@ -7,6 +7,7 @@
#include <nativefiledialog/nfd.h> #include <nativefiledialog/nfd.h>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/any.hpp> #include <boost/any.hpp>
#include <boost/sort/spreadsort/string_sort.hpp>
#include "../Common.h" #include "../Common.h"
#include "../GLM.h" #include "../GLM.h"
#include <glm/gtx/common.hpp> #include <glm/gtx/common.hpp>
@@ -118,6 +119,7 @@ private:
const std::string formatEntityName(EntityWrapper entity); const std::string formatEntityName(EntityWrapper entity);
GLuint tryLoadTexture(std::string filePath); GLuint tryLoadTexture(std::string filePath);
void openModal(const std::string& modal); void openModal(const std::string& modal);
static bool compareCharArray(const char* c1, const char* c2);
// Entity file handling methods // Entity file handling methods
void entityImport(World* world); void entityImport(World* world);
+8 -1
View File
@@ -234,10 +234,12 @@ void EditorGUI::drawComponents(EntityWrapper entity)
componentTypes.push_back(pair.first.c_str()); componentTypes.push_back(pair.first.c_str());
} }
} }
// Sort components in alphabetical order
std::sort(componentTypes.begin(), componentTypes.end(), compareCharArray);
// Draw combo box // Draw combo box
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() - 10.f); ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() - 10.f);
int selectedItem = -1; int selectedItem = -1;
if (ImGui::Combo("", &selectedItem, componentTypes.data(), componentTypes.size())) { if (ImGui::Combo("", &selectedItem, componentTypes.data(), componentTypes.size(), componentTypes.size())) {
if (selectedItem != -1) { if (selectedItem != -1) {
if (m_OnComponentAttach != nullptr) { if (m_OnComponentAttach != nullptr) {
std::string chosenComponentType(componentTypes.at(selectedItem)); std::string chosenComponentType(componentTypes.at(selectedItem));
@@ -644,6 +646,11 @@ void EditorGUI::openModal(const std::string& modal)
m_ModalsToOpen.insert(modal); m_ModalsToOpen.insert(modal);
} }
bool EditorGUI::compareCharArray(const char* c1, const char* c2)
{
return strcmp(c1, c2) < 0;
}
void EditorGUI::SetDirty(EntityWrapper entity) void EditorGUI::SetDirty(EntityWrapper entity)
{ {
EntityWrapper baseParent = entity; EntityWrapper baseParent = entity;