Constructs an identifiable object from a list of components, in a declarative fashion.
Constructs an identifiable object from a list of components, in a declarative fashion.
LCD_ObjID id; LCD_Error err = LCD_OBJECT(&id, { LCD_RECT(pos_rect, { .width = 10, .height = 10, .fill_color = LCD_COL_RED, }), LCD_TEXT(pos_text, { .text = "Hello, World!", .font = LCD_DEF_FONT_SYSTEM, .text_color = LCD_COL_BLUE, }), });
#ifndef __GLCD_MACROS_H
#define __GLCD_MACROS_H
#include <stdlib.h>
#include <string.h>
#define LCD_OBJECT_DEFINE(...) \
(LCD_Obj) \
{ \
.comps = (LCD_Component[]){__VA_ARGS__}, \
.comps_size = sizeof((LCD_Component[]){__VA_ARGS__}) / sizeof(LCD_Component) \
}
#define LCD_OBJECT(id, ...) \
LCD_RMAdd(&((LCD_Obj){.comps = (LCD_Component[])__VA_ARGS__, \
.comps_size = sizeof((LCD_Component[])__VA_ARGS__) / sizeof(LCD_Component)}), \
id, 0);
#define LCD_INVISIBLE_OBJECT(id, ...) \
LCD_RMAdd(&((LCD_Obj){.comps = (LCD_Component[])__VA_ARGS__, \
.comps_size = sizeof((LCD_Component[])__VA_ARGS__) / sizeof(LCD_Component)}), \
id, LCD_ADD_OBJ_OPT_DONT_MARK_VISIBLE);
#define LCD_OBJECT_UPDATE_COMMANDS(id, redraw_underneath, ...) \
({ \
LCD_Error __err = LCD_RMSetVisibility(id, false, redraw_underneath); \
if (__err == LCD_ERR_OK) \
{ \
__VA_ARGS__ \
__err = LCD_RMSetVisibility(id, true, false); \
} \
__err; \
})
#define LCD_RENDER_TMP(...) \
LCD_RMRenderTemporary(&(LCD_Obj){.comps = (LCD_Component[])__VA_ARGS__, \
.comps_size = sizeof((LCD_Component[])__VA_ARGS__) / sizeof(LCD_Component)})
#define LCD_LINE(...) \
(LCD_Component) \
{ \
.type = LCD_COMP_LINE, .object.line = (LCD_Line *)&((LCD_Line)__VA_ARGS__) \
}
#define LCD_RECT(coords, ...) \
(LCD_Component) \
{ \
.type = LCD_COMP_RECT, .pos = coords, .object.rect = (LCD_Rect *)&((LCD_Rect)__VA_ARGS__) \
}
#define LCD_RECT2(x, y, ...) \
(LCD_Component) \
{ \
.type = LCD_COMP_RECT, .pos = (LCD_Coordinate){x, y}, .object.rect = (LCD_Rect *)&((LCD_Rect)__VA_ARGS__) \
}
#define LCD_CIRCLE(...) \
(LCD_Component) \
{ \
.type = LCD_COMP_CIRCLE, .object.circle = (LCD_Circle *)&((LCD_Circle)__VA_ARGS__) \
}
#define LCD_IMAGE(coords, img) \
(LCD_Component) \
{ \
.type = LCD_COMP_IMAGE, .pos = coords, .object.image = (LCD_Image *)&(img) \
}
#define LCD_IMAGE2(x, y, img) \
(LCD_Component) \
{ \
.type = LCD_COMP_IMAGE, .pos = (LCD_Coordinate){x, y}, .object.image = (LCD_Image *)&(img) \
}
#define LCD_TEXT(coords, ...) \
(LCD_Component) \
{ \
.type = LCD_COMP_TEXT, .pos = coords, .object.text = (LCD_Text *)&((LCD_Text)__VA_ARGS__) \
}
#define LCD_TEXT2(x, y, ...) \
(LCD_Component) \
{ \
.type = LCD_COMP_TEXT, .pos = (LCD_Coordinate){x, y}, .object.text = (LCD_Text *)&((LCD_Text)__VA_ARGS__) \
}
#define LCD_BUTTON_LABEL(...) (LCD_ButtonLabel) __VA_ARGS__
#define LCD_BUTTON2(x, y, out_button_area, ...) \
((out_button_area = TP_AssignButtonArea((LCD_Button)__VA_ARGS__, (LCD_Coordinate){x, y})), \
(LCD_Component){ \
.type = LCD_COMP_BUTTON, \
.pos = (LCD_Coordinate){x, y}, \
.object.button = (LCD_Button *)&((LCD_Button)__VA_ARGS__), \
})
#define LCD_BUTTON(coords, out_button_area, ...) \
((out_button_area = TP_AssignButtonArea((LCD_Button)__VA_ARGS__, coords)), \
(LCD_Component){ \
.type = LCD_COMP_BUTTON, \
.pos = coords, \
.object.button = (LCD_Button *)&((LCD_Button)__VA_ARGS__), \
})
#endif