small perf improvements, add auto resize

Signed-off-by: crueter <crueter@eden-emu.dev>
This commit is contained in:
crueter 2026-02-06 22:25:02 -05:00
parent 8527f6952f
commit ac930b1e96
No known key found for this signature in database
GPG Key ID: 425ACD2D4830EBC6
3 changed files with 42 additions and 16 deletions

View File

@ -19,7 +19,7 @@ void GameCard::paint(QPainter* painter, const QStyleOptionViewItem& option,
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
// padding // padding
QRect cardRect = option.rect.adjusted(4, 4, -4, -4); QRect cardRect = option.rect.adjusted(4 + m_padding / 2, 4, -4 - m_padding / 2, -4);
// colors // colors
QPalette palette = option.palette; QPalette palette = option.palette;
@ -58,7 +58,6 @@ void GameCard::paint(QPainter* painter, const QStyleOptionViewItem& option,
iconRect = QRect(x, y, scaledSize.width(), scaledSize.height()); iconRect = QRect(x, y, scaledSize.width(), scaledSize.height());
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setRenderHint(QPainter::SmoothPixmapTransform, true); painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
// Put this in a separate thing on the painter stack to prevent clipping the text. // Put this in a separate thing on the painter stack to prevent clipping the text.
@ -114,6 +113,7 @@ QSize GameCard::sizeHint(const QStyleOptionViewItem& option, const QModelIndex&
return m_size; return m_size;
} }
void GameCard::setSize(const QSize& newSize) { void GameCard::setSize(const QSize& newSize, const int padding) {
m_size = newSize; m_size = newSize;
m_padding = padding;
} }

View File

@ -20,8 +20,9 @@ public:
QSize sizeHint(const QStyleOptionViewItem &option, QSize sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const override; const QModelIndex &index) const override;
void setSize(const QSize& newSize); void setSize(const QSize& newSize, const int padding);
private: private:
QSize m_size; QSize m_size;
int m_padding;
}; };

