]> git.tdb.fi Git - libs/gltk.git/blob - source/row.cpp
92f3fe62b19e77c8bdf9792f033420be58f88347
[libs/gltk.git] / source / row.cpp
1 #include "row.h"
2
3 namespace Msp {
4 namespace GLtk {
5
6 Row::Row(Layout &l):
7         Arrangement(l),
8         first(true),
9         split_here(false),
10         gravity(-1)
11 { }
12
13 void Row::split()
14 {
15         if(gravity>0)
16                 throw arrangement_error("already split");
17
18         split_here = true;
19         gravity = 1;
20 }
21
22 void Row::process_widget(Widget &wdg, Side side, bool aligned)
23 {
24         if(side==LEFT)
25         {
26                 bool snug = (edges[RIGHT].aligned && aligned && !split_here);
27                 add_constraint(wdg, (snug ? Layout::RIGHT_OF : Layout::FAR_RIGHT_OF), RIGHT);
28                 if(first)
29                         edges[LEFT].add(wdg, aligned);
30         }
31         else if(side==RIGHT)
32                 next_right.add(wdg, (aligned && gravity>0));
33         else
34         {
35                 if(edges[side].aligned && aligned)
36                         add_constraint(wdg, (side==TOP ? Layout::ALIGN_TOP : Layout::ALIGN_BOTTOM), side);
37                 edges[side].add(wdg, aligned);
38         }
39 }
40
41 void Row::finish_widget(Widget &wdg)
42 {
43         layout.set_gravity(wdg, gravity, 1);
44 }
45
46 void Row::finish_slot()
47 {
48         edges[RIGHT] = next_right;
49         next_right.clear();
50         split_here = false;
51         first = false;
52 }
53
54
55 Row::Loader::Loader(Row &c):
56         DataFile::ObjectLoader<Row>(c)
57 {
58         add("split", &Loader::split);
59 }
60
61 void Row::Loader::split()
62 {
63         obj.split();
64 }
65
66 } // namespace GLtk
67 } // namespace Msp