-
Notifications
You must be signed in to change notification settings - Fork 388
Expand file tree
/
Copy pathWBorderLayout.h
More file actions
148 lines (125 loc) · 4.17 KB
/
WBorderLayout.h
File metadata and controls
148 lines (125 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2008 Emweb bv, Herent, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef WBORDER_LAYOUT_H_
#define WBORDER_LAYOUT_H_
#include <Wt/WGridLayout.h>
namespace Wt {
/*! \brief Enumeration of possible positions in the layout.
*/
enum class LayoutPosition {
North, //!< North (top)
East, //!< East (right)
South, //!< South (bottom)
West, //!< West (left)
Center //!< Center
};
/*! \class WBorderLayout Wt/WBorderLayout.h Wt/WBorderLayout.h
* \brief A layout manager which divides the container region in five regions.
*
* The five regions are composed of:
* <pre>
------------------------------------
| North |
------------------------------------
| | | |
| West | Center | East |
| | | |
------------------------------------
| South |
------------------------------------
* </pre>
*
* Each region may hold no more than one widget, and for all but the
* Center region, the widget is optional.
*
* The North, West, East, and South widgets will take their preferred
* sizes, while the Center widget takes all available remaining space.
*
* \if cpp
* Usage example:
* \code
* auto w = addWidget(std::make_unique<Wt::WContainerWidget>());
* auto layout = std::make_unique<Wt::WBorderLayout>();
* layout->addWidget(std::make_unique<Wt::WText>("West-side is best"), Wt::LayoutPosition::West);
* layout->addWidget(std::make_unique<Wt::WText>("East-side is best"), Wt::LayoutPosition::East);
* layout->addWidget(std::move(contents), Wt::LayoutPosition::Center);
*
* // use layout but do not justify vertically
* w->setLayout(std::move(layout), Wt::AlignmentFlag::Top | Wt::AlignmentFlag::Justify);
* \endcode
* \endif
*/
class WT_API WBorderLayout : public WLayout
{
public:
/*! \brief Typedef for enum Wt::LayoutPosition */
typedef LayoutPosition Position;
/*! \brief Creates a new border layout.
*/
WBorderLayout();
/*! \brief Destructor.
*/
virtual ~WBorderLayout() override;
/*! \brief Sets spacing between each item.
*
* The default spacing is 6 pixels.
*/
void setSpacing(int size);
/*! \brief Returns the spacing between each item.
*
* \sa setSpacing()
*/
int spacing() const { return grid_.horizontalSpacing_; }
virtual void addItem(std::unique_ptr<WLayoutItem> item) override;
virtual std::unique_ptr<WLayoutItem> removeItem(WLayoutItem *item) override;
virtual WLayoutItem *itemAt(int index) const override;
virtual int count() const override;
/*! \brief Adds a widget to the given position.
*
* Only one widget per position is supported.
*
* \sa add(WLayoutItem *, Position)
*/
void addWidget(std::unique_ptr<WWidget> widget, LayoutPosition position);
template <typename Widget>
Widget *addWidget(std::unique_ptr<Widget> widget, LayoutPosition position)
#ifndef WT_TARGET_JAVA
{
Widget *result = widget.get();
addWidget(std::unique_ptr<WWidget>(std::move(widget)), position);
return result;
}
#else // WT_TARGET_JAVA
;
#endif // WT_TARGET_JAVA
/*! \brief Adds a layout item to the given position.
*
* Only one widget per position is supported.
*/
void add(std::unique_ptr<WLayoutItem> item, LayoutPosition position);
/*! \brief Returns the widget at a position.
*
* Returns \c 0 if no widget was set for that position.
*/
WWidget *widgetAt(LayoutPosition position) const;
/*! \brief Returns the item at a position.
*
* Returns \c 0 if no item was set for that position.
*/
WLayoutItem *itemAt(LayoutPosition position) const;
/*! \brief Returns the position at which the given layout item is set.
*/
LayoutPosition position(WLayoutItem *item) const;
virtual void iterateWidgets(const HandleWidgetMethod& method) const override;
private:
Impl::Grid grid_;
const Impl::Grid::Item& itemAtPosition(LayoutPosition position) const;
Impl::Grid::Item& itemAtPosition(LayoutPosition position);
virtual void setParentWidget(WWidget *parent) override;
};
}
#endif // WBORDER_LAYOUT_H_