Qt: Defer initial layout of game grid

Knocks ~200ms off the startup time.

For some reason, the pixelMetric() call was taking all the time...
This commit is contained in:
Stenzek
2025-12-31 17:53:51 +10:00
parent 170d4b9fb8
commit f03bb5b255
2 changed files with 14 additions and 5 deletions

View File

@@ -2194,11 +2194,14 @@ void GameListWidget::setShowCoverTitles(bool enabled)
Core::SetBaseBoolSettingValue("UI", "GameListShowCoverTitles", enabled);
Host::CommitBaseSettingChanges();
m_model->setShowCoverTitles(enabled);
m_grid_view->updateLayout();
m_grid_view->updateLayout(false);
}
void GameListWidget::setViewMode(int stack_index)
{
if (stack_index == VIEW_MODE_GRID && m_grid_view->isLayoutUpdatedDeferred())
m_grid_view->updateLayout(true);
const int prev_stack_index = m_ui.stack->currentIndex();
m_ui.stack->setCurrentIndex(stack_index);
setFocusProxy(m_ui.stack->currentWidget());
@@ -2628,7 +2631,6 @@ GameListGridView::GameListGridView(GameListModel* model, GameListSortModel* sort
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
verticalScrollBar()->setSingleStep(15);
connect(m_model, &GameListModel::coverScaleChanged, this, &GameListGridView::updateLayout);
updateLayout();
}
GameListGridView::~GameListGridView() = default;
@@ -2655,7 +2657,7 @@ void GameListGridView::wheelEvent(QWheelEvent* e)
void GameListGridView::resizeEvent(QResizeEvent* e)
{
QListView::resizeEvent(e);
updateLayout();
updateLayout(false);
}
void GameListGridView::adjustZoom(float delta)
@@ -2664,8 +2666,11 @@ void GameListGridView::adjustZoom(float delta)
m_model->setCoverScale(new_scale);
}
void GameListGridView::updateLayout()
void GameListGridView::updateLayout(bool disable_defer)
{
if (!disable_defer && m_layout_update_deferred)
return;
const QSize item_size = m_model->getCoverArtItemSize();
const int item_spacing = m_model->getCoverArtSpacing();
const int item_margin = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this) * 2;
@@ -2686,6 +2691,7 @@ void GameListGridView::updateLayout()
m_horizontal_offset = margin;
m_vertical_offset = item_spacing;
m_layout_update_deferred = false;
}
int GameListGridView::horizontalOffset() const

View File

@@ -231,12 +231,14 @@ public:
GameListGridView(GameListModel* model, GameListSortModel* sort_model, QWidget* parent);
~GameListGridView() override;
ALWAYS_INLINE bool isLayoutUpdatedDeferred() const { return m_layout_update_deferred; }
int horizontalOffset() const override;
int verticalOffset() const override;
void adjustZoom(float delta);
void updateLayout();
void updateLayout(bool disable_defer);
protected:
void wheelEvent(QWheelEvent* e) override;
@@ -247,6 +249,7 @@ private:
GameListSortModel* m_sort_model = nullptr;
int m_horizontal_offset = 0;
int m_vertical_offset = 0;
bool m_layout_update_deferred = true;
};
class GameListWidget final : public QWidget