diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/gui/char_select.cpp | 3 | ||||
-rw-r--r-- | src/gui/inventorywindow.cpp | 1 | ||||
-rw-r--r-- | src/gui/login.cpp | 1 | ||||
-rw-r--r-- | src/gui/serverdialog.cpp | 1 | ||||
-rw-r--r-- | src/gui/widgets/layout.cpp | 35 | ||||
-rw-r--r-- | src/gui/widgets/layout.h | 43 | ||||
-rw-r--r-- | src/gui/window.cpp | 10 |
8 files changed, 65 insertions, 35 deletions
@@ -6,6 +6,12 @@ * src/gui/widgets/layout.cpp: Allowed for decreasing sizes in layout. * src/gui/inventorywindow.cpp, src/gui/inventorywindow.cpp: Delegated resizing events to layout handler. + * src/gui/widgets/layout.cpp, src/gui/widgets/layout.h: Renamed padding + to spacing. Added margin around layout. Constified code. + * src/gui/window.cpp, src/gui/login.cpp, src/gui/char_select.cpp, + src/gui/serverdialog.cpp, src/gui/inventorywindow.cpp: Removed window + padding and replaced it by layout margin, so that the grip on resizable + window is not outside the inner clip area. 2007-10-20 Guillaume Melquiond <guillaume.melquiond@gmail.com> diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index ea04b6bc..f7042c70 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -102,7 +102,6 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo, mMoneyLabel = new gcn::Label(strprintf(_("Money: %d"), 0)); mPlayerBox = new PlayerBox(); - setPadding(8); Layout &layout = getLayout(); place(0, 0, mPlayerBox, 1, 5).setPadding(3); place(1, 0, mNameLabel, 3); @@ -112,7 +111,7 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo, place(2, 3, mNextButton); place(1, 4, mNewCharButton); place(2, 4, mDelCharButton); - layout.setWidth(230); + layout.setWidth(250); layout.setColWidth(0, 80); layout.setColWidth(3, Layout::FILL); layout.matchColWidth(1, 2); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 9aaba37a..fabbf541 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -81,7 +81,6 @@ InventoryWindow::InventoryWindow(): mWeightLabel = new gcn::Label( strprintf(_("Total Weight: %d - Maximum Weight: %d"), 0, 0)); - setPadding(8); place(0, 0, mWeightLabel, 4); place(0, 1, mInvenScroll, 4).setPadding(3); place(0, 2, mItemNameLabel, 4); diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 9a7d1e5b..f35f427a 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -61,7 +61,6 @@ LoginDialog::LoginDialog(LoginData *loginData): mPassField->addActionListener(this); mKeepCheck->addActionListener(this); - setPadding(8); place(0, 0, userLabel); place(0, 1, passLabel); place(1, 0, mUserField, 3).setPadding(2); diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index aaaa5eca..2051518d 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -148,7 +148,6 @@ ServerDialog::ServerDialog(LoginData *loginData): mPortField->addActionListener(this); mMostUsedServersDropDown->addActionListener(mDropDownListener); - setPadding(8); place(0, 0, serverLabel); place(0, 1, portLabel); place(1, 0, mServerNameField, 3).setPadding(3); diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 228eac74..252cf198 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -85,11 +85,12 @@ Cell &Layout::place(gcn::Widget *widget, int x, int y, int w, int h) return cell; } -void Layout::align(int &pos, int &size, int dim, Cell &cell, int *sizes) +void Layout::align(int &pos, int &size, int dim, + Cell const &cell, int *sizes) const { int size_max = sizes[0] - cell.mPadding * 2; for (int i = 1; i < cell.mExtent[dim]; ++i) - size_max += sizes[i] + mPadding; + size_max += sizes[i] + mSpacing; size = std::min(dim == 0 ? cell.mWidget->getWidth() : cell.mWidget->getHeight(), size_max); pos += cell.mPadding; @@ -110,7 +111,7 @@ void Layout::align(int &pos, int &size, int dim, Cell &cell, int *sizes) } } -std::vector< int > Layout::compute(int dim, int upp) +std::vector< int > Layout::compute(int dim, int upp) const { int gridW = mSizes[0].size(), gridH = mSizes[1].size(); std::vector< int > sizes = mSizes[dim]; @@ -120,7 +121,7 @@ std::vector< int > Layout::compute(int dim, int upp) { for (int gridX = 0; gridX < gridW; ++gridX) { - Cell &cell = mCells[gridY][gridX]; + Cell const &cell = mCells[gridY][gridX]; if (!cell.mWidget) continue; if (cell.mExtent[dim] == 1) @@ -142,9 +143,9 @@ std::vector< int > Layout::compute(int dim, int upp) if (mSizes[dim][i] == FILL) ++nbFill; if (sizes[i] == FILL) sizes[i] = 0; else upp -= sizes[i]; - upp -= mPadding; + upp -= mSpacing; } - upp += mPadding; + upp = upp + mSpacing - mMargin * 2; if (nbFill == 0) return sizes; @@ -160,17 +161,17 @@ std::vector< int > Layout::compute(int dim, int upp) return sizes; } -void Layout::reflow() +void Layout::reflow(int &nw, int &nh) { int gridW = mSizes[0].size(), gridH = mSizes[1].size(); std::vector< int > widths = compute(0, mW); std::vector< int > heights = compute(1, mH); - int y = mY; + int x, y = mY + mMargin; for (int gridY = 0; gridY < gridH; ++gridY) { - int x = mX; + x = mX + mMargin; for (int gridX = 0; gridX < gridW; ++gridX) { Cell &cell = mCells[gridY][gridX]; @@ -181,19 +182,21 @@ void Layout::reflow() align(dy, dh, 1, cell, &heights[gridY]); cell.mWidget->setDimension(gcn::Rectangle(dx, dy, dw, dh)); } - x += widths[gridX] + mPadding; - mNW = x - mX; + x += widths[gridX] + mSpacing; } - y += heights[gridY] + mPadding; - mNH = y - mY; + y += heights[gridY] + mSpacing; } + + nw = x - mX - mSpacing + mMargin; + nh = y - mY - mSpacing + mMargin; } void Layout::flush() { - reflow(); - mY += mNH; - mW = mNW - mPadding; + int w, h; + reflow(w, h); + mY += h; + mW = w; mSizes[0].clear(); mSizes[1].clear(); mCells.clear(); diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index 05a84d53..ae03ed9d 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -82,14 +82,27 @@ class Cell * 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. + * The process is similar for table rows. By default, there is a spacing of 4 + * pixels between rows and between columns, and a margin of 6 pixels around the + * whole layout. */ class Layout { public: - Layout(): mPadding(4), mX(0), mY(0), mW(0), mH(0) {} + Layout(): mSpacing(4), mMargin(6), mX(0), mY(0), mW(0), mH(0) {} + + /** + * Gets the x-coordinate of the top left point of the layout. + */ + int getX() const + { return mX; } + + /** + * Gets the y-coordinate of the top left point of the layout. + */ + int getY() const + { return mY; } /** * Sets the minimum width of a column. @@ -123,10 +136,16 @@ class Layout { mH = h; } /** - * Sets the padding between cells. + * Sets the spacing between cells. */ - void setPadding(int p) - { mPadding = p; } + void setSpacing(int p) + { mSpacing = p; } + + /** + * Sets the margin around the layout. + */ + void setMargin(int m) + { mMargin = m; } /** * Places a widget in a given cell. @@ -134,9 +153,10 @@ class Layout Cell &place(gcn::Widget *, int x, int y, int w, int h); /** - * Computes the positions of all the widgets. + * Computes the positions of all the widgets. Returns the size of the + * layout. */ - void reflow(); + void reflow(int &nW, int &nH); /** * Reflows the current layout. Then starts a new layout just below with @@ -154,7 +174,8 @@ class Layout /** * Gets the position and size of a widget along a given axis */ - void align(int &pos, int &size, int dim, Cell &cell, int *sizes); + void align(int &pos, int &size, int dim, + Cell const &cell, int *sizes) const; /** * Ensures the private vectors are large enough. @@ -164,12 +185,12 @@ class Layout /** * Gets the column/row sizes along a given axis. */ - std::vector< int > compute(int dim, int upp); + std::vector< int > compute(int dim, int upp) const; std::vector< int > mSizes[2]; std::vector< std::vector < Cell > > mCells; - int mPadding; + int mSpacing, mMargin; int mX, mY, mW, mH, mNW, mNH; }; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index bf5f03db..f8d4a503 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -233,7 +233,8 @@ void Window::setSize(int width, int height) { mLayout->setWidth(width - 2 * getPadding()); mLayout->setHeight(height - getPadding() - getTitleBarHeight()); - mLayout->reflow(); + int w, h; + mLayout->reflow(w, h); } fireWindowEvent(WindowEvent(this, WindowEvent::WINDOW_RESIZED)); @@ -621,10 +622,13 @@ Cell &Window::place(int x, int y, gcn::Widget *wg, int w, int h) void Window::reflowLayout() { if (!mLayout) return; - mLayout->reflow(); + int w, h; + mLayout->reflow(w, h); + w += mLayout->getX(); + h += mLayout->getY(); Layout *tmp = mLayout; // Hide it so that the incoming resize does not reflow the layout again. mLayout = NULL; - resizeToContent(); + setContentSize(w, h); mLayout = tmp; } |