]> git.tdb.fi Git - libs/gltk.git/blob - source/arrangement.cpp
Combine common parts of Column and Row into LinearArrangement
[libs/gltk.git] / source / arrangement.cpp
1 #include "arrangement.h"
2
3 using namespace std;
4
5 namespace Msp {
6 namespace GLtk {
7
8 Arrangement::Arrangement(Layout &l):
9         layout(l),
10         parent(layout.get_arrangement())
11 {
12         layout.push_arrangement(*this);
13 }
14
15 Arrangement::~Arrangement()
16 {
17         layout.pop_arrangement(*this);
18 }
19
20 void Arrangement::arrange(Widget &wdg)
21 {
22         for(unsigned i=0; i<4; ++i)
23                 process_widget(wdg, static_cast<Side>(i), true);
24         finish_widget(wdg);
25         finish_slot();
26 }
27
28 void Arrangement::arrange(Arrangement &arr)
29 {
30         for(unsigned i=0; i<4; ++i)
31         {
32                 Side side = static_cast<Side>(i);
33                 const Edge &edge = arr.get_edge(side);
34                 for(list<Widget *>::const_iterator j=edge.widgets.begin(); j!=edge.widgets.end(); ++j)
35                         process_widget(**j, side, edge.aligned);
36         }
37         finish_slot();
38 }
39
40 void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, Side side)
41 {
42         add_constraint(wdg, type, edges[side]);
43 }
44
45 void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, const Edge &edge)
46 {
47         for(list<Widget *>::const_iterator i=edge.widgets.begin(); i!=edge.widgets.end(); ++i)
48                 layout.add_constraint(wdg, type, **i);
49 }
50
51 Layout::ConstraintType Arrangement::get_order_constraint(Side s, bool slack)
52 {
53         switch(s)
54         {
55         case TOP:    return (slack ? Layout::FAR_ABOVE : Layout::ABOVE);
56         case RIGHT:  return (slack ? Layout::FAR_RIGHT_OF : Layout::RIGHT_OF);
57         case BOTTOM: return (slack ? Layout::FAR_BELOW : Layout::BELOW);
58         case LEFT:   return (slack ? Layout::FAR_LEFT_OF : Layout::LEFT_OF);
59         default: throw invalid_argument("Arrangement::get_align_constraint");
60         }
61 }
62
63 Layout::ConstraintType Arrangement::get_align_constraint(Side s)
64 {
65         switch(s)
66         {
67         case TOP:    return Layout::ALIGN_TOP;
68         case RIGHT:  return Layout::ALIGN_RIGHT;
69         case BOTTOM: return Layout::ALIGN_BOTTOM;
70         case LEFT:   return Layout::ALIGN_LEFT;
71         default: throw invalid_argument("Arrangement::get_align_constraint");
72         }
73 }
74
75
76 Arrangement::Edge::Edge():
77         aligned(false)
78 { }
79
80 void Arrangement::Edge::clear()
81 {
82         widgets.clear();
83         aligned = false;
84 }
85
86 void Arrangement::Edge::add(Widget &wdg, bool algn)
87 {
88         if(aligned)
89                 return;
90
91         if(algn)
92                 widgets.clear();
93
94         widgets.push_back(&wdg);
95         aligned = algn;
96 }
97
98 } // namespace GLtk
99 } // namespace Msp