GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_widget_tabs.h
Go to the documentation of this file.
1//SPDX-License-Identifier: LGPL-2.0-or-later
2
3/*
4
5 Copyright (c) 2014-2024 Cyril Hrubis <metan@ucw.cz>
6
7 */
8
23#ifndef GP_WIDGET_TABS_H
24#define GP_WIDGET_TABS_H
25
26struct gp_widget_tab {
27 char *label;
28 gp_widget *widget;
29};
30
31struct gp_widget_tabs {
32 unsigned int active_tab;
33
34 int title_focused:1;
35 int widget_focused:1;
36
37 struct gp_widget_tab *tabs;
38
39 char payload[];
40};
41
49
60gp_widget *gp_widget_tabs_new(unsigned int tabs_cnt, unsigned int active_tab,
61 const char *tab_labels[], int flags);
62
70unsigned int gp_widget_tabs_cnt(gp_widget *self);
71
81gp_widget *gp_widget_tabs_put(gp_widget *self, unsigned int tab,
82 gp_widget *child);
83
92static inline gp_widget *gp_widget_tabs_rem(gp_widget *self, unsigned int tab)
93{
94 return gp_widget_tabs_put(self, tab, NULL);
95}
96
106
107static inline void gp_widget_tabs_del(gp_widget *self, unsigned int tab)
108{
109 gp_widget *ret = gp_widget_tabs_rem(self, tab);
110
111 gp_widget_free(ret);
112}
113
122void gp_widget_tabs_tab_ins(gp_widget *self, unsigned int tab,
123 const char *label, gp_widget *child);
124
135 const char *label, gp_widget *child);
136
144static inline void gp_widget_tabs_tab_prepend(gp_widget *self,
145 const char *label,
146 gp_widget *child)
147{
148 return gp_widget_tabs_tab_ins(self, 0, label, child);
149}
150
160
170
182{
183 if (!gp_widget_tabs_tab_rem_by_child(self, child))
184 return 1;
185
186 gp_widget_free(child);
187
188 return 0;
189}
190
199static inline void gp_widget_tabs_tab_del(gp_widget *self, unsigned int tab)
200{
201 gp_widget *ret = gp_widget_tabs_tab_rem(self, tab);
202
203 gp_widget_free(ret);
204}
205
214
223
230void gp_widget_tabs_active_set(gp_widget *self, unsigned int tab);
231
239void gp_widget_tabs_active_set_rel(gp_widget *self, int dir, int wrap_around);
240
250
259const char *gp_widget_tabs_label_get(gp_widget *self, unsigned int tab);
260
269
270#endif /* GP_WIDGET_TABS_H */
void gp_widget_free(gp_widget *self)
Frees widget memory.
static int gp_widget_tabs_tab_del_by_child(gp_widget *self, gp_widget *child)
Delete a tab identified by a child widget.
gp_widget * gp_widget_tabs_child_get(gp_widget *self, unsigned int tab)
Returns a pointer to a child in a tab.
gp_widget * gp_widget_tabs_new(unsigned int tabs_cnt, unsigned int active_tab, const char *tab_labels[], int flags)
Allocates and initializes a new tabs widget.
static void gp_widget_tabs_tab_prepend(gp_widget *self, const char *label, gp_widget *child)
Appends a tab at the begining.
int gp_widget_tabs_tab_rem_by_child(gp_widget *self, gp_widget *child)
Remove a tab identified by a child widget.
unsigned int gp_widget_tabs_tab_append(gp_widget *self, const char *label, gp_widget *child)
Appends a tab at the end.
gp_widget_tabs_event_type
A gp_widget_event::sub_type for a tabs widget.
@ GP_WIDGET_TABS_ACTIVATED
A tab activated.
@ GP_WIDGET_TABS_DEACTIVATED
A tab is deactivated.
void gp_widget_tabs_active_set_rel(gp_widget *self, int dir, int wrap_around)
Set active tab position relative to the currently active tab.
int gp_widget_tabs_tab_by_child(gp_widget *self, gp_widget *child)
Returns tab idx by child pointer.
unsigned int gp_widget_tabs_active_get(gp_widget *self)
Returns active tab index.
gp_widget * gp_widget_tabs_active_child_get(gp_widget *self)
Returns active tab child widget.
const char * gp_widget_tabs_label_get(gp_widget *self, unsigned int tab)
Returns a tab label.
gp_widget * gp_widget_tabs_tab_rem(gp_widget *self, unsigned int tab)
Remove a tab at position.
unsigned int gp_widget_tabs_cnt(gp_widget *self)
Returns number of tabs.
void gp_widget_tabs_tab_ins(gp_widget *self, unsigned int tab, const char *label, gp_widget *child)
Adds a tab at an offset.
gp_widget * gp_widget_tabs_put(gp_widget *self, unsigned int tab, gp_widget *child)
Puts a child into a tab.
void gp_widget_tabs_active_set(gp_widget *self, unsigned int tab)
Set active tab.
static void gp_widget_tabs_tab_del(gp_widget *self, unsigned int tab)
Delete a tab at position.
static gp_widget * gp_widget_tabs_rem(gp_widget *self, unsigned int tab)
Removes child from a tab and returns pointer to it.
const char * gp_widget_tabs_active_label_get(gp_widget *self)
Returns active tab label.
A widget base.
Definition gp_widget.h:28