#include "info_card.h" #include "info_card_private.h" #define MY_CLASS (&lv_info_card_class) static void lv_info_card_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj); static void lv_info_card_event(const lv_obj_class_t* class_p, lv_event_t* e); const lv_obj_class_t lv_info_card_class = { .constructor_cb = lv_info_card_constructor, .event_cb = lv_info_card_event, .width_def = LV_SIZE_CONTENT, .height_def = LV_SIZE_CONTENT, .instance_size = sizeof(lv_info_card_t), .base_class = &lv_obj_class, .name = "lv_info_card", LV_PROPERTY_CLASS_FIELDS(info_card, INFO_CARD) }; static void lv_info_card_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj) { LV_UNUSED(class_p); LV_TRACE_OBJ_CREATE("begin"); lv_info_card_t* card = (lv_info_card_t*)obj; LV_TRACE_OBJ_CREATE("finished"); } static void lv_info_card_event(const lv_obj_class_t* class_p, lv_event_t* e) { LV_UNUSED(class_p); lv_result_t res; res = lv_obj_event_base(MY_CLASS, e); if (res != LV_RESULT_OK) return; } lv_obj_t* lv_info_card_create(lv_obj_t* parent, lv_image_dsc_t* icon) { LV_LOG_INFO("begin"); uint32_t bg_color = 0x040507; lv_obj_t* obj = lv_obj_class_create_obj(MY_CLASS, parent); lv_obj_class_init_obj(obj); lv_obj_set_layout(obj, LV_LAYOUT_FLEX); lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW); lv_obj_set_size(obj, lv_pct(100), LV_SIZE_CONTENT); lv_obj_set_flex_align( obj, LV_FLEX_ALIGN_START, // 主轴(水平) LV_FLEX_ALIGN_CENTER, // 交叉轴(垂直) LV_FLEX_ALIGN_CENTER // track ); lv_obj_set_style_bg_color(obj, lv_color_hex(bg_color), 0); lv_info_card_t* self = (lv_info_card_t*)obj; lv_obj_set_style_border_color(obj, lv_color_hex(0x191B1D), 0); lv_obj_set_style_border_width(obj, 1, 0); lv_obj_set_style_radius(obj, 8, 0); lv_obj_set_style_pad_all(obj, 2, 0); self->icon = lv_image_create(obj); lv_image_set_src(self->icon, icon); lv_obj_t* right_panel = lv_obj_create(obj); lv_obj_set_style_bg_color(right_panel, lv_color_hex(bg_color), 0); lv_obj_set_style_pad_all(right_panel, 4, 0); lv_obj_set_layout(right_panel, LV_LAYOUT_FLEX); lv_obj_set_flex_flow(right_panel, LV_FLEX_FLOW_COLUMN); lv_obj_set_size(right_panel, LV_SIZE_CONTENT, LV_SIZE_CONTENT); lv_obj_set_flex_grow(right_panel, 1); self->title = lv_label_create(right_panel); lv_label_set_text(self->title, "title"); lv_obj_set_size(self->title, lv_pct(100), LV_SIZE_CONTENT); lv_obj_set_style_bg_color(self->title, lv_color_hex(bg_color), 0); lv_obj_set_style_text_color(self->title, lv_color_hex(0x6b6b6b), 0); self->content = lv_label_create(right_panel); lv_label_set_text(self->content, "content"); lv_obj_set_size(self->content, lv_pct(100), LV_SIZE_CONTENT); LV_FONT_DECLARE(lv_font_din_26); lv_obj_set_style_text_font(self->content, &lv_font_din_26, 0); lv_obj_set_style_bg_color(self->content, lv_color_hex(bg_color), 0); lv_obj_set_style_text_color(self->content, lv_color_white(), 0); self->footer = lv_label_create(right_panel); lv_label_set_text(self->footer, "footer"); lv_obj_set_size(self->footer, lv_pct(100), LV_SIZE_CONTENT); lv_obj_set_style_bg_color(self->footer, lv_color_hex(bg_color), 0); lv_obj_set_style_text_color(self->footer, lv_color_hex(0x6b6b6b), 0); return obj; } void lv_info_card_set_title(lv_obj_t* obj, const char* title) { lv_info_card_t* self = (lv_info_card_t*)obj; lv_label_set_text(self->title, title); } void lv_info_card_set_content(lv_obj_t* obj, const char* content) { lv_info_card_t* self = (lv_info_card_t*)obj; lv_label_set_text(self->content, content); } void lv_info_card_set_footer(lv_obj_t* obj, const char* footer) { lv_info_card_t* self = (lv_info_card_t*)obj; lv_label_set_text(self->footer, footer); }