6#include "fifechan/widgets/flowcontainer.hpp"
15#include "fifechan/exception.hpp"
20 FlowContainer::FlowContainer()
25 FlowContainer::~FlowContainer() =
default;
47 std::vector<int> layoutMax;
51 int visibleChilds = 0;
52 std::list<Widget*>::const_iterator currChild(
mChildren.begin());
53 std::list<Widget*>::const_iterator endChildren(
mChildren.end());
54 for (; currChild != endChildren; ++currChild) {
55 Widget const * child = *currChild;
61 if (
mLayout == LayoutPolicy::Vertical) {
68 layoutMax.push_back(tmpSize);
82 layoutMax.push_back(tmpSize);
92 layoutMax.push_back(tmpSize);
100 unsigned int layout = 0;
101 if (
mLayout == LayoutPolicy::Vertical && visibleChilds > 0) {
104 for (; currChild != endChildren; ++currChild) {
105 if (!(*currChild)->isVisible()) {
108 int columnW = layoutMax.at(layout);
109 int const layoutW = (*currChild)->getWidth() + (*currChild)->getMarginLeft() +
110 ((*currChild)->getMarginRight() > 0 ? (*currChild)->getMarginRight() : 0);
112 (*currChild)->getMarginLeft(), (*currChild)->getMarginTop(), layoutW, (*currChild)->getHeight());
116 if (y + (*currChild)->getMarginTop() + dim.
height +
117 ((*currChild)->getMarginBottom() > 0 ? (*currChild)->getMarginBottom() : 0) >
122 columnW = layoutMax.at(layout);
127 case Alignment::Left:
130 case Alignment::Center:
131 dim.
x += x + ((columnW - layoutW) / 2);
133 case Alignment::Right:
134 dim.
x += x + (columnW - layoutW);
140 (*currChild)->setDimension(dim);
141 y += (*currChild)->getHeight() + (*currChild)->getMarginTop() + (*currChild)->getMarginBottom() +
143 totalW = std::max(totalW, dim.
x + dim.
width);
144 totalH = std::max(totalH, y);
149 totalH = std::max(totalH, containerH);
151 totalW = std::max(totalW, containerW);
153 }
else if (
mLayout == LayoutPolicy::Horizontal && visibleChilds > 0) {
156 for (; currChild != endChildren; ++currChild) {
157 if (!(*currChild)->isVisible()) {
160 int rowH = layoutMax.at(layout);
161 int const layoutH = (*currChild)->getHeight() + (*currChild)->getMarginTop() +
162 ((*currChild)->getMarginBottom() > 0 ? (*currChild)->getMarginBottom() : 0);
164 (*currChild)->getMarginLeft(), (*currChild)->getMarginTop(), (*currChild)->getWidth(), layoutH);
168 if (x + (*currChild)->getMarginLeft() + dim.
width +
169 ((*currChild)->getMarginRight() > 0 ? (*currChild)->getMarginRight() : 0) >
174 rowH = layoutMax.at(layout);
182 case Alignment::Center:
183 dim.
y += y + ((rowH - layoutH) / 2);
185 case Alignment::Bottom:
186 dim.
y += y + (rowH - layoutH);
192 (*currChild)->setDimension(dim);
193 x += (*currChild)->getWidth() + (*currChild)->getMarginLeft() + (*currChild)->getMarginRight() +
195 totalW = std::max(totalW, x);
196 totalH = std::max(totalH, dim.
y + dim.
height);
201 totalW = std::max(totalW, containerW);
203 totalH = std::max(totalH, containerH);
215 if (policy == LayoutPolicy::Circular) {
216 throwException(
"Circular layout is not implemented for the FlowContainer.");
225 std::list<Widget*>::const_iterator currChild(
mChildren.begin());
226 std::list<Widget*>::const_iterator
const endChildren(
mChildren.end());
227 for (; currChild != endChildren; ++currChild) {
228 if (!(*currChild)->isVisible()) {
231 (*currChild)->resizeToContent(recursion);
235 if (
mLayout != Container::LayoutPolicy::Absolute) {
244 if (
mLayout != Container::LayoutPolicy::Absolute) {
249 std::list<Widget*>::const_iterator currChild(
mChildren.begin());
250 std::list<Widget*>::const_iterator
const endChildren(
mChildren.end());
251 for (; currChild != endChildren; ++currChild) {
252 if (!(*currChild)->isVisible()) {
255 (*currChild)->expandContent(recursion);
virtual void setLayout(LayoutPolicy policy)
Sets the layout of the container.
LayoutPolicy mLayout
Layout.
LayoutPolicy
The layout policy of the container.
Rectangle getChildrenArea() override
Gets the area of the widget occupied by the widget's children.
virtual unsigned int getHorizontalSpacing() const
Get the horizontal spacing between rows.
virtual void setOpaque(bool opaque)
Sets the container to be opaque or not.
virtual unsigned int getVerticalSpacing() const
Get the vertical spacing between rows.
Alignment mAlignment
Current alignment used when laying out child widgets.
virtual void setAlignment(FlowContainer::Alignment alignment)
Sets the alignment of the widgets.
virtual FlowContainer::Alignment getAlignment() const
Gets the alignment of the widgets.
void resizeToContent(bool recursion=true) override
Resize flow layout to fit its children.
void expandContent()
Expands the child widgets to the size of this widget, calls recursively all childs.
void setLayout(Container::LayoutPolicy policy) override
Sets the layout of the container.
virtual void adjustContent()
Sets the size of the container and sorts the children.
Alignment
Alignments for widgets.
Represents a rectangular area (X, Y, Width, Height).
int width
Holds the width of the rectangle.
int y
Holds the x coordinate of the rectangle.
int x
Holds the x coordinate of the rectangle.
int height
Holds the height of the rectangle.
Used replacement tokens by configure_file():
void throwException(std::string const &message, std::source_location location=std::source_location::current())
Throw an Exception capturing the current source location.