]> git.tdb.fi Git - libs/gltk.git/blob - source/grid.cpp
fb08823817db11fa7b04da88b46ad5169fb45e70
[libs/gltk.git] / source / grid.cpp
1 #include "grid.h"
2
3 using namespace std;
4
5 namespace Msp {
6 namespace GLtk {
7
8 Grid::Grid(bool u):
9         uniform(u),
10         cur_column(0),
11         first(true),
12         skipped(false)
13 { }
14
15 void Grid::start_row()
16 {
17         cur_column = 0;
18         first = true;
19 }
20
21 void Grid::skip_cell()
22 {
23         ++cur_column;
24         skipped = true;
25         if(cur_column>=columns.size())
26                 columns.push_back(0);
27 }
28
29 Layout::Slot *Grid::create_slot(Widget &wdg)
30 {
31         Slot *slot = new Slot(*this, wdg);
32
33         slot->vert_pack.gravity = 1;
34
35         if(!slots.empty())
36         {
37                 Slot &prev = *slots.back();
38                 if(first)
39                         slot->constraints.push_back(Constraint(BELOW, prev));
40                 else
41                 {
42                         slot->constraints.push_back(Constraint(ALIGN_TOP, prev));
43                         slot->constraints.push_back(Constraint(ALIGN_BOTTOM, prev));
44                         if(!skipped)
45                                 slot->constraints.push_back(Constraint(RIGHT_OF, prev));
46                 }
47
48                 if(uniform)
49                 {
50                         slot->constraints.push_back(Constraint(COPY_WIDTH, prev));
51                         slot->constraints.push_back(Constraint(COPY_HEIGHT, prev));
52                 }
53
54                 if(cur_column<columns.size() && columns[cur_column])
55                 {
56                         Slot &col = *columns[cur_column];
57                         slot->constraints.push_back(Constraint(ALIGN_LEFT, col));
58                         slot->constraints.push_back(Constraint(ALIGN_RIGHT, col));
59                 }
60         }
61
62         if(cur_column>=columns.size())
63                 columns.push_back(slot);
64         else if(!columns[cur_column])
65                 columns[cur_column] = slot;
66
67         first = false;
68         skipped = false;
69         ++cur_column;
70
71         return slot;
72 }
73
74 } // namespace GLtk
75 } // namespace Msp