]> git.tdb.fi Git - libs/gltk.git/blob - source/arrangement.h
2decb3eb4fc5ef71513fe9985b86462e5cf04425
[libs/gltk.git] / source / arrangement.h
1 #ifndef MSP_GLTK_ARRANGEMENT_H_
2 #define MSP_GLTK_ARRANGEMENT_H_
3
4 #include <list>
5 #include <stdexcept>
6 #include "layout.h"
7 #include "mspgltk_api.h"
8
9 namespace Msp {
10 namespace GLtk {
11
12 class Widget;
13
14 class MSPGLTK_API arrangement_error: public std::logic_error
15 {
16 public:
17         arrangement_error(const std::string &w): std::logic_error(w) { }
18         virtual ~arrangement_error() throw() { }
19 };
20
21 class MSPGLTK_API Arrangement
22 {
23 protected:
24         enum Side
25         {
26                 TOP,
27                 RIGHT,
28                 BOTTOM,
29                 LEFT
30         };
31
32         struct Edge
33         {
34                 std::list<Widget *> widgets;
35                 bool aligned = false;
36
37                 bool empty() { return widgets.empty(); }
38                 void clear();
39                 void add(Widget &, bool);
40                 void align();
41         };
42
43         Layout &layout;
44         Arrangement *parent = nullptr;
45         Edge edges[4];
46
47         Arrangement(Layout &);
48 public:
49         virtual ~Arrangement();
50
51         void arrange(Widget &);
52         void arrange(Arrangement &);
53
54 protected:
55         virtual void process_widget(Widget &, Side, bool) = 0;
56         virtual void finish_widget(Widget &) = 0;
57         virtual void finish_slot() = 0;
58         const Edge &get_edge(Side s) const { return edges[s]; }
59         void add_constraint(Widget &, Layout::ConstraintType, Side, int = -1);
60         void add_constraint(Widget &, Layout::ConstraintType, const Edge &, int = -1);
61
62         static Layout::ConstraintType get_order_constraint(Side, bool);
63         static Layout::ConstraintType get_align_constraint(Side);
64 };
65
66 } // namespace GLtk
67 } // namespace Msp
68
69 #endif