CanvasCV: CanvasCV-doxygen/src/canvascv/widgets/autolayout.h Source File
CanvasCV  1.0.0
autolayout.h
1 #ifndef AUTOLAYOUT_H
2 #define AUTOLAYOUT_H
3 
4 #include "layoutbase.h"
5 #include "compoundwidget.h"
6 
7 namespace canvascv
8 {
9 
15 class AutoLayout : public CompoundWidget
16 {
17 public:
18 
37  int getPadding() const;
38 
56  void setPadding(int value);
57 
58  virtual void addWidget(const std::shared_ptr<Widget> &widget);
59  virtual std::shared_ptr<Widget> rmvWidget(const std::shared_ptr<Widget> &widget);
60 
62  void rmvWidget(int i);
63 
65  template <typename T=Widget>
66  T *at(int index);
67 
69  size_t size() const;
70 
72  bool getWrap() const;
73 
75  void setWrap(bool value);
76 
77 
79  int getMaxWidgetWidth();
80 
82  int getMaxWidgetHeight();
83 
84 protected:
85 
86  AutoLayout(const cv::Point& pos);
87 
88  void recalcAndAllocate();
89  virtual const cv::Rect getBoundaries() const;
90 
91  int padding;
92  bool wrap;
93  int maxWidth;
94  int maxHeight;
95 };
96 
97 // simplest case is the special case
98 template<>
99 Widget *AutoLayout::at(int index);
100 
101 template<typename T>
102 T *AutoLayout::at(int index)
103 {
104  Widget *pWidget = nullptr;
105  if (index < widgets.size())
106  {
107  auto i = widgets.begin();
108  std::advance(i, index);
109  pWidget = i->get();
110  assert (pWidget->getType() == T::type);
111  }
112  return static_cast<T*>(pWidget);
113 }
114 
115 }
116 #endif // AUTOLAYOUT_H
int getMaxWidgetWidth()
get the maximum width from all contained widgets
The CompoundWidget class.
Definition: compoundwidget.h:18
void setPadding(int value)
setPadding set number of pixels to pad from Layout rect during layout
T * at(int index)
return a widget at index &#39;i&#39; (or 0 if type is wrong ot &#39;i&#39; is too big)
Definition: autolayout.h:102
void setWrap(bool value)
set if the layout will wrap widgets past forcedWidth / forcedHeight
virtual const char * getType() const =0
getType is always implemented by derived to return the same static pointer per widget.
bool getWrap() const
get if the layout will wrap widgets past forcedWidth / forcedHeight
The AutoLayout class.
Definition: autolayout.h:15
This namespace holds all the classes of the CanvasCV library.
Definition: canvas.h:20
int getMaxWidgetHeight()
get the maximum height from all contained widgets
size_t size() const
returns the number of widgets in the layout
virtual void addWidget(const std::shared_ptr< Widget > &widget)
adds the widget to this Layout after removing it from it&#39;s previous layout
virtual std::shared_ptr< Widget > rmvWidget(const std::shared_ptr< Widget > &widget)
rmvWidget
int getPadding() const
getPadding get number of pixels to pad from Layout rect during layout
The Widget class.
Definition: widget.h:28