View File

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
#include <QAbstractItemView>
#include <QApplication> #include <QApplication>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
@ -13,13 +14,11 @@
#include <QMenu> #include <QMenu>
#include <QScrollBar> #include <QScrollBar>
#include <QScroller> #include <QScroller>
#include <QScrollerProperties>
#include <QThreadPool> #include <QThreadPool>
#include <QToolButton> #include <QToolButton>
#include <QVariantAnimation> #include <QVariantAnimation>
#include <fmt/ranges.h> #include <fmt/ranges.h>
#include <QAbstractItemView>
#include <QScroller>
#include <QScrollerProperties>
#include <qnamespace.h> #include <qnamespace.h>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/logging/log.h" #include "common/logging/log.h"
@ -29,6 +28,7 @@
#include "core/file_sys/registered_cache.h" #include "core/file_sys/registered_cache.h"
#include "game/game_card.h" #include "game/game_card.h"
#include "qt_common/config/uisettings.h" #include "qt_common/config/uisettings.h"
#include "qt_common/qt_common.h"
#include "qt_common/util/game.h" #include "qt_common/util/game.h"
#include "yuzu/compatibility_list.h" #include "yuzu/compatibility_list.h"
#include "yuzu/game/game_list.h" #include "yuzu/game/game_list.h"
@ -36,7 +36,6 @@
#include "yuzu/game/game_list_worker.h" #include "yuzu/game/game_list_worker.h"
#include "yuzu/main_window.h" #include "yuzu/main_window.h"
#include "yuzu/util/controller_navigation.h" #include "yuzu/util/controller_navigation.h"
#include "qt_common/qt_common.h"
GameListSearchField::KeyReleaseEater::KeyReleaseEater(GameList* gamelist_, QObject* parent) GameListSearchField::KeyReleaseEater::KeyReleaseEater(GameList* gamelist_, QObject* parent)
: QObject(parent), gamelist{gamelist_} {} : QObject(parent), gamelist{gamelist_} {}
@ -394,9 +393,9 @@ GameList::GameList(FileSys::VirtualFilesystem vfs_, FileSys::ManualContentProvid
tree_view->setStyleSheet(QStringLiteral("QTreeView{ border: none; }")); tree_view->setStyleSheet(QStringLiteral("QTreeView{ border: none; }"));
// list view setup // list view setup
list_view->setViewMode(QListView::IconMode); list_view->setViewMode(QListView::ListMode);
list_view->setResizeMode(QListView::Adjust); list_view->setResizeMode(QListView::Fixed);
list_view->setUniformItemSizes(false); list_view->setUniformItemSizes(true);
list_view->setSelectionMode(QAbstractItemView::SingleSelection); list_view->setSelectionMode(QAbstractItemView::SingleSelection);
list_view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); list_view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
list_view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); list_view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
@ -408,7 +407,7 @@ GameList::GameList(FileSys::VirtualFilesystem vfs_, FileSys::ManualContentProvid
list_view->setEditTriggers(QAbstractItemView::NoEditTriggers); list_view->setEditTriggers(QAbstractItemView::NoEditTriggers);
list_view->setContextMenuPolicy(Qt::CustomContextMenu); list_view->setContextMenuPolicy(Qt::CustomContextMenu);
list_view->setGridSize(QSize(140, 160)); list_view->setGridSize(QSize(140, 160));
m_gameCard->setSize(list_view->gridSize()); m_gameCard->setSize(list_view->gridSize(), 0);
list_view->setSpacing(10); list_view->setSpacing(10);
list_view->setWordWrap(true); list_view->setWordWrap(true);
@ -1039,9 +1038,28 @@ void GameList::UpdateIconSize() {
heightMargin = 24; heightMargin = 24;
} }
// TODO(crueter): Auto size // "auto" resize //
list_view->setGridSize(QSize(icon_size + widthMargin, icon_size + heightMargin)); const int view_width = list_view->viewport()->width();
m_gameCard->setSize(list_view->gridSize());
// Tiny space padding to prevent the list view from forcing its own resize operation.
const double spacing = 0.01;
const int min_item_width = icon_size + widthMargin;
// And now stretch it a bit to fill out remaining space.
// Not perfect but works well enough for now
int columns = std::max(1, view_width / min_item_width);
int stretched_width = (view_width - (spacing * (columns - 1))) / columns;
// only updates things if grid size is changed
QSize grid_size(stretched_width, icon_size + heightMargin);
if (list_view->gridSize() != grid_size) {
list_view->setUpdatesEnabled(false);
list_view->setGridSize(grid_size);
m_gameCard->setSize(grid_size, stretched_width - min_item_width);
list_view->setUpdatesEnabled(true);
}
} }
void GameList::PopulateAsync(QVector<UISettings::GameDir>& game_dirs) { void GameList::PopulateAsync(QVector<UISettings::GameDir>& game_dirs) {
@ -1054,7 +1072,8 @@ void GameList::PopulateAsync(QVector<UISettings::GameDir>& game_dirs) {
tree_view->setColumnHidden(COLUMN_SIZE, !UISettings::values.show_size); tree_view->setColumnHidden(COLUMN_SIZE, !UISettings::values.show_size);
tree_view->setColumnHidden(COLUMN_PLAY_TIME, !UISettings::values.show_play_time); tree_view->setColumnHidden(COLUMN_PLAY_TIME, !UISettings::values.show_play_time);
UpdateIconSize(); if (!m_isTreeMode)
UpdateIconSize();
// Cancel any existing worker. // Cancel any existing worker.
current_worker.reset(); current_worker.reset();
@ -1288,6 +1307,12 @@ bool GameList::eventFilter(QObject* obj, QEvent* event) {
m_currentView->setCurrentIndex(QModelIndex()); m_currentView->setCurrentIndex(QModelIndex());
} }
} }
if (obj == list_view->viewport() && event->type() == QEvent::Resize) {
UpdateIconSize();
return true;
}
return QWidget::eventFilter(obj, event); return QWidget::eventFilter(obj, event);
} }