8 #ifndef UI_RECT_COLLECTION_H
9 #define UI_RECT_COLLECTION_H
33 #ifndef UI_RECT_COLLECTION_MAX_LENGTH
34 #define UI_RECT_COLLECTION_MAX_LENGTH 8u
46 ui_rect_t data[UI_RECT_COLLECTION_MAX_LENGTH];
60 collection->length = 0;
69 UI_RECT_COLLECTION_clear(collection);
80 return collection->length;
91 return UI_RECT_COLLECTION_get_length(collection) >= UI_RECT_COLLECTION_MAX_LENGTH;
102 return collection->length == 0u;
113 return UI_RECT_COLLECTION_is_empty(collection) ? NULL : (collection->data + collection->length - 1u);
124 return collection->data + collection->length;
134 static inline void UI_RECT_COLLECTION_add_rect(
ui_rect_collection_t* collection,
const ui_rect_t element) {
135 assert(!UI_RECT_COLLECTION_is_full(collection));
136 collection->data[collection->length] = element;
137 collection->length++;
146 static inline void UI_RECT_COLLECTION_remove_rect(
ui_rect_collection_t* collection, ui_rect_t* element) {
147 assert(!UI_RECT_COLLECTION_is_empty(collection));
148 assert(element >= collection->data);
149 assert(element < (collection->data + collection->length));
150 *element = *UI_RECT_COLLECTION_get_last(collection);
151 collection->length--;
160 for (
size_t i = 0; i < collection->length;) {
161 if (UI_RECT_is_empty(&collection->data[i])) {
162 UI_RECT_COLLECTION_remove_rect(collection, &collection->data[i]);