1_页面跳转
TTGOClass *ttgo;
lv_obj_t* btn1,* btn2;
lv_obj_t* current_app_obj_user=NULL;
static void btn_event_handler(lv_obj_t * obj, lv_event_t event)
{
lv_obj_t* parent_menu;
if (event == LV_EVENT_CLICKED) {
if (obj == btn1) {
if (current_app_obj_user == NULL) {
current_app_obj_user = lv_obj_create(LV_DESKTOP, NULL);
lv_obj_set_size(current_app_obj_user, LV_HOR_RES_MAX, LV_VER_RES_MAX);
parent_menu = current_app_obj_user;
lv_obj_t* lable = lv_label_create(parent_menu, NULL);
lv_label_set_text(lable, "lv_pages_2");
lv_obj_align(lable, NULL, LV_ALIGN_CENTER, 0, -10);
btn2 = lv_btn_create(parent_menu, NULL);
lv_obj_t* label_btn = lv_label_create(btn2, NULL);
lv_label_set_text(label_btn, "Back");
lv_obj_align(btn2, lable, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
lv_obj_set_event_cb(btn2, btn_event_handler);
}
}
else if (obj == btn2) {
lv_obj_del(current_app_obj_user);
current_app_obj_user = NULL;
}
}
}
void lv_pages_1(void)
{
lv_obj_t* desktop = lv_obj_create(lv_disp_get_scr_act(NULL), NULL);
lv_obj_set_size(desktop, LV_HOR_RES_MAX, LV_VER_RES_MAX);
lv_obj_t* lable = lv_label_create(desktop, NULL);
lv_label_set_text(lable, "lv_pages_1");
lv_obj_align(lable, NULL, LV_ALIGN_CENTER, 0, 0);
btn1 = lv_btn_create(desktop, NULL);
lv_obj_t *label_btn = lv_label_create(btn1, NULL);
lv_label_set_text(label_btn, "button");
lv_obj_align(btn1, lable, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
lv_obj_set_event_cb(btn1, btn_event_handler);
}
void setup()
{
Serial.begin(115200);
ttgo = TTGOClass::getWatch();
ttgo->begin();
ttgo->openBL();
ttgo->lvgl_begin();
lv_pages_1();
}
void loop()
{
lv_task_handler();
delay(5);
}
2_容器
TTGOClass *ttgo;
static lv_obj_t * label;
int text_value=0;
static void event_handler(lv_obj_t *obj, lv_event_t event)
{
if (event == LV_EVENT_CLICKED) {
lv_label_set_text_fmt(label, "%d",++text_value);
}
}
void lv_ex_cont_1(void)
{
lv_obj_t * cont;
cont = lv_cont_create(lv_scr_act(), NULL);
lv_obj_set_event_cb(cont, event_handler);
lv_obj_set_auto_realign(cont, true);
lv_obj_align_origo(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_cont_set_fit(cont, LV_FIT_TIGHT);
lv_cont_set_layout(cont, LV_LAYOUT_COLUMN_MID);
LV_IMG_DECLARE(wifi);
lv_obj_t * img1 = lv_img_create(cont, NULL);
lv_img_set_src(img1, &wifi);
lv_obj_align(img1, NULL, LV_ALIGN_CENTER, 0,0);
label = lv_label_create(cont, NULL);
lv_label_set_text(label, "0");
lv_obj_set_auto_realign(label, true);
lv_obj_align(label,NULL,LV_ALIGN_CENTER, 0,-55);
}
void setup()
{
Serial.begin(115200);
ttgo = TTGOClass::getWatch();
ttgo->begin();
ttgo->openBL();
ttgo->lvgl_begin();
lv_ex_cont_1();
}
void loop()
{
lv_task_handler();
delay(5);
}
3_消息框
TTGOClass *ttgo;
static void event_handler(lv_obj_t *obj, lv_event_t event)
{
if (event == LV_EVENT_CLICKED) {
static const char * btns[] ={"Apply", "Close", ""};
lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
lv_msgbox_set_text(mbox1, "A message box with two buttons.");
lv_msgbox_add_btns(mbox1, btns);
lv_obj_set_width(mbox1, 200);
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0);
}
}
void setup()
{
Serial.begin(115200);
ttgo = TTGOClass::getWatch();
ttgo->begin();
ttgo->openBL();
ttgo->lvgl_begin();
lv_obj_t *label;
lv_obj_t *btn1 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_event_cb(btn1, event_handler);
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0,40);
label = lv_label_create(btn1, NULL);
lv_label_set_text(label, "Button");
}
void loop()
{
lv_task_handler();
delay(5);
}