applist: Use enums to explictly describe value checks

This commit is contained in:
Joel16 2022-06-28 13:46:14 -04:00
parent 5c630b6195
commit 4144652b09
3 changed files with 23 additions and 23 deletions

View File

@ -10,6 +10,17 @@ typedef struct {
extern config_t cfg;
enum SortBy {
SortTitle,
SortTitleID
};
enum SortFolders {
SortBoth,
SortAppsOnly,
SortFoldersOnly
};
namespace Config {
int Save(config_t &config);
int Load(void);

View File

@ -206,8 +206,8 @@ namespace AppList {
}
bool SortAppAsc(const AppInfoIcon &entryA, const AppInfoIcon &entryB) {
std::string entryAname = cfg.sort_by == 0? entryA.title : entryA.titleId;
std::string entryBname = cfg.sort_by == 0? entryB.title : entryB.titleId;
std::string entryAname = cfg.sort_by == SortTitle? entryA.title : entryA.titleId;
std::string entryBname = cfg.sort_by == SortTitle? entryB.title : entryB.titleId;
std::transform(entryAname.begin(), entryAname.end(), entryAname.begin(), [](unsigned char c){ return std::tolower(c); });
std::transform(entryBname.begin(), entryBname.end(), entryBname.begin(), [](unsigned char c){ return std::tolower(c); });
@ -219,8 +219,8 @@ namespace AppList {
}
bool SortAppDesc(const AppInfoIcon &entryA, const AppInfoIcon &entryB) {
std::string entryAname = cfg.sort_by == 0? entryA.title : entryA.titleId;
std::string entryBname = cfg.sort_by == 0? entryB.title : entryB.titleId;
std::string entryAname = cfg.sort_by == SortTitle? entryA.title : entryA.titleId;
std::string entryBname = cfg.sort_by == SortTitle? entryB.title : entryB.titleId;
std::transform(entryAname.begin(), entryAname.end(), entryAname.begin(), [](unsigned char c){ return std::tolower(c); });
std::transform(entryBname.begin(), entryBname.end(), entryBname.begin(), [](unsigned char c){ return std::tolower(c); });
@ -232,8 +232,8 @@ namespace AppList {
}
bool SortChildAppAsc(const AppInfoChild &entryA, const AppInfoChild &entryB) {
std::string entryAname = cfg.sort_by == 0? entryA.title : entryA.titleId;
std::string entryBname = cfg.sort_by == 0? entryB.title : entryB.titleId;
std::string entryAname = cfg.sort_by == SortTitle? entryA.title : entryA.titleId;
std::string entryBname = cfg.sort_by == SortTitle? entryB.title : entryB.titleId;
std::transform(entryAname.begin(), entryAname.end(), entryAname.begin(), [](unsigned char c){ return std::tolower(c); });
std::transform(entryBname.begin(), entryBname.end(), entryBname.begin(), [](unsigned char c){ return std::tolower(c); });
@ -245,8 +245,8 @@ namespace AppList {
}
bool SortChildAppDesc(const AppInfoChild &entryA, const AppInfoChild &entryB) {
std::string entryAname = cfg.sort_by == 0? entryA.title : entryA.titleId;
std::string entryBname = cfg.sort_by == 0? entryB.title : entryB.titleId;
std::string entryAname = cfg.sort_by == SortTitle? entryA.title : entryA.titleId;
std::string entryBname = cfg.sort_by == SortTitle? entryB.title : entryB.titleId;
std::transform(entryAname.begin(), entryAname.end(), entryAname.begin(), [](unsigned char c){ return std::tolower(c); });
std::transform(entryBname.begin(), entryBname.end(), entryBname.begin(), [](unsigned char c){ return std::tolower(c); });
@ -268,7 +268,7 @@ namespace AppList {
}
// App/Game belongs to a folder
if ((entries.icons[i].pageNo < 0) && (cfg.sort_folders == 0 || cfg.sort_folders == 2)) {
if ((entries.icons[i].pageNo < 0) && (cfg.sort_folders == SortBoth || cfg.sort_folders == SortFoldersOnly)) {
for (unsigned int j = 0; j < entries.folders.size(); j++) {
if (entries.icons[i].pageId == entries.folders[j].pageId) {
entries.icons[i].pos = entries.folders[j].index;
@ -276,7 +276,7 @@ namespace AppList {
}
}
}
else if ((entries.icons[i].pageNo >= 0) && (cfg.sort_folders == 0 || cfg.sort_folders == 1)) {
else if ((entries.icons[i].pageNo >= 0) && (cfg.sort_folders == SortBoth || cfg.sort_folders == SortAppsOnly)) {
entries.icons[i].pos = pos;
entries.icons[i].pageId = entries.pages[pageCounter].pageId;
pos++;

View File

@ -42,17 +42,6 @@ namespace GUI {
StateError
};
enum SortBy {
SortTitle,
SortTitleID
};
enum SortFolders {
SortBoth,
SortAppsOnly,
SortFoldersOnly
};
enum SortMode {
SortDefault,
SortAsc,
@ -543,9 +532,9 @@ namespace GUI {
if (ImGui::Begin("VITA Homebrew Sorter", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse)) {
if (ImGui::BeginTabBar("VITA Homebrew Sorter tabs")) {
GUI::SortTab(entries, state);
GUI::DisableButtonInit(cfg.beta_features? false : true);
GUI::DisableButtonInit(!cfg.beta_features);
GUI::LoadoutsTab(loadouts, state, date_format, loadout_name);
GUI::DisableButtonExit(cfg.beta_features? false : true);
GUI::DisableButtonExit(!cfg.beta_features);
GUI::SettingsTab();
ImGui::EndTabBar();
}