diff --git a/include/Engine/Editor/EditorGUI.h b/include/Engine/Editor/EditorGUI.h index 973f6a90..c2cd1001 100644 --- a/include/Engine/Editor/EditorGUI.h +++ b/include/Engine/Editor/EditorGUI.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "../Common.h" #include "../GLM.h" #include @@ -118,6 +119,7 @@ private: const std::string formatEntityName(EntityWrapper entity); GLuint tryLoadTexture(std::string filePath); void openModal(const std::string& modal); + static bool compareCharArray(const char* c1, const char* c2); // Entity file handling methods void entityImport(World* world); diff --git a/src/Engine/Editor/EditorGUI.cpp b/src/Engine/Editor/EditorGUI.cpp index 1200ce34..0d747b86 100644 --- a/src/Engine/Editor/EditorGUI.cpp +++ b/src/Engine/Editor/EditorGUI.cpp @@ -234,10 +234,12 @@ void EditorGUI::drawComponents(EntityWrapper entity) componentTypes.push_back(pair.first.c_str()); } } + // Sort components in alphabetical order + std::sort(componentTypes.begin(), componentTypes.end(), compareCharArray); // Draw combo box ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() - 10.f); 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 (m_OnComponentAttach != nullptr) { std::string chosenComponentType(componentTypes.at(selectedItem)); @@ -644,6 +646,11 @@ void EditorGUI::openModal(const std::string& modal) m_ModalsToOpen.insert(modal); } +bool EditorGUI::compareCharArray(const char* c1, const char* c2) +{ + return strcmp(c1, c2) < 0; +} + void EditorGUI::SetDirty(EntityWrapper entity) { EntityWrapper baseParent = entity;