Ardour  8.7-15-gadf511264b
canvas/canvas/table.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Paul Davis <paul@linuxaudiosystems.com>
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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef __CANVAS_TABLE_H__
20 #define __CANVAS_TABLE_H__
21 
22 #include <unordered_map>
23 
24 #include "canvas/rectangle.h"
25 
26 namespace ArdourCanvas
27 {
28 
29 class Rectangle;
30 
32 {
33 public:
35  Table (Item *);
36 
39 
40  void set_padding (FourDimensions const & padding);
41 
42 #if 0
43  void set_margin (double top, double right = -1.0, double bottom = -1.0, double left = -1.0);
44 
45  /* aliases so that CSS box model terms work */
46  void set_border_width (double w) { set_outline_width (w); }
47  void set_border_color (Gtkmm2ext::Color c) { set_outline_color (c); }
48 
49  void set_collapse_on_hide (bool);
50 
51 #endif
52  void set_homogenous (bool);
53  void set_row_homogenous (bool);
54  void set_col_homogenous (bool);
55  void compute_bounding_box () const;
56  void size_request (double& w, double& h) const;
57  void size_allocate_children (Rect const & r);
58 
59  struct Index {
60  Index (uint32_t xv, uint32_t yv) : x (xv), y (yv) {}
61 
62  bool operator== (Index const & other) const {
63  return x == other.x && y == other.y;
64  }
65 
66  uint32_t x;
67  uint32_t y;
68  };
69 
70  /* These three functions cannot be used with Table, and will cause a
71  fatal error if called.
72  */
73  void add (Item *);
74  void add_front (Item *);
75  void remove (Item *);
76 
77  /* How to place an item in a table
78  */
79 
80  void attach (Item*, uint32_t upper_left_x, uint32_t upper_left_y, uint32_t lower_right_x, uint32_t lower_right_y, PackOptions row_options = PackOptions (0), PackOptions col_options = PackOptions (0), FourDimensions padding = FourDimensions (0.));
81  void attach (Item*, uint32_t upper_left_x, uint32_t upper_right_y, PackOptions row_options = PackOptions (0), PackOptions col_options = PackOptions (0), FourDimensions padding = FourDimensions (0.));
82  void attach_with_span (Item*, uint32_t upper_left_x, uint32_t upper_left_y, uint32_t hspan, uint32_t vspan, PackOptions row_options = PackOptions (0), PackOptions col_options = PackOptions (0), FourDimensions padding = FourDimensions (0.));
83 
84  // Not implemented, but also not needed thus far
85  // void detach (Item*);
86 
87  void set_row_size (uint32_t row, Distance);
88  void set_col_size (uint32_t row, Distance);
89 
90  protected:
91  void child_changed (bool bbox_changed);
92 
93  private:
103 
104  mutable bool ignore_child_changes;
105 
106  struct CellInfo {
116 
117  CellInfo (Item* i, PackOptions ro, PackOptions co, Index const & ul, Index const & lr, FourDimensions const & p)
118  : content (i)
119  , row_options (ro)
120  , col_options (co)
121  , upper_left (ul)
122  , lower_right (lr)
123  , padding (p)
124  {}
125  };
126 
127  struct index_hash {
128  std::size_t operator() (Table::Index const & i) const {
129  /* use upper left coordinate for hash */
130  return ((uint64_t) i.x << 32) | i.y;
131  }
132  };
133 
134  /* cell lookup, indexed by upper left corner only
135  */
136 
137  typedef std::unordered_map<Index, CellInfo, index_hash> Cells;
139 
140  struct AxisInfo {
141  uint32_t expanders;
142  uint32_t shrinkers;
147  bool occupied;
149 
150  AxisInfo() : expanders (0), shrinkers (0), natural_size (0), expand (0), shrink (0), user_size (0), occupied (false), spacing (0) {}
151 
152  void reset () {
153  expanders = 0;
154  shrinkers = 0;
155  natural_size = 0;
156  expand = 0;
157  shrink = 0;
158  /* leave user size alone */
159  occupied = false;
160  spacing = 0;
161  }
162  };
163 
164  typedef std::vector<AxisInfo> AxisInfos;
167 
168  void _add (Item *);
169  void _add_front (Item *);
170  void _remove (Item *);
171 
172  void layout ();
173  Duple compute (Rect const &);
174 };
175 
176 } /* namespace */
177 
178 #endif /* __CANVAS_TABLE_H__ */
#define LIBCANVAS_API
void size_request(double &w, double &h) const
void _remove(Item *)
void _add(Item *)
void add(Item *)
void attach(Item *, uint32_t upper_left_x, uint32_t upper_right_y, PackOptions row_options=PackOptions(0), PackOptions col_options=PackOptions(0), FourDimensions padding=FourDimensions(0.))
void attach_with_span(Item *, uint32_t upper_left_x, uint32_t upper_left_y, uint32_t hspan, uint32_t vspan, PackOptions row_options=PackOptions(0), PackOptions col_options=PackOptions(0), FourDimensions padding=FourDimensions(0.))
void set_row_size(uint32_t row, Distance)
void set_col_size(uint32_t row, Distance)
void set_col_spacing(Distance s)
void set_row_homogenous(bool)
void set_padding(FourDimensions const &padding)
void set_row_spacing(Distance s)
void set_col_homogenous(bool)
void add_front(Item *)
void compute_bounding_box() const
void size_allocate_children(Rect const &r)
void child_changed(bool bbox_changed)
std::unordered_map< Index, CellInfo, index_hash > Cells
Duple compute(Rect const &)
void set_homogenous(bool)
void attach(Item *, uint32_t upper_left_x, uint32_t upper_left_y, uint32_t lower_right_x, uint32_t lower_right_y, PackOptions row_options=PackOptions(0), PackOptions col_options=PackOptions(0), FourDimensions padding=FourDimensions(0.))
std::vector< AxisInfo > AxisInfos
void remove(Item *)
void _add_front(Item *)
uint32_t Color
Definition: colors.h:33
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)
CellInfo(Item *i, PackOptions ro, PackOptions co, Index const &ul, Index const &lr, FourDimensions const &p)
Index(uint32_t xv, uint32_t yv)