mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 03:58:12 +00:00
GFontDatabase: Iterate the font database in alphabetical order
This makes font menus look nicer.
This commit is contained in:
parent
cfe09784a4
commit
21ee24b995
1 changed files with 15 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
|
#include <AK/QuickSort.h>
|
||||||
#include <LibCore/CDirIterator.h>
|
#include <LibCore/CDirIterator.h>
|
||||||
#include <LibGUI/GFontDatabase.h>
|
|
||||||
#include <LibDraw/Font.h>
|
#include <LibDraw/Font.h>
|
||||||
|
#include <LibGUI/GFontDatabase.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -40,17 +41,26 @@ GFontDatabase::~GFontDatabase()
|
||||||
|
|
||||||
void GFontDatabase::for_each_font(Function<void(const StringView&)> callback)
|
void GFontDatabase::for_each_font(Function<void(const StringView&)> callback)
|
||||||
{
|
{
|
||||||
for (auto& it : m_name_to_metadata) {
|
Vector<String> names;
|
||||||
callback(it.key);
|
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)
|
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) {
|
for (auto& it : m_name_to_metadata) {
|
||||||
if (it.value.is_fixed_width)
|
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)
|
RefPtr<Font> GFontDatabase::get_by_name(const StringView& name)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue