W800_Smart_Watch/src/W800 SDK v1.00.08/app/gfx/menu_screen.c

144 lines
5.4 KiB
C

#include "lvgl.h"
#include "common_screen_components.h"
#include "menu_screen.h"
#include "settings_screen.h"
#include "watch_face.h"
#include "compass_screen.h"
#define array_size(array) (sizeof(array)/sizeof(array[0]))
static void menu_item_cb(lv_event_t *e)
{
uint32_t icon_id = (uint32_t)e->user_data;
LV_LOG_USER("Menu icon pressed : %u", icon_id);
switch(icon_id)
{
case 0:
{
extern WatchFace_t watchFace;
watch_face_create(&watchFace);
lv_scr_load_anim(watchFace.display, LV_SCR_LOAD_ANIM_MOVE_LEFT, 400, 0, true);
}
break;
case 1:
{
extern CompassScreen_t compassScreen;
compass_screen_create(&compassScreen);
lv_scr_load_anim(compassScreen.display, LV_SCR_LOAD_ANIM_MOVE_LEFT, 400, 0, true);
}
break;
case 7:
{
extern SettingsScreen_t settingsScreen;
settings_screen_create(&settingsScreen);
lv_scr_load_anim(settingsScreen.display, LV_SCR_LOAD_ANIM_MOVE_LEFT, 400, 0, true);
}
break;
default:
LV_LOG_USER("Not handled");
}
}
static void cleanup_event_cb(lv_event_t * e)
{
MenuScreen_t *menuScreen = e->user_data;
menu_screen_destroy(menuScreen);
LV_LOG_USER("cleanup");
}
void menu_screen_init(MenuScreen_t * const menuScreen)
{
if(!menuScreen)
{
LV_LOG_ERROR("NULL pointer given !");
return;
}
memset(menuScreen, 0, sizeof(MenuScreen_t));
}
static void menu_screen_add_item(lv_obj_t *scroll_item_container, uint8_t position, const lv_img_dsc_t *itemImg,const char *itemTitle, lv_event_cb_t itemClickEventCb)
{
//We add the image button with the icon of the item
lv_obj_t *item_btn = lv_imgbtn_create(scroll_item_container);
lv_obj_set_size(item_btn, itemImg->header.w, itemImg->header.h);
lv_obj_set_pos(item_btn, 42, 52 * position);
lv_imgbtn_set_src(item_btn, LV_IMGBTN_STATE_RELEASED, NULL, itemImg, NULL);
lv_obj_add_event_cb(item_btn, itemClickEventCb, LV_EVENT_CLICKED, (void *)(uint32_t)position);
//We add the click-able label with the title of the item
lv_obj_t *item_label = lv_label_create(scroll_item_container);
lv_label_set_text_static(item_label, itemTitle);
lv_obj_set_style_text_font(item_label, &lv_font_montserrat_16, LV_PART_MAIN);
lv_obj_set_pos(item_label, 84+12, 15 + 52 * position);
lv_obj_set_style_text_color(item_label, lv_color_make(145, 145, 145), LV_PART_MAIN);
lv_obj_set_ext_click_area(item_label, 10);
lv_obj_add_flag(item_label, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_event_cb(item_label, itemClickEventCb, LV_EVENT_CLICKED , (void *)(uint32_t)position);
}
void menu_screen_create(MenuScreen_t * const menuScreen)
{
if(!menuScreen)
{
LV_LOG_ERROR("NULL pointer given !");
return;
}
//We declare all the needed assets by the menu screen:
LV_IMG_DECLARE(watch_menu_clock_icon)
LV_IMG_DECLARE(watch_menu_dialer_icon)
LV_IMG_DECLARE(watch_menu_mail_icon)
LV_IMG_DECLARE(watch_menu_contacts_icon)
LV_IMG_DECLARE(watch_menu_alarm_icon)
LV_IMG_DECLARE(watch_menu_settings_icon)
LV_IMG_DECLARE(watch_menu_messages_icon)
LV_IMG_DECLARE(watch_menu_compass_icon)
//We create our parent screen :
if(menuScreen->display)
{
LV_LOG_ERROR("display should be NULL here !");
lv_obj_del(menuScreen->display);
menuScreen->display = NULL;
}
menuScreen->display = lv_obj_create(NULL);
//We add the screen header
common_screen_header_component(menuScreen->display, "Menu", 65);
lv_obj_t *scroll_item_container = lv_obj_create(menuScreen->display);
lv_obj_set_style_bg_color(scroll_item_container, lv_color_make(0xFF,0xFF,0xFF), LV_PART_MAIN);
lv_obj_set_size(scroll_item_container, lv_pct(100), 240-65);
lv_obj_set_pos(scroll_item_container, 0, 65);
lv_obj_set_style_pad_all(scroll_item_container, 0, LV_PART_MAIN);
lv_obj_set_style_pad_top(scroll_item_container, 10, LV_PART_MAIN);
lv_obj_set_style_pad_bottom(scroll_item_container, 20, LV_PART_MAIN);
lv_obj_set_style_radius(scroll_item_container, 0, LV_PART_MAIN);
lv_obj_set_style_border_width(scroll_item_container, 0, LV_PART_MAIN);
lv_obj_set_style_pad_right(scroll_item_container, 15, LV_PART_SCROLLBAR);
menu_screen_add_item(scroll_item_container, 0, &watch_menu_clock_icon, "Watch", &(menu_item_cb));
menu_screen_add_item(scroll_item_container, 1, &watch_menu_compass_icon, "Compass", &(menu_item_cb));
menu_screen_add_item(scroll_item_container, 2, &watch_menu_alarm_icon, "Alarm", &(menu_item_cb));
menu_screen_add_item(scroll_item_container, 3, &watch_menu_messages_icon, "Text messages", &(menu_item_cb));
menu_screen_add_item(scroll_item_container, 4, &watch_menu_mail_icon, "Mails", &(menu_item_cb));
menu_screen_add_item(scroll_item_container, 5, &watch_menu_dialer_icon, "Phone", &(menu_item_cb));
menu_screen_add_item(scroll_item_container, 6, &watch_menu_contacts_icon, "Contacts", &(menu_item_cb));
menu_screen_add_item(scroll_item_container, 7, &watch_menu_settings_icon, "Settings", &(menu_item_cb));
//We register the event callback to handle the cleanup
lv_obj_add_event_cb(menuScreen->display, &(cleanup_event_cb), LV_EVENT_DELETE, menuScreen);
}
void menu_screen_destroy(MenuScreen_t * const menuScreen)
{
if(!menuScreen)
{
LV_LOG_ERROR("NULL pointer given !");
return;
}
menuScreen->display = NULL;
}