Multiple layout improvements when running in vertical screen orientation.

Also cleaned up some code.
This commit is contained in:
Leon Styhre 2023-02-10 00:25:22 +01:00
parent 589068f747
commit a2e400dd2b
12 changed files with 130 additions and 88 deletions

View file

@ -21,6 +21,7 @@
GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(std::string title) GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(std::string title)
: GuiSettings {title} : GuiSettings {title}
, mRenderer {Renderer::getInstance()}
, mAddedCustomCollection {false} , mAddedCustomCollection {false}
, mDeletedCustomCollection {false} , mDeletedCustomCollection {false}
{ {
@ -217,9 +218,11 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(std::string title)
if (Settings::getInstance()->getBool("VirtualKeyboard")) { if (Settings::getInstance()->getBool("VirtualKeyboard")) {
row.makeAcceptInputHandler([this, createCollectionCall] { row.makeAcceptInputHandler([this, createCollectionCall] {
mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), "New Collection Name", "", const float verticalPosition {
createCollectionCall, false, "CREATE", mRenderer->getIsVerticalOrientation() ? getMenu().getPosition().y : 0.0f};
"CREATE COLLECTION?")); mWindow->pushGui(new GuiTextEditKeyboardPopup(
getHelpStyle(), verticalPosition, "New Collection Name", "", createCollectionCall,
false, "CREATE", "CREATE COLLECTION?"));
}); });
} }
else { else {
@ -304,8 +307,9 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(std::string title)
// Make the menu slightly wider to fit the scroll indicators. // Make the menu slightly wider to fit the scroll indicators.
glm::vec2 menuSize {ss->getMenuSize()}; glm::vec2 menuSize {ss->getMenuSize()};
glm::vec3 menuPos {ss->getMenuPosition()}; glm::vec3 menuPos {ss->getMenuPosition()};
ss->setMenuSize(glm::vec2 {menuSize.x * 1.08f, menuSize.y}); const float maxWidthModifier {mRenderer->getIsVerticalOrientation() ? 1.0f : 1.08f};
menuPos.x = (Renderer::getScreenWidth() - ss->getMenuSize().x) / 2.0f; ss->setMenuSize(glm::vec2 {menuSize.x * maxWidthModifier, menuSize.y});
menuPos.x = (mRenderer->getScreenWidth() - ss->getMenuSize().x) / 2.0f;
ss->setMenuPosition(menuPos); ss->setMenuPosition(menuPos);
mWindow->pushGui(ss); mWindow->pushGui(ss);
}); });

View file

@ -22,6 +22,7 @@ public:
private: private:
void createCustomCollection(std::string inName); void createCustomCollection(std::string inName);
Renderer* mRenderer;
std::shared_ptr<OptionListComponent<std::string>> mCollectionSystemsAuto; std::shared_ptr<OptionListComponent<std::string>> mCollectionSystemsAuto;
std::shared_ptr<OptionListComponent<std::string>> mCollectionSystemsCustom; std::shared_ptr<OptionListComponent<std::string>> mCollectionSystemsCustom;

View file

