diff options
author | Thomas Keppler <winfr34k@gmail.com> | 2021-05-23 18:53:45 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-24 09:08:23 +0100 |
commit | 7dfc804d7d749203974fde1687b9c9c4d6442cea (patch) | |
tree | 115561002d74c28280bf960951e3ad11aadd8f75 /Userland/Applications | |
parent | a1f8c10fe5d8a84dabc661ed0d5342b6ac03ab67 (diff) | |
download | serenity-7dfc804d7d749203974fde1687b9c9c4d6442cea.zip |
FontSettingsWidget: Reduce duplication in Label setup code
Pull out the Label updating code into its own function.
Ideally, we should probably transform this code to use its own widget
rather than doing this all in-line.
I.e., having a `FontSettingWidget` that that ties the FontPicker, Label
and Button into its own little widget, so that we can stay extendible in
the main widget and reduce duplication some more!
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/DisplaySettings/FontSettingsWidget.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp b/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp index 7bd2eae8e1..d3c430a491 100644 --- a/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp +++ b/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Thomas Keppler <winfr34k@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -13,35 +14,33 @@ namespace DisplaySettings { +static void update_label_with_font(GUI::Label&, Gfx::Font const&); + FontSettingsWidget::FontSettingsWidget() { load_from_gml(font_settings_gml); auto& default_font = Gfx::FontDatabase::default_font(); m_default_font_label = *find_descendant_of_type_named<GUI::Label>("default_font_label"); - m_default_font_label->set_font(default_font); - m_default_font_label->set_text(default_font.qualified_name()); + update_label_with_font(*m_default_font_label, default_font); auto& default_font_button = *find_descendant_of_type_named<GUI::Button>("default_font_button"); default_font_button.on_click = [this] { auto font_picker = GUI::FontPicker::construct(window(), &m_default_font_label->font(), false); if (font_picker->exec() == GUI::Dialog::ExecOK) { - m_default_font_label->set_font(font_picker->font()); - m_default_font_label->set_text(font_picker->font()->qualified_name()); + update_label_with_font(*m_default_font_label, *font_picker->font()); } }; auto& default_fixed_width_font = Gfx::FontDatabase::default_fixed_width_font(); m_fixed_width_font_label = *find_descendant_of_type_named<GUI::Label>("fixed_width_font_label"); - m_fixed_width_font_label->set_font(default_fixed_width_font); - m_fixed_width_font_label->set_text(default_fixed_width_font.qualified_name()); + update_label_with_font(*m_fixed_width_font_label, default_fixed_width_font); auto& fixed_width_font_button = *find_descendant_of_type_named<GUI::Button>("fixed_width_font_button"); fixed_width_font_button.on_click = [this] { auto font_picker = GUI::FontPicker::construct(window(), &m_fixed_width_font_label->font(), true); if (font_picker->exec() == GUI::Dialog::ExecOK) { - m_fixed_width_font_label->set_font(font_picker->font()); - m_fixed_width_font_label->set_text(font_picker->font()->qualified_name()); + update_label_with_font(*m_fixed_width_font_label, *font_picker->font()); } }; } @@ -50,6 +49,12 @@ FontSettingsWidget::~FontSettingsWidget() { } +static void update_label_with_font(GUI::Label& label, Gfx::Font const& font) +{ + label.set_text(font.qualified_name()); + label.set_font(font); +} + void FontSettingsWidget::apply_settings() { GUI::WindowServerConnection::the().set_system_fonts(m_default_font_label->text(), m_fixed_width_font_label->text()); |