From 186de9fe4d9a2b11a5f448cfb11f702b066990fe Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 20 Dec 2021 19:26:34 +0100 Subject: [PATCH] LibGUI: Make GUI::try_create_default_icon() tolerate single-size icons Some icons only exist in 16x16 and we should still allow them to be loaded via the LibGUI default icon system. This patch also reimplements GUI::default_icon() as a MUST() wrapper around try_create_default_icon(). --- Userland/Libraries/LibGUI/Icon.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibGUI/Icon.cpp b/Userland/Libraries/LibGUI/Icon.cpp index b4aebf43b8..aa592bc624 100644 --- a/Userland/Libraries/LibGUI/Icon.cpp +++ b/Userland/Libraries/LibGUI/Icon.cpp @@ -74,6 +74,11 @@ void IconImpl::set_bitmap_for_size(int size, RefPtr&& bitmap) } Icon Icon::default_icon(StringView name) +{ + return MUST(try_create_default_icon(name)); +} + +ErrorOr Icon::try_create_default_icon(StringView name) { RefPtr bitmap16; RefPtr bitmap32; @@ -81,13 +86,9 @@ Icon Icon::default_icon(StringView name) bitmap16 = bitmap_or_error.release_value(); if (auto bitmap_or_error = Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/32x32/{}.png", name)); !bitmap_or_error.is_error()) bitmap32 = bitmap_or_error.release_value(); - return Icon(move(bitmap16), move(bitmap32)); -} -ErrorOr Icon::try_create_default_icon(StringView name) -{ - RefPtr bitmap16 = TRY(Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/16x16/{}.png", name))); - RefPtr bitmap32 = TRY(Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/32x32/{}.png", name))); + if (!bitmap16 && !bitmap32) + return Error::from_string_literal("Default icon not found"sv); return Icon(move(bitmap16), move(bitmap32)); }