mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-07 00:56:14 +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:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user