Rose
Tab.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <utility>
11 
12 #include "Border.h"
13 #include "Button.h"
14 #include "Container.h"
15 #include "Frame.h"
16 #include "ScrollArea.h"
17 #include "Signals.h"
18 
19 namespace rose {
20 
25  class TabPage : public Border {
26  protected:
27  std::string mTabLabel{};
28 
29  public:
30  TabPage() = delete;
31  ~TabPage() override = default;
32  TabPage(TabPage &&) = delete;
33  TabPage(const TabPage &) = delete;
34  TabPage& operator=(TabPage &&) = delete;
35  TabPage& operator=(const TabPage &) = delete;
36 
38  explicit TabPage(std::string label) : Border(), mTabLabel(std::move(label)) {}
39 
41  explicit TabPage(std::string_view label) : TabPage(std::string(label)) {}
42 
44  explicit TabPage(const char *label) : TabPage(std::string(label)) {}
45 
50  const std::string& tabLabel() const noexcept { return mTabLabel; }
51  };
52 
57  class TabBody : public Container {
58  protected:
59 
67  template<class WidgetType>
68  std::shared_ptr<WidgetType> activeChild() {
69  for (auto &child : mChildren) {
70  if (child->mVisible)
71  return child->as<WidgetType>();
72  }
73  return nullptr;
74  }
75 
76  public:
77  TabBody() = default;
78  ~TabBody() override = default;
79  TabBody(TabBody &&) = delete;
80  TabBody(const TabBody &) = delete;
81  TabBody& operator=(TabBody &&) = delete;
82  TabBody& operator=(const TabBody &) = delete;
83 
87  void initializeComposite() override;
88 
92  void draw(sdl::Renderer &renderer, Rectangle parentRect) override;
93 
97  Rectangle widgetLayout(sdl::Renderer &renderer, Rectangle available, uint layoutStage) override;
98 
100  bool mouseButtonEvent(const Position &mousePos, int button, bool down, int modifiers) override;
101 
103  bool mouseMotionEvent(const Position &cursorPosition, const Position &rel, int button, int modifiers) override;
104 
106  bool mouseDragEvent(const Position &p, const Position &rel, int button, int modifiers) override;
107 
109  bool mouseEnterEvent(const Position &p, bool enter) override;
110 
112  bool scrollEvent(const Position &p, int32_t x, int32_t y) override;
113 
115  bool focusEvent(bool focused) override;
116 
117 // /// Handle a keyboard event (default implementation: do nothing)
118 // bool keyboardEvent(int key, int scancode, int action, int modifiers) override;
119 
121  bool keyboardCharacterEvent(unsigned int codepoint) override;
122 
128  std::shared_ptr<Widget> findWidget(const Position &pos) override;
129 
137  std::shared_ptr<Widget> findWidget(const Id &id) override;
138  };
139 
140  using TabHeader = Row;
141 
148  class Tab : public Column {
149  protected:
150  std::size_t mActiveTab{};
151  std::shared_ptr<TabHeader> mHdr{};
152  std::shared_ptr<Frame> mFrame{};
153  std::shared_ptr<Container> mBody{};
154 
155  std::shared_ptr<Slot<Button::SignalType>> rxState{};
156  std::shared_ptr<Slot<Button::SignalType>> rxPushed{};
157 
158  public:
159  Tab() = default;
160  ~Tab() override = default;
161 
165  void initializeComposite() override;
166 
170  void draw(sdl::Renderer &renderer, Rectangle parentRect) override;
171 
175  Rectangle widgetLayout(sdl::Renderer &renderer, Rectangle available, uint layoutStage) override;
176 
181  void addChild(const std::shared_ptr <Widget> &widget) override;
182 
188  void addTabButton(const string &label);
189 
194  void activeTab(size_t tabIdx);
195  };
196 }
197 
const std::string & tabLabel() const noexcept
Access the TabPage label.
Definition: Tab.h:50
TabPage(std::string_view label)
Constructor.
Definition: Tab.h:41
A container which holds the subordinate Node objects.
Definition: StructuredTypes.h:325
std::string mTabLabel
The identity of the TabPage, will be the TabButton Label.
Definition: Tab.h:27
A TabBody manages a number of TabPages.
Definition: Tab.h:57
A position in integer (x, y) co-ordinates.
Definition: Types.h:95
Definition: Manager.h:73
std::shared_ptr< WidgetType > activeChild()
Find the active TabPage.
Definition: Tab.h:68
A composite of a Position and a Size.
Definition: Types.h:307
A type to specify an Id value.
Definition: StructuredTypes.h:148
Written as a workaround for an issue in the SDL2 Library.
Definition: Renderer.h:64
TabPage(std::string label)
Constructor.
Definition: Tab.h:38
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
A TabPage manages a single Widget which displays the page contents.
Definition: Tab.h:25
TabPage(const char *label)
Constructor.
Definition: Tab.h:44
Definition: Manager.h:59
Establish an intra-application signaling protocol.
A Tab Widget.
Definition: Tab.h:148