Pārlūkot izejas kodu

LibGUI+Applications: Let GlyphMapWidget initialize a null Font

FontEditor will need to clear references to its mutable font in
the future while CharacterMap has no use for the highlights clone,
so let's convert GlyphMapWidget's set_font wrapper into a separate
initialize function for the editor and stop hiding the base function
for others. Setting font null in either ultimately points the map to
the system's default font.
thankyouverycool 2 gadi atpakaļ
vecāks
revīzija
0ad5e85163

+ 1 - 2
Userland/Applications/CharacterMap/CharacterMapWidget.cpp

@@ -167,8 +167,7 @@ ErrorOr<void> CharacterMapWidget::initialize_menubar(GUI::Window& window)
 
 void CharacterMapWidget::did_change_font()
 {
-    // No need to track glyph modifications by cloning
-    m_glyph_map->GUI::AbstractScrollableWidget::set_font(font());
+    m_glyph_map->set_font(font());
     m_font_name_label->set_text(String::from_deprecated_string(font().human_readable_name()).release_value_but_fixme_should_propagate_errors());
     m_output_box->set_font(font());
 }

+ 1 - 1
Userland/Applications/FontEditor/MainWidget.cpp

@@ -637,7 +637,7 @@ ErrorOr<void> MainWidget::initialize(StringView path, RefPtr<Gfx::BitmapFont>&&
     if (m_font == mutable_font)
         return {};
 
-    TRY(m_glyph_map_widget->set_font(*mutable_font));
+    TRY(m_glyph_map_widget->initialize(mutable_font));
 
     auto active_glyph = m_glyph_map_widget->active_glyph();
     m_glyph_map_widget->set_focus(true);

+ 5 - 2
Userland/Libraries/LibGUI/GlyphMapWidget.cpp

@@ -573,9 +573,12 @@ bool GlyphMapWidget::glyph_is_modified(u32 glyph)
     return m_modified_glyphs.contains(glyph);
 }
 
-ErrorOr<void> GlyphMapWidget::set_font(Gfx::Font const& font)
+ErrorOr<void> GlyphMapWidget::initialize(Gfx::Font const* font)
 {
-    m_original_font = TRY(font.try_clone());
+    if (font)
+        m_original_font = TRY(font->try_clone());
+    else
+        m_original_font = nullptr;
     m_modified_glyphs.clear();
     AbstractScrollableWidget::set_font(font);
     return {};

+ 1 - 1
Userland/Libraries/LibGUI/GlyphMapWidget.h

@@ -20,7 +20,7 @@ class GlyphMapWidget final : public AbstractScrollableWidget {
 public:
     virtual ~GlyphMapWidget() override = default;
 
-    ErrorOr<void> set_font(Gfx::Font const&);
+    ErrorOr<void> initialize(Gfx::Font const*);
 
     class Selection {
     public: