summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-30 18:04:36 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-30 20:37:51 +0100
commit8fe1643c4bbec97286791233e979a6d0b9d4747a (patch)
treeb2d1cf92ceea705051e166ed8c77cc402da1cf04
parent34ae57092832cc28b960446ca83b5032a71aa8da (diff)
downloadserenity-8fe1643c4bbec97286791233e979a6d0b9d4747a.zip
LibGUI: Make FontPicker correctly select the current font when opened
-rw-r--r--Libraries/LibGUI/FontPicker.cpp21
-rw-r--r--Libraries/LibGUI/FontPicker.h2
2 files changed, 16 insertions, 7 deletions
diff --git a/Libraries/LibGUI/FontPicker.cpp b/Libraries/LibGUI/FontPicker.cpp
index 5fe9efd918..9204b47419 100644
--- a/Libraries/LibGUI/FontPicker.cpp
+++ b/Libraries/LibGUI/FontPicker.cpp
@@ -85,7 +85,7 @@ FontPicker::FontPicker(Window* parent_window, const Gfx::Font* current_font, boo
m_weight_list_view->set_model(ItemListModel<int>::create(m_weights));
m_weight_list_view->set_cursor(m_weight_list_view->model()->index(index_of_old_weight_in_new_list.value_or(0)), GUI::AbstractView::SelectionUpdate::Set);
- update_sample_label();
+ update_font();
};
m_weight_list_view->on_selection = [this](auto& index) {
@@ -104,12 +104,12 @@ FontPicker::FontPicker(Window* parent_window, const Gfx::Font* current_font, boo
m_size_list_view->set_model(ItemListModel<int>::create(m_sizes));
m_size_list_view->set_cursor(m_size_list_view->model()->index(index_of_old_size_in_new_list.value_or(0)), GUI::AbstractView::SelectionUpdate::Set);
- update_sample_label();
+ update_font();
};
m_size_list_view->on_selection = [this](auto& index) {
m_size = index.data().to_i32();
- update_sample_label();
+ update_font();
};
auto& ok_button = static_cast<Button&>(*widget.find_descendant_by_name("ok_button"));
@@ -137,6 +137,9 @@ void FontPicker::set_font(const Gfx::Font* font)
m_sample_text_label->set_font(m_font);
if (!m_font) {
+ m_family = {};
+ m_weight = {};
+ m_size = {};
m_weights.clear();
m_sizes.clear();
m_weight_list_view->set_model(nullptr);
@@ -144,6 +147,10 @@ void FontPicker::set_font(const Gfx::Font* font)
return;
}
+ m_family = font->family();
+ m_weight = font->weight();
+ m_size = font->presentation_size();
+
size_t family_index = 0;
for (size_t i = 0; i < m_families.size(); ++i) {
if (m_families[i] == m_font->family()) {
@@ -175,10 +182,12 @@ void FontPicker::set_font(const Gfx::Font* font)
m_size_list_view->set_cursor(m_size_list_view->model()->index(size_index), GUI::AbstractView::SelectionUpdate::Set);
}
-void FontPicker::update_sample_label()
+void FontPicker::update_font()
{
- if (m_family.has_value() && m_size.has_value() && m_weight.has_value())
- set_font(Gfx::FontDatabase::the().get(m_family.value(), m_size.value(), m_weight.value()));
+ if (m_family.has_value() && m_size.has_value() && m_weight.has_value()) {
+ m_font = Gfx::FontDatabase::the().get(m_family.value(), m_size.value(), m_weight.value());
+ m_sample_text_label->set_font(m_font);
+ }
}
}
diff --git a/Libraries/LibGUI/FontPicker.h b/Libraries/LibGUI/FontPicker.h
index a1d388342a..89ba8143f6 100644
--- a/Libraries/LibGUI/FontPicker.h
+++ b/Libraries/LibGUI/FontPicker.h
@@ -43,7 +43,7 @@ public:
private:
FontPicker(Window* parent_window = nullptr, const Gfx::Font* current_font = nullptr, bool fixed_width_only = false);
- void update_sample_label();
+ void update_font();
const bool m_fixed_width_only;