Add help component theme options entrySpacing and iconTextSpacing.

This commit is contained in:
Sophia Hadash 2021-08-20 17:20:05 +02:00 committed by SophiaHadash
parent d25670361a
commit 6672fd1ec8
4 changed files with 18 additions and 8 deletions

View file

@ -18,6 +18,8 @@ HelpStyle::HelpStyle()
origin = glm::vec2{}; origin = glm::vec2{};
iconColor = 0x777777FF; iconColor = 0x777777FF;
textColor = 0x777777FF; textColor = 0x777777FF;
entrySpacing = 16.0f;
iconTextSpacing = 8.0f;
if (FONT_SIZE_SMALL != 0) if (FONT_SIZE_SMALL != 0)
font = Font::get(FONT_SIZE_SMALL); font = Font::get(FONT_SIZE_SMALL);
@ -47,4 +49,10 @@ void HelpStyle::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::s
if (elem->has("fontPath") || elem->has("fontSize")) if (elem->has("fontPath") || elem->has("fontSize"))
font = Font::getFromTheme(elem, ThemeFlags::ALL, font); font = Font::getFromTheme(elem, ThemeFlags::ALL, font);
if (elem->has("entrySpacing"))
entrySpacing = elem->get<float>("entrySpacing");
if (elem->has("iconTextSpacing"))
iconTextSpacing = elem->get<float>("iconTextSpacing");
} }

View file

@ -24,6 +24,8 @@ struct HelpStyle {
unsigned int iconColor; unsigned int iconColor;
unsigned int textColor; unsigned int textColor;
std::shared_ptr<Font> font; std::shared_ptr<Font> font;
float entrySpacing;
float iconTextSpacing;
HelpStyle(); // Default values. HelpStyle(); // Default values.
void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view); void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view);

View file

@ -153,7 +153,9 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>> The
{"textColor", COLOR}, {"textColor", COLOR},
{"iconColor", COLOR}, {"iconColor", COLOR},
{"fontPath", PATH}, {"fontPath", PATH},
{"fontSize", FLOAT}}}, {"fontSize", FLOAT},
{"entrySpacing", FLOAT},
{"iconTextSpacing", FLOAT}}},
{"navigationsounds", {"navigationsounds",
{{"systembrowseSound", PATH}, {{"systembrowseSound", PATH},
{"quicksysselectSound", PATH}, {"quicksysselectSound", PATH},

View file

@ -16,9 +16,6 @@
#include "resources/TextureResource.h" #include "resources/TextureResource.h"
#include "utils/StringUtil.h" #include "utils/StringUtil.h"
#define ICON_TEXT_SPACING 8.0f // Space between [icon] and [text] (px).
#define ENTRY_SPACING 16.0f // Space between [text] and next [icon] (px).
static std::map<std::string, std::string> sIconPathMap{}; static std::map<std::string, std::string> sIconPathMap{};
HelpComponent::HelpComponent(Window* window) HelpComponent::HelpComponent(Window* window)
@ -135,8 +132,9 @@ void HelpComponent::updateGrid()
font, mStyle.textColor); font, mStyle.textColor);
labels.push_back(lbl); labels.push_back(lbl);
width += icon->getSize().x + lbl->getSize().x + width +=
((ICON_TEXT_SPACING + ENTRY_SPACING) * Renderer::getScreenWidthModifier()); icon->getSize().x + lbl->getSize().x +
((mStyle.iconTextSpacing + mStyle.entrySpacing) * Renderer::getScreenWidthModifier());
} }
mGrid->setSize(width, height); mGrid->setSize(width, height);
@ -144,8 +142,8 @@ void HelpComponent::updateGrid()
for (unsigned int i = 0; i < icons.size(); i++) { for (unsigned int i = 0; i < icons.size(); i++) {
const int col = i * 4; const int col = i * 4;
mGrid->setColWidthPerc(col, icons.at(i)->getSize().x / width); mGrid->setColWidthPerc(col, icons.at(i)->getSize().x / width);
mGrid->setColWidthPerc(col + 1, mGrid->setColWidthPerc(
(ICON_TEXT_SPACING * Renderer::getScreenWidthModifier()) / width); col + 1, (mStyle.iconTextSpacing * Renderer::getScreenWidthModifier()) / width);
mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x / width); mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x / width);
mGrid->setEntry(icons.at(i), glm::ivec2{col, 0}, false, false); mGrid->setEntry(icons.at(i), glm::ivec2{col, 0}, false, false);