diff --git a/src/components/MenuComponent.cpp b/src/components/MenuComponent.cpp index 59b4187fa..010fd7b4b 100644 --- a/src/components/MenuComponent.cpp +++ b/src/components/MenuComponent.cpp @@ -1,7 +1,8 @@ #include "MenuComponent.h" #include "ButtonComponent.h" -#define BUTTON_GRID_HEIGHT ((float)Font::get(FONT_SIZE_MEDIUM)->getHeight() + 32) +#define BUTTON_GRID_VERT_PADDING 20 +#define BUTTON_GRID_HORIZ_PADDING 16 using namespace Eigen; @@ -27,9 +28,14 @@ MenuComponent::MenuComponent(Window* window, const char* title) : GuiComponent(w mGrid.resetCursor(); } +float MenuComponent::getButtonGridHeight() const +{ + return (mButtonGrid ? mButtonGrid->getSize().y() : Font::get(FONT_SIZE_MEDIUM)->getHeight() + BUTTON_GRID_VERT_PADDING); +} + void MenuComponent::updateSize() { - float height = mTitle->getSize().y() + mList->getTotalRowHeight() + BUTTON_GRID_HEIGHT + 2; + float height = mTitle->getSize().y() + mList->getTotalRowHeight() + getButtonGridHeight() + 2; if(height > Renderer::getScreenHeight() * 0.7f) height = Renderer::getScreenHeight() * 0.7f; @@ -42,7 +48,7 @@ void MenuComponent::onSizeChanged() // update grid row/col sizes mGrid.setRowHeightPerc(0, mTitle->getSize().y() / mSize.y()); - mGrid.setRowHeightPerc(2, (BUTTON_GRID_HEIGHT) / mSize.y()); + mGrid.setRowHeightPerc(2, getButtonGridHeight() / mSize.y()); mGrid.setSize(mSize); } @@ -77,7 +83,7 @@ std::shared_ptr makeButtonGrid(Window* window, const std::vector< { std::shared_ptr buttonGrid = std::make_shared(window, Vector2i(buttons.size(), 1)); - float buttonGridWidth = 16.0f * buttons.size(); // initialize to padding + float buttonGridWidth = (float)BUTTON_GRID_HORIZ_PADDING * buttons.size(); // initialize to padding for(int i = 0; i < (int)buttons.size(); i++) { buttonGrid->setEntry(buttons.at(i), Vector2i(i, 0), true, false); @@ -85,10 +91,10 @@ std::shared_ptr makeButtonGrid(Window* window, const std::vector< } for(unsigned int i = 0; i < buttons.size(); i++) { - buttonGrid->setColWidthPerc(i, (buttons.at(i)->getSize().x() + 16) / buttonGridWidth); + buttonGrid->setColWidthPerc(i, (buttons.at(i)->getSize().x() + BUTTON_GRID_HORIZ_PADDING) / buttonGridWidth); } - buttonGrid->setSize(buttonGridWidth, buttons.at(0)->getSize().y()); + buttonGrid->setSize(buttonGridWidth, buttons.at(0)->getSize().y() + BUTTON_GRID_VERT_PADDING); return buttonGrid; } diff --git a/src/components/MenuComponent.h b/src/components/MenuComponent.h index c1068908f..52e5bae24 100644 --- a/src/components/MenuComponent.h +++ b/src/components/MenuComponent.h @@ -37,6 +37,7 @@ public: private: void updateSize(); void updateGrid(); + float getButtonGridHeight() const; NinePatchComponent mBackground; ComponentGrid mGrid; diff --git a/src/components/ScraperSearchComponent.cpp b/src/components/ScraperSearchComponent.cpp index 0e5931376..06a485442 100644 --- a/src/components/ScraperSearchComponent.cpp +++ b/src/components/ScraperSearchComponent.cpp @@ -98,28 +98,31 @@ void ScraperSearchComponent::onSizeChanged() // metadata // (mMD_Grid has already been resized by mGrid) - const int fontHeight = (int)(mMD_Grid->getSize().y() / mMD_Pairs.size() * 0.8f); - auto fontLbl = Font::get(fontHeight, FONT_PATH_REGULAR); - auto fontComp = Font::get(fontHeight, FONT_PATH_LIGHT); - - // update label fonts - float maxLblWidth = 0; - for(auto it = mMD_Pairs.begin(); it != mMD_Pairs.end(); it++) + if(mMD_Grid->getSize().y() > mMD_Pairs.size()) { - it->first->setFont(fontLbl); - it->first->setSize(0, 0); - if(it->first->getSize().x() > maxLblWidth) - maxLblWidth = it->first->getSize().x() + 6; + const int fontHeight = (int)(mMD_Grid->getSize().y() / mMD_Pairs.size() * 0.8f); + auto fontLbl = Font::get(fontHeight, FONT_PATH_REGULAR); + auto fontComp = Font::get(fontHeight, FONT_PATH_LIGHT); + + // update label fonts + float maxLblWidth = 0; + for(auto it = mMD_Pairs.begin(); it != mMD_Pairs.end(); it++) + { + it->first->setFont(fontLbl); + it->first->setSize(0, 0); + if(it->first->getSize().x() > maxLblWidth) + maxLblWidth = it->first->getSize().x() + 6; + } + + // update component fonts + mMD_ReleaseDate->setFont(fontComp); + mMD_Developer->setFont(fontComp); + mMD_Publisher->setFont(fontComp); + mMD_Genre->setFont(fontComp); + mMD_Players->setFont(fontComp); + + mMD_Grid->setColWidthPerc(0, maxLblWidth / mMD_Grid->getSize().x()); } - - // update component fonts - mMD_ReleaseDate->setFont(fontComp); - mMD_Developer->setFont(fontComp); - mMD_Publisher->setFont(fontComp); - mMD_Genre->setFont(fontComp); - mMD_Players->setFont(fontComp); - - mMD_Grid->setColWidthPerc(0, maxLblWidth / mMD_Grid->getSize().x()); } void ScraperSearchComponent::updateViewStyle() diff --git a/src/guis/GuiGameScraper.cpp b/src/guis/GuiGameScraper.cpp index 8e462f223..7d1f48af5 100644 --- a/src/guis/GuiGameScraper.cpp +++ b/src/guis/GuiGameScraper.cpp @@ -17,18 +17,9 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std:: addChild(&mBox); addChild(&mGrid); - setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); - - mGrid.setSize(mSize.x() * 0.7f, mSize.y() * 0.65f); - - auto headerFont = Font::get(FONT_SIZE_LARGE); - - mGrid.setRowHeightPerc(0, headerFont->getHeight() / mGrid.getSize().y()); // header - mGrid.setRowHeightPerc(2, 0.19f); // buttons - // header - mGrid.setEntry(std::make_shared(mWindow, getCleanFileName(mSearchParams.game->getName()), - headerFont, 0x777777FF, true), Eigen::Vector2i(0, 0), false, true); + mHeader = std::make_shared(mWindow, getCleanFileName(mSearchParams.game->getName()), Font::get(FONT_SIZE_LARGE), 0x777777FF, true); + mGrid.setEntry(mHeader, Eigen::Vector2i(0, 0), false, true); // ScraperSearchComponent mSearch = std::make_shared(window, ScraperSearchComponent::NEVER_AUTO_ACCEPT); @@ -38,13 +29,9 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std:: std::vector< std::shared_ptr > buttons; buttons.push_back(std::make_shared(mWindow, "INPUT", "manually search")); buttons.push_back(std::make_shared(mWindow, "CANCEL", "cancel", [&] { delete this; })); - auto buttonGrid = makeButtonGrid(mWindow, buttons); + mButtonGrid = makeButtonGrid(mWindow, buttons); - mGrid.setEntry(buttonGrid, Eigen::Vector2i(0, 2), true, false); - - // center everything - mGrid.setPosition((mSize.x() - mGrid.getSize().x()) / 2, (mSize.y() - mGrid.getSize().y()) / 2); - mBox.fitTo(mGrid.getSize(), mGrid.getPosition(), Eigen::Vector2f(-32, -32)); + mGrid.setEntry(mButtonGrid, Eigen::Vector2i(0, 2), true, false); // we call this->close() instead of just delete this; in the accept callback: // this is because of how GuiComponent::update works. if it was just delete this, this would happen when the metadata resolver is done: @@ -71,10 +58,22 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std:: mSearch->setAcceptCallback([this, doneFunc](const ScraperSearchResult& result) { doneFunc(result); close(); }); mSearch->setCancelCallback([&] { delete this; }); + setSize(Renderer::getScreenWidth() * 0.7f, Renderer::getScreenHeight() * 0.65f); + setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, (Renderer::getScreenHeight() - mSize.y()) / 2); + mGrid.resetCursor(); mSearch->search(params); // start the search } +void GuiGameScraper::onSizeChanged() +{ + mBox.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32)); + + mGrid.setSize(mSize); + mGrid.setRowHeightPerc(0, mHeader->getFont()->getHeight() / mSize.y()); // header + mGrid.setRowHeightPerc(2, mButtonGrid->getSize().y() / mSize.y()); // buttons +} + bool GuiGameScraper::input(InputConfig* config, Input input) { if(config->isMappedTo("b", input) && input.value) diff --git a/src/guis/GuiGameScraper.h b/src/guis/GuiGameScraper.h index fa27ecc03..46c45db17 100644 --- a/src/guis/GuiGameScraper.h +++ b/src/guis/GuiGameScraper.h @@ -9,6 +9,8 @@ class GuiGameScraper : public GuiComponent public: GuiGameScraper(Window* window, ScraperSearchParams params, std::function doneFunc); + void onSizeChanged() override; + bool input(InputConfig* config, Input input) override; void update(int deltaTime); virtual std::vector getHelpPrompts() override; @@ -20,7 +22,9 @@ private: ComponentGrid mGrid; NinePatchComponent mBox; + std::shared_ptr mHeader; std::shared_ptr mSearch; + std::shared_ptr mButtonGrid; ScraperSearchParams mSearchParams; diff --git a/src/guis/GuiMsgBox.cpp b/src/guis/GuiMsgBox.cpp index 0c997f61e..da58c6c5f 100644 --- a/src/guis/GuiMsgBox.cpp +++ b/src/guis/GuiMsgBox.cpp @@ -5,8 +5,6 @@ #include "../components/MenuComponent.h" // for makeButtonGrid #include "../Util.h" -#define BUTTON_VERT_PADDING 32.0f - GuiMsgBox::GuiMsgBox(Window* window, const std::string& text, const std::string& name1, const std::function& func1, const std::string& name2, const std::function& func2, @@ -60,7 +58,7 @@ GuiMsgBox::GuiMsgBox(Window* window, const std::string& text, } const float msgHeight = std::max(Font::get(FONT_SIZE_LARGE)->getHeight(), mMsg->getSize().y()); - setSize(width, msgHeight + mButtonGrid->getSize().y() + BUTTON_VERT_PADDING); + setSize(width, msgHeight + mButtonGrid->getSize().y()); // center for good measure setPosition((Renderer::getScreenWidth() - mSize.x()) / 2.0f, (Renderer::getScreenHeight() - mSize.y()) / 2.0f); @@ -85,7 +83,7 @@ void GuiMsgBox::onSizeChanged() mGrid.setSize(mSize); mBackground.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32)); - mGrid.setRowHeightPerc(1, (mButtonGrid->getSize().y() + BUTTON_VERT_PADDING) / mSize.y()); + mGrid.setRowHeightPerc(1, mButtonGrid->getSize().y() / mSize.y()); } void GuiMsgBox::deleteMeAndCall(const std::function& func) diff --git a/src/guis/GuiScraperMulti.cpp b/src/guis/GuiScraperMulti.cpp index 179dfcd50..efa4d7d5b 100644 --- a/src/guis/GuiScraperMulti.cpp +++ b/src/guis/GuiScraperMulti.cpp @@ -37,7 +37,6 @@ GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue(mWindow, "SKIP", "skip this game", std::bind(&GuiScraperMulti::skip, this))); buttons.push_back(std::make_shared(mWindow, "STOP", "cancel scraping", std::bind(&GuiScraperMulti::finish, this))); mButtonGrid = makeButtonGrid(mWindow, buttons); - mButtonGrid->setSize(mButtonGrid->getSize().x(), mButtonGrid->getSize().y() + 32); mGrid.setEntry(mButtonGrid, Vector2i(0, 3), true, false); setSize(Renderer::getScreenWidth() * 0.7f, Renderer::getScreenHeight() * 0.65f); diff --git a/src/guis/GuiTextEditPopup.cpp b/src/guis/GuiTextEditPopup.cpp index 342f74785..1c540cb12 100644 --- a/src/guis/GuiTextEditPopup.cpp +++ b/src/guis/GuiTextEditPopup.cpp @@ -27,7 +27,7 @@ GuiTextEditPopup::GuiTextEditPopup(Window* window, const std::string& title, con float textHeight = mText->getFont()->getHeight(); if(multiLine) - textHeight *= 3; + textHeight *= 6; setSize(Renderer::getScreenWidth() * 0.5f, mTitle->getFont()->getHeight() + textHeight + mButtonGrid->getSize().y()); setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, (Renderer::getScreenHeight() - mSize.y()) / 2);