ui/sidebar: Fix the inconsistent padding in different languages. (#28746)

cleanup
pull/28760/head
Dean Lee 2 years ago committed by GitHub
parent 3e1ba3ff35
commit 7ac22a0d7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      selfdrive/ui/qt/onroad.cc
  2. 10
      selfdrive/ui/qt/sidebar.cc
  3. 6
      selfdrive/ui/qt/util.cc
  4. 1
      selfdrive/ui/qt/util.h

@ -391,7 +391,7 @@ void AnnotatedCameraWidget::drawHud(QPainter &p) {
}
void AnnotatedCameraWidget::drawText(QPainter &p, int x, int y, const QString &text, int alpha) {
QRect real_rect = getTextRect(p, 0, text);
QRect real_rect = p.fontMetrics().boundingRect(text);
real_rect.moveCenter({x, y - real_rect.height() / 2});
p.setPen(QColor(0xff, 0xff, 0xff, alpha));

@ -21,15 +21,7 @@ void Sidebar::drawMetric(QPainter &p, const QPair<QString, QString> &label, QCol
p.setPen(QColor(0xff, 0xff, 0xff));
configFont(p, "Inter", 35, "SemiBold");
QRect label_rect = getTextRect(p, Qt::AlignCenter, label.first);
label_rect.setWidth(218);
label_rect.moveLeft(rect.left() + 22);
label_rect.moveTop(rect.top() + 19);
p.drawText(label_rect, Qt::AlignCenter, label.first);
label_rect.moveTop(rect.top() + 65);
p.drawText(label_rect, Qt::AlignCenter, label.second);
p.drawText(rect.adjusted(22, 0, 0, 0), Qt::AlignCenter, label.first + "\n" + label.second);
}
Sidebar::Sidebar(QWidget *parent) : QFrame(parent), onroad(false), flag_pressed(false), settings_pressed(false) {

@ -162,12 +162,6 @@ QPixmap loadPixmap(const QString &fileName, const QSize &size, Qt::AspectRatioMo
}
}
QRect getTextRect(QPainter &p, int flags, const QString &text) {
QFontMetrics fm(p.font());
QRect init_rect = fm.boundingRect(text);
return fm.boundingRect(init_rect, flags, text);
}
void drawRoundedRect(QPainter &painter, const QRectF &rect, qreal xRadiusTop, qreal yRadiusTop, qreal xRadiusBottom, qreal yRadiusBottom){
qreal w_2 = rect.width() / 2;
qreal h_2 = rect.height() / 2;

@ -25,6 +25,5 @@ QWidget* topWidget (QWidget* widget);
QPixmap loadPixmap(const QString &fileName, const QSize &size = {}, Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
QPixmap bootstrapPixmap(const QString &id);
QRect getTextRect(QPainter &p, int flags, const QString &text);
void drawRoundedRect(QPainter &painter, const QRectF &rect, qreal xRadiusTop, qreal yRadiusTop, qreal xRadiusBottom, qreal yRadiusBottom);
QColor interpColor(float xv, std::vector<float> xp, std::vector<QColor> fp);

Loading…
Cancel
Save