summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-10-20 17:38:23 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-10-20 17:38:23 +0000
commit94ab3f3afa12f9f73d7f832e95aa0af2d9efdf16 (patch)
treef16d0fbe9c185ed57ff311ca99db02b29a455fe9 /src/gui
parentaab0b1724897e186d2d4056da7f0cd34ccc12fcb (diff)
downloadMana-94ab3f3afa12f9f73d7f832e95aa0af2d9efdf16.tar.gz
Mana-94ab3f3afa12f9f73d7f832e95aa0af2d9efdf16.tar.bz2
Mana-94ab3f3afa12f9f73d7f832e95aa0af2d9efdf16.tar.xz
Mana-94ab3f3afa12f9f73d7f832e95aa0af2d9efdf16.zip
Set FILL as default size in layout. Converted server selection dialog to layout handler.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/serverdialog.cpp43
-rw-r--r--src/gui/widgets/layout.cpp11
-rw-r--r--src/gui/widgets/layout.h18
3 files changed, 35 insertions, 37 deletions
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 292e8fca..aaaa5eca 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -34,6 +34,8 @@
#include "scrollarea.h"
#include "textfield.h"
+#include "widgets/layout.h"
+
#include "../configuration.h"
#include "../log.h"
#include "../logindata.h"
@@ -138,27 +140,6 @@ ServerDialog::ServerDialog(LoginData *loginData):
mOkButton = new Button(_("Ok"), "ok", this);
mCancelButton = new Button(_("Cancel"), "cancel", this);
- setContentSize(200, 100);
-
- serverLabel->setPosition(10, 5);
- portLabel->setPosition(10, 14 + serverLabel->getHeight());
-
- mServerNameField->setPosition(60, 5);
- mPortField->setPosition(60, 14 + serverLabel->getHeight());
- mServerNameField->setWidth(130);
- mPortField->setWidth(130);
-
- mMostUsedServersDropDown->setPosition(10, 10 +
- portLabel->getY() + portLabel->getHeight());
- mMostUsedServersDropDown->setWidth(180);
-
- mCancelButton->setPosition(
- 200 - mCancelButton->getWidth() - 5,
- 100 - mCancelButton->getHeight() - 5);
- mOkButton->setPosition(
- mCancelButton->getX() - mOkButton->getWidth() - 5,
- 100 - mOkButton->getHeight() - 5);
-
mServerNameField->setActionEventId("ok");
mPortField->setActionEventId("ok");
mMostUsedServersDropDown->setActionEventId("changeSelection");
@@ -167,13 +148,19 @@ ServerDialog::ServerDialog(LoginData *loginData):
mPortField->addActionListener(this);
mMostUsedServersDropDown->addActionListener(mDropDownListener);
- add(serverLabel);
- add(portLabel);
- add(mServerNameField);
- add(mPortField);
- add(mMostUsedServersDropDown);
- add(mOkButton);
- add(mCancelButton);
+ setPadding(8);
+ place(0, 0, serverLabel);
+ place(0, 1, portLabel);
+ place(1, 0, mServerNameField, 3).setPadding(3);
+ place(1, 1, mPortField, 3).setPadding(3);
+ place(0, 2, mMostUsedServersDropDown, 4).setPadding(3);
+ place(2, 3, mOkButton);
+ place(3, 3, mCancelButton);
+ Layout &layout = getLayout();
+ layout.setWidth(250);
+ layout.setColWidth(1, Layout::FILL);
+ reflowLayout();
+ forgetLayout();
setLocationRelativeTo(getParent());
setVisible(true);
diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp
index 2133b077..9d0b4791 100644
--- a/src/gui/widgets/layout.cpp
+++ b/src/gui/widgets/layout.cpp
@@ -31,14 +31,14 @@ void Layout::resizeGrid(int w, int h)
if (extH)
{
- mSizes[1].resize(h, 0);
+ mSizes[1].resize(h, FILL);
mCells.resize(h);
if (!extW) w = mSizes[0].size();
}
if (extW)
{
- mSizes[0].resize(w, 0);
+ mSizes[0].resize(w, FILL);
}
for (std::vector< std::vector< Cell > >::iterator
@@ -79,6 +79,9 @@ Cell &Layout::place(gcn::Widget *widget, int x, int y, int w, int h)
cell.mPadding = 0;
cell.mAlign[0] = Cell::FILL;
cell.mAlign[1] = Cell::FILL;
+ int &cs = mSizes[0][x], &rs = mSizes[1][y];
+ if (cs == FILL) cs = 0;
+ if (rs == FILL) rs = 0;
return cell;
}
@@ -137,8 +140,8 @@ std::vector< int > Layout::compute(int dim, int upp)
for (int i = 0; i < nb; ++i)
{
if (mSizes[dim][i] == FILL) ++nbFill;
- if (sizes[i] > 0) upp -= sizes[i];
- upp -= mPadding;
+ if (sizes[i] == FILL) sizes[i] = 0;
+ else upp -= sizes[i];
}
upp += mPadding;
diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h
index 09b511f6..05a84d53 100644
--- a/src/gui/widgets/layout.h
+++ b/src/gui/widgets/layout.h
@@ -76,10 +76,14 @@ class Cell
/**
* This class is an helper for setting the position of widgets. They are
- * positioned along the cells of a rectangular table. The size of a given
- * table column can either be set manually or be chosen from the widest widget
- * of the column. The process is similar for table rows. By default, there is a
- * padding of 4 pixels between rows and between columns.
+ * positioned along the cells of a rectangular table.
+ *
+ * The size of a given table column can either be set manually or be chosen
+ * from the widest widget of the column. An empty column has a FILL width,
+ * which means it will be extended so that the layout fits its minimum width.
+ *
+ * The process is similar for table rows. By default, there is a padding of 4
+ * pixels between rows and between columns.
*/
class Layout
{
@@ -89,11 +93,15 @@ class Layout
/**
* Sets the minimum width of a column.
+ * @note Setting the width to FILL and then placing a widget in the
+ * column will reset the width to zero.
*/
void setColWidth(int n, int w);
/**
* Sets the minimum height of a row.
+ * @note Setting the height to FILL and then placing a widget in the
+ * row will reset the height to zero.
*/
void setRowHeight(int n, int h);
@@ -138,7 +146,7 @@ class Layout
enum
{
- FILL = -1, /**< Expand until the layout as the expected size. */
+ FILL = -42, /**< Expand until the layout as the expected size. */
};
private: