tb_tab_container.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef TB_TAB_CONTAINER_H
  6. #define TB_TAB_CONTAINER_H
  7. #include "tb_widgets_common.h"
  8. namespace tb {
  9. /** TBTabLayout is a TBLayout used in TBTabContainer to apply
  10. some default properties on any TBButton added to it. */
  11. class TBTabLayout : public TBLayout
  12. {
  13. public:
  14. // For safe typecasting
  15. TBOBJECT_SUBCLASS(TBTabLayout, TBLayout);
  16. virtual void OnChildAdded(TBWidget *child);
  17. virtual PreferredSize OnCalculatePreferredContentSize(const SizeConstraints &constraints);
  18. };
  19. /** TBTabContainer - A container with tabs for multiple pages. */
  20. class TBTabContainer : public TBWidget
  21. {
  22. public:
  23. // For safe typecasting
  24. TBOBJECT_SUBCLASS(TBTabContainer, TBWidget);
  25. TBTabContainer();
  26. ~TBTabContainer();
  27. /** Set along which axis the content should layouted.
  28. Use SetAlignment instead for more choice! Also, calling
  29. SetAxis directly does not update the current alignment. */
  30. virtual void SetAxis(AXIS axis);
  31. virtual AXIS GetAxis() const { return m_root_layout.GetAxis(); }
  32. /** Set alignment of the tabs. */
  33. void SetAlignment(TB_ALIGN align);
  34. TB_ALIGN GetAlignment() const { return m_align; }
  35. /** Set which page should be selected and visible. */
  36. virtual void SetValue(int value);
  37. virtual int GetValue() { return m_current_page; }
  38. /** Set which page should be selected and visible. */
  39. void SetCurrentPage(int index) { SetValue(index); }
  40. int GetCurrentPage() { return GetValue(); }
  41. int GetNumPages();
  42. /** Return the widget that is the current page, or nullptr if none is active. */
  43. TBWidget *GetCurrentPageWidget() const;
  44. virtual void OnInflate(const INFLATE_INFO &info);
  45. virtual bool OnEvent(const TBWidgetEvent &ev);
  46. virtual void OnProcess();
  47. virtual TBWidget *GetContentRoot() { return &m_content_root; }
  48. TBLayout *GetTabLayout() { return &m_tab_layout; }
  49. protected:
  50. TBLayout m_root_layout;
  51. TBTabLayout m_tab_layout;
  52. TBWidget m_content_root;
  53. bool m_need_page_update;
  54. int m_current_page;
  55. TB_ALIGN m_align;
  56. };
  57. };
  58. #endif // TB_TAB_CONTAINER_H