1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00

LibGUI: Add a setting to make GLabel stretch its icon.

Use this in QuickShow to allow arbitrarily scaling the opened image.
This commit is contained in:
Andreas Kling 2019-03-22 04:20:48 +01:00
parent 86570d3b1a
commit d563dc0565
3 changed files with 38 additions and 4 deletions

View file

@ -34,11 +34,16 @@ void GLabel::paint_event(GPaintEvent& event)
{
Painter painter(*this);
painter.set_clip_rect(event.rect());
if (fill_with_background_color())
painter.fill_rect({ 0, 0, width(), height() }, background_color());
if (m_icon) {
auto icon_location = rect().center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2));
painter.blit(icon_location, *m_icon, m_icon->rect());
if (m_should_stretch_icon) {
painter.draw_scaled_bitmap(rect(), *m_icon, m_icon->rect());
} else {
auto icon_location = rect().center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2));
painter.blit(icon_location, *m_icon, m_icon->rect());
}
}
if (!text().is_empty())
painter.draw_text({ 0, 0, width(), height() }, text(), m_text_alignment, foreground_color());