diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-08-29 19:30:48 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-29 19:30:48 +0200 |
commit | 21ee24b9955467c6dcdd1c95d6f8f555058f127f (patch) | |
tree | e731ffe5be5589fbe91bbb9df4d83ac28e2cebc0 /Libraries/LibGUI | |
parent | cfe09784a40619949412be2262425b16653f806b (diff) | |
download | serenity-21ee24b9955467c6dcdd1c95d6f8f555058f127f.zip |
GFontDatabase: Iterate the font database in alphabetical order
This makes font menus look nicer.
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r-- | Libraries/LibGUI/GFontDatabase.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/Libraries/LibGUI/GFontDatabase.cpp b/Libraries/LibGUI/GFontDatabase.cpp index a8fee8844c..c6712186e8 100644 --- a/Libraries/LibGUI/GFontDatabase.cpp +++ b/Libraries/LibGUI/GFontDatabase.cpp @@ -1,6 +1,7 @@ +#include <AK/QuickSort.h> #include <LibCore/CDirIterator.h> -#include <LibGUI/GFontDatabase.h> #include <LibDraw/Font.h> +#include <LibGUI/GFontDatabase.h> #include <dirent.h> #include <stdio.h> #include <stdlib.h> @@ -40,17 +41,26 @@ GFontDatabase::~GFontDatabase() void GFontDatabase::for_each_font(Function<void(const StringView&)> callback) { - for (auto& it : m_name_to_metadata) { - callback(it.key); - } + Vector<String> names; + names.ensure_capacity(m_name_to_metadata.size()); + for (auto& it : m_name_to_metadata) + names.append(it.key); + quick_sort(names.begin(), names.end(), AK::is_less_than<String>); + for (auto& name : names) + callback(name); } void GFontDatabase::for_each_fixed_width_font(Function<void(const StringView&)> callback) { + Vector<String> names; + names.ensure_capacity(m_name_to_metadata.size()); for (auto& it : m_name_to_metadata) { if (it.value.is_fixed_width) - callback(it.key); + names.append(it.key); } + quick_sort(names.begin(), names.end(), AK::is_less_than<String>); + for (auto& name : names) + callback(name); } RefPtr<Font> GFontDatabase::get_by_name(const StringView& name) |