canvas::grid starts being able to do its job a little
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 30 Jan 2017 15:31:35 +0000 (16:31 +0100)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 1 Feb 2017 20:58:20 +0000 (21:58 +0100)
libs/canvas/canvas/item.h
libs/canvas/canvas/widget.h
libs/canvas/grid.cc
libs/canvas/widget.cc

index a480ec38a1a8ce891fe20c731f2ea5dd5ed05adc..02f84a62ee355bad7b5d2dac9e7d92ffca6ab378 100644 (file)
@@ -138,7 +138,7 @@ public:
 
        /* item implementations can override this if they need to */
        virtual Rect size_request() const { return bounding_box (true); }
-       void size_allocate (Rect const&);
+       virtual void size_allocate (Rect const&);
 
        /** bounding box is the public API to get the size of the item.
           If @param for_own_purposes is false, then it will return the
index c1f6dc1f36852679350b99eea00e0a5cd7271d12..4c00592403ee17c114c33d0c33770e392c9090c6 100644 (file)
@@ -37,6 +37,8 @@ public:
        void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const;
        void compute_bounding_box () const;
 
+       void size_allocate (Rect const &);
+
        CairoWidget const & get () const {
                return _widget;
        }
index fe23ea3aec63874be97130aaa1c5bcdb8ddf85c6..323cdbf1ad9ee2bba89ad1cb4bf999bddae7ad23 100644 (file)
@@ -33,7 +33,7 @@ Grid::Grid (Canvas* canvas)
        , spacing (0)
        , top_padding (0), right_padding (0), bottom_padding (0), left_padding (0)
        , top_margin (0), right_margin (0), bottom_margin (0), left_margin (0)
-       , homogenous (true)
+       , homogenous (false)
 {
        self = new Rectangle (this);
        self->set_outline (false);
@@ -45,7 +45,7 @@ Grid::Grid (Item* parent)
        , spacing (0)
        , top_padding (0), right_padding (0), bottom_padding (0), left_padding (0)
        , top_margin (0), right_margin (0), bottom_margin (0), left_margin (0)
-       , homogenous (true)
+       , homogenous (false)
 {
        self = new Rectangle (this);
        self->set_outline (false);
@@ -64,6 +64,12 @@ Grid::Grid (Item* parent, Duple const & p)
        self->set_fill (false);
 }
 
+void
+Grid::set_homogenous (bool yn)
+{
+       homogenous = yn;
+}
+
 void
 Grid::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
 {
@@ -193,12 +199,16 @@ Grid::reposition_children ()
        if (homogenous) {
                for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
 
+                       if (*i == self) {
+                               continue;
+                       }
+
                        Rect bb = (*i)->bounding_box();
 
                        if (!bb) {
                                continue;
                        }
-                       cerr << "\tbb is " << bb << endl;
+                       cerr << "\tbb for " << (*i)->whatami() << " is " << bb << endl;
                        uniform_size.y1 = max (uniform_size.y1, bb.height());
                        uniform_size.x1 = max (uniform_size.x1, bb.width());
                }
@@ -211,10 +221,10 @@ Grid::reposition_children ()
                                continue;
                        }
                        (*i)->size_allocate (uniform_size);
-                       for (uint32_t n = 0; n < max_row; ++n) {
+                       for (uint32_t n = 0; n < max_col; ++n) {
                                col_dimens[n] = uniform_size.width();
                        }
-                       for (uint32_t n = 0; n < max_col; ++n) {
+                       for (uint32_t n = 0; n < max_row; ++n) {
                                row_dimens[n] = uniform_size.height();
                        }
                }
@@ -252,6 +262,7 @@ Grid::reposition_children ()
                        /* 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 + top_padding + bottom_padding;
                }
        }
@@ -263,6 +274,7 @@ Grid::reposition_children ()
                        /* a width was defined for this column */
                        const double w = col_dimens[n]; /* save width of this column */
                        col_dimens[n] = current_right_edge;
+                       cerr << "col[" << n << "] @ " << col_dimens[n] << endl;
                        current_right_edge = current_right_edge + w + left_padding + right_padding;
                }
        }
@@ -279,6 +291,9 @@ Grid::reposition_children ()
                }
 
                (*i)->set_position (Duple (col_dimens[c->second.x], row_dimens[c->second.y]));
+               cerr << "place " << (*i)->whatami() << " @ " << c->second.x << ", " << c->second.y << " at "
+                    << Duple (col_dimens[c->second.x], row_dimens[c->second.y])
+                    << endl;
        }
 
        _bounding_box_dirty = true;
index db43a68119800e9d6ae8f1a9fda0b50795eb64ca..4c98d6651d1ff302c7e60d5d38e26a70fc5e7ec5 100644 (file)
@@ -109,6 +109,18 @@ Widget::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
        context->restore ();
 }
 
+void
+Widget::size_allocate (Rect const & r)
+{
+       Item::size_allocate (r);
+       Gtk::Allocation alloc;
+       alloc.set_x (0);
+       alloc.set_y (0);
+       alloc.set_width (r.width());
+       alloc.set_height (r.height());
+       _widget.size_allocate (alloc);
+}
+
 void
 Widget::compute_bounding_box () const
 {