summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-07-16 22:23:16 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-07-17 14:52:06 +0200
commite6dceba196e5bc8e305101c63add0c76a3912ff0 (patch)
tree54d492bdc0c1c4db3d0309ab5ca28ad0e1879873
parentf83b1d648fc6ec2c64fd2c3483fede23c973c20f (diff)
downloadmana-e6dceba196e5bc8e305101c63add0c76a3912ff0.tar.gz
mana-e6dceba196e5bc8e305101c63add0c76a3912ff0.tar.bz2
mana-e6dceba196e5bc8e305101c63add0c76a3912ff0.tar.xz
mana-e6dceba196e5bc8e305101c63add0c76a3912ff0.zip
Use layout system for Confirm and Ok dialogs
Fixes some issues with the manual layout.
-rw-r--r--src/gui/confirmdialog.cpp50
-rw-r--r--src/gui/confirmdialog.h5
-rw-r--r--src/gui/okdialog.cpp37
-rw-r--r--src/gui/okdialog.h5
4 files changed, 25 insertions, 72 deletions
diff --git a/src/gui/confirmdialog.cpp b/src/gui/confirmdialog.cpp
index c0b471c1..360b399b 100644
--- a/src/gui/confirmdialog.cpp
+++ b/src/gui/confirmdialog.cpp
@@ -22,49 +22,34 @@
#include "gui/confirmdialog.h"
#include "gui/widgets/button.h"
+#include "gui/widgets/layout.h"
#include "gui/widgets/textbox.h"
#include "utils/gettext.h"
#include <guichan/font.hpp>
-ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
- Window *parent):
+ConfirmDialog::ConfirmDialog(const std::string &title,
+ const std::string &msg,
+ Window *parent):
Window(title, true, parent)
{
- mTextBox = new TextBox;
- mTextBox->setEditable(false);
- mTextBox->setOpaque(false);
- mTextBox->setTextWrapped(msg, 260);
+ auto textBox = new TextBox;
+ textBox->setEditable(false);
+ textBox->setOpaque(false);
+ textBox->setTextWrapped(msg, 260);
gcn::Button *yesButton = new Button(_("Yes"), "yes", this);
gcn::Button *noButton = new Button(_("No"), "no", this);
- const int numRows = mTextBox->getNumberOfRows();
- const int inWidth = yesButton->getWidth() + noButton->getWidth() +
- (2 * getPadding());
- const int fontHeight = getFont()->getHeight();
- const int height = numRows * fontHeight;
- int width = getFont()->getWidth(title);
+ auto place = getPlacer(0, 0);
+ place(0, 0, textBox);
- if (width < mTextBox->getMinWidth())
- width = mTextBox->getMinWidth();
- if (width < inWidth)
- width = inWidth;
-
- setContentSize(mTextBox->getMinWidth() + fontHeight, height + fontHeight +
- noButton->getHeight());
- mTextBox->setPosition(getPadding(), getPadding());
-
- // 8 is the padding that GUIChan adds to button widgets
- // (top and bottom combined)
- yesButton->setPosition((width - inWidth) / 2, height + 8);
- noButton->setPosition(yesButton->getX() + inWidth - noButton->getWidth(),
- height + 8);
-
- add(mTextBox);
- add(yesButton);
- add(noButton);
+ place = getPlacer(0, 1);
+ place(0, 0, yesButton);
+ place(1, 0, noButton);
+ place.getCell().setHAlign(Layout::CENTER);
+ reflowLayout();
if (getParent())
{
@@ -79,8 +64,5 @@ void ConfirmDialog::action(const gcn::ActionEvent &event)
{
setActionEventId(event.getId());
distributeActionEvent();
-
- // Can we receive anything else anyway?
- if (event.getId() == "yes" || event.getId() == "no")
- scheduleDelete();
+ scheduleDelete();
}
diff --git a/src/gui/confirmdialog.h b/src/gui/confirmdialog.h
index ba51558e..6098b3f7 100644
--- a/src/gui/confirmdialog.h
+++ b/src/gui/confirmdialog.h
@@ -25,8 +25,6 @@
#include <guichan/actionlistener.hpp>
-class TextBox;
-
/**
* An option dialog.
*
@@ -42,7 +40,4 @@ class ConfirmDialog : public Window, public gcn::ActionListener
* Called when receiving actions from the widgets.
*/
void action(const gcn::ActionEvent &event) override;
-
- private:
- TextBox *mTextBox;
};
diff --git a/src/gui/okdialog.cpp b/src/gui/okdialog.cpp
index 5a710890..287ee1b8 100644
--- a/src/gui/okdialog.cpp
+++ b/src/gui/okdialog.cpp
@@ -22,6 +22,7 @@
#include "gui/okdialog.h"
#include "gui/widgets/button.h"
+#include "gui/widgets/layout.h"
#include "gui/widgets/textbox.h"
#include "utils/gettext.h"
@@ -32,33 +33,16 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg,
bool modal, Window *parent):
Window(title, modal, parent)
{
- mTextBox = new TextBox;
- mTextBox->setEditable(false);
- mTextBox->setOpaque(false);
- mTextBox->setTextWrapped(msg, 260);
+ auto textBox = new TextBox;
+ textBox->setEditable(false);
+ textBox->setOpaque(false);
+ textBox->setTextWrapped(msg, 260);
gcn::Button *okButton = new Button(_("OK"), "ok", this);
- const int numRows = mTextBox->getNumberOfRows();
- const int fontHeight = getFont()->getHeight();
- const int height = numRows * fontHeight;
- int width = getFont()->getWidth(title);
-
- if (width < mTextBox->getMinWidth())
- width = mTextBox->getMinWidth();
- if (width < okButton->getWidth())
- width = okButton->getWidth();
-
- setContentSize(mTextBox->getMinWidth() + fontHeight, height +
- fontHeight + okButton->getHeight());
- mTextBox->setPosition(getPadding(), getPadding());
-
- // 8 is the padding that GUIChan adds to button widgets
- // (top and bottom combined)
- okButton->setPosition((width - okButton->getWidth()) / 2, height + 8);
-
- add(mTextBox);
- add(okButton);
+ place(0, 0, textBox);
+ place(0, 1, okButton).setHAlign(Layout::CENTER);
+ reflowLayout();
center();
setVisible(true);
@@ -69,8 +53,5 @@ void OkDialog::action(const gcn::ActionEvent &event)
{
setActionEventId(event.getId());
distributeActionEvent();
-
- // Can we receive anything else anyway?
- if (event.getId() == "ok")
- scheduleDelete();
+ scheduleDelete();
}
diff --git a/src/gui/okdialog.h b/src/gui/okdialog.h
index f56f24e2..18bca454 100644
--- a/src/gui/okdialog.h
+++ b/src/gui/okdialog.h
@@ -25,8 +25,6 @@
#include <guichan/actionlistener.hpp>
-class TextBox;
-
/**
* An 'Ok' button dialog.
*
@@ -42,7 +40,4 @@ class OkDialog : public Window, public gcn::ActionListener
* Called when receiving actions from the widgets.
*/
void action(const gcn::ActionEvent &event) override;
-
- private:
- TextBox *mTextBox;
};