Add help component theme options textStyle.

This commit is contained in:
Sophia Hadash 2021-08-20 17:51:36 +02:00 committed by SophiaHadash
parent cc38f06141
commit 5ed0d7b7eb
6 changed files with 44 additions and 3 deletions

View file

@ -20,6 +20,7 @@ HelpStyle::HelpStyle()
textColor = 0x777777FF;
entrySpacing = 16.0f;
iconTextSpacing = 8.0f;
textStyle = "uppercase";
if (FONT_SIZE_SMALL != 0)
font = Font::get(FONT_SIZE_SMALL);
@ -55,4 +56,7 @@ void HelpStyle::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::s
if (elem->has("iconTextSpacing"))
iconTextSpacing = elem->get<float>("iconTextSpacing");
if (elem->has("textStyle"))
textStyle = elem->get<std::string>("textStyle");
}

View file

@ -26,6 +26,7 @@ struct HelpStyle {
std::shared_ptr<Font> font;
float entrySpacing;
float iconTextSpacing;
std::string textStyle;
HelpStyle(); // Default values.
void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view);

View file

@ -155,7 +155,8 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>> The
{"fontPath", PATH},
{"fontSize", FLOAT},
{"entrySpacing", FLOAT},
{"iconTextSpacing", FLOAT}}},
{"iconTextSpacing", FLOAT},
{"textStyle", STRING}}},
{"navigationsounds",
{{"systembrowseSound", PATH},
{"quicksysselectSound", PATH},

View file

@ -128,8 +128,19 @@ void HelpComponent::updateGrid()
icon->setResize(0, height);
icons.push_back(icon);
auto lbl = std::make_shared<TextComponent>(mWindow, Utils::String::toUpper(it->second),
font, mStyle.textColor);
// Format label according to theme style.
std::string lblInput = it->second;
if (mStyle.textStyle == "lowercase") {
lblInput = Utils::String::toLower(lblInput);
}
else if (mStyle.textStyle == "camelcase") {
lblInput = Utils::String::toCamelCase(lblInput);
}
else {
lblInput = Utils::String::toUpper(lblInput);
}
auto lbl = std::make_shared<TextComponent>(mWindow, lblInput, font, mStyle.textColor);
labels.push_back(lbl);
width +=

View file

@ -541,6 +541,29 @@ namespace Utils
return stringUpper;
}
std::string toCamelCase(const std::string& stringArg)
{
std::string line = stringArg;
bool active = true;
for (int i = 0; line[i] != '\0'; i++) {
if (std::isalpha(line[i])) {
if (active) {
line[i] = Utils::String::toUpper(std::string(1, line[i]))[0];
active = false;
}
else {
line[i] = Utils::String::toLower(std::string(1, line[i]))[0];
}
}
else if (line[i] == ' ') {
active = true;
}
}
return line;
}
std::string trim(const std::string& stringArg)
{
const size_t strBegin = stringArg.find_first_not_of(" \t");

View file

@ -26,6 +26,7 @@ namespace Utils
size_t moveCursor(const std::string& stringArg, const size_t cursor, const int amount);
std::string toLower(const std::string& stringArg);
std::string toUpper(const std::string& stringArg);
std::string toCamelCase(const std::string& stringArg);
std::string trim(const std::string& stringArg);
std::string replace(const std::string& stringArg,
const std::string& replace,