mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
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().
This commit is contained in:
parent
452a5531be
commit
186de9fe4d
Notes:
sideshowbarker
2024-07-17 22:33:00 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/186de9fe4d9
1 changed files with 7 additions and 6 deletions
|
@ -74,6 +74,11 @@ void IconImpl::set_bitmap_for_size(int size, RefPtr<Gfx::Bitmap>&& bitmap)
|
|||
}
|
||||
|
||||
Icon Icon::default_icon(StringView name)
|
||||
{
|
||||
return MUST(try_create_default_icon(name));
|
||||
}
|
||||
|
||||
ErrorOr<Icon> Icon::try_create_default_icon(StringView name)
|
||||
{
|
||||
RefPtr<Gfx::Bitmap> bitmap16;
|
||||
RefPtr<Gfx::Bitmap> 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> Icon::try_create_default_icon(StringView name)
|
||||
{
|
||||
RefPtr<Gfx::Bitmap> bitmap16 = TRY(Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/16x16/{}.png", name)));
|
||||
RefPtr<Gfx::Bitmap> 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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue