ElementTabSet.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUICONTROLSELEMENTTABSET_H
  29. #define RMLUICONTROLSELEMENTTABSET_H
  30. #include "../Core/Element.h"
  31. #include "../Core/EventListener.h"
  32. #include "Header.h"
  33. namespace Rml {
  34. namespace Controls {
  35. /**
  36. A tabulated set of panels.
  37. @author Lloyd Weehuizen
  38. */
  39. class RMLUICONTROLS_API ElementTabSet : public Core::Element, public Core::EventListener
  40. {
  41. public:
  42. ElementTabSet(const Rml::Core::String& tag);
  43. ~ElementTabSet();
  44. /// Sets the specifed tab index's tab title RML.
  45. /// @param[in] tab_index The tab index to set. If it doesn't already exist, it will be created.
  46. /// @param[in] rml The RML to set on the tab title.
  47. void SetTab(int tab_index, const Rml::Core::String& rml);
  48. /// Sets the specifed tab index's tab panel RML.
  49. /// @param[in] tab_index The tab index to set. If it doesn't already exist, it will be created.
  50. /// @param[in] rml The RML to set on the tab panel.
  51. void SetPanel(int tab_index, const Rml::Core::String& rml);
  52. /// Set the specifed tab index's title element.
  53. /// @param[in] tab_index The tab index to set. If it doesn't already exist, it will be created.
  54. /// @param[in] element The root of the element tree to set as the tab title.
  55. void SetTab(int tab_index, Core::Element* element);
  56. /// Set the specified tab index's body element.
  57. /// @param[in] tab_index The tab index to set. If it doesn't already exist, it will be created.
  58. /// @param[in] element The root of the element tree to set as the window.
  59. void SetPanel(int tab_index, Core::Element* element);
  60. /// Remove one of the tab set's panels and its corresponding tab.
  61. /// @param[in] tab_index The tab index to remove. If no tab matches this index, nothing will be removed.
  62. void RemoveTab(int tab_index);
  63. /// Retrieve the number of tabs in the tabset.
  64. /// @return The number of tabs.
  65. int GetNumTabs();
  66. /// Sets the currently active (visible) tab index.
  67. /// @param[in] tab_index Index of the tab to display.
  68. void SetActiveTab(int tab_index);
  69. /// Get the current active tab index.
  70. /// @return The index of the active tab.
  71. int GetActiveTab() const;
  72. /// Process the incoming event.
  73. void ProcessEvent(Core::Event& event);
  74. /// Called when the listener has been attached to a new Element
  75. void OnAttach(Element* element);
  76. /// Called when the listener has been detached from a Element
  77. void OnDetach(Element* element);
  78. protected:
  79. // Catch child add/removes so we can correctly set up their events.
  80. virtual void OnChildAdd(Core::Element* child);
  81. virtual void OnChildRemove(Core::Element* child);
  82. private:
  83. Core::Element* GetChildByTag(const Rml::Core::String& tag);
  84. int active_tab;
  85. };
  86. }
  87. }
  88. #endif