mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2026-05-06 21:16:20 -05:00
Truncate item name in config menu if needed
This commit is contained in:
parent
d03caa26a0
commit
d483c4e39b
|
|
@ -1,17 +1,54 @@
|
|||
#include "ConfigRendererItem.h"
|
||||
|
||||
#include "utils/DrawUtils.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
#include <config/WUPSConfigItem.h>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace {
|
||||
std::string truncateTextToWidth(const std::string &str, uint32_t maxWidth) {
|
||||
if (DrawUtils::getTextWidth(str.c_str()) <= maxWidth) {
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string ellipsis = "...";
|
||||
const uint32_t ellipsisWidth = DrawUtils::getTextWidth(ellipsis.c_str());
|
||||
|
||||
if (maxWidth <= ellipsisWidth) {
|
||||
return ellipsis;
|
||||
}
|
||||
|
||||
std::string result = str;
|
||||
while (!result.empty()) {
|
||||
result.pop_back(); // Remove one character from the end
|
||||
if (DrawUtils::getTextWidth((result + ellipsis).c_str()) <= maxWidth) {
|
||||
return result + ellipsis;
|
||||
}
|
||||
}
|
||||
|
||||
return ellipsis;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
ConfigRendererItem::ConfigRendererItem(const WUPSConfigAPIBackend::WUPSConfigItem *item) : mItem(item) {
|
||||
assert(item);
|
||||
}
|
||||
|
||||
void ConfigRendererItem::Draw(const uint32_t yOffset, const bool isHighlighted) const {
|
||||
assert(mItem);
|
||||
drawGenericBoxAndText(yOffset, mItem->getDisplayName(), isHighlighted);
|
||||
|
||||
const auto displayName = mItem->getDisplayName();
|
||||
|
||||
DrawUtils::setFontSize(24);
|
||||
|
||||
const uint32_t widthValueText = DrawUtils::getTextWidth(mCurItemText.c_str());
|
||||
const uint32_t maxNameWidth = (780 > widthValueText) ? (780 - widthValueText) : 0;
|
||||
|
||||
const std::string renderItemName = truncateTextToWidth(displayName, maxNameWidth);
|
||||
|
||||
// Draw the item
|
||||
drawGenericBoxAndText(yOffset, renderItemName, isHighlighted);
|
||||
DrawUtils::setFontSize(24);
|
||||
DrawUtils::print(SCREEN_WIDTH - 16 * 2, yOffset + 8 + 24, mCurItemText.c_str(), true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user