Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_toggle_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_TOGGLE_CONTAINER_H
7 #define TB_TOGGLE_CONTAINER_H
8 
9 #include "tb_widgets_common.h"
10 
11 namespace tb {
12 
19 {
20 public:
21  // For safe typecasting
22  TBOBJECT_SUBCLASS(TBToggleContainer, TBWidget);
23 
25 
27  enum TOGGLE {
32  };
33 
35  void SetToggle(TOGGLE toggle);
36  TOGGLE GetToggle() const { return m_toggle; }
37 
39  void SetInvert(bool invert);
40  bool GetInvert() const { return m_invert; }
41 
43  bool GetIsOn() const { return m_invert ? !m_value : !!m_value; }
44 
47  virtual void SetValue(long value);
48  virtual long GetValue() const { return m_value; }
49 
50  virtual void OnInflate(const INFLATE_INFO &info);
51 private:
52  void UpdateInternal();
53  TOGGLE m_toggle;
54  bool m_invert;
55  int m_value;
56 };
57 
61 class TBSectionHeader : public TBButton
62 {
63 public:
64  // For safe typecasting
65  TBOBJECT_SUBCLASS(TBSectionHeader, TBButton);
66 
68 
69  virtual bool OnEvent(const TBWidgetEvent &ev);
70 };
71 
83 class TBSection : public TBWidget
84 {
85 public:
86  // For safe typecasting
87  TBOBJECT_SUBCLASS(TBSection, TBWidget);
88 
89  TBSection();
90  ~TBSection();
91 
92  TBLayout *GetLayout() { return &m_layout; }
93  TBSectionHeader *GetHeader() { return &m_header; }
94  TBToggleContainer *GetContainer() { return &m_toggle_container; }
95 
97  void SetPendingScrollIntoView(bool pending_scroll) { m_pending_scroll = pending_scroll; }
98 
100  virtual bool SetText(const TBStr & text) { return m_header.SetText(text); }
101  virtual bool GetText(TBStr &text) const { return m_header.GetText(text); }
102  using TBWidget::GetText;
103 
104  virtual void SetValue(long value);
105  virtual long GetValue() const { return m_toggle_container.GetValue(); }
106 
107  virtual TBWidget *GetContentRoot() { return m_toggle_container.GetContentRoot(); }
108  virtual void OnProcessAfterChildren();
109 
110  virtual PreferredSize OnCalculatePreferredSize(const SizeConstraints &constraints);
111 private:
112  TBLayout m_layout;
113  TBSectionHeader m_header;
114  TBToggleContainer m_toggle_container;
115  bool m_pending_scroll;
116 };
117 
118 } // namespace tb
119 
120 #endif // TB_TOGGLE_CONTAINER_H
virtual bool GetText(TBStr &text) const
Get the text of this widget.
Definition: tb_widgets_common.h:141
TBSectionHeader is just a thin wrapper for a TBButton that is in toggle mode with the skin TBSectionH...
Definition: tb_toggle_container.h:61
The base TBWidget class.
Definition: tb_widgets.h:418
virtual PreferredSize OnCalculatePreferredSize(const SizeConstraints &constraints)
Calculate the preferred size for this widget.
Definition: tb_toggle_container.cpp:81
Definition: tb_widgets.h:112
virtual bool SetText(const TBStr &text)
Set the text of the button.
Definition: tb_widgets_common.cpp:175
virtual void SetValue(long value)
Set the value of this widget.
Definition: tb_toggle_container.cpp:120
TBToggleContainer is a widget that toggles a property when its value change between 0 and 1...
Definition: tb_toggle_container.h:18
virtual TBWidget * GetContentRoot()
Get this widget or a child widget that should be root for other children.
Definition: tb_toggle_container.h:107
Specifies size constraints used during size calculations.
Definition: tb_widgets.h:321
void SetInvert(bool invert)
Set if the toggle state should be inverted.
Definition: tb_toggle_container.cpp:112
virtual long GetValue() const
See TBWidget::SetValue.
Definition: tb_toggle_container.h:105
bool GetIsOn() const
Get the current value, after checking the invert mode.
Definition: tb_toggle_container.h:43
virtual void SetValue(long value)
< Make all versions in base class available.
Definition: tb_toggle_container.cpp:66
virtual void OnProcessAfterChildren()
Callback for doing anything that might be needed before paint.
Definition: tb_toggle_container.cpp:72
virtual long GetValue() const
See TBWidget::SetValue.
Definition: tb_toggle_container.h:48
TBButton is a regular button widget with auto repeat, toggle and group capabilities.
Definition: tb_widgets_common.h:111
TBSection is a widget with a header that when clicked toggles its children on and off (using a intern...
Definition: tb_toggle_container.h:83
Nothing happens (the default)
Definition: tb_toggle_container.h:28
virtual TBWidget * GetContentRoot()
Get this widget or a child widget that should be root for other children.
Definition: tb_widgets.h:828
INFLATE_INFO contains info passed to TBWidget::OnInflate during resource loading. ...
Definition: tb_widgets_reader.h:21
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:738
TBStr is a simple string class.
Definition: tb_str.h:62
void SetToggle(TOGGLE toggle)
Set what should toggle when the value changes.
Definition: tb_toggle_container.cpp:100
Expanded/collapsed (In parent axis direction)
Definition: tb_toggle_container.h:31
TOGGLE
Defines what should toggle when the value changes.
Definition: tb_toggle_container.h:27
virtual bool GetText(TBStr &text) const
Get the text of this widget.
Definition: tb_toggle_container.h:101
virtual bool OnEvent(const TBWidgetEvent &ev)
Callback for handling events.
Definition: tb_toggle_container.cpp:21
virtual bool SetText(const TBStr &text)
Set the text of the text field.
Definition: tb_toggle_container.h:100
PreferredSize contains size preferences for a TBWidget.
Definition: tb_widgets.h:277
Opacity 1/0.
Definition: tb_toggle_container.h:30
TBLayout layouts its children along the given axis.
Definition: tb_layout.h:96
Enabled/disabled state.
Definition: tb_toggle_container.h:29
void SetPendingScrollIntoView(bool pending_scroll)
Set if the section should be scrolled into view after next layout.
Definition: tb_toggle_container.h:97
TBStr GetText() const
Get the text of this widget.
Definition: tb_widgets.h:942