Some minor code cleanup.

This commit is contained in:
Leon Styhre 2022-01-17 20:47:30 +01:00
parent a6be6225d8
commit 2ebfb45bdf
3 changed files with 31 additions and 33 deletions

View file

@ -308,9 +308,7 @@ bool ISimpleGamelistView::input(InputConfig* config, Input input)
else else
favoritesSorting = Settings::getInstance()->getBool("FavoritesFirst"); favoritesSorting = Settings::getInstance()->getBool("FavoritesFirst");
if (favoritesSorting && if (favoritesSorting && mRoot->getSystem()->getName() != "recent" && !isEditing) {
static_cast<std::string>(mRoot->getSystem()->getName()) != "recent" &&
!isEditing) {
FileData* entryToSelect; FileData* entryToSelect;
// Add favorite flag. // Add favorite flag.
if (!getCursor()->getFavorite()) { if (!getCursor()->getFavorite()) {

View file

@ -119,8 +119,8 @@ public:
if (!mEnabled) if (!mEnabled)
return true; return true;
// Move selection to previous. // Move selection to previous.
unsigned int i = getSelectedId(); unsigned int i {getSelectedId()};
int next = static_cast<int>(i) - 1; int next {static_cast<int>(i) - 1};
if (next < 0) if (next < 0)
next += static_cast<int>(mEntries.size()); next += static_cast<int>(mEntries.size());
@ -143,7 +143,7 @@ public:
if (!mEnabled) if (!mEnabled)
return true; return true;
// Move selection to next. // Move selection to next.
unsigned int i = getSelectedId(); unsigned int i {getSelectedId()};
int next = (i + 1) % mEntries.size(); int next = (i + 1) % mEntries.size();
mEntries.at(i).selected = false; mEntries.at(i).selected = false;
mEntries.at(next).selected = true; mEntries.at(next).selected = true;
@ -424,7 +424,7 @@ private:
auto font = Font::get(FONT_SIZE_MEDIUM); auto font = Font::get(FONT_SIZE_MEDIUM);
ComponentListRow row; ComponentListRow row;
bool hasSelectedRow = false; bool hasSelectedRow {false};
// If the exclusive selection flag has been set, i.e. only a single row can be selected // If the exclusive selection flag has been set, i.e. only a single row can be selected
// at a time, then make sure to gray out and disable any non-selected rows. // at a time, then make sure to gray out and disable any non-selected rows.
@ -452,7 +452,7 @@ private:
textComponent.get()->setEnabled(false); textComponent.get()->setEnabled(false);
} }
OptionListData& e = *it; OptionListData& e {*it};
if (mParent->mMultiSelect) { if (mParent->mMultiSelect) {
// Add checkbox. // Add checkbox.
@ -468,8 +468,8 @@ private:
// Update checkbox state and selected value. // Update checkbox state and selected value.
row.makeAcceptInputHandler([this, &e, checkbox] { row.makeAcceptInputHandler([this, &e, checkbox] {
auto list = mMenu.getList(); auto list = mMenu.getList();
int cursorId = list->getCursorId(); int cursorId {list->getCursorId()};
bool isEnabled = list->getChild(cursorId * 2)->getEnabled(); bool isEnabled {list->getChild(cursorId * 2)->getEnabled()};
if (mParent->mMultiExclusiveSelect && !isEnabled) if (mParent->mMultiExclusiveSelect && !isEnabled)
return; return;
@ -483,7 +483,7 @@ private:
if (mParent->mMultiExclusiveSelect) { if (mParent->mMultiExclusiveSelect) {
for (unsigned int i = 0; i < mParent->mEntries.size(); ++i) { for (unsigned int i = 0; i < mParent->mEntries.size(); ++i) {
bool isSelected = mParent->mEntries[cursorId].selected; bool isSelected {mParent->mEntries[cursorId].selected};
for (unsigned int i = 0; i < list->getChildCount(); i += 2) { for (unsigned int i = 0; i < list->getChildCount(); i += 2) {
if (i == static_cast<unsigned int>(cursorId) * 2) if (i == static_cast<unsigned int>(cursorId) * 2)

View file

@ -6,8 +6,8 @@
// Text list used for displaying and navigating the gamelist views. // Text list used for displaying and navigating the gamelist views.
// //
#ifndef ES_APP_COMPONENTS_TEXT_LIST_COMPONENT_H #ifndef ES_CORE_COMPONENTS_TEXT_LIST_COMPONENT_H
#define ES_APP_COMPONENTS_TEXT_LIST_COMPONENT_H #define ES_CORE_COMPONENTS_TEXT_LIST_COMPONENT_H
#include "Log.h" #include "Log.h"
#include "Sound.h" #include "Sound.h"
@ -135,8 +135,8 @@ private:
template <typename T> template <typename T>
TextListComponent<T>::TextListComponent(Window* window) TextListComponent<T>::TextListComponent(Window* window)
: IList<TextListData, T>(window) : IList<TextListData, T> {window}
, mSelectorImage(window) , mSelectorImage {window}
{ {
mLoopOffset = 0; mLoopOffset = 0;
mLoopOffset2 = 0; mLoopOffset2 = 0;
@ -192,7 +192,7 @@ template <typename T> void TextListComponent<T>::render(const glm::mat4& parentT
startEntry = size() - screenCount; startEntry = size() - screenCount;
} }
int listCutoff = startEntry + screenCount; int listCutoff {startEntry + screenCount};
if (listCutoff > size()) if (listCutoff > size())
listCutoff = size(); listCutoff = size();
@ -229,7 +229,7 @@ template <typename T> void TextListComponent<T>::render(const glm::mat4& parentT
static_cast<int>(std::round(dim.y))}); static_cast<int>(std::round(dim.y))});
for (int i = startEntry; i < listCutoff; ++i) { for (int i = startEntry; i < listCutoff; ++i) {
typename IList<TextListData, T>::Entry& entry = mEntries.at(static_cast<unsigned int>(i)); typename IList<TextListData, T>::Entry& entry {mEntries.at(static_cast<unsigned int>(i))};
unsigned int color; unsigned int color;
if (mCursor == i && mSelectedColor) if (mCursor == i && mSelectedColor)
@ -360,21 +360,21 @@ template <typename T> void TextListComponent<T>::update(int deltaTime)
mLoopOffset2 = 0; mLoopOffset2 = 0;
// If we're not scrolling and this object's text exceeds our size, then loop it. // If we're not scrolling and this object's text exceeds our size, then loop it.
const float textLength = mFont const float textLength {mFont
->sizeText(Utils::String::toUpper( ->sizeText(Utils::String::toUpper(
mEntries.at(static_cast<unsigned int>(mCursor)).name)) mEntries.at(static_cast<unsigned int>(mCursor)).name))
.x; .x};
const float limit = mSize.x - mHorizontalMargin * 2.0f; const float limit {mSize.x - mHorizontalMargin * 2.0f};
if (textLength > limit) { if (textLength > limit) {
// Loop the text. // Loop the text.
const float speed = mFont->sizeText("ABCDEFGHIJKLMNOPQRSTUVWXYZ").x * 0.247f; const float speed {mFont->sizeText("ABCDEFGHIJKLMNOPQRSTUVWXYZ").x * 0.247f};
const float delay = 3000.0f; const float delay {3000.0f};
const float scrollLength = textLength; const float scrollLength {textLength};
const float returnLength = speed * 1.5f; const float returnLength {speed * 1.5f};
const float scrollTime = (scrollLength * 1000.0f) / speed; const float scrollTime {(scrollLength * 1000.0f) / speed};
const float returnTime = (returnLength * 1000.0f) / speed; const float returnTime {(returnLength * 1000.0f) / speed};
const int maxTime = static_cast<int>(delay + scrollTime + returnTime); const int maxTime {static_cast<int>(delay + scrollTime + returnTime)};
mLoopTime += deltaTime; mLoopTime += deltaTime;
while (mLoopTime > maxTime) while (mLoopTime > maxTime)
@ -423,7 +423,7 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
{ {
GuiComponent::applyTheme(theme, view, element, properties); GuiComponent::applyTheme(theme, view, element, properties);
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "textlist"); const ThemeData::ThemeElement* elem {theme->getElement(view, element, "textlist")};
if (!elem) if (!elem)
return; return;
@ -447,8 +447,8 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
setFont(Font::getFromTheme(elem, properties, mFont)); setFont(Font::getFromTheme(elem, properties, mFont));
const float selectorHeight = const float selectorHeight {
std::max(mFont->getHeight(1.0), static_cast<float>(mFont->getSize())) * mLineSpacing; std::max(mFont->getHeight(1.0), static_cast<float>(mFont->getSize())) * mLineSpacing};
setSelectorHeight(selectorHeight); setSelectorHeight(selectorHeight);
if (properties & ALIGNMENT) { if (properties & ALIGNMENT) {
@ -501,4 +501,4 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
} }
#endif // ES_APP_COMPONENTS_TEXT_LIST_COMPONENT_H #endif // ES_CORE_COMPONENTS_TEXT_LIST_COMPONENT_H