11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
20PROMEKI_NAMESPACE_BEGIN
34class Layout :
public ObjectBase {
35 PROMEKI_OBJECT(Layout, ObjectBase)
37 Layout(ObjectBase *parent =
nullptr);
41 virtual void addWidget(Widget *widget);
44 void removeWidget(Widget *widget);
47 virtual void addLayout(Layout *layout);
50 void setMargins(
int top,
int right,
int bottom,
int left);
53 void setMargins(
int margin) { setMargins(margin, margin, margin, margin); }
56 void setSpacing(
int spacing) { _spacing = spacing; }
59 int spacing()
const {
return _spacing; }
62 void margins(
int &top,
int &right,
int &bottom,
int &left)
const {
65 bottom = _marginBottom;
73 virtual void calculateLayout(
const Rect2Di32 &available) = 0;
78 virtual Size2Di32 sizeHint()
const;
81 const List<Widget *> &widgets()
const {
return _widgets; }
84 const List<Layout *> &layouts()
const {
return _layouts; }
90 Rect2Di32 contentRect(
const Rect2Di32 &available)
const;
92 List<Widget *> _widgets;
93 List<Layout *> _layouts;
99 int _marginBottom = 0;
122class BoxLayout :
public Layout {
123 PROMEKI_OBJECT(BoxLayout, Layout)
130 BoxLayout(BoxDirection direction, ObjectBase *parent =
nullptr);
133 BoxDirection direction()
const {
return _direction; }
136 void addWidget(Widget *widget)
override;
139 void addLayout(Layout *layout)
override;
142 void addStretch(
int factor = 1);
145 void setStretch(
int index,
int factor);
148 void calculateLayout(
const Rect2Di32 &available)
override;
151 Size2Di32 sizeHint()
const override;
162 Widget *widget =
nullptr;
163 Layout *layout =
nullptr;
164 int stretchFactor = 0;
167 BoxDirection _direction;
175class HBoxLayout :
public BoxLayout {
176 PROMEKI_OBJECT(HBoxLayout, BoxLayout)
178 HBoxLayout(ObjectBase *parent =
nullptr) : BoxLayout(LeftToRight, parent) {}
185class VBoxLayout :
public BoxLayout {
186 PROMEKI_OBJECT(VBoxLayout, BoxLayout)
188 VBoxLayout(ObjectBase *parent =
nullptr) : BoxLayout(TopToBottom, parent) {}
195class GridLayout :
public Layout {
196 PROMEKI_OBJECT(GridLayout, Layout)
198 GridLayout(ObjectBase *parent =
nullptr);
202 using Layout::addWidget;
207 void addWidget(Widget *widget,
int row,
int col,
int rowSpan = 1,
int colSpan = 1);
210 void setRowStretch(
int row,
int factor);
213 void setColumnStretch(
int col,
int factor);
216 void setRowMinimumHeight(
int row,
int height);
219 void setColumnMinimumWidth(
int col,
int width);
222 void calculateLayout(
const Rect2Di32 &available)
override;
232 List<GridItem> _items;
233 Map<int, int> _rowStretch;
234 Map<int, int> _colStretch;
235 Map<int, int> _rowMinHeight;
236 Map<int, int> _colMinWidth;