From 6672fd1ec8808c293871afa8273dae964088d893 Mon Sep 17 00:00:00 2001 From: Sophia Hadash Date: Fri, 20 Aug 2021 17:20:05 +0200 Subject: [PATCH] Add help component theme options `entrySpacing` and `iconTextSpacing`. --- es-core/src/HelpStyle.cpp | 8 ++++++++ es-core/src/HelpStyle.h | 2 ++ es-core/src/ThemeData.cpp | 4 +++- es-core/src/components/HelpComponent.cpp | 12 +++++------- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/es-core/src/HelpStyle.cpp b/es-core/src/HelpStyle.cpp index 2a6cb917a..bd59352c2 100644 --- a/es-core/src/HelpStyle.cpp +++ b/es-core/src/HelpStyle.cpp @@ -18,6 +18,8 @@ HelpStyle::HelpStyle() origin = glm::vec2{}; iconColor = 0x777777FF; textColor = 0x777777FF; + entrySpacing = 16.0f; + iconTextSpacing = 8.0f; if (FONT_SIZE_SMALL != 0) font = Font::get(FONT_SIZE_SMALL); @@ -47,4 +49,10 @@ void HelpStyle::applyTheme(const std::shared_ptr& theme, const std::s if (elem->has("fontPath") || elem->has("fontSize")) font = Font::getFromTheme(elem, ThemeFlags::ALL, font); + + if (elem->has("entrySpacing")) + entrySpacing = elem->get("entrySpacing"); + + if (elem->has("iconTextSpacing")) + iconTextSpacing = elem->get("iconTextSpacing"); } diff --git a/es-core/src/HelpStyle.h b/es-core/src/HelpStyle.h index b6eb62e68..118b15c46 100644 --- a/es-core/src/HelpStyle.h +++ b/es-core/src/HelpStyle.h @@ -24,6 +24,8 @@ struct HelpStyle { unsigned int iconColor; unsigned int textColor; std::shared_ptr font; + float entrySpacing; + float iconTextSpacing; HelpStyle(); // Default values. void applyTheme(const std::shared_ptr& theme, const std::string& view); diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 2af478067..753033603 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -153,7 +153,9 @@ std::map> The {"textColor", COLOR}, {"iconColor", COLOR}, {"fontPath", PATH}, - {"fontSize", FLOAT}}}, + {"fontSize", FLOAT}, + {"entrySpacing", FLOAT}, + {"iconTextSpacing", FLOAT}}}, {"navigationsounds", {{"systembrowseSound", PATH}, {"quicksysselectSound", PATH}, diff --git a/es-core/src/components/HelpComponent.cpp b/es-core/src/components/HelpComponent.cpp index d04218bab..8899b173f 100644 --- a/es-core/src/components/HelpComponent.cpp +++ b/es-core/src/components/HelpComponent.cpp @@ -16,9 +16,6 @@ #include "resources/TextureResource.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 sIconPathMap{}; HelpComponent::HelpComponent(Window* window) @@ -135,8 +132,9 @@ void HelpComponent::updateGrid() font, mStyle.textColor); labels.push_back(lbl); - width += icon->getSize().x + lbl->getSize().x + - ((ICON_TEXT_SPACING + ENTRY_SPACING) * Renderer::getScreenWidthModifier()); + width += + icon->getSize().x + lbl->getSize().x + + ((mStyle.iconTextSpacing + mStyle.entrySpacing) * Renderer::getScreenWidthModifier()); } mGrid->setSize(width, height); @@ -144,8 +142,8 @@ void HelpComponent::updateGrid() for (unsigned int i = 0; i < icons.size(); i++) { const int col = i * 4; mGrid->setColWidthPerc(col, icons.at(i)->getSize().x / width); - mGrid->setColWidthPerc(col + 1, - (ICON_TEXT_SPACING * Renderer::getScreenWidthModifier()) / width); + mGrid->setColWidthPerc( + col + 1, (mStyle.iconTextSpacing * Renderer::getScreenWidthModifier()) / width); mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x / width); mGrid->setEntry(icons.at(i), glm::ivec2{col, 0}, false, false);