]> git.tdb.fi Git - libs/gltk.git/blob - source/mixedrows.cpp
275629d940d794f657af5adb851cc0f258303291
[libs/gltk.git] / source / mixedrows.cpp
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2011  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "mixedrows.h"
9
10 namespace Msp {
11 namespace GLtk {
12
13 MixedRows::MixedRows(bool u):
14         uniform_rows(u),
15         uniform_cols(false),
16         hgravity(-1),
17         hsplit(false),
18         vgravity(1),
19         vsplit(false),
20         first(true)
21 { }
22
23 void MixedRows::start_row(bool u)
24 {
25         uniform_cols = u;
26         first = true;
27         hgravity = -1;
28         hsplit = false;
29 }
30
31 void MixedRows::split_rows()
32 {
33         vgravity = -1;
34         vsplit = true;
35 }
36
37 void MixedRows::split_columns()
38 {
39         hgravity = 1;
40         hsplit = true;
41 }
42
43 Layout::Slot *MixedRows::create_slot(Widget &wdg)
44 {
45         Slot *slot = new Slot(*this, wdg);
46
47         slot->horiz_pack.gravity = hgravity;
48         slot->vert_pack.gravity = vgravity;
49
50         if(!first)
51         {
52                 Slot *prev = slots.back();
53                 if(!hsplit)
54                         slot->constraints.push_back(Constraint(RIGHT_OF, *prev));
55                 slot->constraints.push_back(Constraint(ALIGN_TOP, *prev));
56                 slot->constraints.push_back(Constraint(ALIGN_BOTTOM, *prev));
57                 if(uniform_cols)
58                         slot->constraints.push_back(Constraint(COPY_WIDTH, *prev));
59         }
60         else if(!slots.empty())
61         {
62                 Slot *prev = slots.back();
63                 if(!vsplit)
64                         slot->constraints.push_back(Constraint(BELOW, *prev));
65                 if(uniform_rows)
66                         slot->constraints.push_back(Constraint(COPY_HEIGHT, *prev));
67         }
68
69         first = false;
70         hsplit = false;
71         vsplit = false;
72
73         return slot;
74 }
75
76 } // namespace GLtk
77 } // namespace Msp