浏览代码

LibGUI: Allow Button::set_icon to accept a bitmap without a move

Previously, Button::set_icon required moving the bitmap into the
button, preventing the same bitmap from being used by multiple
buttons at once. While this works for buttons that are created once,
any button that is dynamically added would require the same bitmap to
be loaded every single time. In addition to being ineffecient, this
also makes error checking more difficult.

With this change, a bitmap can be loaded once, and passed to multiple
buttons.
Dylan Katz 3 年之前
父节点
当前提交
a2a93727db
共有 2 个文件被更改,包括 2 次插入2 次删除
  1. 1 1
      Userland/Libraries/LibGUI/Button.cpp
  2. 1 1
      Userland/Libraries/LibGUI/Button.h

+ 1 - 1
Userland/Libraries/LibGUI/Button.cpp

@@ -134,7 +134,7 @@ void Button::set_action(Action& action)
         set_checked(action.is_checked());
         set_checked(action.is_checked());
 }
 }
 
 
-void Button::set_icon(RefPtr<Gfx::Bitmap>&& icon)
+void Button::set_icon(RefPtr<Gfx::Bitmap> icon)
 {
 {
     if (m_icon == icon)
     if (m_icon == icon)
         return;
         return;

+ 1 - 1
Userland/Libraries/LibGUI/Button.h

@@ -20,7 +20,7 @@ class Button : public AbstractButton {
 public:
 public:
     virtual ~Button() override;
     virtual ~Button() override;
 
 
-    void set_icon(RefPtr<Gfx::Bitmap>&&);
+    void set_icon(RefPtr<Gfx::Bitmap>);
     void set_icon_from_path(String const&);
     void set_icon_from_path(String const&);
     const Gfx::Bitmap* icon() const { return m_icon.ptr(); }
     const Gfx::Bitmap* icon() const { return m_icon.ptr(); }
     Gfx::Bitmap* icon() { return m_icon.ptr(); }
     Gfx::Bitmap* icon() { return m_icon.ptr(); }