From 94443bab7ea163576764027b2d583d8db88cbce7 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 1 Feb 2017 20:22:19 +0100 Subject: basics of row/col span for Canvas::Grid --- libs/canvas/grid.cc | 58 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 19 deletions(-) (limited to 'libs/canvas/grid.cc') diff --git a/libs/canvas/grid.cc b/libs/canvas/grid.cc index f8fd0bcce4..15d57b4886 100644 --- a/libs/canvas/grid.cc +++ b/libs/canvas/grid.cc @@ -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()); - } - } - - /* 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. - */ + const double per_col_width = bb.width() / c->second.col_span; + const double per_row_height = bb.height() / c->second.row_span; - double current_top_edge = top_margin + top_padding; + /* set the width of each column spanned by this item + */ - 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; + 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 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_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 (); } -- cgit v1.2.3