EasyGUI
gui_linkedlist.h
1 
6 /*
7  * Copyright (c) 2019 Tilen MAJERLE
8  *
9  * Permission is hereby granted, free of charge, to any person
10  * obtaining a copy of this software and associated documentation
11  * files (the "Software"), to deal in the Software without restriction,
12  * including without limitation the rights to use, copy, modify, merge,
13  * publish, distribute, sublicense, and/or sell copies of the Software,
14  * and to permit persons to whom the Software is furnished to do so,
15  * subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
23  * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  *
29  * This file is part of EasyGUI library.
30  *
31  * Author: Tilen Majerle <tilen@majerle.eu>
32  */
33 #ifndef GUI_HDR_LINKEDLIST_H
34 #define GUI_HDR_LINKEDLIST_H
35 
36 /* C++ detection */
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #include "gui/gui_utils.h"
42 
50 #if defined(GUI_INTERNAL) || __DOXYGEN__
51 
59 #define gui_linkedlist_multi_getdata(e) (((e) != NULL) ? (e)->element : NULL)
60 
61 void gui_linkedlist_add_gen(gui_linkedlistroot_t* const root, gui_linkedlist_t* const element);
66 uint8_t gui_linkedlist_movedown_gen(gui_linkedlistroot_t* const root, gui_linkedlist_t* const element);
67 uint8_t gui_linkedlist_moveup_gen(gui_linkedlistroot_t* const root, gui_linkedlist_t* const element);
74 uint8_t gui_linkedlist_multi_find_remove(gui_linkedlistroot_t* const root, void* const element);
75 
82 #define gui_linkedlist_hasentries(root) ((root)->first != NULL)
83 
101 #define gui_linkedlist_iswidgetfirst(h) ((h) == NULL || (h)->list.prev == NULL)
102 
110 #define gui_linkedlist_iswidgetlast(h) ((h) == NULL || (h)->list.next == NULL)
111 
112 void gui_linkedlist_widgetadd(gui_handle_p parent, gui_handle_p h);
113 void gui_linkedlist_widgetremove(gui_handle_p h);
114 uint8_t gui_linkedlist_widgetmoveup(gui_handle_p h);
115 uint8_t gui_linkedlist_widgetmovedown(gui_handle_p h);
116 gui_handle_p gui_linkedlist_widgetgetnext(gui_handle_p parent, gui_handle_p h);
117 gui_handle_p gui_linkedlist_widgetgetprev(gui_handle_p parent, gui_handle_p h);
118 uint8_t gui_linkedlist_widgetmovetobottom(gui_handle_p h);
119 uint8_t gui_linkedlist_widgetmovetotop(gui_handle_p h);
120 
121 #define GUI_LINKEDLIST_WIDGETSLISTNEXT(parent, current) for ((current) = gui_linkedlist_widgetgetnext((parent), NULL); (current) != NULL; (current) = gui_linkedlist_widgetgetnext(NULL, (current)))
122 #define GUI_LINKEDLIST_WIDGETSLISTPREV(parent, current) for ((current) = gui_linkedlist_widgetgetprev((parent), NULL); (current) != NULL; (current) = gui_linkedlist_widgetgetprev(NULL, (current)))
123 
128 void gui_linkedlist_printlist(void);
129 
130 #endif /* GUI_INTERNAL || __DOXYGEN__ */
131 
136 /* C++ detection */
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 #endif /* GUI_HDR_LINKEDLIST_H */
gui_linkedlist_t * gui_linkedlist_getnext_byindex_gen(gui_linkedlistroot_t *const root, uint16_t index)
Get item from linked list by index.
Definition: gui_linkedlist.c:288
void gui_linkedlist_widgetadd(gui_handle_p parent, gui_handle_p h)
Add new widget to linked list of parent widget.
Definition: gui_linkedlist.c:456
Linked list root structure for start and end widget in structure.
Definition: gui_defs.h:196
uint8_t gui_linkedlist_widgetmoveup(gui_handle_p h)
Move widget up for one in linked list.
Definition: gui_linkedlist.c:489
uint8_t gui_linkedlist_multi_moveup_gen(gui_linkedlistroot_t *const root, gui_linkedlistmulti_t *const element)
Move widget up for one on multi linked list.
Definition: gui_linkedlist.c:417
uint8_t gui_linkedlist_movedown_gen(gui_linkedlistroot_t *const root, gui_linkedlist_t *const element)
Move widget down for one on doubly linked list.
Definition: gui_linkedlist.c:195
void gui_linkedlist_add_gen(gui_linkedlistroot_t *const root, gui_linkedlist_t *const element)
Add element to doubly linked list.
Definition: gui_linkedlist.c:80
gui_linkedlistmulti_t * gui_linkedlist_multi_getnext_gen(gui_linkedlistroot_t *const root, gui_linkedlistmulti_t *const element)
Get next element structure from multi linked list.
Definition: gui_linkedlist.c:355
uint8_t gui_linkedlist_widgetmovetotop(gui_handle_p h)
Move widget to top in linked list of parent widget.
Definition: gui_linkedlist.c:641
gui_linkedlistmulti_t * gui_linkedlist_multi_getprev_gen(gui_linkedlistroot_t *const root, gui_linkedlistmulti_t *const element)
Get previous element structure from multi linked list.
Definition: gui_linkedlist.c:384
uint8_t gui_linkedlist_multi_find_remove(gui_linkedlistroot_t *const root, void *const element)
Remove element from linked list in multi linked list.
Definition: gui_linkedlist.c:432
gui_linkedlist_t * gui_linkedlist_getnext_gen(gui_linkedlistroot_t *const root, gui_linkedlist_t *const element)
Get next element structure from doubly linked list.
Definition: gui_linkedlist.c:146
uint8_t gui_linkedlist_widgetmovedown(gui_handle_p h)
Move widget down for one in linked list.
Definition: gui_linkedlist.c:504
void gui_linkedlist_widgetremove(gui_handle_p h)
Remove widget from linked list of parent widget.
Definition: gui_linkedlist.c:473
gui_linkedlist_t * gui_linkedlist_remove_gen(gui_linkedlistroot_t *const root, gui_linkedlist_t *const element)
Remove element from doubly linked list.
Definition: gui_linkedlist.c:100
Linked list structure.
Definition: gui_defs.h:177
uint8_t gui_linkedlist_multi_movedown_gen(gui_linkedlistroot_t *const root, gui_linkedlistmulti_t *const element)
Move widget down for one on multi linked list.
Definition: gui_linkedlist.c:404
gui_linkedlist_t * gui_linkedlist_getprev_gen(gui_linkedlistroot_t *const root, gui_linkedlist_t *const element)
Get previous element structure from doubly linked list.
Definition: gui_linkedlist.c:175
gui_handle_p gui_linkedlist_widgetgetnext(gui_handle_p parent, gui_handle_p h)
Get next widget from current widget handle.
Definition: gui_linkedlist.c:532
Structure used for dynamic struct allocation.
Definition: gui_defs.h:186
uint8_t gui_linkedlist_widgetmovetobottom(gui_handle_p h)
Move widget to bottom in linked list of parent widget.
Definition: gui_linkedlist.c:591
gui_linkedlistmulti_t * gui_linkedlist_multi_add_gen(gui_linkedlistroot_t *const root, void *const element)
Add element to multi linked list.
Definition: gui_linkedlist.c:307
uint8_t gui_linkedlist_moveup_gen(gui_linkedlistroot_t *const root, gui_linkedlist_t *const element)
Move widget up for one on doubly linked list.
Definition: gui_linkedlist.c:242
uint8_t gui_linkedlist_multi_remove_gen(gui_linkedlistroot_t *const root, gui_linkedlistmulti_t *element)
Remove element from linked list in multi linked list.
Definition: gui_linkedlist.c:328
gui_handle_p gui_linkedlist_widgetgetprev(gui_handle_p parent, gui_handle_p h)
Get previous widget from current widget handle.
Definition: gui_linkedlist.c:564
void gui_linkedlist_printlist(void)
Prints widget structure from root tree.
Definition: gui_linkedlist.c:687