1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 19:37:35 +00:00

LibGUI: Add GIcon::default_icon(name).

This is a convenience helper to instantiate a GIcon like so:

    auto icon = GIcon::default_icon("filetype-image");

This will give you the "filetype-image" icon in both 16x16 and 32x32 sizes.
This commit is contained in:
Andreas Kling 2019-03-25 14:46:37 +01:00
parent 43bb7aad4c
commit be604652ae
13 changed files with 16 additions and 7 deletions

View file

@ -57,12 +57,12 @@ DirectoryModel::DirectoryModel()
{ {
create_thread(thumbnail_thread, this); create_thread(thumbnail_thread, this);
m_directory_icon = GIcon(GraphicsBitmap::load_from_file("/res/icons/folder16.png"), GraphicsBitmap::load_from_file("/res/icons/32x32/folder.png")); m_directory_icon = GIcon::default_icon("filetype-folder");
m_file_icon = GIcon(GraphicsBitmap::load_from_file("/res/icons/file16.png"), GraphicsBitmap::load_from_file("/res/icons/32x32/file.png")); m_file_icon = GIcon::default_icon("filetype-unknown");
m_symlink_icon = GIcon(GraphicsBitmap::load_from_file("/res/icons/link16.png")); m_symlink_icon = GIcon::default_icon("filetype-symlink");
m_socket_icon = GIcon(GraphicsBitmap::load_from_file("/res/icons/socket16.png")); m_socket_icon = GIcon::default_icon("filetype-socket");
m_executable_icon = GIcon(GraphicsBitmap::load_from_file("/res/icons/executable16.png"), GraphicsBitmap::load_from_file("/res/icons/32x32/filetype-executable.png")); m_executable_icon = GIcon::default_icon("filetype-executable");
m_filetype_image_icon = GIcon(GraphicsBitmap::load_from_file("/res/icons/16x16/filetype-image.png"), GraphicsBitmap::load_from_file("/res/icons/32x32/filetype-image.png")); m_filetype_image_icon = GIcon::default_icon("filetype-image");
setpwent(); setpwent();
while (auto* passwd = getpwent()) while (auto* passwd = getpwent())

View file

@ -71,7 +71,7 @@ GWindow* make_launcher_window()
new LauncherButton("/res/icons/Terminal.png", "/bin/Terminal", widget); new LauncherButton("/res/icons/Terminal.png", "/bin/Terminal", widget);
new LauncherButton("/res/icons/FontEditor.png", "/bin/FontEditor", widget); new LauncherButton("/res/icons/FontEditor.png", "/bin/FontEditor", widget);
new LauncherButton("/res/icons/folder32.png", "/bin/FileManager", widget); new LauncherButton("/res/icons/32x32/filetype-folder.png", "/bin/FileManager", widget);
new LauncherButton("/res/icons/TextEditor.png", "/bin/TextEditor", widget); new LauncherButton("/res/icons/TextEditor.png", "/bin/TextEditor", widget);
return window; return window;

View file

Before

Width:  |  Height:  |  Size: 879 B

After

Width:  |  Height:  |  Size: 879 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 272 B

After

Width:  |  Height:  |  Size: 272 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 904 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 335 B

View file

@ -61,3 +61,10 @@ void GIconImpl::set_bitmap_for_size(int size, RetainPtr<GraphicsBitmap>&& bitmap
} }
m_bitmaps.set(size, move(bitmap)); m_bitmaps.set(size, move(bitmap));
} }
GIcon GIcon::default_icon(const String& name)
{
auto bitmap16 = GraphicsBitmap::load_from_file(String::format("/res/icons/16x16/%s.png", name.characters()));
auto bitmap32 = GraphicsBitmap::load_from_file(String::format("/res/icons/32x32/%s.png", name.characters()));
return GIcon(move(bitmap16), move(bitmap32));
}

View file

@ -25,6 +25,8 @@ public:
GIcon(const GIcon&); GIcon(const GIcon&);
~GIcon() { } ~GIcon() { }
static GIcon default_icon(const String&);
GIcon& operator=(const GIcon& other) GIcon& operator=(const GIcon& other)
{ {
m_impl = other.m_impl.copy_ref(); m_impl = other.m_impl.copy_ref();