2 Copyright (C) 2018 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "canvas/grid.h"
22 #include "canvas/rectangle.h"
24 using namespace ArdourCanvas;
26 Grid::Grid (Canvas* canvas)
29 , top_padding (0), right_padding (0), bottom_padding (0), left_padding (0)
30 , top_margin (0), right_margin (0), bottom_margin (0), left_margin (0)
33 self = new Rectangle (this);
34 self->set_outline (false);
35 self->set_fill (false);
38 Grid::Grid (Item* parent)
41 , top_padding (0), right_padding (0), bottom_padding (0), left_padding (0)
42 , top_margin (0), right_margin (0), bottom_margin (0), left_margin (0)
45 self = new Rectangle (this);
46 self->set_outline (false);
47 self->set_fill (false);
50 Grid::Grid (Item* parent, Duple const & p)
53 , top_padding (0), right_padding (0), bottom_padding (0), left_padding (0)
54 , top_margin (0), right_margin (0), bottom_margin (0), left_margin (0)
57 self = new Rectangle (this);
58 self->set_outline (false);
59 self->set_fill (false);
63 Grid::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
65 Item::render_children (area, context);
69 Grid::compute_bounding_box () const
71 _bounding_box = boost::none;
74 _bounding_box_dirty = false;
78 add_child_bounding_boxes (!collapse_on_hide);
81 Rect r = _bounding_box.get();
83 _bounding_box = r.expand (top_padding + outline_width() + top_margin,
84 right_padding + outline_width() + right_margin,
85 bottom_padding + outline_width() + bottom_margin,
86 left_padding + outline_width() + left_margin);
89 _bounding_box_dirty = false;
93 Grid::set_spacing (double s)
99 Grid::set_padding (double t, double r, double b, double l)
108 right_padding = last;
112 bottom_padding = last;
120 Grid::set_margin (double t, double r, double b, double l)
131 bottom_margin = last;
141 if (_bounding_box_dirty) {
142 compute_bounding_box ();
145 if (!_bounding_box) {
150 Rect r (_bounding_box.get());
152 /* XXX need to shrink by margin */
158 Grid::reposition_children ()
160 Duple previous_edge (0, 0);
161 Distance largest_width = 0;
162 Distance largest_height = 0;
166 for (std::list<Item*>::iterator i = _items.begin(); ++i != _items.end(); ++i) {
167 boost::optional<Rect> bb = (*i)->bounding_box();
169 largest_height = std::max (largest_height, bb.get().height());
170 largest_width = std::max (largest_width, bb.get().width());
175 for (std::list<Item*>::iterator i = _items.begin(); ++i != _items.end(); ++i) {
179 _bounding_box_dirty = true;
184 Grid::place (Item* i, Duple at)
190 Grid::child_changed ()
192 /* catch visibility and size changes */
194 Item::child_changed ();
195 reposition_children ();
199 Grid::set_collapse_on_hide (bool yn)
201 if (collapse_on_hide != yn) {
202 collapse_on_hide = yn;
203 reposition_children ();