GlistEngine
Loading...
Searching...
No Matches
gGUINotebook.h
Go to the documentation of this file.
1/*
2 * gGUINotebook.h
3 *
4 * Created on: 30 Apr 2024
5 * Author: Metehan Gezer
6 */
7
8#ifndef UI_GGUINOTEBOOK_H_
9#define UI_GGUINOTEBOOK_H_
10
11#include "gGUIContainer.h"
12#include "gGUIPanel.h"
13#include "gRenderer.h"
14#include "gFont.h"
15#include <deque>
16#include <utility>
17
19public:
20 enum class TabPosition {
21 TOP,
22 BOTTOM,
23 LEFT,
24 RIGHT
25 };
26
28 virtual ~gGUINotebook();
29
30 void set(gBaseApp* root, gBaseGUIObject* topParentGUIObject, gBaseGUIObject* parentGUIObject, int parentSlotLineNo, int parentSlotColumnNo, int x, int y, int w, int h) override;
31
32 void draw() override;
33
34
42
52
58 void setTabVisibility(bool visible);
59
68 void setActiveTab(int index);
69
77 int getActiveTab() const;
78
85 void setTabClosable(int index, bool isClosable);
86
87
96 bool isTabClosable(int index);
97
98
105 void setTabAutoClose(int index, bool autoClose);
106
113 bool isTabAutoClose(int index);
114
115
126 int addTab(gGUISizer* sizer, std::string title, bool closable = true);
127
136 void closeTab(int index);
137
147
157 gGUISizer* getTabSizerByTitle(const std::string& title);
158
159private:
160 struct Box {
161 int ox = 0, oy = 0, x, y, w, h;
162
163 bool enabled = false;
164
165 bool isPointInside(int tx, int ty) {
166 if (!enabled) {
167 return false;
168 }
169 return tx >= ox + x && tx <= ox + x + w && ty >= oy + y && ty <= oy + y + h;
170 }
171
172 void flipXY() {
173 int t = x;
174 x = y,
175 y = t;
176
177 t = h;
178 h = w;
179 w = t;
180 }
181
182 Box rotate(TabPosition pos, int boxw, int boxh) const {
183 switch (pos) {
184 case TabPosition::TOP: {
185 return *this;
186 }
187 case TabPosition::LEFT: {
188 Box box = *this;
189 box.flipXY();
190 return box;
191 }
192 case TabPosition::RIGHT: {
193 Box box = *this;
194 box.flipXY();
195 box.x = boxw - box.w;
196 return box;
197 }
198 case TabPosition::BOTTOM: {
199 Box box = *this;
200 box.y = boxh - box.h;
201 return box;
202 }
203 default:
204 return *this;
205 }
206 }
207
208 void render() const {
209 gDrawRectangle(x + ox, y + oy, w, h);
210 }
211
212 };
213 struct Tab {
214 gGUISizer* sizer;
215 std::string title;
216 bool closable;
217 bool autoclose;
218
219 // text size of the title tab
220 int titlewidth;
221 int titleheight;
222
223 // total size of the title tab
224 int tabwidth;
225
226 Box tabbox;
227 Box closebox;
228
229 Tab(gGUISizer* sizer, std::string title, bool closable, int titlewidth, int titleheight)
230 : sizer(sizer), title(std::move(title)), closable(closable), autoclose(false),
231 titlewidth(titlewidth), titleheight(titleheight), tabwidth(0) {
232
233 }
234 };
235
236
237 void drawHeader();
238 void drawHeaderBackground();
239
240 void mousePressed(int x, int y, int button) override;
241 void mouseMoved(int x, int y) override;
242 void mouseScrolled(int x, int y) override;
243
244 void updateSizer();
245
246 Tab* getTab(int index);
247 int findIndexByTitle(const std::string& title);
248
249private:
250 std::vector<Tab> tabs;
251 int tabscroll;
252 int activetab;
253 int headerheight;
254
255 int titlepadding;
256 int tabgap; // gap between each tab
257 int scrollbuttonwidth;
258 int closebuttonsize;
259
260 int lastmousex = 0;
261 int lastmousey = 0;
262
263 bool tabvisibility;
264 Box scrollpreviousbutton;
265 Box scrollnextbutton;
266 Box headerbox;
267 Box notebookbox;
268
269 TabPosition tabposition;
270 gGUISizer notebooksizer;
271 gFont* titlefont;
272 gFbo fbo;
273};
274
275#endif /* UI_GGUINOTEBOOK_H_ */
Definition gBaseApp.h:16
Definition gBaseGUIObject.h:18
gBaseApp * root
Definition gBaseGUIObject.h:147
std::string title
Definition gBaseGUIObject.h:145
Definition gFbo.h:15
Definition gFont.h:47
Definition gGUIContainer.h:15
Definition gGUINotebook.h:18
gGUISizer * getTabSizer(int index)
Gets the tab sizer of the tab at the given index.
void set(gBaseApp *root, gBaseGUIObject *topParentGUIObject, gBaseGUIObject *parentGUIObject, int parentSlotLineNo, int parentSlotColumnNo, int x, int y, int w, int h) override
int addTab(gGUISizer *sizer, std::string title, bool closable=true)
Add a tab to a GUI sizer.
void setActiveTab(int index)
Sets the active tab of the notebook.
gGUISizer * getTabSizerByTitle(const std::string &title)
Gets the tab sizer by its title.
TabPosition getTabPosition() const
Get the current tab position.
int getActiveTab() const
Gets the index of the active tab.
void closeTab(int index)
Closes the tab at the specified index.
virtual ~gGUINotebook()
bool isTabAutoClose(int index)
Returns if a tab is set to automatically close when switched out of it.
bool isTabClosable(int index)
Returns if a tab is closable or not.
void setTabAutoClose(int index, bool autoClose)
Sets whether a tab is automatically closed when switched out of it.
void setTabClosable(int index, bool isClosable)
Sets whether a tab is closable or not.
void draw() override
TabPosition
Definition gGUINotebook.h:20
void setTabPosition(TabPosition position)
Sets the position of the tab bar.
void setTabVisibility(bool visible)
int boxh
Definition gGUIScrollable.h:155
int boxw
Definition gGUIScrollable.h:155
Definition gGUISizer.h:14
void gDrawRectangle(float x, float y, float w, float h, bool isFilled=false)
Definition gUUID.h:56