mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 18:47:44 +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
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)
|
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> bitmap16;
|
||||||
RefPtr<Gfx::Bitmap> bitmap32;
|
RefPtr<Gfx::Bitmap> bitmap32;
|
||||||
|
@ -81,13 +86,9 @@ Icon Icon::default_icon(StringView name)
|
||||||
bitmap16 = bitmap_or_error.release_value();
|
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())
|
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();
|
bitmap32 = bitmap_or_error.release_value();
|
||||||
return Icon(move(bitmap16), move(bitmap32));
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorOr<Icon> Icon::try_create_default_icon(StringView name)
|
if (!bitmap16 && !bitmap32)
|
||||||
{
|
return Error::from_string_literal("Default icon not found"sv);
|
||||||
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)));
|
|
||||||
|
|
||||||
return Icon(move(bitmap16), move(bitmap32));
|
return Icon(move(bitmap16), move(bitmap32));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue