fix: apply same margin to svg buttons as to pixmap buttons (#6085)

Co-authored-by: Nerixyz <nerixdev@outlook.de>
This commit is contained in:
pajlada
2025-03-16 18:09:30 +01:00
committed by GitHub
parent b1279f3e67
commit 95703efb29
4 changed files with 39 additions and 11 deletions
+34 -9
View File
@@ -194,7 +194,23 @@ void Button::paintButton(QPainter &painter)
{
painter.setOpacity(this->getCurrentDimAmount());
this->svgRenderer->render(&painter);
auto rect = this->rect();
if (this->enableMargin_)
{
auto s = this->getMargin();
auto outSize = rect.size() - QSize{2 * s, 2 * s};
outSize = this->svgRenderer->defaultSize().scaled(
outSize, Qt::KeepAspectRatio);
auto margin = rect.size() - outSize;
rect = QRect{
QPoint{margin.width() / 2, margin.height() / 2},
outSize,
};
}
this->svgRenderer->render(&painter, rect);
}
else if (!this->pixmap_.isNull())
{
@@ -205,14 +221,14 @@ void Button::paintButton(QPainter &painter)
resizePixmap(this->resizedPixmap_, this->pixmap_, rect.size(),
this->devicePixelRatio());
int margin = this->height() < 22 * this->scale() ? 3 : 6;
int s = this->enableMargin_ ? int(margin * this->scale()) : 0;
rect.moveLeft(s);
rect.setRight(rect.right() - s - s);
rect.moveTop(s);
rect.setBottom(rect.bottom() - s - s);
if (this->enableMargin_)
{
auto s = this->getMargin();
rect.moveLeft(s);
rect.setRight(rect.right() - s - s);
rect.moveTop(s);
rect.setBottom(rect.bottom() - s - s);
}
painter.drawPixmap(rect, this->resizedPixmap_);
@@ -443,4 +459,13 @@ void Button::showMenu()
this->menuVisible_ = true;
}
int Button::getMargin() const
{
assert(this->enableMargin_);
int baseMargin = this->height() < 22 * this->scale() ? 3 : 6;
return static_cast<int>(baseMargin * this->scale());
}
} // namespace chatterino
+2
View File
@@ -88,6 +88,8 @@ private:
void onMouseEffectTimeout();
void showMenu();
int getMargin() const;
QColor borderColor_{};
QPixmap pixmap_{};
QSvgRenderer *svgRenderer{};
+2 -1
View File
@@ -295,7 +295,8 @@ void SplitInput::updateEmoteButton()
}
this->ui_.emoteButton->setFixedHeight(int(18 * scale));
this->ui_.emoteButton->setFixedWidth(int(18 * scale));
// Make button slightly wider so it's easier to click
this->ui_.emoteButton->setFixedWidth(int(24 * scale));
}
void SplitInput::updateCancelReplyButton()