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

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.
This commit is contained in:
Andreas Kling 2021-03-25 22:41:40 +01:00
parent 11e190b323
commit 32c6e31f4c
2 changed files with 6 additions and 2 deletions

View file

@ -94,8 +94,8 @@ void Button::paint_event(PaintEvent& event)
}
auto& font = is_checked() ? Gfx::FontDatabase::default_bold_font() : this->font();
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() };

View file

@ -60,6 +60,9 @@ public:
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:
explicit Button(String text = {});
virtual void paint_event(PaintEvent&) override;
@ -69,6 +72,7 @@ private:
Gfx::ButtonStyle m_button_style { Gfx::ButtonStyle::Normal };
Gfx::TextAlignment m_text_alignment { Gfx::TextAlignment::Center };
WeakPtr<Action> m_action;
int m_icon_spacing { 4 };
};
}