From 52718b341163dab439596049392b9c80fb8635ec Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 30 Jan 2017 14:46:14 +0100 Subject: some initial bits of work on canvas allocation --- libs/canvas/box.cc | 52 ++++++++++++++++++++++------------------------ libs/canvas/grid.cc | 60 ++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 71 insertions(+), 41 deletions(-) (limited to 'libs/canvas') diff --git a/libs/canvas/box.cc b/libs/canvas/box.cc index c75bee5770..f32aeab020 100644 --- a/libs/canvas/box.cc +++ b/libs/canvas/box.cc @@ -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::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)); diff --git a/libs/canvas/grid.cc b/libs/canvas/grid.cc index 02e18f79b8..fe23ea3aec 100644 --- a/libs/canvas/grid.cc +++ b/libs/canvas/grid.cc @@ -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::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::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::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::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 -- cgit v1.2.3