Skip to content

Commit 4b472dd

Browse files
committed
GameList: Improve grid size calculations
Can't seem to get the width to compute incorrectly on my machine anymore.
1 parent ddaac7e commit 4b472dd

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/duckstation-qt/gamelistwidget.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,22 +2028,19 @@ void GameListGridView::setZoomPct(int int_scale)
20282028

20292029
void GameListGridView::updateLayout()
20302030
{
2031-
const QScrollBar* const vertical_scrollbar = verticalScrollBar();
2032-
const int scrollbar_width = vertical_scrollbar->isVisible() ? vertical_scrollbar->width() : 0;
20332031
const int icon_width = m_model->getCoverArtSize();
20342032
const int item_spacing = m_model->getCoverArtSpacing();
2035-
const int item_margin = style()->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, this);
2036-
2037-
// Split margin+spacing evenly across both sides of each item.
2038-
// I hate this +2. Not sure what's not being accounted for, but without it the calculation is off by 2 pixels...
2039-
const int item_width = icon_width + item_margin + item_spacing + 2;
2033+
const int item_margin = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this) * 2;
2034+
const int item_width = icon_width + item_margin + item_spacing;
20402035

20412036
// one line of text
20422037
const int item_height = item_width + (m_model->getShowCoverTitles() ? fontMetrics().height() : 0);
20432038

2044-
const int available_width = width() - scrollbar_width;
2045-
const int num_columns = available_width / item_width;
2046-
const int num_rows = (height() + (item_height - 1)) / item_height;
2039+
// the -1 here seems to be necessary otherwise we calculate too many columns..
2040+
// can't see where in qlistview.cpp it's coming from though.
2041+
const int available_width = viewport()->width();
2042+
const int num_columns = (available_width - 1) / item_width;
2043+
const int num_rows = (viewport()->height() + (item_height - 1)) / item_height;
20472044
const int margin = (available_width - (num_columns * item_width)) / 2;
20482045

20492046
setGridSize(QSize(item_width, item_height));

src/duckstation-qt/qthost.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ bool QtHost::SetCriticalFolders()
534534
!FileSystem::DirectoryExists(EmuFolders::Resources.c_str())
535535
#ifdef __linux__
536536
// Broken packages that won't stop distributing my application.
537-
|| StringUtil::StartsWithNoCase(EmuFolders::AppRoot, "/usr/lib")
537+
|| StringUtil::StartsWithNoCase(EmuFolders::AppRoot, "/usr""/lib")
538538
#endif
539539
)
540540
{

0 commit comments

Comments
 (0)