diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2017-01-14 12:56:26 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2017-01-15 12:13:03 +0000 |
commit | 99b86f0f056ea0f10aacfa4cf4e279cf948a71f2 (patch) | |
tree | aa9f5d83b9697945f2a52e2acfcfad8fc6ee46d8 /libs/canvas | |
parent | 0d1a083a5dedd20681724f3066fd53cc3c4dd69c (diff) |
basic (and probably wrong) Canvas::Grid child placement
Diffstat (limited to 'libs/canvas')
-rw-r--r-- | libs/canvas/canvas/grid.h | 5 | ||||
-rw-r--r-- | libs/canvas/grid.cc | 55 |
2 files changed, 47 insertions, 13 deletions
diff --git a/libs/canvas/canvas/grid.h b/libs/canvas/canvas/grid.h index a13cdf0a22..435a4e5eb1 100644 --- a/libs/canvas/canvas/grid.h +++ b/libs/canvas/canvas/grid.h @@ -19,6 +19,8 @@ #ifndef __CANVAS_GRID_H__ #define __CANVAS_GRID_H__ +#include <map> + #include "canvas/item.h" namespace ArdourCanvas @@ -58,6 +60,9 @@ public: void child_changed (); private: + typedef std::map<Item*,Duple> CoordsByItem; + CoordsByItem coords_by_item; + Rectangle *self; bool collapse_on_hide; bool homogenous; diff --git a/libs/canvas/grid.cc b/libs/canvas/grid.cc index cc12feb8db..de1602f33a 100644 --- a/libs/canvas/grid.cc +++ b/libs/canvas/grid.cc @@ -17,11 +17,14 @@ */ #include <algorithm> +#include <vector> #include "canvas/grid.h" #include "canvas/rectangle.h" using namespace ArdourCanvas; +using std::vector; +using std::max; Grid::Grid (Canvas* canvas) : Item (canvas) @@ -157,23 +160,48 @@ Grid::reset_self () void Grid::reposition_children () { - Duple previous_edge (0, 0); - Distance largest_width = 0; - Distance largest_height = 0; - - if (homogenous) { - - for (std::list<Item*>::iterator i = _items.begin(); ++i != _items.end(); ++i) { - boost::optional<Rect> bb = (*i)->bounding_box(); - if (bb) { - largest_height = std::max (largest_height, bb.get().height()); - largest_width = std::max (largest_width, bb.get().width()); - } + uint32_t max_row = 0; + uint32_t max_col = 0; + + for (CoordsByItem::const_iterator c = coords_by_item.begin(); c != coords_by_item.end(); ++c) { + max_col = max (max_col, (uint32_t) c->second.x); + max_row = max (max_row, (uint32_t) c->second.y); + } + + vector<double> row_dimens; + vector<double> col_dimens; + + row_dimens.assign (0, max_row); + col_dimens.assign (0, max_col); + + for (std::list<Item*>::iterator i = _items.begin(); ++i != _items.end(); ++i) { + boost::optional<Rect> bb = (*i)->bounding_box(); + + if (!bb) { + continue; } + + CoordsByItem::const_iterator c = coords_by_item.find (*i); + + row_dimens[c->second.x] = max (row_dimens[c->second.x], bb.get().width()); + col_dimens[c->second.y] = max (col_dimens[c->second.y], bb.get().height()); } 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()) { + continue; + } + + Duple pos (0,0); + for (uint32_t n = 0; n < c->second.x; ++n) { + pos.x += row_dimens[n]; + pos.y += col_dimens[n]; + } + + (*i)->set_position (pos); } _bounding_box_dirty = true; @@ -183,7 +211,8 @@ Grid::reposition_children () void Grid::place (Item* i, Duple at) { - + add (i); + coords_by_item.insert (std::make_pair (i, at)); } void |