summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2017-02-01 20:22:19 +0100
committerPaul Davis <paul@linuxaudiosystems.com>2017-02-01 21:58:20 +0100
commit94443bab7ea163576764027b2d583d8db88cbce7 (patch)
tree74f17517b35184cd5437e4def8284d09efc2a309 /libs
parent33bd5b3939d974703fee6dd4898624a25279dd6c (diff)
basics of row/col span for Canvas::Grid
Diffstat (limited to 'libs')
-rw-r--r--libs/canvas/canvas/grid.h9
-rw-r--r--libs/canvas/grid.cc58
2 files changed, 47 insertions, 20 deletions
diff --git a/libs/canvas/canvas/grid.h b/libs/canvas/canvas/grid.h
index c0afa4bdfa..36dac116eb 100644
--- a/libs/canvas/canvas/grid.h
+++ b/libs/canvas/canvas/grid.h
@@ -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;
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 ();
}