Some code cleanup.

This commit is contained in:
Leon Styhre 2022-10-09 17:59:27 +02:00
parent 565c4a1187
commit 50832a5b64
2 changed files with 26 additions and 26 deletions

View file

@ -134,7 +134,7 @@ void ComponentList::update(int deltaTime)
mLoopTime = 0; mLoopTime = 0;
} }
const float totalHeight = getTotalRowHeight(); const float totalHeight {getTotalRowHeight()};
// Scroll indicator logic, used by ScrollIndicatorComponent. // Scroll indicator logic, used by ScrollIndicatorComponent.
bool scrollIndicatorChanged = false; bool scrollIndicatorChanged = false;
@ -236,17 +236,17 @@ void ComponentList::onCursorChanged(const CursorState& state)
void ComponentList::updateCameraOffset() void ComponentList::updateCameraOffset()
{ {
float oldCameraOffset = mCameraOffset; float oldCameraOffset {mCameraOffset};
// Move the camera to scroll. // Move the camera to scroll.
const float totalHeight = getTotalRowHeight(); const float totalHeight {getTotalRowHeight()};
if (totalHeight > mSize.y) { if (totalHeight > mSize.y) {
float target = float target {mSelectorBarOffset + getRowHeight(mEntries.at(mCursor).data) / 2.0f -
mSelectorBarOffset + getRowHeight(mEntries.at(mCursor).data) / 2.0f - (mSize.y / 2.0f); (mSize.y / 2.0f)};
// Clamp the camera to prevent a fraction of a row from being displayed. // Clamp the camera to prevent a fraction of a row from being displayed.
mCameraOffset = 0.0f; mCameraOffset = 0.0f;
unsigned int i = 0; unsigned int i {0};
while (mCameraOffset < target && i < mEntries.size()) { while (mCameraOffset < target && i < mEntries.size()) {
mCameraOffset += getRowHeight(mEntries.at(i).data); mCameraOffset += getRowHeight(mEntries.at(i).data);
if (mCameraOffset > totalHeight - mSize.y) { if (mCameraOffset > totalHeight - mSize.y) {
@ -305,7 +305,7 @@ void ComponentList::render(const glm::mat4& parentTrans)
// Draw our entries. // Draw our entries.
std::vector<GuiComponent*> drawAfterCursor; std::vector<GuiComponent*> drawAfterCursor;
bool drawAll; bool drawAll {false};
for (size_t i = 0; i < mEntries.size(); ++i) { for (size_t i = 0; i < mEntries.size(); ++i) {
if (mLoopRows && mFocused && mLoopOffset > 0) { if (mLoopRows && mFocused && mLoopOffset > 0) {
@ -337,16 +337,16 @@ void ComponentList::render(const glm::mat4& parentTrans)
if (mFocused && i == static_cast<size_t>(mCursor) && if (mFocused && i == static_cast<size_t>(mCursor) &&
it->component->getValue() != "") { it->component->getValue() != "") {
// Check if we're dealing with text or an image component. // Check if we're dealing with text or an image component.
bool isTextComponent = true; bool isTextComponent {true};
unsigned int origColor = it->component->getColor(); unsigned int origColor {it->component->getColor()};
if (origColor == 0) { if (origColor == 0) {
origColor = it->component->getColorShift(); origColor = it->component->getColorShift();
isTextComponent = false; isTextComponent = false;
} }
// Check if the color is neutral. // Check if the color is neutral.
unsigned char byteRed = origColor >> 24 & 0xFF; unsigned char byteRed {static_cast<unsigned char>(origColor >> 24 & 0xFF)};
unsigned char byteGreen = origColor >> 16 & 0xFF; unsigned char byteGreen {static_cast<unsigned char>(origColor >> 16 & 0xFF)};
unsigned char byteBlue = origColor >> 8 & 0xFF; unsigned char byteBlue {static_cast<unsigned char>(origColor >> 8 & 0xFF)};
// If it's neutral, just proceed with normal rendering. // If it's neutral, just proceed with normal rendering.
if (byteRed == byteGreen && byteGreen == byteBlue) { if (byteRed == byteGreen && byteGreen == byteBlue) {
renderLoopFunc(); renderLoopFunc();
@ -379,7 +379,7 @@ void ComponentList::render(const glm::mat4& parentTrans)
// Draw selector bar. // Draw selector bar.
if (mFocused) { if (mFocused) {
const float selectedRowHeight = getRowHeight(mEntries.at(mCursor).data); const float selectedRowHeight {getRowHeight(mEntries.at(mCursor).data)};
if (mOpacity == 1.0f) { if (mOpacity == 1.0f) {
mRenderer->drawRect(0.0f, mSelectorBarOffset, std::round(mSize.x), selectedRowHeight, mRenderer->drawRect(0.0f, mSelectorBarOffset, std::round(mSize.x), selectedRowHeight,
@ -401,7 +401,7 @@ void ComponentList::render(const glm::mat4& parentTrans)
} }
// Draw separators. // Draw separators.
float y = 0; float y {0.0f};
for (unsigned int i = 0; i < mEntries.size(); ++i) { for (unsigned int i = 0; i < mEntries.size(); ++i) {
mRenderer->drawRect(0.0f, y, std::round(mSize.x), mRenderer->drawRect(0.0f, y, std::round(mSize.x),
1.0f * Renderer::getScreenHeightModifier(), 0xC6C7C6FF, 0xC6C7C6FF, 1.0f * Renderer::getScreenHeightModifier(), 0xC6C7C6FF, 0xC6C7C6FF,
@ -417,7 +417,7 @@ void ComponentList::render(const glm::mat4& parentTrans)
float ComponentList::getRowHeight(const ComponentListRow& row) const float ComponentList::getRowHeight(const ComponentListRow& row) const
{ {
// Returns the highest component height found in the row. // Returns the highest component height found in the row.
float height = 0; float height {0.0f};
for (unsigned int i = 0; i < row.elements.size(); ++i) { for (unsigned int i = 0; i < row.elements.size(); ++i) {
if (row.elements.at(i).component->getSize().y > height) if (row.elements.at(i).component->getSize().y > height)
height = row.elements.at(i).component->getSize().y; height = row.elements.at(i).component->getSize().y;
@ -428,7 +428,7 @@ float ComponentList::getRowHeight(const ComponentListRow& row) const
float ComponentList::getTotalRowHeight() const float ComponentList::getTotalRowHeight() const
{ {
float height = 0; float height {0.0f};
for (auto it = mEntries.cbegin(); it != mEntries.cend(); ++it) for (auto it = mEntries.cbegin(); it != mEntries.cend(); ++it)
height += getRowHeight(it->data); height += getRowHeight(it->data);
@ -437,13 +437,13 @@ float ComponentList::getTotalRowHeight() const
void ComponentList::updateElementPosition(const ComponentListRow& row) void ComponentList::updateElementPosition(const ComponentListRow& row)
{ {
float yOffset = 0; float yOffset {0.0f};
for (auto it = mEntries.cbegin(); it != mEntries.cend() && &it->data != &row; ++it) for (auto it = mEntries.cbegin(); it != mEntries.cend() && &it->data != &row; ++it)
yOffset += getRowHeight(it->data); yOffset += getRowHeight(it->data);
// Assumes updateElementSize has already been called. // Assumes updateElementSize has already been called.
float rowHeight = getRowHeight(row); float rowHeight {getRowHeight(row)};
float x = mHorizontalPadding / 2.0f; float x {mHorizontalPadding / 2.0f};
for (unsigned int i = 0; i < row.elements.size(); ++i) { for (unsigned int i = 0; i < row.elements.size(); ++i) {
const auto comp = row.elements.at(i).component; const auto comp = row.elements.at(i).component;
@ -456,7 +456,7 @@ void ComponentList::updateElementPosition(const ComponentListRow& row)
void ComponentList::updateElementSize(const ComponentListRow& row) void ComponentList::updateElementSize(const ComponentListRow& row)
{ {
float width = mSize.x - mHorizontalPadding; float width {mSize.x - mHorizontalPadding};
std::vector<std::shared_ptr<GuiComponent>> resizeVec; std::vector<std::shared_ptr<GuiComponent>> resizeVec;
for (auto it = row.elements.cbegin(); it != row.elements.cend(); ++it) { for (auto it = row.elements.cbegin(); it != row.elements.cend(); ++it) {
@ -485,11 +485,11 @@ std::vector<HelpPrompt> ComponentList::getHelpPrompts()
if (!size()) if (!size())
return std::vector<HelpPrompt>(); return std::vector<HelpPrompt>();
std::vector<HelpPrompt> prompts = std::vector<HelpPrompt> prompts {
mEntries.at(mCursor).data.elements.back().component->getHelpPrompts(); mEntries.at(mCursor).data.elements.back().component->getHelpPrompts()};
if (size() > 1) { if (size() > 1) {
bool addMovePrompt = true; bool addMovePrompt {true};
for (auto it = prompts.cbegin(); it != prompts.cend(); ++it) { for (auto it = prompts.cbegin(); it != prompts.cend(); ++it) {
if (it->first == "up/down" || it->first == "up/down/left/right") { if (it->first == "up/down" || it->first == "up/down/left/right") {
addMovePrompt = false; addMovePrompt = false;
@ -505,7 +505,7 @@ std::vector<HelpPrompt> ComponentList::getHelpPrompts()
bool ComponentList::moveCursor(int amt) bool ComponentList::moveCursor(int amt)
{ {
bool ret = listInput(amt); bool ret {listInput(amt)};
listInput(0); listInput(0);
return ret; return ret;
} }

View file

@ -265,7 +265,7 @@ void TextComponent::onTextChanged()
const bool isMultiline {mAutoCalcExtent.y == 1 || mSize.y > lineHeight}; const bool isMultiline {mAutoCalcExtent.y == 1 || mSize.y > lineHeight};
const bool isScrollable {mParent && mParent->isScrollable()}; const bool isScrollable {mParent && mParent->isScrollable()};
if (isMultiline && text.size() && !isScrollable) { if (isMultiline && !isScrollable) {
const std::string wrappedText { const std::string wrappedText {
font->wrapText(text, mSize.x, (mVerticalAutoSizing ? 0.0f : mSize.y - lineHeight), font->wrapText(text, mSize.x, (mVerticalAutoSizing ? 0.0f : mSize.y - lineHeight),
mLineSpacing, isMultiline)}; mLineSpacing, isMultiline)};
@ -337,7 +337,7 @@ void TextComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
componentName = "gamelistInfoComponent"; componentName = "gamelistInfoComponent";
} }
const ThemeData::ThemeElement* elem = theme->getElement(view, element, elementType); const ThemeData::ThemeElement* elem {theme->getElement(view, element, elementType)};
if (!elem) if (!elem)
return; return;