#include "GUI.h"
#include "GUI_img.h"
#include "lvgl.h"
#include "string.h"
static void meanu_btn_event_handler(lv_obj_t * btn, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
lv_obj_t * mbox = lv_mbox_create(lv_scr_act(), NULL);//创建消息框
lv_obj_set_width(mbox, 200);//设置宽度
static const char * mbox_btns[] = {"ok","cancel", ""};//设置按钮名字
lv_mbox_add_btns(mbox, mbox_btns); /*The default action is close*///给消息框添加一个按钮,默然按钮事件会关闭消息框
lv_obj_align(mbox, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, LV_DPI / 2);//按钮居中
if (strcmp(lv_list_get_btn_text(btn), "Camera") == 0)
{
lv_mbox_set_text(mbox, "im Camera");//设置消息框的内容
}
else if (strcmp(lv_list_get_btn_text(btn), "Wifi") == 0)
{
lv_mbox_set_text(mbox, "im Wifi");//设置消息框的内容
}
else if (strcmp(lv_list_get_btn_text(btn), "Servo") == 0)
{
lv_mbox_set_text(mbox, "im Servo");//设置消息框的内容
}
else if (strcmp(lv_list_get_btn_text(btn), "Cycl") == 0)
{
lv_mbox_set_text(mbox, "im Cycl");//设置消息框的内容
}
else if (strcmp(lv_list_get_btn_text(btn), "Temp") == 0)
{
lv_mbox_set_text(mbox, "im Temp");//设置消息框的内容
}
else if (strcmp(lv_list_get_btn_text(btn), "GPS") == 0)
{
lv_mbox_set_text(mbox, "im GPS");//设置消息框的内容
}
else if (strcmp(lv_list_get_btn_text(btn), "Power") == 0)
{
lv_mbox_set_text(mbox, "im Power");//设置消息框的内容
}
}
}
void GUI_init(void)
{
//*********主题黑色
lv_theme_t * th =lv_theme_night_init(210, NULL);
lv_theme_set_current(th);
th = lv_theme_get_current(); /*If `LV_THEME_LIVE_UPDATE 1` `th` is not used directly so get the real theme after set*/
lv_obj_t * scr = lv_cont_create(NULL, NULL);
lv_disp_load_scr(scr);
//***********菜单按钮
lv_obj_t * Camera_btn = lv_btn_create(scr, NULL);
lv_obj_set_width(Camera_btn,100);
lv_obj_set_height(Camera_btn,55);
lv_obj_set_pos(Camera_btn,10,10);
lv_obj_set_event_cb(Camera_btn, meanu_btn_event_handler);
lv_obj_t * Camera_btn_label = lv_label_create(Camera_btn, NULL);
lv_label_set_text(Camera_btn_label, "Camera");
lv_obj_t * Wifi_btn = lv_btn_create(scr, NULL);
lv_obj_set_width(Wifi_btn,100);
lv_obj_set_height(Wifi_btn,55);
lv_obj_set_pos(Wifi_btn,120,10);
lv_obj_set_event_cb(Wifi_btn, meanu_btn_event_handler);
lv_obj_t * Wifi_btn_label = lv_label_create(Wifi_btn, NULL);
lv_label_set_text(Wifi_btn_label, "Wifi");
lv_obj_t * Servo_btn = lv_btn_create(scr, NULL);
lv_obj_set_width(Servo_btn,100);
lv_obj_set_height(Servo_btn,55);
lv_obj_set_pos(Servo_btn,10,80);
lv_obj_set_event_cb(Servo_btn, meanu_btn_event_handler);
lv_obj_t * Servo_btn_label = lv_label_create(Servo_btn, NULL);
lv_label_set_text(Servo_btn_label, "Servo");
lv_obj_t * Cycl_btn = lv_btn_create(scr, NULL);
lv_obj_set_width(Cycl_btn,100);
lv_obj_set_height(Cycl_btn,55);
lv_obj_set_pos(Cycl_btn,120,80);
lv_obj_set_event_cb(Cycl_btn, meanu_btn_event_handler);
lv_obj_t * Cycl_btn_label = lv_label_create(Cycl_btn, NULL);
lv_label_set_text(Cycl_btn_label, "Cycl");
lv_obj_t * Temp_btn = lv_btn_create(scr, NULL);
lv_obj_set_width(Temp_btn,100);
lv_obj_set_height(Temp_btn,55);
lv_obj_set_pos(Temp_btn,10,150);
lv_obj_set_event_cb(Temp_btn, meanu_btn_event_handler);
lv_obj_t * Temp_btn_label = lv_label_create(Temp_btn, NULL);
lv_label_set_text(Temp_btn_label, "Temp");
lv_obj_t * GPS_btn = lv_btn_create(scr, NULL);
lv_obj_set_width(GPS_btn,100);
lv_obj_set_height(GPS_btn,55);
lv_obj_set_pos(GPS_btn,120,150);
lv_obj_set_event_cb(GPS_btn, meanu_btn_event_handler);
lv_obj_t * GPS_btn_label = lv_label_create(GPS_btn, NULL);
lv_label_set_text(GPS_btn_label, "GPS");
lv_obj_t * Power_btn = lv_btn_create(scr, NULL);
lv_obj_set_width(Power_btn,100);
lv_obj_set_height(Power_btn,55);
lv_obj_set_pos(Power_btn,10,220);
lv_obj_set_event_cb(Power_btn, meanu_btn_event_handler);
lv_obj_t * Power_btn_label = lv_label_create(Power_btn, NULL);
lv_label_set_text(Power_btn_label, "Power");
}
网友评论