GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_widget_tabs.h
1//SPDX-License-Identifier: LGPL-2.0-or-later
2
3/*
4
5 Copyright (c) 2014-2021 Cyril Hrubis <metan@ucw.cz>
6
7 */
8
9#ifndef GP_WIDGET_TABS_H
10#define GP_WIDGET_TABS_H
11
12struct gp_widget_tab {
13 char *label;
14 gp_widget *widget;
15};
16
17struct gp_widget_tabs {
18 unsigned int active_tab;
19
20 int title_focused:1;
21 int widget_focused:1;
22
23 struct gp_widget_tab *tabs;
24
25 char payload[];
26};
27
28enum gp_widget_tabs_event_type {
29 GP_WIDGET_TABS_DEACTIVATED, /* A tab is deactivated */
30 GP_WIDGET_TABS_ACTIVATED, /* A tab activated */
31};
32
42gp_widget *gp_widget_tabs_new(unsigned int tabs_cnt, unsigned int active_tab,
43 const char *tab_labels[], int flags);
44
52unsigned int gp_widget_tabs_cnt(gp_widget *self);
53
63gp_widget *gp_widget_tabs_put(gp_widget *self, unsigned int tab,
64 gp_widget *child);
65
74static inline gp_widget *gp_widget_tabs_rem(gp_widget *self, unsigned int tab)
75{
76 return gp_widget_tabs_put(self, tab, NULL);
77}
78
87gp_widget *gp_widget_tabs_child_get(gp_widget *self, unsigned int tab);
88
89static inline void gp_widget_tabs_del(gp_widget *self, unsigned int tab)
90{
91 gp_widget *ret = gp_widget_tabs_rem(self, tab);
92
93 gp_widget_free(ret);
94}
95
104void gp_widget_tabs_tab_ins(gp_widget *self, unsigned int tab,
105 const char *label, gp_widget *child);
106
116unsigned int gp_widget_tabs_tab_append(gp_widget *self,
117 const char *label, gp_widget *child);
118
126static inline void gp_widget_tabs_tab_prepend(gp_widget *self,
127 const char *label,
128 gp_widget *child)
129{
130 return gp_widget_tabs_tab_ins(self, 0, label, child);
131}
132
141gp_widget *gp_widget_tabs_tab_rem(gp_widget *self, unsigned int tab);
142
151int gp_widget_tabs_tab_rem_by_child(gp_widget *self, gp_widget *child);
152
163static inline int gp_widget_tabs_tab_del_by_child(gp_widget *self, gp_widget *child)
164{
165 if (!gp_widget_tabs_tab_rem_by_child(self, child))
166 return 1;
167
168 gp_widget_free(child);
169
170 return 0;
171}
172
181static inline void gp_widget_tabs_tab_del(gp_widget *self, unsigned int tab)
182{
183 gp_widget *ret = gp_widget_tabs_tab_rem(self, tab);
184
185 gp_widget_free(ret);
186}
187
195unsigned int gp_widget_tabs_active_get(gp_widget *self);
196
204gp_widget *gp_widget_tabs_active_child_get(gp_widget *self);
205
212void gp_widget_tabs_active_set(gp_widget *self, unsigned int tab);
213
221void gp_widget_tabs_active_set_rel(gp_widget *self, int dir, int wrap_around);
222
231int gp_widget_tabs_tab_by_child(gp_widget *self, gp_widget *child);
232
241const char *gp_widget_tabs_label_get(gp_widget *self, unsigned int tab);
242
250const char *gp_widget_tabs_active_label_get(gp_widget *self);
251
252#endif /* GP_WIDGET_TABS_H */