f4191971140b4c2bf6948f3aabcfb28f9de8378e
[ardour.git] / libs / canvas / canvas / grid.h
1 /*
2     Copyright (C) 2018 Paul Davis
3
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.
8
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.
13
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.
17 */
18
19 #ifndef __CANVAS_GRID_H__
20 #define __CANVAS_GRID_H__
21
22 #include <map>
23
24 #include "canvas/item.h"
25
26 namespace ArdourCanvas
27 {
28
29 class Rectangle;
30
31 /** Canvas container that renders its children in a grid layout
32  */
33 class LIBCANVAS_API Grid : public Item
34 {
35 public:
36         Grid (Canvas *);
37         Grid (Item *);
38         Grid (Item *, Duple const & position);
39
40         void set_spacing (double s);
41         void set_padding (double top, double right = -1.0, double bottom = -1.0, double left = -1.0);
42         void set_margin (double top, double right = -1.0, double bottom = -1.0, double left = -1.0);
43
44         /* aliases so that CSS box model terms work */
45         void set_border_width (double w) { set_outline_width (w); }
46         void set_border_color (Color c)  { set_outline_color (c); }
47
48         void place (Item*, Duple coord);
49
50         void set_collapse_on_hide (bool);
51         void set_homogenous (bool);
52
53         void compute_bounding_box () const;
54         void render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const;
55
56   protected:
57         double spacing;
58         double top_padding, right_padding, bottom_padding, left_padding;
59         double top_margin, right_margin, bottom_margin, left_margin;
60
61         void child_changed ();
62   private:
63         typedef std::map<Item*,Duple> CoordsByItem;
64         CoordsByItem coords_by_item;
65
66         Rectangle *self;
67         bool collapse_on_hide;
68         bool homogenous;
69
70         void reset_self ();
71         void reposition_children ();
72 };
73
74 }
75
76 #endif