list position fixed

This commit is contained in:
DawnFire42 2026-06-08 21:08:04 -04:00
parent 7ca066389f
commit 6837cc52c1
No known key found for this signature in database
GPG key ID: 24BB855EE2911B33
2 changed files with 26 additions and 7 deletions

View file

@ -182,7 +182,7 @@ void GameView::clearSubtypeLabels()
QtUtils::clearLayoutRec(subtypeCountLayout);
}
void GameView::rebuildSubtypeLabels(const QList<SubtypeEntry> &entries)
QSize GameView::rebuildSubtypeLabels(const QList<SubtypeEntry> &entries)
{
clearSubtypeLabels();
@ -190,6 +190,10 @@ void GameView::rebuildSubtypeLabels(const QList<SubtypeEntry> &entries)
const QString countStyle =
QStringLiteral("color: white; font-size: 14px; font-weight: bold; background: transparent;");
int totalHeight = 0;
int maxNameWidth = 0;
int maxCountWidth = 0;
int row = 0;
for (const SubtypeEntry &entry : entries) {
auto *nameLabel = new QLabel(entry.name, subtypeCountContainer);
@ -202,8 +206,23 @@ void GameView::rebuildSubtypeLabels(const QList<SubtypeEntry> &entries)
countLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
subtypeCountLayout->addWidget(countLabel, row, 1);
QSize nameSize = nameLabel->sizeHint();
QSize countSize = countLabel->sizeHint();
maxNameWidth = qMax(maxNameWidth, nameSize.width());
maxCountWidth = qMax(maxCountWidth, countSize.width());
totalHeight += qMax(nameSize.height(), countSize.height());
++row;
}
int spacing = subtypeCountLayout->spacing();
int margins = subtypeCountLayout->contentsMargins().left() + subtypeCountLayout->contentsMargins().right();
int verticalMargins = subtypeCountLayout->contentsMargins().top() + subtypeCountLayout->contentsMargins().bottom();
int width = maxNameWidth + spacing + maxCountWidth + margins;
int height = totalHeight + (row - 1) * spacing + verticalMargins;
return QSize(width, height);
}
void GameView::updateSelectionCount(const QSize &viewSize)
@ -255,16 +274,16 @@ void GameView::updateSelectionCount(const QSize &viewSize)
return;
}
rebuildSubtypeLabels(entries);
subtypeCountContainer->adjustSize();
QSize containerSize = rebuildSubtypeLabels(entries);
subtypeCountContainer->resize(containerSize);
int x = availableWidth - subtypeCountContainer->width() - kMarginInPixels;
int x = availableWidth - containerSize.width() - kMarginInPixels;
int y;
if (totalCountLabel->isVisible()) {
y = totalCountLabel->y() - subtypeCountContainer->height() - kSpacingBetweenLabels;
y = totalCountLabel->y() - containerSize.height() - kSpacingBetweenLabels;
} else {
y = availableHeight - subtypeCountContainer->height() - kMarginInPixels;
y = availableHeight - containerSize.height() - kMarginInPixels;
}
y = qMax(kMarginInPixels, y);

View file

@ -27,7 +27,7 @@ private:
QGridLayout *subtypeCountLayout; ///< Grid layout for subtype name/count pairs
QPointF selectionOrigin;
void rebuildSubtypeLabels(const QList<SubtypeEntry> &entries);
QSize rebuildSubtypeLabels(const QList<SubtypeEntry> &entries);
void clearSubtypeLabels();
protected: