basics of row/col span for Canvas::Grid
This commit is contained in:
parent
33bd5b3939
commit
94443bab7e
@ -63,7 +63,14 @@ public:
|
||||
|
||||
void child_changed ();
|
||||
private:
|
||||
typedef std::map<Item*,Duple> CoordsByItem;
|
||||
struct ChildInfo {
|
||||
double x;
|
||||
double y;
|
||||
double col_span;
|
||||
double row_span;
|
||||
};
|
||||
|
||||
typedef std::map<Item*,ChildInfo> CoordsByItem;
|
||||
CoordsByItem coords_by_item;
|
||||
|
||||
Rectangle *bg;
|
||||
|
@ -256,29 +256,29 @@ Grid::reposition_children ()
|
||||
|
||||
CoordsByItem::const_iterator c = coords_by_item.find (*i);
|
||||
|
||||
row_dimens[c->second.y] = max (row_dimens[c->second.y], bb.height());
|
||||
col_dimens[c->second.x] = max (col_dimens[c->second.x] , bb.width());
|
||||
const double per_col_width = bb.width() / c->second.col_span;
|
||||
const double per_row_height = bb.height() / c->second.row_span;
|
||||
|
||||
/* set the width of each column spanned by this item
|
||||
*/
|
||||
|
||||
for (int n = 0; n < (int) c->second.col_span; ++n) {
|
||||
col_dimens[c->second.x + n] = max (col_dimens[c->second.x + n], per_col_width);
|
||||
}
|
||||
for (int n = 0; n < (int) c->second.row_span; ++n) {
|
||||
row_dimens[c->second.y + n] = max (row_dimens[c->second.y + n], per_row_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* now sum the row and column widths, so that row_dimens is transformed
|
||||
* into the y coordinate of the upper left of each row, and col_dimens
|
||||
* is transformed into the x coordinate of the left edge of each
|
||||
* column.
|
||||
/* now progressively sum the row and column widths, once we're done:
|
||||
*
|
||||
* col_dimens: transformed into the x coordinate of the left edge of each column.
|
||||
*
|
||||
* row_dimens: transformed into the y coordinate of the upper left of each row,
|
||||
*
|
||||
*/
|
||||
|
||||
double current_top_edge = top_margin + top_padding;
|
||||
|
||||
for (uint32_t n = 0; n < max_row; ++n) {
|
||||
if (row_dimens[n]) {
|
||||
/* height defined for this row */
|
||||
const double h = row_dimens[n]; /* save height */
|
||||
row_dimens[n] = current_top_edge;
|
||||
cerr << "row[" << n << "] @ " << row_dimens[n] << endl;
|
||||
current_top_edge = current_top_edge + h + row_spacing;
|
||||
}
|
||||
}
|
||||
|
||||
double current_right_edge = left_margin + left_padding;
|
||||
|
||||
for (uint32_t n = 0; n < max_col; ++n) {
|
||||
@ -291,6 +291,18 @@ Grid::reposition_children ()
|
||||
}
|
||||
}
|
||||
|
||||
double current_top_edge = top_margin + top_padding;
|
||||
|
||||
for (uint32_t n = 0; n < max_row; ++n) {
|
||||
if (row_dimens[n]) {
|
||||
/* height defined for this row */
|
||||
const double h = row_dimens[n]; /* save height */
|
||||
row_dimens[n] = current_top_edge;
|
||||
cerr << "row[" << n << "] @ " << row_dimens[n] << endl;
|
||||
current_top_edge = current_top_edge + h + row_spacing;
|
||||
}
|
||||
}
|
||||
|
||||
/* position each item at the upper left of its (row, col) coordinate,
|
||||
* given the width of all rows or columns before it.
|
||||
*/
|
||||
@ -315,8 +327,16 @@ Grid::reposition_children ()
|
||||
void
|
||||
Grid::place (Item* i, double x, double y, double col_span, double row_span)
|
||||
{
|
||||
ChildInfo ci;
|
||||
|
||||
add (i);
|
||||
coords_by_item.insert (std::make_pair (i, Duple (x, y)));
|
||||
|
||||
ci.x = x;
|
||||
ci.y = y;
|
||||
ci.col_span = col_span;
|
||||
ci.row_span = row_span;
|
||||
|
||||
coords_by_item.insert (std::make_pair (i, ci));
|
||||
reposition_children ();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user