summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-10-21 11:20:55 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-10-21 11:20:55 +0000
commit59c3b69103bf9bc346f6a4337c2ede0f43bfb6bf (patch)
tree72ee20339fa7dec7934b8343bdddc29a633946b0 /src/gui/widgets
parent4f6ebd0c62299e3ab2d4b4ef70fd2a27d5b4908c (diff)
downloadmana-client-59c3b69103bf9bc346f6a4337c2ede0f43bfb6bf.tar.gz
mana-client-59c3b69103bf9bc346f6a4337c2ede0f43bfb6bf.tar.bz2
mana-client-59c3b69103bf9bc346f6a4337c2ede0f43bfb6bf.tar.xz
mana-client-59c3b69103bf9bc346f6a4337c2ede0f43bfb6bf.zip
Made visible the resizable grip on inventory window.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/layout.cpp35
-rw-r--r--src/gui/widgets/layout.h43
2 files changed, 51 insertions, 27 deletions
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;
};