summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-30 17:47:27 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-30 20:37:51 +0100
commit7e40c7cf998a42882426bcfd74551499d284296e (patch)
treeebd3e9e2686c8e303a1225f00b711e9fb6205b8f
parentddaa526769680adbe5a5204d4221d64873905b4c (diff)
downloadserenity-7e40c7cf998a42882426bcfd74551499d284296e.zip
LibGUI: Allow GUI::FilePicker to show only fixed-width fonts
This is useful when you really only want something monospaced. :^)
-rw-r--r--Libraries/LibGUI/FontPicker.cpp9
-rw-r--r--Libraries/LibGUI/FontPicker.h4
2 files changed, 11 insertions, 2 deletions
diff --git a/Libraries/LibGUI/FontPicker.cpp b/Libraries/LibGUI/FontPicker.cpp
index cde2a09ede..5fe9efd918 100644
--- a/Libraries/LibGUI/FontPicker.cpp
+++ b/Libraries/LibGUI/FontPicker.cpp
@@ -35,8 +35,9 @@
namespace GUI {
-FontPicker::FontPicker(Window* parent_window, const Gfx::Font* current_font)
+FontPicker::FontPicker(Window* parent_window, const Gfx::Font* current_font, bool fixed_width_only)
: Dialog(parent_window)
+ , m_fixed_width_only(fixed_width_only)
{
set_title("Font picker");
resize(540, 300);
@@ -53,6 +54,8 @@ FontPicker::FontPicker(Window* parent_window, const Gfx::Font* current_font)
HashTable<String> families;
Gfx::FontDatabase::the().for_each_font([&](auto& font) {
+ if (m_fixed_width_only && !font.is_fixed_width())
+ return;
families.set(font.family());
});
@@ -65,6 +68,8 @@ FontPicker::FontPicker(Window* parent_window, const Gfx::Font* current_font)
m_family = index.data().to_string();
HashTable<int> weights;
Gfx::FontDatabase::the().for_each_font([&](auto& font) {
+ if (m_fixed_width_only && !font.is_fixed_width())
+ return;
if (font.family() == m_family.value())
weights.set(font.weight());
});
@@ -88,6 +93,8 @@ FontPicker::FontPicker(Window* parent_window, const Gfx::Font* current_font)
m_sizes.clear();
Optional<size_t> index_of_old_size_in_new_list;
Gfx::FontDatabase::the().for_each_font([&](auto& font) {
+ if (m_fixed_width_only && !font.is_fixed_width())
+ return;
if (font.family() == m_family.value() && font.weight() == m_weight.value()) {
if (m_size.has_value() && m_size.value() == font.presentation_size())
index_of_old_size_in_new_list = m_sizes.size();
diff --git a/Libraries/LibGUI/FontPicker.h b/Libraries/LibGUI/FontPicker.h
index 28a4d73450..a1d388342a 100644
--- a/Libraries/LibGUI/FontPicker.h
+++ b/Libraries/LibGUI/FontPicker.h
@@ -41,10 +41,12 @@ public:
void set_font(const Gfx::Font*);
private:
- FontPicker(Window* parent_window = nullptr, const Gfx::Font* current_font = nullptr);
+ FontPicker(Window* parent_window = nullptr, const Gfx::Font* current_font = nullptr, bool fixed_width_only = false);
void update_sample_label();
+ const bool m_fixed_width_only;
+
RefPtr<Gfx::Font> m_font;
RefPtr<ListView> m_family_list_view;