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