diff options
author | Thomas Keppler <winfr34k@gmail.com> | 2021-05-23 17:14:22 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-24 09:08:23 +0100 |
commit | a1f8c10fe5d8a84dabc661ed0d5342b6ac03ab67 (patch) | |
tree | db0f64878b564f23cbd887130e88ec199af0ce8b /Userland/Applications | |
parent | 883d0d24663f9d4ef62a2bd4675791ccbd5acc3e (diff) | |
download | serenity-a1f8c10fe5d8a84dabc661ed0d5342b6ac03ab67.zip |
FontSettingsWidget: Promote Labels as instance members
In order to not resolve the widgets twice, we capture them in ivars.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/DisplaySettings/FontSettingsWidget.cpp | 42 | ||||
-rw-r--r-- | Userland/Applications/DisplaySettings/FontSettingsWidget.h | 4 |
2 files changed, 23 insertions, 23 deletions
diff --git a/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp b/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp index 323df514f2..7bd2eae8e1 100644 --- a/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp +++ b/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp @@ -8,7 +8,6 @@ #include <Applications/DisplaySettings/FontSettingsGML.h> #include <LibGUI/Button.h> #include <LibGUI/FontPicker.h> -#include <LibGUI/Label.h> #include <LibGUI/WindowServerConnection.h> #include <LibGfx/FontDatabase.h> @@ -18,32 +17,31 @@ FontSettingsWidget::FontSettingsWidget() { load_from_gml(font_settings_gml); - auto& default_font_label = *find_descendant_of_type_named<GUI::Label>("default_font_label"); - auto& default_font_button = *find_descendant_of_type_named<GUI::Button>("default_font_button"); - auto& fixed_width_font_label = *find_descendant_of_type_named<GUI::Label>("fixed_width_font_label"); - auto& fixed_width_font_button = *find_descendant_of_type_named<GUI::Button>("fixed_width_font_button"); - auto& default_font = Gfx::FontDatabase::default_font(); - default_font_label.set_font(default_font); - default_font_label.set_text(default_font.qualified_name()); - - auto& default_fixed_width_font = Gfx::FontDatabase::default_fixed_width_font(); - fixed_width_font_label.set_font(default_fixed_width_font); - fixed_width_font_label.set_text(default_fixed_width_font.qualified_name()); + 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()); - default_font_button.on_click = [this, &default_font_label] { - auto font_picker = GUI::FontPicker::construct(window(), &default_font_label.font(), false); + 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) { - default_font_label.set_font(font_picker->font()); - default_font_label.set_text(font_picker->font()->qualified_name()); + m_default_font_label->set_font(font_picker->font()); + m_default_font_label->set_text(font_picker->font()->qualified_name()); } }; - fixed_width_font_button.on_click = [this, &fixed_width_font_label] { - auto font_picker = GUI::FontPicker::construct(window(), &fixed_width_font_label.font(), true); + 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()); + + 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) { - fixed_width_font_label.set_font(font_picker->font()); - fixed_width_font_label.set_text(font_picker->font()->qualified_name()); + m_fixed_width_font_label->set_font(font_picker->font()); + m_fixed_width_font_label->set_text(font_picker->font()->qualified_name()); } }; } @@ -54,9 +52,7 @@ FontSettingsWidget::~FontSettingsWidget() void FontSettingsWidget::apply_settings() { - auto& default_font_label = *find_descendant_of_type_named<GUI::Label>("default_font_label"); - auto& fixed_width_font_label = *find_descendant_of_type_named<GUI::Label>("fixed_width_font_label"); - GUI::WindowServerConnection::the().set_system_fonts(default_font_label.text(), fixed_width_font_label.text()); + GUI::WindowServerConnection::the().set_system_fonts(m_default_font_label->text(), m_fixed_width_font_label->text()); } } diff --git a/Userland/Applications/DisplaySettings/FontSettingsWidget.h b/Userland/Applications/DisplaySettings/FontSettingsWidget.h index f8cb0ab91c..4bd734111e 100644 --- a/Userland/Applications/DisplaySettings/FontSettingsWidget.h +++ b/Userland/Applications/DisplaySettings/FontSettingsWidget.h @@ -6,6 +6,7 @@ #pragma once +#include <LibGUI/Label.h> #include <LibGUI/Widget.h> namespace DisplaySettings { @@ -20,6 +21,9 @@ public: private: FontSettingsWidget(); + + RefPtr<GUI::Label> m_default_font_label; + RefPtr<GUI::Label> m_fixed_width_font_label; }; } |