diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp index 88ab9f8de..cd5907784 100644 --- a/WickedEngine/wiGUI.cpp +++ b/WickedEngine/wiGUI.cpp @@ -44,9 +44,11 @@ void wiGUI::Update(const wiCanvas& canvas, float dt) } } - std::sort(widgets.begin(), widgets.end(), [](const wiWidget* a, const wiWidget* b) { - return a->priority < b->priority; - }); + if(priority > 0) //Sort only if there are priority changes + //Use std::stable_sort instead of std::sort to preserve UI element order with equal priorities + std::stable_sort(widgets.begin(), widgets.end(), [](const wiWidget* a, const wiWidget* b) { + return a->priority < b->priority; + }); } void wiGUI::Render(const wiCanvas& canvas, CommandList cmd) const diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index db729a580..424d3c598 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -1727,9 +1727,11 @@ void wiWindow::Update(const wiCanvas& canvas, float dt) } } - std::sort(widgets.begin(), widgets.end(), [](const wiWidget* a, const wiWidget* b) { - return a->priority < b->priority; - }); + if(priority > 0) //Sort only if there are priority changes + //Use std::stable_sort instead of std::sort to preserve UI element order with equal priorities + std::stable_sort(widgets.begin(), widgets.end(), [](const wiWidget* a, const wiWidget* b) { + return a->priority < b->priority; + }); if (IsMinimized()) {