summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2017-02-01 21:30:29 +0100
committerPaul Davis <paul@linuxaudiosystems.com>2017-02-01 21:58:20 +0100
commitf5d6c908acc27cd44b96ca00122f2127811047f9 (patch)
tree7b9683532310408cb07c2f25987d51f17baf2e4a /libs
parentfa2c4c525b9f5f302beafac8eeea4e700fbf90f2 (diff)
canvas::grid - more tweaks and improvements
Diffstat (limited to 'libs')
-rw-r--r--libs/canvas/canvas/grid.h1
-rw-r--r--libs/canvas/grid.cc68
2 files changed, 41 insertions, 28 deletions
diff --git a/libs/canvas/canvas/grid.h b/libs/canvas/canvas/grid.h
index 36dac116eb..8e6dd3b7de 100644
--- a/libs/canvas/canvas/grid.h
+++ b/libs/canvas/canvas/grid.h
@@ -64,6 +64,7 @@ public:
void child_changed ();
private:
struct ChildInfo {
+ Item* item;
double x;
double y;
double col_span;
diff --git a/libs/canvas/grid.cc b/libs/canvas/grid.cc
index e5d05e9f05..e46a184e42 100644
--- a/libs/canvas/grid.cc
+++ b/libs/canvas/grid.cc
@@ -189,29 +189,30 @@ Grid::reposition_children ()
*/
for (CoordsByItem::const_iterator c = coords_by_item.begin(); c != coords_by_item.end(); ++c) {
+ if (collapse_on_hide && !c->second.item->visible()) {
+ continue;
+ }
max_col = max (max_col, (uint32_t) (c->second.x + c->second.col_span));
max_row = max (max_row, (uint32_t) (c->second.y + c->second.row_span));
}
- max_row++;
- max_col++;
-
/* Now compute the width of the widest child for each column, and the
- * height of the tallest child for each row.
+ * height of the tallest child for each row. Store the results in
+ * row_dimens and col_dimens, making sure they are suitably sized first.
*/
vector<double> row_dimens;
vector<double> col_dimens;
- row_dimens.assign (max_row, 0);
- col_dimens.assign (max_col, 0);
+ row_dimens.assign (max_row + 1, 0);
+ col_dimens.assign (max_col + 1, 0);
- Rect uniform_size;
+ Rect uniform_cell_size;
if (homogenous) {
for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
- if (*i == bg) {
+ if (*i == bg || (collapse_on_hide && !(*i)->visible())) {
continue;
}
@@ -220,30 +221,41 @@ Grid::reposition_children ()
if (!bb) {
continue;
}
- 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());
+
+ CoordsByItem::const_iterator c = coords_by_item.find (*i);
+
+ uniform_cell_size.x1 = max (uniform_cell_size.x1, (bb.width()/c->second.col_span));
+ uniform_cell_size.y1 = max (uniform_cell_size.y1, (bb.height()/c->second.row_span));
+ }
+
+ for (uint32_t n = 0; n < max_col; ++n) {
+ col_dimens[n] = uniform_cell_size.width();
}
- cerr << "Uniform size will be " << uniform_size << endl;
+ for (uint32_t n = 0; n < max_row; ++n) {
+ row_dimens[n] = uniform_cell_size.height();
+ }
for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
- if (*i == bg) {
+
+ if (*i == bg || (collapse_on_hide && !(*i)->visible())) {
/* bg rect is not a normal child */
continue;
}
- (*i)->size_allocate (uniform_size);
- for (uint32_t n = 0; n < max_col; ++n) {
- col_dimens[n] = uniform_size.width();
- }
- for (uint32_t n = 0; n < max_row; ++n) {
- row_dimens[n] = uniform_size.height();
- }
+
+ CoordsByItem::const_iterator c = coords_by_item.find (*i);
+
+ Rect r = uniform_cell_size;
+ r.x1 *= c->second.col_span;
+ r.y1 *= c->second.row_span;
+
+ (*i)->size_allocate (r);
}
+
} else {
for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
- if (*i == bg) {
+ if (*i == bg || (collapse_on_hide && !(*i)->visible())) {
/* bg rect is not a normal child */
continue;
}
@@ -286,7 +298,6 @@ 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 + col_spacing;
}
}
@@ -298,7 +309,6 @@ 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 + row_spacing;
}
}
@@ -314,10 +324,11 @@ Grid::reposition_children ()
continue;
}
+ /* do this even for hidden items - it will be corrected when
+ * they become visible again.
+ */
+
(*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;
@@ -331,10 +342,11 @@ Grid::place (Item* i, double x, double y, double col_span, double row_span)
add (i);
+ ci.item = i;
ci.x = x;
ci.y = y;
- ci.col_span = col_span;
- ci.row_span = row_span;
+ ci.col_span = max (1.0, col_span);
+ ci.row_span = max (1.0, row_span);
coords_by_item.insert (std::make_pair (i, ci));
reposition_children ();