]> git.tdb.fi Git - libs/gltk.git/blob - source/mixedrows.cpp
Add constraint types that allow flexible spacing between widgets
[libs/gltk.git] / source / mixedrows.cpp
1 #include "mixedrows.h"
2
3 namespace Msp {
4 namespace GLtk {
5
6 MixedRows::MixedRows(bool u):
7         uniform_rows(u),
8         uniform_cols(false),
9         hgravity(-1),
10         hsplit(false),
11         vgravity(1),
12         vsplit(false),
13         first(true)
14 { }
15
16 void MixedRows::start_row(bool u)
17 {
18         uniform_cols = u;
19         first = true;
20         hgravity = -1;
21         hsplit = false;
22 }
23
24 void MixedRows::split_rows()
25 {
26         vgravity = -1;
27         vsplit = true;
28 }
29
30 void MixedRows::split_columns()
31 {
32         hgravity = 1;
33         hsplit = true;
34 }
35
36 Layout::Slot *MixedRows::create_slot(Widget &wdg)
37 {
38         Slot *slot = new Slot(*this, wdg);
39
40         slot->horiz_pack.gravity = hgravity;
41         slot->vert_pack.gravity = vgravity;
42
43         if(!first)
44         {
45                 Slot *prev = slots.back();
46                 slot->constraints.push_back(Constraint((hsplit ? FAR_RIGHT_OF : RIGHT_OF), *prev));
47                 slot->constraints.push_back(Constraint(ALIGN_TOP, *prev));
48                 slot->constraints.push_back(Constraint(ALIGN_BOTTOM, *prev));
49                 if(uniform_cols)
50                         slot->constraints.push_back(Constraint(COPY_WIDTH, *prev));
51         }
52         else if(!slots.empty())
53         {
54                 Slot *prev = slots.back();
55                 slot->constraints.push_back(Constraint((vsplit ? FAR_BELOW : BELOW), *prev));
56                 if(uniform_rows)
57                         slot->constraints.push_back(Constraint(COPY_HEIGHT, *prev));
58         }
59
60         first = false;
61         hsplit = false;
62         vsplit = false;
63
64         return slot;
65 }
66
67 } // namespace GLtk
68 } // namespace Msp