mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-02-16 20:15:38 +00:00
Added the ability to GuiMsgBox to change the text of an open dialog.
Also added an option for whether to delete the dialog when calling a function mapped to a button.
This commit is contained in:
parent
172182a4e8
commit
dd851bee40
|
@ -18,15 +18,20 @@ GuiMsgBox::GuiMsgBox(Window* window, const HelpStyle& helpstyle, const std::stri
|
||||||
const std::string& name1, const std::function<void()>& func1,
|
const std::string& name1, const std::function<void()>& func1,
|
||||||
const std::string& name2, const std::function<void()>& func2,
|
const std::string& name2, const std::function<void()>& func2,
|
||||||
const std::string& name3, const std::function<void()>& func3,
|
const std::string& name3, const std::function<void()>& func3,
|
||||||
bool disableBackButton)
|
bool disableBackButton,
|
||||||
|
bool deleteOnButtonPress)
|
||||||
: GuiComponent(window),
|
: GuiComponent(window),
|
||||||
mHelpStyle(helpstyle),
|
mHelpStyle(helpstyle),
|
||||||
mBackground(window, ":/graphics/frame.svg"),
|
mBackground(window, ":/graphics/frame.svg"),
|
||||||
mGrid(window, Vector2i(1, 2)),
|
mGrid(window, Vector2i(1, 2)),
|
||||||
mDisableBackButton(disableBackButton)
|
mDisableBackButton(disableBackButton),
|
||||||
|
mDeleteOnButtonPress(deleteOnButtonPress)
|
||||||
{
|
{
|
||||||
float width = Renderer::getScreenWidth() * 0.6f; // Max width.
|
// For narrower displays (e.g. in 4:3 ratio), allow the window to fill 80% of the screen
|
||||||
float minWidth = Renderer::getScreenWidth() * 0.3f; // Minimum width.
|
// width rather than the 60% allowed for wider displays.
|
||||||
|
float width = Renderer::getScreenWidth() *
|
||||||
|
((Renderer::getScreenAspectRatio() < 1.4f) ? 0.8f : 0.6f);
|
||||||
|
float minWidth = Renderer::getScreenWidth() * 0.3f;
|
||||||
|
|
||||||
mMsg = std::make_shared<TextComponent>(mWindow, text, Font::get(FONT_SIZE_MEDIUM),
|
mMsg = std::make_shared<TextComponent>(mWindow, text, Font::get(FONT_SIZE_MEDIUM),
|
||||||
0x777777FF, ALIGN_CENTER);
|
0x777777FF, ALIGN_CENTER);
|
||||||
|
@ -66,6 +71,9 @@ GuiMsgBox::GuiMsgBox(Window* window, const HelpStyle& helpstyle, const std::stri
|
||||||
width = std::max(mButtonGrid->getSize().x(), mMsg->getSize().x());
|
width = std::max(mButtonGrid->getSize().x(), mMsg->getSize().x());
|
||||||
width = std::max(width, minWidth);
|
width = std::max(width, minWidth);
|
||||||
}
|
}
|
||||||
|
else if (mButtonGrid->getSize().x() > width) {
|
||||||
|
width = mButtonGrid->getSize().x();
|
||||||
|
}
|
||||||
|
|
||||||
// Now that we know width, we can find height.
|
// Now that we know width, we can find height.
|
||||||
mMsg->setSize(width, 0); // mMsg->getSize.y() now returns the proper length.
|
mMsg->setSize(width, 0); // mMsg->getSize.y() now returns the proper length.
|
||||||
|
@ -82,6 +90,36 @@ GuiMsgBox::GuiMsgBox(Window* window, const HelpStyle& helpstyle, const std::stri
|
||||||
addChild(&mGrid);
|
addChild(&mGrid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiMsgBox::changeText(const std::string& newText)
|
||||||
|
{
|
||||||
|
mMsg->setText(newText);
|
||||||
|
mMsg->setSize(mMsg->getFont()->sizeText(newText));
|
||||||
|
|
||||||
|
// For narrower displays (e.g. in 4:3 ratio), allow the window to fill 80% of the screen
|
||||||
|
// width rather than the 60% allowed for wider displays.
|
||||||
|
float width = Renderer::getScreenWidth() *
|
||||||
|
((Renderer::getScreenAspectRatio() < 1.4f) ? 0.8f : 0.6f);
|
||||||
|
|
||||||
|
float minWidth = Renderer::getScreenWidth() * 0.3f;
|
||||||
|
|
||||||
|
// Decide final width.
|
||||||
|
if (mMsg->getSize().x() < width && mButtonGrid->getSize().x() < width) {
|
||||||
|
// mMsg and buttons are narrower than width.
|
||||||
|
width = std::max(mButtonGrid->getSize().x(), mMsg->getSize().x());
|
||||||
|
width = std::max(width, minWidth);
|
||||||
|
}
|
||||||
|
else if (mButtonGrid->getSize().x() > mSize.x()) {
|
||||||
|
width = mButtonGrid->getSize().x();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now that we know width, we can find height.
|
||||||
|
mMsg->setSize(width, 0); // mMsg->getSize.y() now returns the proper length.
|
||||||
|
const float msgHeight = std::max(Font::get(FONT_SIZE_LARGE)->getHeight(),
|
||||||
|
mMsg->getSize().y() * 1.225f);
|
||||||
|
setSize(width + HORIZONTAL_PADDING_PX * 2 * Renderer::getScreenWidthModifier(),
|
||||||
|
msgHeight + mButtonGrid->getSize().y());
|
||||||
|
}
|
||||||
|
|
||||||
bool GuiMsgBox::input(InputConfig* config, Input input)
|
bool GuiMsgBox::input(InputConfig* config, Input input)
|
||||||
{
|
{
|
||||||
// Special case for when GuiMsgBox comes up to report errors before
|
// Special case for when GuiMsgBox comes up to report errors before
|
||||||
|
@ -118,6 +156,8 @@ void GuiMsgBox::onSizeChanged()
|
||||||
void GuiMsgBox::deleteMeAndCall(const std::function<void()>& func)
|
void GuiMsgBox::deleteMeAndCall(const std::function<void()>& func)
|
||||||
{
|
{
|
||||||
auto funcCopy = func;
|
auto funcCopy = func;
|
||||||
|
|
||||||
|
if (mDeleteOnButtonPress)
|
||||||
delete this;
|
delete this;
|
||||||
|
|
||||||
if (funcCopy)
|
if (funcCopy)
|
||||||
|
|
|
@ -20,11 +20,20 @@ class TextComponent;
|
||||||
class GuiMsgBox : public GuiComponent
|
class GuiMsgBox : public GuiComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiMsgBox(Window* window, const HelpStyle& helpstyle, const std::string& text,
|
GuiMsgBox(
|
||||||
const std::string& name1 = "OK", const std::function<void()>& func1 = nullptr,
|
Window* window,
|
||||||
const std::string& name2 = "", const std::function<void()>& func2 = nullptr,
|
const HelpStyle& helpstyle,
|
||||||
const std::string& name3 = "", const std::function<void()>& func3 = nullptr,
|
const std::string& text,
|
||||||
bool disableBackButton = false);
|
const std::string& name1 = "OK",
|
||||||
|
const std::function<void()>& func1 = nullptr,
|
||||||
|
const std::string& name2 = "",
|
||||||
|
const std::function<void()>& func2 = nullptr,
|
||||||
|
const std::string& name3 = "",
|
||||||
|
const std::function<void()>& func3 = nullptr,
|
||||||
|
bool disableBackButton = false,
|
||||||
|
bool deleteOnButtonPress = true);
|
||||||
|
|
||||||
|
void changeText(const std::string& newText);
|
||||||
|
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
|
@ -44,6 +53,7 @@ private:
|
||||||
std::shared_ptr<ComponentGrid> mButtonGrid;
|
std::shared_ptr<ComponentGrid> mButtonGrid;
|
||||||
std::function<void()> mAcceleratorFunc;
|
std::function<void()> mAcceleratorFunc;
|
||||||
bool mDisableBackButton;
|
bool mDisableBackButton;
|
||||||
|
bool mDeleteOnButtonPress;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ES_CORE_GUIS_GUI_MSG_BOX_H
|
#endif // ES_CORE_GUIS_GUI_MSG_BOX_H
|
||||||
|
|
Loading…
Reference in a new issue