]> git.tdb.fi Git - libs/gltk.git/blob - source/lineararrangement.cpp
Combine common parts of Column and Row into LinearArrangement
[libs/gltk.git] / source / lineararrangement.cpp
1 #include "lineararrangement.h"
2
3 namespace Msp {
4 namespace GLtk {
5
6 LinearArrangement::LinearArrangement(Layout &l, Side p):
7         Arrangement(l),
8         primary(p),
9         opposite(static_cast<Side>((primary+2)%4)),
10         first(true),
11         split_here(false),
12         gravity(opposite)
13 { }
14
15 void LinearArrangement::split()
16 {
17         if(gravity==primary)
18                 throw arrangement_error("already split");
19
20         split_here = true;
21         gravity = primary;
22 }
23
24 void LinearArrangement::process_widget(Widget &wdg, Side side, bool aligned)
25 {
26         if(side==opposite)
27         {
28                 bool snug = (edges[primary].aligned && aligned && !split_here);
29                 add_constraint(wdg, get_order_constraint(primary, !snug), primary);
30                 if(first)
31                         edges[side].add(wdg, aligned);
32         }
33         else if(side==primary)
34                 next.add(wdg, (aligned && gravity==primary));
35         else
36         {
37                 if(edges[side].aligned && aligned)
38                         add_constraint(wdg, get_align_constraint(side), side);
39                 edges[side].add(wdg, aligned);
40         }
41 }
42
43 void LinearArrangement::finish_slot()
44 {
45         edges[primary] = next;
46         next.clear();
47         split_here = false;
48         first = false;
49 }
50
51
52 LinearArrangement::Loader::Loader(LinearArrangement &c):
53         DataFile::ObjectLoader<LinearArrangement>(c)
54 {
55         add("split", &Loader::split);
56 }
57
58 void LinearArrangement::Loader::split()
59 {
60         obj.split();
61 }
62
63 } // namespace GLtk
64 } // namespace Msp