Reworked the menu_screen internal working to be able to register an item clicked callback used to vibrate the watch as a configurable feedback to the user.
This commit is contained in:
parent
8ee9f96de2
commit
0580425401
@ -12,13 +12,18 @@
|
|||||||
|
|
||||||
static void menu_item_cb(lv_event_t *e)
|
static void menu_item_cb(lv_event_t *e)
|
||||||
{
|
{
|
||||||
uint32_t icon_id = (uint32_t)e->user_data;
|
lv_obj_t *item = lv_event_get_target(e);
|
||||||
LV_LOG_USER("Menu icon pressed : %u", icon_id);
|
uint32_t clicked_item_id = (uint32_t) lv_obj_get_user_data(item);
|
||||||
|
MenuScreen_t *menuScreen = (MenuScreen_t*) lv_event_get_user_data(e);
|
||||||
|
|
||||||
// Give some user feedback that an item was clicked
|
LV_LOG_USER("Menu item clicked : %u", clicked_item_id);
|
||||||
common_screen_onclick_vibration();
|
|
||||||
|
|
||||||
switch(icon_id)
|
// Give some user feedback that an item was clicked by calling the
|
||||||
|
// callback if one is registered
|
||||||
|
if(menuScreen->menuScreenOnMenuItemClickCb)
|
||||||
|
menuScreen->menuScreenOnMenuItemClickCb();
|
||||||
|
|
||||||
|
switch(clicked_item_id)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
@ -77,25 +82,38 @@ void menu_screen_init(MenuScreen_t * const menuScreen)
|
|||||||
memset(menuScreen, 0, sizeof(MenuScreen_t));
|
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)
|
void menu_screen_register_on_menu_item_click_cb(MenuScreen_t * const menuScreen, MenuScreenOnMenuItemClickCb_t menuScreenOnMenuItemClickCb)
|
||||||
|
{
|
||||||
|
if(!menuScreen)
|
||||||
|
{
|
||||||
|
LV_LOG_ERROR("NULL pointer given !");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
menuScreen->menuScreenOnMenuItemClickCb = menuScreenOnMenuItemClickCb;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void menu_screen_add_item(MenuScreen_t * const menuScreen, 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
|
//We add the image button with the icon of the item
|
||||||
lv_obj_t *item_btn = lv_img_create(scroll_item_container);
|
lv_obj_t *item_btn = lv_img_create(menuScreen->scrollItemContainer);
|
||||||
|
lv_obj_set_user_data(item_btn, (void *)(uint32_t)position);
|
||||||
lv_obj_set_size(item_btn, itemImg->header.w, itemImg->header.h);
|
lv_obj_set_size(item_btn, itemImg->header.w, itemImg->header.h);
|
||||||
lv_obj_add_flag(item_btn, LV_OBJ_FLAG_ADV_HITTEST | LV_OBJ_FLAG_CLICKABLE);
|
lv_obj_add_flag(item_btn, LV_OBJ_FLAG_ADV_HITTEST | LV_OBJ_FLAG_CLICKABLE);
|
||||||
lv_obj_set_pos(item_btn, 42, 52 * position);
|
lv_obj_set_pos(item_btn, 42, 52 * position);
|
||||||
lv_img_set_src(item_btn, itemImg);
|
lv_img_set_src(item_btn, itemImg);
|
||||||
lv_obj_add_event_cb(item_btn, itemClickEventCb, LV_EVENT_CLICKED, (void *)(uint32_t)position);
|
lv_obj_add_event_cb(item_btn, itemClickEventCb, LV_EVENT_CLICKED, (void *)menuScreen);
|
||||||
|
|
||||||
//We add the click-able label with the title of the item
|
//We add the click-able label with the title of the item
|
||||||
lv_obj_t *item_label = lv_label_create(scroll_item_container);
|
lv_obj_t *item_label = lv_label_create(menuScreen->scrollItemContainer);
|
||||||
|
lv_obj_set_user_data(item_label, (void *)(uint32_t)position);
|
||||||
lv_label_set_text_static(item_label, itemTitle);
|
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_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_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_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_set_ext_click_area(item_label, 10);
|
||||||
lv_obj_add_flag(item_label, LV_OBJ_FLAG_CLICKABLE);
|
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);
|
lv_obj_add_event_cb(item_label, itemClickEventCb, LV_EVENT_CLICKED , (void *)menuScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void menu_screen_create(MenuScreen_t * const menuScreen)
|
void menu_screen_create(MenuScreen_t * const menuScreen)
|
||||||
@ -147,17 +165,17 @@ void menu_screen_create(MenuScreen_t * const menuScreen)
|
|||||||
lv_obj_set_style_border_width(menuScreen->scrollItemContainer, 0, LV_PART_MAIN);
|
lv_obj_set_style_border_width(menuScreen->scrollItemContainer, 0, LV_PART_MAIN);
|
||||||
lv_obj_set_style_pad_right(menuScreen->scrollItemContainer, 15, LV_PART_SCROLLBAR);
|
lv_obj_set_style_pad_right(menuScreen->scrollItemContainer, 15, LV_PART_SCROLLBAR);
|
||||||
|
|
||||||
menu_screen_add_item(menuScreen->scrollItemContainer, 0, &watch_menu_clock_icon, translation_get_word(TRANSLATION_WATCH), &(menu_item_cb));
|
menu_screen_add_item(menuScreen, 0, &watch_menu_clock_icon, translation_get_word(TRANSLATION_WATCH), &(menu_item_cb));
|
||||||
menu_screen_add_item(menuScreen->scrollItemContainer, 1, &watch_menu_alarm_icon, translation_get_word(TRANSLATION_ALARM), &(menu_item_cb));
|
menu_screen_add_item(menuScreen, 1, &watch_menu_alarm_icon, translation_get_word(TRANSLATION_ALARM), &(menu_item_cb));
|
||||||
menu_screen_add_item(menuScreen->scrollItemContainer, 2, &watch_menu_music_player_icon, translation_get_word(TRANSLATION_MUSIC), &(menu_item_cb));
|
menu_screen_add_item(menuScreen, 2, &watch_menu_music_player_icon, translation_get_word(TRANSLATION_MUSIC), &(menu_item_cb));
|
||||||
menu_screen_add_item(menuScreen->scrollItemContainer, 3, &watch_menu_compass_icon, translation_get_word(TRANSLATION_COMPASS), &(menu_item_cb));
|
menu_screen_add_item(menuScreen, 3, &watch_menu_compass_icon, translation_get_word(TRANSLATION_COMPASS), &(menu_item_cb));
|
||||||
menu_screen_add_item(menuScreen->scrollItemContainer, 4, &watch_menu_lost_phone_icon, translation_get_word(TRANSLATION_FIND_MY_PHONE), &(menu_item_cb));
|
menu_screen_add_item(menuScreen, 4, &watch_menu_lost_phone_icon, translation_get_word(TRANSLATION_FIND_MY_PHONE), &(menu_item_cb));
|
||||||
/*
|
/*
|
||||||
menu_screen_add_item(menuScreen->scrollItemContainer, 3, &watch_menu_messages_icon, "Text messages", &(menu_item_cb));
|
menu_screen_add_item(menuScreen, 3, &watch_menu_messages_icon, "Text messages", &(menu_item_cb));
|
||||||
menu_screen_add_item(menuScreen->scrollItemContainer, 4, &watch_menu_mail_icon, "Mails", &(menu_item_cb));
|
menu_screen_add_item(menuScreen, 4, &watch_menu_mail_icon, "Mails", &(menu_item_cb));
|
||||||
menu_screen_add_item(menuScreen->scrollItemContainer, 5, &watch_menu_dialer_icon, "Phone", &(menu_item_cb));
|
menu_screen_add_item(menuScreen, 5, &watch_menu_dialer_icon, "Phone", &(menu_item_cb));
|
||||||
menu_screen_add_item(menuScreen->scrollItemContainer, 6, &watch_menu_contacts_icon, "Contacts", &(menu_item_cb));*/
|
menu_screen_add_item(menuScreen, 6, &watch_menu_contacts_icon, "Contacts", &(menu_item_cb));*/
|
||||||
menu_screen_add_item(menuScreen->scrollItemContainer, 5, &watch_menu_settings_icon, translation_get_word(TRANSLATION_SETTINGS), &(menu_item_cb));
|
menu_screen_add_item(menuScreen, 5, &watch_menu_settings_icon, translation_get_word(TRANSLATION_SETTINGS), &(menu_item_cb));
|
||||||
|
|
||||||
//Lets restore the previous scrolling position
|
//Lets restore the previous scrolling position
|
||||||
lv_obj_scroll_to_y(menuScreen->scrollItemContainer, menuScreen->lastScrollPosition, LV_ANIM_OFF);
|
lv_obj_scroll_to_y(menuScreen->scrollItemContainer, menuScreen->lastScrollPosition, LV_ANIM_OFF);
|
||||||
|
@ -3,19 +3,30 @@
|
|||||||
|
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
|
|
||||||
|
typedef void (*MenuScreenOnMenuItemClickCb_t)(void);
|
||||||
|
|
||||||
// Menu screen context object
|
// Menu screen context object
|
||||||
typedef struct MenuScreen
|
typedef struct MenuScreen
|
||||||
{
|
{
|
||||||
//Can be erased attributes
|
// Can be erased attributes
|
||||||
lv_obj_t *display;
|
lv_obj_t *display;
|
||||||
lv_obj_t *scrollItemContainer;
|
lv_obj_t *scrollItemContainer;
|
||||||
//Should not be erased attributes
|
// Should not be erased attributes
|
||||||
lv_coord_t lastScrollPosition;
|
lv_coord_t lastScrollPosition;
|
||||||
|
MenuScreenOnMenuItemClickCb_t menuScreenOnMenuItemClickCb;
|
||||||
} MenuScreen_t;
|
} MenuScreen_t;
|
||||||
|
|
||||||
/* Initializes the menu screen context object */
|
/* Initializes the menu screen context object */
|
||||||
void menu_screen_init(MenuScreen_t * const menuScreen);
|
void menu_screen_init(MenuScreen_t * const menuScreen);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param menuScreen
|
||||||
|
* @param menuScreenOnMenuItemClickCb
|
||||||
|
*/
|
||||||
|
void menu_screen_register_on_menu_item_click_cb(MenuScreen_t * const menuScreen, MenuScreenOnMenuItemClickCb_t menuScreenOnMenuItemClickCb);
|
||||||
|
|
||||||
/* Builds the menu screen graphically */
|
/* Builds the menu screen graphically */
|
||||||
void menu_screen_create(MenuScreen_t * const menuScreen);
|
void menu_screen_create(MenuScreen_t * const menuScreen);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user