mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-03-06 14:27:43 +00:00
Fixed an issue where the helpsystem would be incorrectly positioned when right-aligned.
This commit is contained in:
parent
7c02db291e
commit
71b8eba9ce
|
@ -22,6 +22,7 @@ HelpStyle::HelpStyle()
|
||||||
, entrySpacing {0.00833f}
|
, entrySpacing {0.00833f}
|
||||||
, iconTextSpacing {0.00416f}
|
, iconTextSpacing {0.00416f}
|
||||||
, opacity {1.0f}
|
, opacity {1.0f}
|
||||||
|
, legacyTheme {false}
|
||||||
, letterCase {"uppercase"}
|
, letterCase {"uppercase"}
|
||||||
{
|
{
|
||||||
if (FONT_SIZE_SMALL != 0)
|
if (FONT_SIZE_SMALL != 0)
|
||||||
|
@ -36,6 +37,8 @@ void HelpStyle::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::s
|
||||||
if (!elem)
|
if (!elem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
legacyTheme = theme->isLegacyTheme();
|
||||||
|
|
||||||
if (elem->has("pos"))
|
if (elem->has("pos"))
|
||||||
position = elem->get<glm::vec2>("pos") *
|
position = elem->get<glm::vec2>("pos") *
|
||||||
glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()};
|
glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()};
|
||||||
|
|
|
@ -28,6 +28,7 @@ struct HelpStyle {
|
||||||
float entrySpacing;
|
float entrySpacing;
|
||||||
float iconTextSpacing;
|
float iconTextSpacing;
|
||||||
float opacity;
|
float opacity;
|
||||||
|
bool legacyTheme;
|
||||||
std::string letterCase;
|
std::string letterCase;
|
||||||
|
|
||||||
struct CustomButtonIcons {
|
struct CustomButtonIcons {
|
||||||
|
|
|
@ -202,22 +202,13 @@ void HelpComponent::updateGrid()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Font>& font {mStyle.font};
|
std::shared_ptr<Font>& font {mStyle.font};
|
||||||
|
mGrid = std::make_shared<ComponentGrid>(glm::ivec2 {static_cast<int>(mPrompts.size()) * 5, 1});
|
||||||
mGrid = std::make_shared<ComponentGrid>(glm::ivec2 {static_cast<int>(mPrompts.size()) * 4, 1});
|
|
||||||
|
|
||||||
// [icon] [spacer1] [text] [spacer2]
|
|
||||||
|
|
||||||
std::vector<std::shared_ptr<ImageComponent>> icons;
|
std::vector<std::shared_ptr<ImageComponent>> icons;
|
||||||
std::vector<std::shared_ptr<TextComponent>> labels;
|
std::vector<std::shared_ptr<TextComponent>> labels;
|
||||||
|
|
||||||
float width {0.0f};
|
float width {0.0f};
|
||||||
float height {std::round(font->getLetterHeight() * 1.25f)};
|
float height {font->getLetterHeight() * 1.25f};
|
||||||
|
|
||||||
// Make sure both text and icons have either odd or equal sizes to avoid alignment issues.
|
|
||||||
if (static_cast<int>(font->getHeight()) % 2 != static_cast<int>(height) % 2)
|
|
||||||
--height;
|
|
||||||
|
|
||||||
// State variable indicating whether the GUI is dimmed.
|
|
||||||
bool isDimmed {mWindow->isBackgroundDimmed()};
|
bool isDimmed {mWindow->isBackgroundDimmed()};
|
||||||
|
|
||||||
for (auto it = mPrompts.cbegin(); it != mPrompts.cend(); ++it) {
|
for (auto it = mPrompts.cbegin(); it != mPrompts.cend(); ++it) {
|
||||||
|
@ -249,17 +240,31 @@ void HelpComponent::updateGrid()
|
||||||
mGrid->setSize(width, height);
|
mGrid->setSize(width, height);
|
||||||
|
|
||||||
for (int i = 0; i < static_cast<int>(icons.size()); ++i) {
|
for (int i = 0; i < static_cast<int>(icons.size()); ++i) {
|
||||||
const int col {i * 4};
|
const int col {i * 5};
|
||||||
mGrid->setColWidthPerc(col, icons.at(i)->getSize().x / width);
|
mGrid->setColWidthPerc(col, icons.at(i)->getSize().x / width);
|
||||||
mGrid->setColWidthPerc(col + 1,
|
mGrid->setColWidthPerc(col + 1,
|
||||||
(mStyle.iconTextSpacing * mRenderer->getScreenWidth()) / width);
|
(mStyle.iconTextSpacing * mRenderer->getScreenWidth()) / width);
|
||||||
mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x / width);
|
mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x / width);
|
||||||
|
mGrid->setColWidthPerc(col + 3,
|
||||||
|
(mStyle.entrySpacing * mRenderer->getScreenWidth()) / width);
|
||||||
|
|
||||||
mGrid->setEntry(icons.at(i), glm::ivec2 {col, 0}, false, false);
|
mGrid->setEntry(icons.at(i), glm::ivec2 {col, 0}, false, false);
|
||||||
mGrid->setEntry(labels.at(i), glm::ivec2 {col + 2, 0}, false, false);
|
mGrid->setEntry(labels.at(i), glm::ivec2 {col + 2, 0}, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
mGrid->setPosition({mStyle.position.x, mStyle.position.y, 0.0f});
|
// There is a bug for legacy themes where the entrySpacing width is added to the right of
|
||||||
|
// the grid when aligning to the right using an X origin value of 1. This issue is retained
|
||||||
|
// for legacy themes for backward compatibility reasons.
|
||||||
|
if (mStyle.legacyTheme) {
|
||||||
|
mGrid->setPosition({mStyle.position.x, mStyle.position.y, 0.0f});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mGrid->setPosition(
|
||||||
|
{mStyle.position.x +
|
||||||
|
((mStyle.entrySpacing * mRenderer->getScreenWidth()) * mStyle.origin.x),
|
||||||
|
mStyle.position.y, 0.0f});
|
||||||
|
}
|
||||||
|
|
||||||
mGrid->setOrigin(mStyle.origin);
|
mGrid->setOrigin(mStyle.origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue