some initial bits of work on canvas allocation
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 30 Jan 2017 13:46:14 +0000 (14:46 +0100)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 1 Feb 2017 20:58:20 +0000 (21:58 +0100)
gtk2_ardour/canvas_test.cc
libs/canvas/box.cc
libs/canvas/grid.cc

index ff1063a83724f624eb3ef04235ab18eca6ef71eb..3e922c2344b4a25b2826b9e5552ba473b1ed0a10 100644 (file)
@@ -23,6 +23,8 @@
 #include "canvas/canvas.h"
 #include "canvas/container.h"
 #include "canvas/colors.h"
+#include "canvas/debug.h"
+#include "canvas/grid.h"
 #include "canvas/scroll_group.h"
 #include "canvas/text.h"
 #include "canvas/widget.h"
@@ -110,6 +112,7 @@ private:
 
        ArdourCanvas::GtkCanvas* canvas;
        ArdourCanvas::Container* group;
+       ArdourCanvas::Grid* grid;
 
        ArdourButton test_button;
 };
@@ -163,12 +166,60 @@ ArdourCanvas::Container*
 CANVAS_UI::initialize_canvas (ArdourCanvas::Canvas& canvas)
 {
        using namespace ArdourCanvas;
-       canvas.set_background_color (rgba_to_color (0.0, 0.0, 1.0, 1.0));
+       canvas.set_background_color (rgba_to_color (0.0, 0.0, 0.4, 1.0));
 
        ScrollGroup* scroll_group = new ScrollGroup (canvas.root(),
                        ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally));
 
-       ArdourCanvas::Widget* w = new ArdourCanvas::Widget (scroll_group, test_button);
+       grid = new ArdourCanvas::Grid (scroll_group);
+       grid->set_padding (10.0);
+       grid->set_margin (20.0);
+       grid->set_outline_width (3.0);
+       grid->set_outline_color (Color (0x3daec1ff));
+       grid->set_outline (true);
+
+       ArdourCanvas::Text* text1 = new ArdourCanvas::Text (&canvas);
+       text1->set ("hello, world");
+       text1->set_color (Color (0xff0000ff));
+
+       ArdourCanvas::Text* text2 = new ArdourCanvas::Text (&canvas);
+       text2->set ("goodbye, cruel world");
+       text2->set_color (Color (0x00ff00ff));
+
+       ArdourCanvas::Text* text3 = new ArdourCanvas::Text (&canvas);
+       text3->set ("I am the third");
+       text3->set_color (Color (0xff00ffff));
+
+       ArdourCanvas::Text* text4 = new ArdourCanvas::Text (&canvas);
+       text4->set ("I am fourth");
+       text4->set_color (Color (0xffff00ff));
+
+#if 0
+       grid->place (text1, ArdourCanvas::Duple (0, 0));
+       grid->place (text2, ArdourCanvas::Duple (1, 0));
+       grid->place (text3, ArdourCanvas::Duple (0, 1));
+       grid->place (text4, ArdourCanvas::Duple (1, 1));
+#endif
+       ArdourButton* button1 = new ArdourButton ("auto-return");
+       ArdourButton* button2 = new ArdourButton ("auto-play");
+       ArdourButton* button3 = new ArdourButton ("follow range");
+       ArdourButton* button4 = new ArdourButton ("auto-input");
+
+       ArdourCanvas::Widget* w1 = new ArdourCanvas::Widget (&canvas, *button1);
+       CANVAS_DEBUG_NAME (w1, "w1");
+       grid->place (w1, ArdourCanvas::Duple (3, 0));
+       ArdourCanvas::Widget* w2 = new ArdourCanvas::Widget (&canvas, *button2);
+       CANVAS_DEBUG_NAME (w2, "w2");
+       grid->place (w2, ArdourCanvas::Duple (4, 0));
+       ArdourCanvas::Widget* w3 = new ArdourCanvas::Widget (&canvas, *button3);
+       CANVAS_DEBUG_NAME (w3, "w3");
+       grid->place (w3, ArdourCanvas::Duple (3, 1));
+       ArdourCanvas::Widget* w4 = new ArdourCanvas::Widget (&canvas, *button4);
+       CANVAS_DEBUG_NAME (w4, "w4");
+       grid->place (w4, ArdourCanvas::Duple (4, 1));
+
+       //ArdourCanvas::Widget* w = new ArdourCanvas::Widget (scroll_group, test_button);
+       //CANVAS_DEBUG_NAME (w, "TheW");
 
        return new ArdourCanvas::Container (scroll_group);
 }
index c75bee57708209278fe1527e28d406aebef233ae..f32aeab020a42f078f330259393425dc1b87d4df 100644 (file)
@@ -165,6 +165,7 @@ Box::reposition_children ()
        Duple previous_edge (0, 0);
        Distance largest_width = 0;
        Distance largest_height = 0;
+       Rect uniform_size;
 
        if (homogenous) {
 
@@ -175,33 +176,35 @@ Box::reposition_children ()
                                largest_width = std::max (largest_width, bb.width());
                        }
                }
+
+               uniform_size = Rect (0, 0, largest_width, largest_height);
        }
 
        for (std::list<Item*>::iterator i = _items.begin(); ++i != _items.end(); ++i) {
 
                (*i)->set_position (previous_edge);
 
+               if (homogenous) {
+                       (*i)->size_allocate (uniform_size);
+               }
+
                if (orientation == Vertical) {
 
                        Distance shift = 0;
 
-                       if (homogenous) {
-                               shift = largest_height;
-                       } else {
-                               Rect bb = (*i)->bounding_box();
-
-                               if (!(*i)->visible()) {
-                                       /* invisible child */
-                                       if (!collapse_on_hide) {
-                                               /* still add in its size */
-                                               if (bb) {
-                                                       shift += bb.height();
-                                               }
-                                       }
-                               } else {
+                       Rect bb = (*i)->bounding_box();
+
+                       if (!(*i)->visible()) {
+                               /* invisible child */
+                               if (!collapse_on_hide) {
+                                       /* still add in its size */
                                        if (bb) {
                                                shift += bb.height();
-                                       }
+                                               }
+                               }
+                       } else {
+                               if (bb) {
+                                       shift += bb.height();
                                }
                        }
 
@@ -210,23 +213,18 @@ Box::reposition_children ()
                } else {
 
                        Distance shift = 0;
+                       Rect bb = (*i)->bounding_box();
 
-                       if (homogenous) {
-                               shift = largest_width;
-                       } else {
-                               Rect bb = (*i)->bounding_box();
-
-                               if (!(*i)->visible()) {
-                                       if (!collapse_on_hide) {
-                                               if (bb) {
-                                                       shift += bb.width();
-                                               }
-                                       }
-                               } else {
+                       if (!(*i)->visible()) {
+                               if (!collapse_on_hide) {
                                        if (bb) {
                                                shift += bb.width();
                                        }
                                }
+                       } else {
+                               if (bb) {
+                                       shift += bb.width();
+                               }
                        }
 
                        previous_edge = previous_edge.translate (Duple (spacing + shift, 0));
index 02e18f79b88b06293d3a0e15c0bc1f5186add1be..fe23ea3aec63874be97130aaa1c5bcdb8ddf85c6 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 (false)
+       , homogenous (true)
 {
        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 (false)
+       , homogenous (true)
 {
        self = new Rectangle (this);
        self->set_outline (false);
@@ -57,7 +57,7 @@ Grid::Grid (Item* parent, Duple const & p)
        , 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 (false)
+       , homogenous (true)
 {
        self = new Rectangle (this);
        self->set_outline (false);
@@ -188,23 +188,55 @@ Grid::reposition_children ()
        row_dimens.assign (max_row, 0);
        col_dimens.assign (max_col, 0);
 
-       for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
+       Rect uniform_size;
 
-               if (*i == self) {
-                       /* self-rect is not a normal child */
-                       continue;
-               }
+       if (homogenous) {
+               for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
 
-               Rect bb = (*i)->bounding_box();
+                       Rect bb = (*i)->bounding_box();
 
-               if (!bb) {
-                       continue;
+                       if (!bb) {
+                               continue;
+                       }
+                       cerr << "\tbb is " << bb << endl;
+                       uniform_size.y1 = max (uniform_size.y1, bb.height());
+                       uniform_size.x1 = max (uniform_size.x1, bb.width());
                }
 
-               CoordsByItem::const_iterator c = coords_by_item.find (*i);
+               cerr << "Uniform size will be " << uniform_size << endl;
+
+               for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
+                       if (*i == self) {
+                               /* self-rect is not a normal child */
+                               continue;
+                       }
+                       (*i)->size_allocate (uniform_size);
+                       for (uint32_t n = 0; n < max_row; ++n) {
+                               col_dimens[n] = uniform_size.width();
+                       }
+                       for (uint32_t n = 0; n < max_col; ++n) {
+                               row_dimens[n] = uniform_size.height();
+                       }
+               }
+       } else {
+               for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++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());
+                       if (*i == self) {
+                               /* self-rect is not a normal child */
+                               continue;
+                       }
+
+                       Rect bb = (*i)->bounding_box();
+
+                       if (!bb) {
+                               continue;
+                       }
+
+                       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