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:
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;
34
35
43
53
59 void setTabVisibility(bool visible);
60
69 void setActiveTab(int index);
70
78 int getActiveTab() const;
79
86 void setTabClosable(int index, bool isClosable);
87
88
97 bool isTabClosable(int index);
98
99
106 void setTabAutoClose(int index, bool autoClose);
107
114 bool isTabAutoClose(int index);
115
116
127 int addTab(gGUISizer* sizer, std::string title, bool closable = true);
128
137 void closeTab(int index);
138
148
158 gGUISizer* getTabSizerByTitle(const std::string& title);
159
160private:
161 struct Box {
162 int ox = 0, oy = 0, x, y, w, h;
163
164 bool enabled = false;
165
166 bool isPointInside(int tx, int ty) {
167 if (!enabled) {
168 return false;
169 }
170 return tx >= ox + x && tx <= ox + x + w && ty >= oy + y && ty <= oy + y + h;
171 }
172
173 void flipXY() {
174 int t = x;
175 x = y,
176 y = t;
177
178 t = h;
179 h = w;
180 w = t;
181 }
182
183 Box rotate(TabPosition pos, int boxw, int boxh) const {
184 switch (pos) {
185 case TabPosition::TOP: {
186 return *this;
187 }
188 case TabPosition::LEFT: {
189 Box box = *this;
190 box.flipXY();
191 return box;
192 }
193 case TabPosition::RIGHT: {
194 Box box = *this;
195 box.flipXY();
196 box.x = boxw - box.w;
197 return box;
198 }
199 case TabPosition::BOTTOM: {
200 Box box = *this;
201 box.y = boxh - box.h;
202 return box;
203 }
204 default:
205 return *this;
206 }
207 }
208
209 void render() const {
210 gDrawRectangle(x + ox, y + oy, w, h);
211 }
212
213 };
214 struct Tab {
215 gGUISizer* sizer;
216 std::string title;
217 bool closable;
218 bool autoclose;
219
220 // text size of the title tab
221 int titlewidth;
222 int titleheight;
223
224 // total size of the title tab
225 int tabwidth;
226
227 Box tabbox;
228 Box closebox;
229
230 Tab(gGUISizer* sizer, std::string title, bool closable, int titlewidth, int titleheight)
231 : sizer(sizer), title(std::move(title)), closable(closable), autoclose(false),
232 titlewidth(titlewidth), titleheight(titleheight), tabwidth(0) {
233
234 }
235 };
236
237
238 void drawHeader();
239 void drawHeaderBackground();
240
241 void mousePressed(int x, int y, int button) override;
242 void mouseMoved(int x, int y) override;
243 void mouseScrolled(int x, int y) override;
244
245 void updateSizer();
246
247 Tab* getTab(int index);
248 int findIndexByTitle(const std::string& title);
249
250private:
251 std::vector<Tab> tabs;
252 int tabscroll;
253 int activetab;
254 int headerheight;
255
256 int titlepadding;
257 int tabgap; // gap between each tab
258 int scrollbuttonwidth;
259 int closebuttonsize;
260
261 int lastmousex = 0;
262 int lastmousey = 0;
263
264 bool tabvisibility;
265 Box scrollpreviousbutton;
266 Box scrollnextbutton;
267 Box headerbox;
268 Box notebookbox;
269
270 TabPosition tabposition;
271 gGUISizer notebooksizer;
272 gFont* titlefont;
273 gFbo fbo;
274};
275
276#endif /* UI_GGUINOTEBOOK_H_ */
Definition gBaseApp.h:16
Definition gBaseGUIObject.h:18
gBaseApp * root
Definition gBaseGUIObject.h:151
static gFont * font
Definition gBaseGUIObject.h:137
std::string title
Definition gBaseGUIObject.h:149
Definition gFont.h:47
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 setFont(gFont *font)
void draw() override
TabPosition
Definition gGUINotebook.h:20
@ BOTTOM
Definition gGUINotebook.h:22
@ RIGHT
Definition gGUINotebook.h:24
@ TOP
Definition gGUINotebook.h:21
@ LEFT
Definition gGUINotebook.h:23
void setTabPosition(TabPosition position)
Sets the position of the tab bar.
void setTabVisibility(bool visible)
int boxh
Definition gGUIScrollable.h:159
int boxw
Definition gGUIScrollable.h:159
Definition gGUISizer.h:15
void gDrawRectangle(float x, float y, float w, float h, bool isFilled=false, float rotateAngle=0.0f, float pivotx=0.5f, float pivoty=0.5f)