@ -118,9 +118,11 @@ void GuiGamelistFilter::addFiltersToMenu()
if (Settings::getInstance()->getBool("VirtualKeyboard")) { if (Settings::getInstance()->getBool("VirtualKeyboard")) {
row.makeAcceptInputHandler([this, updateVal] { row.makeAcceptInputHandler([this, updateVal] {
mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), "GAME NAME", const float verticalPosition {
mTextFilterField->getValue(), updateVal, Renderer::getIsVerticalOrientation() ? mMenu.getPosition().y : 0.0f};
false, "OK", "APPLY CHANGES?")); mWindow->pushGui(new GuiTextEditKeyboardPopup(
getHelpStyle(), verticalPosition, "GAME NAME", mTextFilterField->getValue(),
updateVal, false, "OK", "APPLY CHANGES?"));
}); });
} }
else { else {

View file

@ -1179,11 +1179,22 @@ void GuiMenu::openConfigInput(GuiSettings* settings)
// the input device settings menu later on. // the input device settings menu later on.
settings->setNeedsSaving(false); settings->setNeedsSaving(false);
std::string message {"THE KEYBOARD AND CONTROLLERS ARE AUTOMATICALLY\n" std::string message;
if (Renderer::getIsVerticalOrientation()) {
message = "THE KEYBOARD AND CONTROLLERS ARE\n"
"AUTOMATICALLY CONFIGURED, BUT USING\n"
"THIS CONFIGURATION TOOL YOU CAN\n"
"OVERRIDE THE DEFAULT BUTTON MAPPINGS\n"
"(THIS WILL NOT AFFECT THE HELP PROMPTS)\n"
"CONTINUE?";
}
else {
message = "THE KEYBOARD AND CONTROLLERS ARE AUTOMATICALLY\n"
"CONFIGURED, BUT USING THIS CONFIGURATION TOOL\n" "CONFIGURED, BUT USING THIS CONFIGURATION TOOL\n"
"YOU CAN OVERRIDE THE DEFAULT BUTTON MAPPINGS\n" "YOU CAN OVERRIDE THE DEFAULT BUTTON MAPPINGS\n"
"(THIS WILL NOT AFFECT THE HELP PROMPTS)\n" "(THIS WILL NOT AFFECT THE HELP PROMPTS)\n"
"CONTINUE?"}; "CONTINUE?";
}
Window* window {mWindow}; Window* window {mWindow};
window->pushGui(new GuiMsgBox( window->pushGui(new GuiMsgBox(
@ -1228,14 +1239,15 @@ void GuiMenu::openOtherOptions()
ViewController::getInstance()->reloadAll(); ViewController::getInstance()->reloadAll();
mWindow->invalidateCachedBackground(); mWindow->invalidateCachedBackground();
}; };
rowMediaDir.makeAcceptInputHandler([this, titleMediaDir, mediaDirectoryStaticText, rowMediaDir.makeAcceptInputHandler([this, s, titleMediaDir, mediaDirectoryStaticText,
defaultDirectoryText, initValueMediaDir, updateValMediaDir, defaultDirectoryText, initValueMediaDir, updateValMediaDir,
multiLineMediaDir] { multiLineMediaDir] {
if (Settings::getInstance()->getBool("VirtualKeyboard")) { if (Settings::getInstance()->getBool("VirtualKeyboard")) {
mWindow->pushGui(new GuiTextEditKeyboardPopup( mWindow->pushGui(new GuiTextEditKeyboardPopup(
getHelpStyle(), titleMediaDir, Settings::getInstance()->getString("MediaDirectory"), getHelpStyle(), s->getMenu().getPosition().y, titleMediaDir,
updateValMediaDir, multiLineMediaDir, "SAVE", "SAVE CHANGES?", Settings::getInstance()->getString("MediaDirectory"), updateValMediaDir,
mediaDirectoryStaticText, defaultDirectoryText, "load default directory")); multiLineMediaDir, "SAVE", "SAVE CHANGES?", mediaDirectoryStaticText,
defaultDirectoryText, "load default directory"));
} }
else { else {
mWindow->pushGui(new GuiTextEditPopup( mWindow->pushGui(new GuiTextEditPopup(

View file

@ -42,7 +42,8 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
std::function<void()> saveCallback, std::function<void()> saveCallback,
std::function<void()> clearGameFunc, std::function<void()> clearGameFunc,
std::function<void()> deleteGameFunc) std::function<void()> deleteGameFunc)
: mBackground {":/graphics/frame.svg"} : mRenderer {Renderer::getInstance()}
, mBackground {":/graphics/frame.svg"}
, mGrid {glm::ivec2 {2, 6}} , mGrid {glm::ivec2 {2, 6}}
, mScraperParams {scraperParams} , mScraperParams {scraperParams}
, mControllerBadges {BadgeComponent::getGameControllers()} , mControllerBadges {BadgeComponent::getGameControllers()}
@ -160,7 +161,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
} }
case MD_RATING: { case MD_RATING: {
auto spacer = std::make_shared<GuiComponent>(); auto spacer = std::make_shared<GuiComponent>();
spacer->setSize(Renderer::getScreenWidth() * 0.0025f, 0.0f); spacer->setSize(mRenderer->getScreenWidth() * 0.0025f, 0.0f);
row.addElement(spacer, false); row.addElement(spacer, false);
ed = std::make_shared<RatingComponent>(true, true); ed = std::make_shared<RatingComponent>(true, true);
@ -176,7 +177,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
} }
case MD_DATE: { case MD_DATE: {
auto spacer = std::make_shared<GuiComponent>(); auto spacer = std::make_shared<GuiComponent>();
spacer->setSize(Renderer::getScreenWidth() * 0.0025f, 0.0f); spacer->setSize(mRenderer->getScreenWidth() * 0.0025f, 0.0f);
row.addElement(spacer, false); row.addElement(spacer, false);
ed = std::make_shared<DateTimeEditComponent>(true); ed = std::make_shared<DateTimeEditComponent>(true);
@ -195,7 +196,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
row.addElement(ed, true); row.addElement(ed, true);
auto spacer = std::make_shared<GuiComponent>(); auto spacer = std::make_shared<GuiComponent>();
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0.0f); spacer->setSize(mRenderer->getScreenWidth() * 0.005f, 0.0f);
row.addElement(spacer, false); row.addElement(spacer, false);
auto bracket = std::make_shared<ImageComponent>(); auto bracket = std::make_shared<ImageComponent>();
@ -258,9 +259,9 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
s->addRow(row, false); s->addRow(row, false);
} }
float aspectValue {1.778f / Renderer::getScreenAspectRatio()}; const float aspectValue {1.778f / mRenderer->getScreenAspectRatio()};
float maxWidthModifier {glm::clamp(0.64f * aspectValue, 0.42f, 0.92f)}; const float maxWidthModifier {glm::clamp(0.64f * aspectValue, 0.42f, 0.92f)};
float maxWidth {Renderer::getScreenWidth() * maxWidthModifier}; const float maxWidth {mRenderer->getScreenWidth() * maxWidthModifier};
s->setMenuSize(glm::vec2 {maxWidth, s->getMenuSize().y}); s->setMenuSize(glm::vec2 {maxWidth, s->getMenuSize().y});
s->setMenuPosition( s->setMenuPosition(
@ -277,7 +278,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
row.addElement(ed, true); row.addElement(ed, true);
auto spacer = std::make_shared<GuiComponent>(); auto spacer = std::make_shared<GuiComponent>();
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0.0f); spacer->setSize(mRenderer->getScreenWidth() * 0.005f, 0.0f);
row.addElement(spacer, false); row.addElement(spacer, false);
auto bracket = std::make_shared<ImageComponent>(); auto bracket = std::make_shared<ImageComponent>();
@ -389,10 +390,10 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
s->addRow(row, false); s->addRow(row, false);
} }
const float aspectValue {1.778f / Renderer::getScreenAspectRatio()}; const float aspectValue {1.778f / mRenderer->getScreenAspectRatio()};
const float maxWidthModifier { const float maxWidthModifier {
glm::clamp(0.64f * aspectValue, 0.42f, 0.92f)}; glm::clamp(0.64f * aspectValue, 0.42f, 0.92f)};
const float maxWidth {static_cast<float>(Renderer::getScreenWidth()) * const float maxWidth {static_cast<float>(mRenderer->getScreenWidth()) *
maxWidthModifier}; maxWidthModifier};
s->setMenuSize(glm::vec2 {maxWidth, s->getMenuSize().y}); s->setMenuSize(glm::vec2 {maxWidth, s->getMenuSize().y});
@ -413,7 +414,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
row.addElement(ed, true); row.addElement(ed, true);
auto spacer = std::make_shared<GuiComponent>(); auto spacer = std::make_shared<GuiComponent>();
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0.0f); spacer->setSize(mRenderer->getScreenWidth() * 0.005f, 0.0f);
row.addElement(spacer, false); row.addElement(spacer, false);
auto bracket = std::make_shared<ImageComponent>(); auto bracket = std::make_shared<ImageComponent>();
@ -510,9 +511,9 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
s->addRow(row, false); s->addRow(row, false);
} }
float aspectValue {1.778f / Renderer::getScreenAspectRatio()}; const float aspectValue {1.778f / mRenderer->getScreenAspectRatio()};
float maxWidthModifier {glm::clamp(0.64f * aspectValue, 0.42f, 0.92f)}; const float maxWidthModifier {glm::clamp(0.64f * aspectValue, 0.42f, 0.92f)};
float maxWidth {Renderer::getScreenWidth() * maxWidthModifier}; const float maxWidth {mRenderer->getScreenWidth() * maxWidthModifier};
s->setMenuSize(glm::vec2 {maxWidth, s->getMenuSize().y}); s->setMenuSize(glm::vec2 {maxWidth, s->getMenuSize().y});
s->setMenuPosition( s->setMenuPosition(
@ -529,7 +530,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
row.addElement(ed, true); row.addElement(ed, true);
auto spacer = std::make_shared<GuiComponent>(); auto spacer = std::make_shared<GuiComponent>();
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0.0f); spacer->setSize(mRenderer->getScreenWidth() * 0.005f, 0.0f);
row.addElement(spacer, false); row.addElement(spacer, false);
auto bracket = std::make_shared<ImageComponent>(); auto bracket = std::make_shared<ImageComponent>();
@ -586,9 +587,11 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
if (Settings::getInstance()->getBool("VirtualKeyboard")) { if (Settings::getInstance()->getBool("VirtualKeyboard")) {
row.makeAcceptInputHandler([this, title, ed, updateVal, multiLine] { row.makeAcceptInputHandler([this, title, ed, updateVal, multiLine] {
const float verticalPosition {
mRenderer->getIsVerticalOrientation() ? mPosition.y : 0.0f};
mWindow->pushGui(new GuiTextEditKeyboardPopup( mWindow->pushGui(new GuiTextEditKeyboardPopup(
getHelpStyle(), title, ed->getValue(), updateVal, multiLine, "apply", getHelpStyle(), verticalPosition, title, ed->getValue(), updateVal,
"APPLY CHANGES?", "", "")); multiLine, "apply", "APPLY CHANGES?", "", ""));
}); });
} }
else { else {
@ -699,7 +702,9 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
mGrid.setEntry(mButtons, glm::ivec2 {0, 5}, true, false, glm::ivec2 {2, 1}); mGrid.setEntry(mButtons, glm::ivec2 {0, 5}, true, false, glm::ivec2 {2, 1});
// Resize + center. // Resize + center.
float width {std::min(Renderer::getScreenHeight() * 1.05f, Renderer::getScreenWidth() * 0.90f)}; float width {std::min(mRenderer->getScreenHeight() * 1.05f,
mRenderer->getScreenWidth() *
(mRenderer->getIsVerticalOrientation() ? 0.95f : 0.90f))};
// Set height explicitly to ten rows for the component list. // Set height explicitly to ten rows for the component list.
float height {mList->getRowHeight(0) * 10.0f + mTitle->getSize().y + mSubtitle->getSize().y + float height {mList->getRowHeight(0) * 10.0f + mTitle->getSize().y + mSubtitle->getSize().y +
@ -723,8 +728,8 @@ void GuiMetaDataEd::onSizeChanged()
mGrid.setSize(mSize); mGrid.setSize(mSize);
mBackground.fitTo(mSize, glm::vec3 {}, glm::vec2 {-32.0f, -32.0f}); mBackground.fitTo(mSize, glm::vec3 {}, glm::vec2 {-32.0f, -32.0f});
setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f, setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f,
(Renderer::getScreenHeight() - mSize.y) / 2.0f); (mRenderer->getScreenHeight() - mSize.y) / 2.0f);
// Add some extra margins to the file/folder name. // Add some extra margins to the file/folder name.
const float newSizeX {mSize.x * 0.96f}; const float newSizeX {mSize.x * 0.96f};

View file

@ -46,6 +46,7 @@ private:
void fetchDone(const ScraperSearchResult& result); void fetchDone(const ScraperSearchResult& result);
void close(); void close();
Renderer* mRenderer;
NinePatchComponent mBackground; NinePatchComponent mBackground;
ComponentGrid mGrid; ComponentGrid mGrid;

View file

@ -923,8 +923,8 @@ void GuiScraperSearch::openInputScreen(ScraperSearchParams& params)
searchString = Utils::String::replace(searchString, "_", " "); searchString = Utils::String::replace(searchString, "_", " ");
if (Settings::getInstance()->getBool("VirtualKeyboard")) { if (Settings::getInstance()->getBool("VirtualKeyboard")) {
mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), "REFINE SEARCH", searchString, mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), 0.0f, "REFINE SEARCH",
searchForFunc, false, "SEARCH", searchString, searchForFunc, false, "SEARCH",
"SEARCH USING REFINED NAME?")); "SEARCH USING REFINED NAME?"));
} }
else { else {

View file

@ -23,7 +23,8 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
GuiSettings::GuiSettings(std::string title) GuiSettings::GuiSettings(std::string title)
: mMenu {title} : mRenderer {Renderer::getInstance()}
, mMenu {title}
, mGoToSystem {nullptr} , mGoToSystem {nullptr}
, mNeedsSaving {false} , mNeedsSaving {false}
, mNeedsCollectionsUpdate {false} , mNeedsCollectionsUpdate {false}
@ -213,12 +214,13 @@ void GuiSettings::addEditableTextComponent(const std::string label,
row.makeAcceptInputHandler([this, label, ed, updateVal, isPassword] { row.makeAcceptInputHandler([this, label, ed, updateVal, isPassword] {
// Never display the value if it's a password, instead set it to blank. // Never display the value if it's a password, instead set it to blank.
if (isPassword) if (isPassword)
mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), label, "", updateVal, mWindow->pushGui(
false, "SAVE", "SAVE CHANGES?")); new GuiTextEditKeyboardPopup(getHelpStyle(), getMenu().getPosition().y, label,
"", updateVal, false, "SAVE", "SAVE CHANGES?"));
else else
mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), label, ed->getValue(), mWindow->pushGui(new GuiTextEditKeyboardPopup(
updateVal, false, "SAVE", getHelpStyle(), getMenu().getPosition().y, label, ed->getValue(), updateVal,
"SAVE CHANGES?")); false, "SAVE", "SAVE CHANGES?"));
}); });
} }
else { else {

View file

@ -64,6 +64,7 @@ public:
HelpStyle getHelpStyle() override { return ViewController::getInstance()->getViewHelpStyle(); } HelpStyle getHelpStyle() override { return ViewController::getInstance()->getViewHelpStyle(); }
private: private:
Renderer* mRenderer;
MenuComponent mMenu; MenuComponent mMenu;
std::vector<std::function<void()>> mSaveFuncs; std::vector<std::function<void()>> mSaveFuncs;
SystemData* mGoToSystem; SystemData* mGoToSystem;

View file

@ -12,6 +12,7 @@
#include "views/ViewController.h" #include "views/ViewController.h"
#include "CollectionSystemsManager.h"
#include "FileFilterIndex.h" #include "FileFilterIndex.h"
#include "InputManager.h" #include "InputManager.h"
#include "Log.h" #include "Log.h"
@ -59,11 +60,11 @@ ViewController* ViewController::getInstance()
void ViewController::invalidSystemsFileDialog() void ViewController::invalidSystemsFileDialog()
{ {
std::string errorMessage = "COULDN'T PARSE THE SYSTEMS CONFIGURATION FILE.\n" std::string errorMessage = "COULDN'T PARSE THE SYSTEMS CONFIGURATION FILE. "
"IF YOU HAVE A CUSTOMIZED es_systems.xml FILE, THEN\n" "IF YOU HAVE A CUSTOMIZED es_systems.xml FILE, THEN "
"SOMETHING IS LIKELY WRONG WITH YOUR XML SYNTAX.\n" "SOMETHING IS LIKELY WRONG WITH YOUR XML SYNTAX. "
"IF YOU DON'T HAVE A CUSTOM SYSTEMS FILE, THEN THE\n" "IF YOU DON'T HAVE A CUSTOM SYSTEMS FILE, THEN THE "
"EMULATIONSTATION INSTALLATION IS BROKEN. SEE THE\n" "EMULATIONSTATION INSTALLATION IS BROKEN. SEE THE "
"APPLICATION LOG FILE es_log.txt FOR ADDITIONAL INFO."; "APPLICATION LOG FILE es_log.txt FOR ADDITIONAL INFO.";
mWindow->pushGui(new GuiMsgBox( mWindow->pushGui(new GuiMsgBox(
@ -78,11 +79,11 @@ void ViewController::invalidSystemsFileDialog()
void ViewController::noGamesDialog() void ViewController::noGamesDialog()
{ {
mNoGamesErrorMessage = "NO GAME FILES WERE FOUND. EITHER PLACE YOUR GAMES IN\n" mNoGamesErrorMessage = "NO GAME FILES WERE FOUND. EITHER PLACE YOUR GAMES IN "
"THE CURRENTLY CONFIGURED ROM DIRECTORY OR CHANGE\n" "THE CURRENTLY CONFIGURED ROM DIRECTORY OR CHANGE "
"ITS PATH USING THE BUTTON BELOW. OPTIONALLY THE ROM\n" "ITS PATH USING THE BUTTON BELOW. OPTIONALLY THE ROM "
"DIRECTORY STRUCTURE CAN BE GENERATED WHICH WILL\n" "DIRECTORY STRUCTURE CAN BE GENERATED WHICH WILL "
"CREATE A TEXT FILE FOR EACH SYSTEM PROVIDING SOME\n" "CREATE A TEXT FILE FOR EACH SYSTEM PROVIDING SOME "
"INFORMATION SUCH AS THE SUPPORTED FILE EXTENSIONS.\n" "INFORMATION SUCH AS THE SUPPORTED FILE EXTENSIONS.\n"
"THIS IS THE CURRENTLY CONFIGURED ROM DIRECTORY:\n"; "THIS IS THE CURRENTLY CONFIGURED ROM DIRECTORY:\n";
@ -103,7 +104,7 @@ void ViewController::noGamesDialog()
#endif #endif
if (Settings::getInstance()->getBool("VirtualKeyboard")) { if (Settings::getInstance()->getBool("VirtualKeyboard")) {
mWindow->pushGui(new GuiTextEditKeyboardPopup( mWindow->pushGui(new GuiTextEditKeyboardPopup(
HelpStyle(), "ENTER ROM DIRECTORY PATH", currentROMDirectory, HelpStyle(), 0.0f, "ENTER ROM DIRECTORY PATH", currentROMDirectory,
[this](const std::string& newROMDirectory) { [this](const std::string& newROMDirectory) {
Settings::getInstance()->setString("ROMDirectory", Settings::getInstance()->setString("ROMDirectory",
Utils::String::trim(newROMDirectory)); Utils::String::trim(newROMDirectory));

View file

@ -77,6 +77,7 @@ std::vector<std::vector<const char*>> kbLastRowLoad {
GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup( GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
const HelpStyle& helpstyle, const HelpStyle& helpstyle,
const float verticalPosition,
const std::string& title, const std::string& title,
const std::string& initValue, const std::string& initValue,
const std::function<void(const std::string&)>& okCallback, const std::function<void(const std::string&)>& okCallback,
@ -104,6 +105,7 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
, mDeleteRepeat {false} , mDeleteRepeat {false}
, mShift {false} , mShift {false}
, mAlt {false} , mAlt {false}
, mVerticalPosition {verticalPosition}
, mDeleteRepeatTimer {0} , mDeleteRepeatTimer {0}
, mNavigationRepeatTimer {0} , mNavigationRepeatTimer {0}
, mNavigationRepeatDirX {0} , mNavigationRepeatDirX {0}
@ -129,7 +131,7 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
mHorizontalKeyCount = static_cast<int>(kbLayout[0].size()); mHorizontalKeyCount = static_cast<int>(kbLayout[0].size());
mKeyboardGrid = std::make_shared<ComponentGrid>( mKeyboardGrid = std::make_shared<ComponentGrid>(
glm::ivec2(mHorizontalKeyCount, static_cast<int>(kbLayout.size()) / 3)); glm::ivec2 {mHorizontalKeyCount, static_cast<int>(kbLayout.size()) / 3});
mText = std::make_shared<TextEditComponent>(); mText = std::make_shared<TextEditComponent>();
mText->setValue(initValue); mText->setValue(initValue);
@ -137,7 +139,7 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
// Header. // Header.
mGrid.setEntry(mTitle, glm::ivec2 {0, 0}, false, true); mGrid.setEntry(mTitle, glm::ivec2 {0, 0}, false, true);
int yPos = 1; int yPos {1};
if (mComplexMode) { if (mComplexMode) {
mInfoString = std::make_shared<TextComponent>(infoString, Font::get(FONT_SIZE_MEDIUM), mInfoString = std::make_shared<TextComponent>(infoString, Font::get(FONT_SIZE_MEDIUM),
@ -157,19 +159,19 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
std::vector<std::vector<std::shared_ptr<ButtonComponent>>> buttonList; std::vector<std::vector<std::shared_ptr<ButtonComponent>>> buttonList;
// Create keyboard. // Create keyboard.
for (int i = 0; i < static_cast<int>(kbLayout.size()) / 4; ++i) { for (int i {0}; i < static_cast<int>(kbLayout.size()) / 4; ++i) {
std::vector<std::shared_ptr<ButtonComponent>> buttons; std::vector<std::shared_ptr<ButtonComponent>> buttons;
for (int j = 0; j < static_cast<int>(kbLayout[i].size()); ++j) { for (int j {0}; j < static_cast<int>(kbLayout[i].size()); ++j) {
std::string lower = kbLayout[4 * i][j]; std::string lower {kbLayout[4 * i][j]};
if (lower.empty() || lower == "-rowspan-" || lower == "-colspan-") if (lower.empty() || lower == "-rowspan-" || lower == "-colspan-")
continue; continue;
std::string upper = kbLayout[4 * i + 1][j]; std::string upper {kbLayout[4 * i + 1][j]};
std::string alted = kbLayout[4 * i + 2][j]; std::string alted {kbLayout[4 * i + 2][j]};
std::string altshifted = kbLayout[4 * i + 3][j]; std::string altshifted {kbLayout[4 * i + 3][j]};
std::shared_ptr<ButtonComponent> button = nullptr; std::shared_ptr<ButtonComponent> button;
if (lower == "DEL") { if (lower == "DEL") {
lower = DELETE_SYMBOL; lower = DELETE_SYMBOL;
@ -211,12 +213,12 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
} }
button->setPadding( button->setPadding(
glm::vec4(BUTTON_GRID_HORIZ_PADDING / 4.0f, BUTTON_GRID_HORIZ_PADDING / 4.0f, glm::vec4 {BUTTON_GRID_HORIZ_PADDING / 4.0f, BUTTON_GRID_HORIZ_PADDING / 4.0f,
BUTTON_GRID_HORIZ_PADDING / 4.0f, BUTTON_GRID_HORIZ_PADDING / 4.0f)); BUTTON_GRID_HORIZ_PADDING / 4.0f, BUTTON_GRID_HORIZ_PADDING / 4.0f});
buttons.push_back(button); buttons.push_back(button);
int colSpan = 1; int colSpan {1};
for (int cs = j + 1; cs < static_cast<int>(kbLayout[i].size()); ++cs) { for (int cs {j + 1}; cs < static_cast<int>(kbLayout[i].size()); ++cs) {
if (std::string(kbLayout[4 * i][cs]) == "-colspan-") if (std::string(kbLayout[4 * i][cs]) == "-colspan-")
++colSpan; ++colSpan;
else else
@ -224,7 +226,7 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
} }
int rowSpan = 1; int rowSpan = 1;
for (int cs = (4 * i) + 4; cs < static_cast<int>(kbLayout.size()); cs += 4) { for (int cs {(4 * i) + 4}; cs < static_cast<int>(kbLayout.size()); cs += 4) {
if (std::string(kbLayout[cs][j]) == "-rowspan-") if (std::string(kbLayout[cs][j]) == "-rowspan-")
++rowSpan; ++rowSpan;
else else
@ -240,7 +242,7 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
mGrid.setEntry(mKeyboardGrid, glm::ivec2 {0, yPos + 1}, true, true, glm::ivec2 {1, 4}); mGrid.setEntry(mKeyboardGrid, glm::ivec2 {0, yPos + 1}, true, true, glm::ivec2 {1, 4});
float textHeight = mText->getFont()->getHeight(); float textHeight {mText->getFont()->getHeight()};
// If the multiLine option has been set, then include three lines of text on screen. // If the multiLine option has been set, then include three lines of text on screen.
if (multiLine) { if (multiLine) {
textHeight *= 3.0f; textHeight *= 3.0f;
@ -268,15 +270,20 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
// Adapt width to the geometry of the display. The 1.778 aspect ratio is the 16:9 reference. // Adapt width to the geometry of the display. The 1.778 aspect ratio is the 16:9 reference.
float aspectValue {1.778f / mRenderer->getScreenAspectRatio()}; float aspectValue {1.778f / mRenderer->getScreenAspectRatio()};
float width {glm::clamp(0.78f * aspectValue, 0.35f, 0.90f) * mRenderer->getScreenWidth()}; const float maxWidthMultiplier {mRenderer->getIsVerticalOrientation() ? 0.95f : 0.90f};
float width {glm::clamp(0.78f * aspectValue, 0.35f, maxWidthMultiplier) *
mRenderer->getScreenWidth()};
// The combination of multiLine and complex mode is not supported as there is currently // The combination of multiLine and complex mode is not supported as there is currently
// no need for that. // no need for that.
if (mMultiLine) { if (mMultiLine) {
setSize(width, KEYBOARD_HEIGHT + textHeight - mText->getFont()->getHeight()); setSize(width, KEYBOARD_HEIGHT + textHeight - mText->getFont()->getHeight());
if (mVerticalPosition == 0.0f)
setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f, setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f,
(mRenderer->getScreenHeight() - mSize.y) / 2.0f); (mRenderer->getScreenHeight() - mSize.y) / 2.0f);
else
setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f, mVerticalPosition);
} }
else { else {
if (mComplexMode) if (mComplexMode)
@ -284,8 +291,11 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
else else
setSize(width, KEYBOARD_HEIGHT); setSize(width, KEYBOARD_HEIGHT);
if (mVerticalPosition == 0.0f)
setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f, setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f,
(mRenderer->getScreenHeight() - mSize.y) / 2.0f); (mRenderer->getScreenHeight() - mSize.y) / 2.0f);
else
setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f, mVerticalPosition);
} }
if (!multiLine) if (!multiLine)
@ -294,7 +304,7 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup(
void GuiTextEditKeyboardPopup::onSizeChanged() void GuiTextEditKeyboardPopup::onSizeChanged()
{ {
mBackground.fitTo(mSize, glm::vec3 {}, glm::vec2 {-32.0f, -32.0f}); mBackground.fitTo(mSize, glm::vec3 {0.0f, 0.0f, 0.0f}, glm::vec2 {-32.0f, -32.0f});
mText->setSize(mSize.x - KEYBOARD_PADDINGX - KEYBOARD_PADDINGX, mText->getSize().y); mText->setSize(mSize.x - KEYBOARD_PADDINGX - KEYBOARD_PADDINGX, mText->getSize().y);
// Update grid. // Update grid.
@ -345,7 +355,7 @@ bool GuiTextEditKeyboardPopup::input(InputConfig* config, Input input)
} }
// Ignore whatever key is mapped to the back button so it can be used for text input. // Ignore whatever key is mapped to the back button so it can be used for text input.
bool keyboardBack {config->getDeviceId() == DEVICE_KEYBOARD && mText->isEditing() && const bool keyboardBack {config->getDeviceId() == DEVICE_KEYBOARD && mText->isEditing() &&
config->isMappedLike("b", input)}; config->isMappedLike("b", input)};
// Pressing back (or the escape key if using keyboard input) closes us. // Pressing back (or the escape key if using keyboard input) closes us.
@ -391,7 +401,7 @@ bool GuiTextEditKeyboardPopup::input(InputConfig* config, Input input)
mDeleteRepeat = true; mDeleteRepeat = true;
mDeleteRepeatTimer = -(DELETE_REPEAT_START_DELAY - DELETE_REPEAT_SPEED); mDeleteRepeatTimer = -(DELETE_REPEAT_START_DELAY - DELETE_REPEAT_SPEED);
bool editing = mText->isEditing(); const bool editing {mText->isEditing()};
if (!editing) if (!editing)
mText->startEditing(); mText->startEditing();
@ -410,7 +420,7 @@ bool GuiTextEditKeyboardPopup::input(InputConfig* config, Input input)
// Right shoulder button inserts a blank space. // Right shoulder button inserts a blank space.
if (config->isMappedTo("rightshoulder", input) && input.value) { if (config->isMappedTo("rightshoulder", input) && input.value) {
bool editing = mText->isEditing(); const bool editing {mText->isEditing()};
if (!editing) if (!editing)
mText->startEditing(); mText->startEditing();
@ -527,7 +537,7 @@ void GuiTextEditKeyboardPopup::updateDeleteRepeat(int deltaTime)
mDeleteRepeatTimer += deltaTime; mDeleteRepeatTimer += deltaTime;
while (mDeleteRepeatTimer >= DELETE_REPEAT_SPEED) { while (mDeleteRepeatTimer >= DELETE_REPEAT_SPEED) {
bool editing = mText->isEditing(); bool editing {mText->isEditing()};
if (!editing) if (!editing)
mText->startEditing(); mText->startEditing();
@ -595,7 +605,7 @@ void GuiTextEditKeyboardPopup::shiftKeys()
} }
else { else {
for (auto& kb : mKeyboardButtons) { for (auto& kb : mKeyboardButtons) {
const std::string& text = mShift ? kb.shiftedKey : kb.key; const std::string& text {mShift ? kb.shiftedKey : kb.key};
auto sz = kb.button->getSize(); auto sz = kb.button->getSize();
kb.button->setText(text, text, false); kb.button->setText(text, text, false);
kb.button->setSize(sz); kb.button->setSize(sz);
@ -628,7 +638,7 @@ void GuiTextEditKeyboardPopup::altKeys()
} }
else { else {
for (auto& kb : mKeyboardButtons) { for (auto& kb : mKeyboardButtons) {
const std::string& text = mAlt ? kb.altedKey : kb.key; const std::string& text {mAlt ? kb.altedKey : kb.key};
auto sz = kb.button->getSize(); auto sz = kb.button->getSize();
kb.button->setText(text, text, false); kb.button->setText(text, text, false);
kb.button->setSize(sz); kb.button->setSize(sz);
@ -639,7 +649,7 @@ void GuiTextEditKeyboardPopup::altKeys()
void GuiTextEditKeyboardPopup::altShiftKeys() void GuiTextEditKeyboardPopup::altShiftKeys()
{ {
for (auto& kb : mKeyboardButtons) { for (auto& kb : mKeyboardButtons) {
const std::string& text = kb.altshiftedKey; const std::string& text {kb.altshiftedKey};
auto sz = kb.button->getSize(); auto sz = kb.button->getSize();
kb.button->setText(text, text, false); kb.button->setText(text, text, false);
kb.button->setSize(sz); kb.button->setSize(sz);
@ -652,7 +662,7 @@ std::shared_ptr<ButtonComponent> GuiTextEditKeyboardPopup::makeButton(
const std::string& altedKey, const std::string& altedKey,
const std::string& altshiftedKey) const std::string& altshiftedKey)
{ {
std::shared_ptr<ButtonComponent> button = std::make_shared<ButtonComponent>( std::shared_ptr<ButtonComponent> button {std::make_shared<ButtonComponent>(
key, key, key, key,
[this, key, shiftedKey, altedKey, altshiftedKey] { [this, key, shiftedKey, altedKey, altshiftedKey] {
if (key == (OK_SYMBOL) || key.find("OK") != std::string::npos) { if (key == (OK_SYMBOL) || key.find("OK") != std::string::npos) {
@ -702,9 +712,9 @@ std::shared_ptr<ButtonComponent> GuiTextEditKeyboardPopup::makeButton(
mText->stopEditing(); mText->stopEditing();
}, },
false, true); false, true)};
KeyboardButton kb(button, key, shiftedKey, altedKey, altshiftedKey); KeyboardButton kb {button, key, shiftedKey, altedKey, altshiftedKey};
mKeyboardButtons.push_back(kb); mKeyboardButtons.push_back(kb);
return button; return button;
} }

View file

@ -19,6 +19,7 @@ class GuiTextEditKeyboardPopup : public GuiComponent
{ {
public: public:
GuiTextEditKeyboardPopup(const HelpStyle& helpstyle, GuiTextEditKeyboardPopup(const HelpStyle& helpstyle,
const float verticalPosition,
const std::string& title, const std::string& title,
const std::string& initValue, const std::string& initValue,
const std::function<void(const std::string&)>& okCallback, const std::function<void(const std::string&)>& okCallback,
@ -101,6 +102,8 @@ private:
bool mShift; bool mShift;
bool mAlt; bool mAlt;
float mVerticalPosition;
int mHorizontalKeyCount; int mHorizontalKeyCount;
int mDeleteRepeatTimer; int mDeleteRepeatTimer;
int mNavigationRepeatTimer; int mNavigationRepeatTimer;