Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_layout.h
1 // ================================================================================
2 // == This file is a part of Turbo Badger. (C) 2011-2014, Emil SegerÃ¥s ==
3 // == See tb_core.h for more information. ==
4 // ================================================================================
5 
6 #ifndef TB_LAYOUT_H
7 #define TB_LAYOUT_H
8 
9 #include "tb_widgets.h"
10 
11 namespace tb {
12 
14 #define SPACING_FROM_SKIN TB_INVALID_DIMENSION
15 
28 };
29 
42 };
44 
56 };
58 
70 };
71 
76 };
77 
83  //LAYOUT_OVERFLOW_WRAP
84 };
85 
96 class TBLayout : public TBWidget
97 {
98 public:
99  // For safe typecasting
100  TBOBJECT_SUBCLASS(TBLayout, TBWidget);
101 
102  TBLayout(AXIS axis = AXIS_X);
103 
105  virtual void SetAxis(AXIS axis);
106  virtual AXIS GetAxis() const { return m_axis; }
107 
110  void SetSpacing(int spacing);
111  int GetSpacing() const { return m_spacing; }
112 
116  void SetOverflowScroll(int overflow_scroll);
117  int GetOverflowScroll() const { return m_overflow_scroll; }
118 
120  void SetPaintOverflowFadeout(bool paint_fadeout) { m_packed.paint_overflow_fadeout = paint_fadeout; }
121 
123  void SetLayoutSize(LAYOUT_SIZE size);
124 
127 
129  void SetLayoutOverflow(LAYOUT_OVERFLOW overflow);
130 
132  void SetLayoutDistribution(LAYOUT_DISTRIBUTION distribution);
133 
136 
139  void SetLayoutOrder(LAYOUT_ORDER order);
140 
141  virtual void InvalidateLayout(INVALIDATE_LAYOUT il);
142 
144 
145  virtual void OnInflate(const INFLATE_INFO &info);
146  virtual void OnDeflate(const INFLATE_INFO &info);
148  virtual WIDGET_HIT_STATUS GetHitStatus(int x, int y);
149  virtual bool OnEvent(const TBWidgetEvent &ev);
150  virtual void OnPaintChildren(const PaintProps &paint_props);
151  virtual void OnProcess();
152  virtual void OnResized(int old_w, int old_h);
153  virtual void OnInflateChild(TBWidget *child);
154  virtual void GetChildTranslation(int &x, int &y) const;
155  virtual void ScrollTo(int x, int y);
157 protected:
158  AXIS m_axis;
159  int m_spacing;
160  int m_overflow;
161  int m_overflow_scroll;
162  union {
163  struct {
164  uint32_t layout_is_invalid : 1;
165  uint32_t layout_mode_size : 4;
166  uint32_t layout_mode_pos : 4;
167  uint32_t layout_mode_overflow : 4;
168  uint32_t layout_mode_dist : 4;
169  uint32_t layout_mode_dist_pos : 4;
170  uint32_t mode_reverse_order : 1;
171  uint32_t paint_overflow_fadeout : 1;
172  } m_packed;
173  uint32_t m_packed_init;
174  };
175  void ValidateLayout(const SizeConstraints &constraints, PreferredSize *calculate_ps = nullptr);
177  bool QualifyForExpansion(WIDGET_GRAVITY gravity) const;
178  int GetWantedHeight(WIDGET_GRAVITY gravity, const PreferredSize &ps, int available_height) const;
179  TBWidget *GetNextNonCollapsedWidget(TBWidget *child) const;
180  int GetTrailingSpace(TBWidget *child, int spacing) const;
181  int CalculateSpacing();
182  TBWidget *GetFirstInLayoutOrder() const;
183  TBWidget *GetNextInLayoutOrder(TBWidget *child) const;
184 };
185 
186 };
187 
188 #endif // TB_LAYOUT_H
AXIS
Definition: tb_widgets.h:251
Create a scroller.
Definition: tb_layout.h:82
virtual void GetChildTranslation(int &x, int &y) const
Return translation the children should have.
Definition: tb_layout.cpp:520
virtual void InvalidateLayout(INVALIDATE_LAYOUT il)
Invalidate layout for this widget so it will be scheduled for relayout.
Definition: tb_layout.cpp:110
Size should grow to all available space.
Definition: tb_layout.h:27
The base TBWidget class.
Definition: tb_widgets.h:418
void SetSpacing(int spacing)
Set the spacing between widgets in this layout.
Definition: tb_layout.cpp:39
Clip the chilren widgtes. [default].
Definition: tb_layout.h:81
virtual PreferredSize OnCalculatePreferredContentSize(const SizeConstraints &constraints)
Calculate the preferred content size for this widget.
Definition: tb_layout.cpp:403
WIDGET_GRAVITY
TBWidget gravity (may be combined).
Definition: tb_widgets.h:237
virtual WIDGET_HIT_STATUS GetHitStatus(int x, int y)
Check if there's an interactible child at the location.
Definition: tb_layout.cpp:411
virtual void OnProcess()
Callback for doing anything that might be needed before paint.
Definition: tb_layout.cpp:502
Definition: tb_widgets.h:112
void SetLayoutDistribution(LAYOUT_DISTRIBUTION distribution)
Set the layout distribution mode.
Definition: tb_layout.cpp:85
LAYOUT_POSITION
Specifies which y position widgets in a AXIS_X layout should have, or which x position widgets in a A...
Definition: tb_layout.h:37
Size will be the preferred so each widget may be sized differently. [default].
Definition: tb_layout.h:53
Size will be the preferred so each widget may be sized differently. [default].
Definition: tb_layout.h:26
virtual void OnDeflate(const INFLATE_INFO &info)
Called when this widget is deflated to a node, before any children have been deflated.
Definition: tb_widgets_reader.cpp:526
virtual bool OnEvent(const TBWidgetEvent &ev)
Callback for handling events.
Definition: tb_layout.cpp:435
Position is to the right for AXIS_Y layout and bottom for AXIS_X layout.
Definition: tb_layout.h:40
Specifies size constraints used during size calculations.
Definition: tb_widgets.h:321
Horizontal layout.
Definition: tb_widgets.h:252
void SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION distribution_pos)
Set the layout distribution position mode.
Definition: tb_layout.cpp:93
Size should grow to all available space.
Definition: tb_layout.h:54
Sizes depend on the gravity for each widget.
Definition: tb_layout.h:24
virtual void OnResized(int old_w, int old_h)
Called when this widget has been resized.
Definition: tb_layout.cpp:508
void SetPaintOverflowFadeout(bool paint_fadeout)
Set if a fadeout should be painter where the layout overflows or not.
Definition: tb_layout.h:120
Information about scrolling for a widget at the time of calling GetScrollInfo.
Definition: tb_widgets.h:871
LAYOUT_DISTRIBUTION_POSITION
Specifies how widgets should be moved horizontally in a AXIS_X layout (or vertically in a AXIS_Y layo...
Definition: tb_layout.h:66
LAYOUT_OVERFLOW
Specifies what happens when there is not enough room for the layout, even when all the children have ...
Definition: tb_layout.h:80
Position depend on the gravity for each widget.
Definition: tb_layout.h:41
From top to bottom widget.
Definition: tb_layout.h:75
Position centered. [default].
Definition: tb_layout.h:67
INVALIDATE_LAYOUT
Type used for InvalidateLayout.
Definition: tb_widgets.h:988
WIDGET_HIT_STATUS
Hit status return value for TBWidget::GetHitStatus.
Definition: tb_widgets.h:398
Position to the lower right.
Definition: tb_layout.h:69
void SetOverflowScroll(int overflow_scroll)
Set the overflow scroll.
Definition: tb_layout.cpp:47
INFLATE_INFO contains info passed to TBWidget::OnInflate during resource loading. ...
Definition: tb_widgets_reader.h:21
LAYOUT_DISTRIBUTION
Specifies which width widgets in a AXIS_X layout should have, or which height widgets in a AXIS_Y lay...
Definition: tb_layout.h:52
bool QualifyForExpansion(WIDGET_GRAVITY gravity) const
Can this TBLayout expand in its direction?
Definition: tb_layout.cpp:160
void SetLayoutSize(LAYOUT_SIZE size)
Set the layout size mode.
Definition: tb_layout.cpp:61
LAYOUT_SIZE
Specifies which height widgets in a AXIS_X layout should have, or which width widgets in a AXIS_Y lay...
Definition: tb_layout.h:23
Position is to the left for AXIS_Y layout and top for AXIS_X layout.
Definition: tb_layout.h:39
virtual void OnInflateChild(TBWidget *child)
Called just after a child has been inflated into this widget.
Definition: tb_layout.cpp:515
virtual void OnPaintChildren(const PaintProps &paint_props)
Callback for painting child widgets.
Definition: tb_layout.cpp:450
virtual void SetAxis(AXIS axis)
Set along which axis the content should be layouted.
Definition: tb_layout.cpp:30
From bottom to top widget (default creation order).
Definition: tb_layout.h:74
Position is centered. [default].
Definition: tb_layout.h:38
Sizes depend on the gravity for each widget.
Definition: tb_layout.h:55
virtual AXIS GetAxis() const
See TBWidget::SetAxis.
Definition: tb_layout.h:106
void SetLayoutPosition(LAYOUT_POSITION pos)
Set the layout position mode.
Definition: tb_layout.cpp:69
virtual void OnInflate(const INFLATE_INFO &info)
Called when this widget is inflated from resources, before any children have been inflated...
Definition: tb_widgets_reader.cpp:453
void SetLayoutOrder(LAYOUT_ORDER order)
Set the layout order.
Definition: tb_layout.cpp:101
Position to the upper left.
Definition: tb_layout.h:68
PreferredSize contains size preferences for a TBWidget.
Definition: tb_widgets.h:277
void SetLayoutOverflow(LAYOUT_OVERFLOW overflow)
Set the layout size mode.
Definition: tb_layout.cpp:77
TBLayout layouts its children along the given axis.
Definition: tb_layout.h:96
virtual TBWidget::ScrollInfo GetScrollInfo()
If this is a widget that scroll children (see GetChildTranslation), it should return the current scro...
Definition: tb_layout.cpp:539
LAYOUT_ORDER
Layout order parameter for TBLayout::SetLayoutOrder.
Definition: tb_layout.h:73
virtual void ScrollTo(int x, int y)
If this is a widget that scroll children (see GetChildTranslation), it should scroll to the coordinat...
Definition: tb_layout.cpp:534