瀏覽代碼

LibGUI: Make it possible to tweak icon spacing on a GUI::Button

This is the space between the icon and the text on buttons that have
both icon and text.
Andreas Kling 4 年之前
父節點
當前提交
32c6e31f4c
共有 2 個文件被更改,包括 6 次插入2 次删除
  1. 2 2
      Userland/Libraries/LibGUI/Button.cpp
  2. 4 0
      Userland/Libraries/LibGUI/Button.h

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

@@ -94,8 +94,8 @@ void Button::paint_event(PaintEvent& event)
     }
     }
     auto& font = is_checked() ? Gfx::FontDatabase::default_bold_font() : this->font();
     auto& font = is_checked() ? Gfx::FontDatabase::default_bold_font() : this->font();
     if (m_icon && !text().is_empty()) {
     if (m_icon && !text().is_empty()) {
-        content_rect.move_by(m_icon->width() + 4, 0);
-        content_rect.set_width(content_rect.width() - m_icon->width() - 4);
+        content_rect.move_by(m_icon->width() + icon_spacing(), 0);
+        content_rect.set_width(content_rect.width() - m_icon->width() - icon_spacing());
     }
     }
 
 
     Gfx::IntRect text_rect { 0, 0, font.width(text()), font.glyph_height() };
     Gfx::IntRect text_rect { 0, 0, font.width(text()), font.glyph_height() };

+ 4 - 0
Userland/Libraries/LibGUI/Button.h

@@ -60,6 +60,9 @@ public:
 
 
     virtual bool is_uncheckable() const override;
     virtual bool is_uncheckable() const override;
 
 
+    int icon_spacing() const { return m_icon_spacing; }
+    void set_icon_spacing(int spacing) { m_icon_spacing = spacing; }
+
 protected:
 protected:
     explicit Button(String text = {});
     explicit Button(String text = {});
     virtual void paint_event(PaintEvent&) override;
     virtual void paint_event(PaintEvent&) override;
@@ -69,6 +72,7 @@ private:
     Gfx::ButtonStyle m_button_style { Gfx::ButtonStyle::Normal };
     Gfx::ButtonStyle m_button_style { Gfx::ButtonStyle::Normal };
     Gfx::TextAlignment m_text_alignment { Gfx::TextAlignment::Center };
     Gfx::TextAlignment m_text_alignment { Gfx::TextAlignment::Center };
     WeakPtr<Action> m_action;
     WeakPtr<Action> m_action;
+    int m_icon_spacing { 4 };
 };
 };
 
 
 }
 }