basics of row/col span for Canvas::Grid
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 1 Feb 2017 19:22:19 +0000 (20:22 +0100)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 1 Feb 2017 20:58:20 +0000 (21:58 +0100)
libs/canvas/canvas/grid.h
libs/canvas/grid.cc

index c0afa4bdfab163d9128defcbf12ceccc243cc90f..36dac116ebe57c5592bb753a3788fdfdea39b3a1 100644 (file)
@@ -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;
index f8fd0bcce4626ca80535ba329edef16ebdb6e67a..15d57b4886a5a61b1bde77fdb0e32f6e7da5c6e6 100644 (file)
@@ -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 ();
 }