Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_scroll_container.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_SCROLL_CONTAINER_H
7 #define TB_SCROLL_CONTAINER_H
8 
9 #include "tb_widgets_common.h"
10 
11 namespace tb {
12 
19 };
20 
24 {
25 private: // May only be used by TBScrollContainer.
26  friend class TBScrollContainer;
28 public:
29  virtual void OnPaintChildren(const PaintProps &paint_props);
30  virtual void GetChildTranslation(int &x, int &y) const;
31 };
32 
36 {
37 public:
38  TBScrollBarVisibility () : x_on(false), y_on(false), visible_w(0), visible_h(0) {}
39 
40  static TBScrollBarVisibility Solve(SCROLL_MODE mode, int content_w, int content_h,
41  int available_w, int available_h,
42  int scrollbar_x_h, int scrollbar_y_w);
43  static bool IsAlwaysOnX(SCROLL_MODE mode) { return mode == SCROLL_MODE_X_Y; }
44  static bool IsAlwaysOnY(SCROLL_MODE mode) { return mode == SCROLL_MODE_X_Y || mode == SCROLL_MODE_Y; }
45 public:
46  bool x_on, y_on;
47  int visible_w, visible_h;
48 };
49 
53 {
54 friend class TBScrollContainerRoot;
55 public:
56  // For safe typecasting
57  TBOBJECT_SUBCLASS(TBScrollContainer, TBWidget);
58 
61 
64  void SetAdaptToContentSize(bool adapt);
65  bool GetAdaptToContentSize() { return m_adapt_to_content_size; }
66 
69  void SetAdaptContentSize(bool adapt);
70  bool GetAdaptContentSize() { return m_adapt_content_size; }
71 
72  void SetScrollMode(SCROLL_MODE mode);
73  SCROLL_MODE GetScrollMode() { return m_mode; }
74 
75  virtual void ScrollTo(int x, int y);
77  virtual TBWidget *GetScrollRoot() { return &m_root; }
78 
79  virtual void InvalidateLayout(INVALIDATE_LAYOUT il);
80 
81  virtual TBRect GetPaddingRect();
83 
84  virtual void OnInflate(const INFLATE_INFO &info);
85  virtual bool OnEvent(const TBWidgetEvent &ev);
86  virtual void OnProcess();
87  virtual void OnResized(int old_w, int old_h);
88 
89  virtual TBWidget *GetContentRoot() { return &m_root; }
90 protected:
91  TBScrollBar m_scrollbar_x;
92  TBScrollBar m_scrollbar_y;
93  TBScrollContainerRoot m_root;
94  bool m_adapt_to_content_size;
95  bool m_adapt_content_size;
96  bool m_layout_is_invalid;
97  SCROLL_MODE m_mode;
98  void ValidateLayout(const SizeConstraints &constraints);
99 };
100 
101 };
102 
103 #endif // TB_SCROLL_CONTAINER_H
virtual TBWidget::ScrollInfo GetScrollInfo()
If this is a widget that scroll children (see GetChildTranslation), it should return the current scro...
Definition: tb_scroll_container.cpp:152
X and Y always scroll-mode: xy.
Definition: tb_scroll_container.h:14
virtual void OnProcess()
Callback for doing anything that might be needed before paint.
Definition: tb_scroll_container.cpp:251
void SetAdaptContentSize(bool adapt)
Set to true if the content should adapt to the available size of this container when it's larger than...
Definition: tb_scroll_container.cpp:125
The base TBWidget class.
Definition: tb_widgets.h:418
virtual TBRect GetPaddingRect()
Get the rectangle inside any padding, relative to this widget.
Definition: tb_scroll_container.cpp:172
virtual PreferredSize OnCalculatePreferredContentSize(const SizeConstraints &constraints)
Calculate the preferred content size for this widget.
Definition: tb_scroll_container.cpp:183
Definition: tb_widgets.h:112
PaintProps contains properties needed for painting a widget.
Definition: tb_widgets.h:731
TBScrollBar is a scroll bar in the given axis.
Definition: tb_widgets_common.h:320
virtual TBWidget * GetContentRoot()
Get this widget or a child widget that should be root for other children.
Definition: tb_scroll_container.h:89
X auto, Y auto scroll-mode: auto.
Definition: tb_scroll_container.h:17
TBScrollContainerRoot - Internal for TBScrollContainer.
Definition: tb_scroll_container.h:23
Specifies size constraints used during size calculations.
Definition: tb_widgets.h:321
Y always (X never) scroll-mode: y.
Definition: tb_scroll_container.h:15
virtual void OnPaintChildren(const PaintProps &paint_props)
Callback for painting child widgets.
Definition: tb_scroll_container.cpp:68
virtual void OnResized(int old_w, int old_h)
Called when this widget has been resized.
Definition: tb_scroll_container.cpp:307
SCROLL_MODE
Definition: tb_scroll_container.h:13
Information about scrolling for a widget at the time of calling GetScrollInfo.
Definition: tb_widgets.h:871
TBScrollContainer - A container with scrollbars that can scroll its children.
Definition: tb_scroll_container.h:52
INVALIDATE_LAYOUT
Type used for InvalidateLayout.
Definition: tb_widgets.h:988
INFLATE_INFO contains info passed to TBWidget::OnInflate during resource loading. ...
Definition: tb_widgets_reader.h:21
virtual bool OnEvent(const TBWidgetEvent &ev)
Callback for handling events.
Definition: tb_scroll_container.cpp:210
X any Y never scroll-mode: off.
Definition: tb_scroll_container.h:18
void SetAdaptToContentSize(bool adapt)
Set to true if the preferred size of this container should adapt to the preferred size of the content...
Definition: tb_scroll_container.cpp:116
Y auto (X never) scroll-mode: y-auto.
Definition: tb_scroll_container.h:16
Simple rectangle class.
Definition: tb_geometry.h:25
virtual TBWidget * GetScrollRoot()
If this widget is implementing ScrollTo and GetScrollInfo but the corresponding GetChildTranslation i...
Definition: tb_scroll_container.h:77
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:567
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_scroll_container.cpp:141
PreferredSize contains size preferences for a TBWidget.
Definition: tb_widgets.h:277
virtual void InvalidateLayout(INVALIDATE_LAYOUT il)
Invalidate layout for this widget so it will be scheduled for relayout.
Definition: tb_scroll_container.cpp:164
virtual void GetChildTranslation(int &x, int &y) const
Return translation the children should have.
Definition: tb_scroll_container.cpp:88
TBScrollBarVisibility - Helper for TBScrollContainer or any other scrollable container that needs to ...
Definition: tb_scroll_container.h:35