]> git.tdb.fi Git - libs/gltk.git/blob - source/lineararrangement.cpp
Support widget expansion in linear layouts
[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::expand()
25 {
26         if(gravity==primary)
27                 throw arrangement_error("already split");
28         if(edges[primary].empty())
29                 throw arrangement_error("no widgets");
30
31         add_constraint(*edges[primary].widgets.front(), get_align_constraint(primary), primary);
32         layout.set_expand(*edges[primary].widgets.front(), false, true);
33         edges[primary].align();
34         gravity = primary;
35 }
36
37 void LinearArrangement::process_widget(Widget &wdg, Side side, bool aligned)
38 {
39         if(side==opposite)
40         {
41                 bool snug = (edges[primary].aligned && aligned && !split_here);
42                 add_constraint(wdg, get_order_constraint(primary, !snug), primary);
43                 if(first)
44                         edges[side].add(wdg, aligned);
45         }
46         else if(side==primary)
47                 next.add(wdg, (aligned && gravity==primary));
48         else
49         {
50                 if(edges[side].aligned && aligned)
51                         add_constraint(wdg, get_align_constraint(side), side);
52                 edges[side].add(wdg, aligned);
53         }
54 }
55
56 void LinearArrangement::finish_slot()
57 {
58         edges[primary] = next;
59         next.clear();
60         split_here = false;
61         first = false;
62 }
63
64
65 LinearArrangement::Loader::Loader(LinearArrangement &c):
66         DataFile::ObjectLoader<LinearArrangement>(c)
67 {
68         add("expand", &Loader::expand);
69         add("split", &Loader::split);
70 }
71
72 void LinearArrangement::Loader::expand()
73 {
74         obj.expand();
75 }
76
77 void LinearArrangement::Loader::split()
78 {
79         obj.split();
80 }
81
82 } // namespace GLtk
83 } // namespace Msp