Sort resolutions by size
This commit is contained in:
@@ -518,6 +518,7 @@ void DynamicRibbonWidget::clearItems()
|
||||
m_scroll_offset = 0;
|
||||
m_max_label_width = 0;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void DynamicRibbonWidget::elementRemoved()
|
||||
{
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
#include <irrString.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "utils/leak_check.hpp"
|
||||
@@ -237,6 +239,13 @@ namespace GUIEngine
|
||||
'updateItemDisplay' to update the display. */
|
||||
void clearItems();
|
||||
|
||||
/** Sort the list of items with a given comparator. */
|
||||
template<typename Compare>
|
||||
void sortItems(Compare comp)
|
||||
{
|
||||
std::sort(m_items.begin(), m_items.end(), comp);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Register a listener to be notified of selection changes within the ribbon.
|
||||
* \note The ribbon takes ownership of this listener and will delete it.
|
||||
|
||||
@@ -126,6 +126,23 @@ void OptionsScreenVideo::loadedFromFile()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
struct SortResolutions
|
||||
{
|
||||
bool operator()(GUIEngine::ItemDescription i1, GUIEngine::ItemDescription i2)
|
||||
{
|
||||
int w1 = -1, w2 = -1, h1 = -1, h2 = -1;
|
||||
if (sscanf(i1.m_code_name.c_str(), "%ix%i", &w1, &h1) != 2 || w1 == -1 || h1 == -1 ||
|
||||
sscanf(i2.m_code_name.c_str(), "%ix%i", &w2, &h2) != 2 || w2 == -1 || h2 == -1)
|
||||
{
|
||||
Log::error("OptionsScreenVideo", "Failed to decode resolution %s or %s",
|
||||
i1.m_code_name.c_str(), i2.m_code_name.c_str());
|
||||
return false;
|
||||
}
|
||||
return w1 < w2 || (w1 == w2 && h1 < h2);
|
||||
}
|
||||
} sortResolutions;
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void OptionsScreenVideo::init()
|
||||
{
|
||||
Screen::init();
|
||||
@@ -307,6 +324,9 @@ void OptionsScreenVideo::init()
|
||||
res->addItem(L"1024\u00D7768", "1024x768", "/gui/screen43.png");
|
||||
}
|
||||
|
||||
// Sort resolutions by size
|
||||
res->sortItems(sortResolutions);
|
||||
|
||||
} // end if not inited
|
||||
|
||||
res->updateItemDisplay();
|
||||
|
||||
Reference in New Issue
Block a user