Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion source/utils/config/CategoryRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ ConfigSubState CategoryRenderer::UpdateStateMain(Input &input, const WUPSConfigS

if (mIsItemMovementAllowed) {
if (input.data.buttons_d & Input::eButtons::BUTTON_DOWN) {
mItemRenderer[mCursorPos]->ResetTextOffset();
mCursorPos++;
} else if (input.data.buttons_d & Input::eButtons::BUTTON_UP) {
mItemRenderer[mCursorPos]->ResetTextOffset();
mCursorPos--;
} else if (input.data.buttons_d & Input::eButtons::BUTTON_A) {
mItemRenderer[mCursorPos]->ResetTextOffset();
if (mCursorPos < (int32_t) mCat->getCategories().size()) {
if (mCurrentOpen != mCursorPos) {
mSubCategoryRenderer.reset();
Expand All @@ -96,6 +99,12 @@ ConfigSubState CategoryRenderer::UpdateStateMain(Input &input, const WUPSConfigS
mNeedsRedraw = true;
return SUB_STATE_RUNNING;
}
} else if ((input.data.buttons_h & Input::eButtons::STICK_L_RIGHT) || (input.data.buttons_h & Input::eButtons::STICK_R_RIGHT)) {
mItemRenderer[mCursorPos]->IncrementTextOffset();
mNeedsRedraw = true;
} else if ((input.data.buttons_h & Input::eButtons::STICK_L_LEFT) || (input.data.buttons_h & Input::eButtons::STICK_R_LEFT)) {
mItemRenderer[mCursorPos]->DecrementTextOffset();
mNeedsRedraw = true;
}
}

Expand Down Expand Up @@ -216,8 +225,10 @@ void CategoryRenderer::RenderStateMain() const {
RenderMainLayout();

uint32_t yOffset = 8 + 24 + 8 + 4;

for (int32_t i = start; i < end; i++) {
bool isHighlighted = (i == mCursorPos);

mItemRenderer[i]->Draw(yOffset, isHighlighted);
yOffset += 42 + 8;
}
Expand Down Expand Up @@ -255,4 +266,4 @@ void CategoryRenderer::RenderMainLayout() const {
DrawUtils::setFontSize(18);
const char *exitHint = "\ue001 Back";
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(exitHint) / 2, SCREEN_HEIGHT - 10, exitHint, true);
}
}
27 changes: 24 additions & 3 deletions source/utils/config/ConfigRendererItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class ConfigRendererItem : public ConfigRendererItemGeneric {

void Draw(uint32_t yOffset, bool isHighlighted) const override {
assert(mItem);
drawGenericBoxAndText(yOffset, mItem->getDisplayName(), isHighlighted);

drawGenericBoxAndText(yOffset, ConfigRenderItemFont::GetOffsettedText(mItem->getDisplayName(), mTextOffset), isHighlighted);
DrawUtils::setFontSize(24);

DrawUtils::print(SCREEN_WIDTH - 16 * 2, yOffset + 8 + 24, mCurItemText.c_str(), true);
}

Expand Down Expand Up @@ -40,6 +42,24 @@ class ConfigRendererItem : public ConfigRendererItemGeneric {
mItem->onSelected(isSelected);
}

void ResetTextOffset() override {
mTextOffset = 0;
}

uint32_t GetTextOffset() const override {
return mTextOffset;
}

void IncrementTextOffset() override {
if (!mItem) return;
ConfigRenderItemFont::IncrementOffset(mItem->getDisplayName(), mTextOffset);
}

void DecrementTextOffset() override {
if (!mItem) return;
if (mTextOffset > 0) mTextOffset--;
}

void OnButtonPressed(WUPSConfigButtons buttons) override {
mItem->onButtonPressed(buttons);
}
Expand All @@ -58,5 +78,6 @@ class ConfigRendererItem : public ConfigRendererItemGeneric {
private:
const WUPSConfigAPIBackend::WUPSConfigItem *mItem;
std::string mCurItemText;
bool mNeedsDraw = true;
};
bool mNeedsDraw = true;
uint32_t mTextOffset = 0;
};
24 changes: 21 additions & 3 deletions source/utils/config/ConfigRendererItemCategory.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

class ConfigRendererItemCategory : public ConfigRendererItemGeneric {
public:
explicit ConfigRendererItemCategory(const WUPSConfigAPIBackend::WUPSConfigCategory *category) : mCategory(category) {
explicit ConfigRendererItemCategory(const WUPSConfigAPIBackend::WUPSConfigCategory *category) : mCategory(category), mTextOffset(0) {
assert(category);
}

void Draw(uint32_t yOffset, bool isHighlighted) const override {
drawGenericBoxAndText(yOffset, mCategory->getName(), isHighlighted);
drawGenericBoxAndText(yOffset, ConfigRenderItemFont::GetOffsettedText(mCategory->getName(), mTextOffset), isHighlighted);
}

void Update(bool) override {
Expand All @@ -22,6 +22,24 @@ class ConfigRendererItemCategory : public ConfigRendererItemGeneric {
void ResetNeedsRedraw() override {
}

void ResetTextOffset() override {
mTextOffset = 0;
}

uint32_t GetTextOffset() const override {
return mTextOffset;
}

void IncrementTextOffset() override {
if (!mCategory) return;
ConfigRenderItemFont::IncrementOffset(mCategory->getName(), mTextOffset);
}

void DecrementTextOffset() override {
if (mTextOffset > 0) mTextOffset--;
}

private:
const WUPSConfigAPIBackend::WUPSConfigCategory *mCategory;
};
uint32_t mTextOffset = 0;
};
52 changes: 48 additions & 4 deletions source/utils/config/ConfigRendererItemGeneric.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,40 @@
#include "ConfigDefines.h"
#include <wups/config.h>

namespace ConfigRenderItemFont {
constexpr uint32_t FONT_SIZE = 24;
constexpr uint32_t MIN_TEXT_WIDTH_FOR_SCROLL = 64;

inline void IncrementOffset(std::string text, uint32_t &offset) {
if (text.size() < MIN_TEXT_WIDTH_FOR_SCROLL) {
offset = 0;
return;
}

if (offset >= text.size()) {
offset = 0;
return;
}

text.erase(0, offset);
if (text.size() < MIN_TEXT_WIDTH_FOR_SCROLL) {
offset = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this a bug?

return;
}

offset++;
}

inline std::string GetOffsettedText(const std::string &text, uint32_t offset) {
if (text.size() < MIN_TEXT_WIDTH_FOR_SCROLL || offset == 0) return text;

std::string offsettedText = text;
offsettedText.erase(0, offset);

return offsettedText;
}
} // namespace ConfigRenderItemFont

class ConfigRendererItemGeneric {
public:
virtual ~ConfigRendererItemGeneric() = default;
Expand All @@ -13,9 +47,10 @@ class ConfigRendererItemGeneric {
DrawUtils::drawRect(16, yOffset, SCREEN_WIDTH - 16 * 2, 44, 2, COLOR_BORDER);
}

DrawUtils::setFontSize(24);
DrawUtils::setFontSize(ConfigRenderItemFont::FONT_SIZE);

DrawUtils::setFontColor(COLOR_TEXT);
DrawUtils::print(16 * 2, yOffset + 8 + 24, displayName.c_str());
DrawUtils::print(16 * 2, yOffset + 8 + ConfigRenderItemFont::FONT_SIZE, displayName.c_str());
}

virtual void Draw(uint32_t yOffset, bool isHighlighted) const = 0;
Expand All @@ -29,7 +64,16 @@ class ConfigRendererItemGeneric {
virtual void SetIsSelected(bool) {
}

virtual void OnButtonPressed(WUPSConfigButtons) {
virtual void ResetTextOffset() = 0;

virtual uint32_t GetTextOffset() const {
return 0;
}
virtual void IncrementTextOffset() = 0;
virtual void DecrementTextOffset() = 0;

virtual void
OnButtonPressed(WUPSConfigButtons) {
}
virtual void OnInput(WUPSConfigSimplePadData) {
}
Expand All @@ -39,4 +83,4 @@ class ConfigRendererItemGeneric {
[[nodiscard]] virtual bool IsMovementAllowed() const {
return true;
}
};
};