From 303b54a3a569d746c89962357260c7fb65ad43a5 Mon Sep 17 00:00:00 2001 From: spycrab Date: Fri, 28 Apr 2017 17:35:23 +0200 Subject: [PATCH] Refactor GameListCtrl --- Source/Core/DolphinWX/GameListCtrl.cpp | 106 ++++++++++--------------- Source/Core/DolphinWX/GameListCtrl.h | 4 + 2 files changed, 46 insertions(+), 64 deletions(-) diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index a1bbb00928..000543b1d8 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -273,9 +273,28 @@ static bool ShouldDisplayGameListItem(const GameListItem& item) wxDEFINE_EVENT(DOLPHIN_EVT_RELOAD_GAMELIST, wxCommandEvent); +struct CGameListCtrl::ColumnInfo +{ + const int id; + const int default_width; + const bool resizable; + bool& visible; +}; + CGameListCtrl::CGameListCtrl(wxWindow* parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, long style) - : wxListCtrl(parent, id, pos, size, style), toolTip(nullptr) + : wxListCtrl(parent, id, pos, size, style), toolTip(nullptr), + m_columns({// {COLUMN, {default_width (without platform padding), resizability, visibility}} + {COLUMN_PLATFORM, 32 + 1 /* icon padding */, false, + SConfig::GetInstance().m_showSystemColumn}, + {COLUMN_BANNER, 96, false, SConfig::GetInstance().m_showBannerColumn}, + {COLUMN_TITLE, 175, true, SConfig::GetInstance().m_showTitleColumn}, + {COLUMN_MAKER, 150, true, SConfig::GetInstance().m_showMakerColumn}, + {COLUMN_FILENAME, 100, true, SConfig::GetInstance().m_showFileNameColumn}, + {COLUMN_ID, 75, false, SConfig::GetInstance().m_showIDColumn}, + {COLUMN_COUNTRY, 32, false, SConfig::GetInstance().m_showRegionColumn}, + {COLUMN_EMULATION_STATE, 48, false, SConfig::GetInstance().m_showStateColumn}, + {COLUMN_SIZE, wxLIST_AUTOSIZE, false, SConfig::GetInstance().m_showSizeColumn}}) { Bind(wxEVT_SIZE, &CGameListCtrl::OnSize, this); Bind(wxEVT_RIGHT_DOWN, &CGameListCtrl::OnRightClick, this); @@ -438,29 +457,13 @@ void CGameListCtrl::ReloadList() #else const int platform_padding = 8; #endif - - const int platform_icon_padding = 1; - // set initial sizes for columns SetColumnWidth(COLUMN_DUMMY, 0); - SetColumnWidth(COLUMN_PLATFORM, SConfig::GetInstance().m_showSystemColumn ? - FromDIP(32 + platform_icon_padding + platform_padding) : - 0); - SetColumnWidth(COLUMN_BANNER, - SConfig::GetInstance().m_showBannerColumn ? FromDIP(96 + platform_padding) : 0); - SetColumnWidth(COLUMN_TITLE, - SConfig::GetInstance().m_showTitleColumn ? FromDIP(175 + platform_padding) : 0); - SetColumnWidth(COLUMN_MAKER, - SConfig::GetInstance().m_showMakerColumn ? FromDIP(150 + platform_padding) : 0); - SetColumnWidth(COLUMN_FILENAME, SConfig::GetInstance().m_showFileNameColumn ? - FromDIP(100 + platform_padding) : - 0); - SetColumnWidth(COLUMN_ID, - SConfig::GetInstance().m_showIDColumn ? FromDIP(75 + platform_padding) : 0); - SetColumnWidth(COLUMN_COUNTRY, - SConfig::GetInstance().m_showRegionColumn ? FromDIP(32 + platform_padding) : 0); - SetColumnWidth(COLUMN_EMULATION_STATE, - SConfig::GetInstance().m_showStateColumn ? FromDIP(48 + platform_padding) : 0); + + for (const auto& c : m_columns) + { + SetColumnWidth(c.id, c.visible ? FromDIP(c.default_width + platform_padding) : 0); + } // add all items for (int i = 0; i < (int)m_ISOFiles.size(); i++) @@ -1430,50 +1433,25 @@ void CGameListCtrl::AutomaticColumnWidth() } else if (GetColumnCount() > 0) { - int resizable = - rc.GetWidth() - (GetColumnWidth(COLUMN_PLATFORM) + GetColumnWidth(COLUMN_BANNER) + - GetColumnWidth(COLUMN_ID) + GetColumnWidth(COLUMN_COUNTRY) + - GetColumnWidth(COLUMN_SIZE) + GetColumnWidth(COLUMN_EMULATION_STATE)); - if (SConfig::GetInstance().m_showTitleColumn && SConfig::GetInstance().m_showMakerColumn && - SConfig::GetInstance().m_showFileNameColumn) + int remaining_width = rc.GetWidth(); + std::vector visible_columns; + + for (const auto& c : m_columns) { - SetColumnWidth(COLUMN_TITLE, resizable / 3); - SetColumnWidth(COLUMN_MAKER, resizable / 3); - SetColumnWidth(COLUMN_FILENAME, resizable / 3); - } - else if (SConfig::GetInstance().m_showMakerColumn && - SConfig::GetInstance().m_showFileNameColumn) - { - SetColumnWidth(COLUMN_MAKER, resizable / 2); - SetColumnWidth(COLUMN_FILENAME, resizable / 2); - } - else if (SConfig::GetInstance().m_showMakerColumn && SConfig::GetInstance().m_showTitleColumn) - { - SetColumnWidth(COLUMN_MAKER, resizable / 2); - SetColumnWidth(COLUMN_TITLE, resizable / 2); - } - else if (SConfig::GetInstance().m_showFileNameColumn && - SConfig::GetInstance().m_showTitleColumn) - { - SetColumnWidth(COLUMN_TITLE, resizable / 2); - SetColumnWidth(COLUMN_FILENAME, resizable / 2); - } - else if (SConfig::GetInstance().m_showMakerColumn) - { - SetColumnWidth(COLUMN_MAKER, resizable); - } - else if (SConfig::GetInstance().m_showFileNameColumn) - { - SetColumnWidth(COLUMN_FILENAME, resizable); - } - else if (SConfig::GetInstance().m_showTitleColumn) - { - SetColumnWidth(COLUMN_TITLE, resizable); - } - else - { - SetColumnWidth(COLUMN_DUMMY, resizable); + if (c.visible) + { + if (c.resizable) + visible_columns.push_back(c.id); + else + remaining_width -= c.default_width; + } } + + if (visible_columns.empty()) + visible_columns.push_back(COLUMN_DUMMY); + + for (const int column : visible_columns) + SetColumnWidth(column, static_cast(remaining_width / visible_columns.size())); } Thaw(); } diff --git a/Source/Core/DolphinWX/GameListCtrl.h b/Source/Core/DolphinWX/GameListCtrl.h index 3f5763588a..a7995768c8 100644 --- a/Source/Core/DolphinWX/GameListCtrl.h +++ b/Source/Core/DolphinWX/GameListCtrl.h @@ -67,6 +67,8 @@ public: #endif private: + struct ColumnInfo; + void ReloadList(); void ClearIsoFiles() { m_ISOFiles.clear(); } @@ -117,4 +119,6 @@ private: int last_sort; wxSize lastpos; wxEmuStateTip* toolTip; + + std::vector m_columns; };