LVGL(一) 创建对象
创建一个对象
#include "lvpage_setting.h"
#include "lvgl.h"
#include "esp_log.h"
static char *TAG = "lvpage_setting";
static void settings_event_handler(lv_event_t *e) {
if (e->code == LV_EVENT_CLICKED) {
ESP_LOGI(TAG, "[SETTINGS] Icon clicked!\r\n"); // 打印LOG
}
}
lv_obj_t *lv_example_settings_page(lv_obj_t *scr) {
// 在父对象上创建一个对象
lv_obj_t * settings_icon = lv_label_create(scr);
// 这个对象为一个图标
lv_label_set_text(settings_icon, LV_SYMBOL_SETTINGS);
// 这个对象可以点击
lv_obj_add_flag(settings_icon, LV_OBJ_FLAG_CLICKABLE);
// 点击之后触发settings_event_handler回调
lv_obj_add_event_cb(settings_icon, settings_event_handler, LV_EVENT_CLICKED, NULL);
// 统一添加样式
static lv_style_t icon_style;
lv_style_init(&icon_style);
lv_style_set_align(&icon_style,LV_ALIGN_CENTER);
lv_style_set_text_color(&icon_style, lv_color_hex(0x3498db));
lv_style_set_text_font(&icon_style, &lv_font_montserrat_48);
lv_obj_add_style(settings_icon, &icon_style, LV_PART_MAIN);
return scr; // 返回新创建的屏幕对象
}
License:
CC BY 4.0