13
0

fix up Canvas::Grid child layout

This commit is contained in:
Paul Davis 2017-01-19 00:23:29 +01:00
parent 73acd5b413
commit b4cf8cfc49
2 changed files with 25 additions and 14 deletions

View File

@ -45,7 +45,7 @@ public:
void set_border_width (double w) { set_outline_width (w); }
void set_border_color (Color c) { set_outline_color (c); }
void place(Item*, Duple coord);
void place (Item*, Duple coord);
void set_collapse_on_hide (bool);
void set_homogenous (bool);

View File

@ -188,7 +188,13 @@ 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) {
for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
if (*i == self) {
/* self-rect is not a normal child */
continue;
}
boost::optional<Rect> bb = (*i)->bounding_box();
if (!bb) {
@ -207,27 +213,33 @@ Grid::reposition_children ()
* column.
*/
double prev = row_dimens[0];
row_dimens[0] = top_margin;
double current_top_edge = top_margin;
for (uint32_t n = 1; n < max_row; ++n) {
row_dimens[n] = row_dimens[n-1] + prev + top_padding + bottom_padding;
prev = row_dimens[n] + bottom_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;
current_top_edge = current_top_edge + h + top_padding + bottom_padding;
}
}
prev = col_dimens[0];
col_dimens[0] = left_margin;
double current_right_edge = left_margin;
for (uint32_t n = 1; n < max_col; ++n) {
col_dimens[n] = col_dimens[n-1] + prev + left_padding + right_padding;
prev = col_dimens[n];
for (uint32_t n = 0; n < max_col; ++n) {
if (col_dimens[n]) {
/* a width was defined for this column */
const double w = col_dimens[n]; /* save width of this column */
col_dimens[n] = current_right_edge;
current_right_edge = current_right_edge + w + left_padding + right_padding;
}
}
/* position each item at the upper left of its (row, col) coordinate,
* given the width of all rows or columns before it.
*/
for (std::list<Item*>::iterator i = _items.begin(); ++i != _items.end(); ++i) {
for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
CoordsByItem::const_iterator c = coords_by_item.find (*i);
if (c == coords_by_item.end()) {
@ -237,7 +249,6 @@ Grid::reposition_children ()
(*i)->set_position (Duple (col_dimens[c->second.x], row_dimens[c->second.y]));
}
_bounding_box_dirty = true;
reset_self ();
}