MXC-A36-Demo/Demo/lv_user_code/app/list.c

755 lines
28 KiB
C
Raw Blame History

#include "lvgl.h"
#include "img_def.h"
#include "demo.h"
#include "mxc_meter.h"
#include "moto_list.h"
#include "language_table.h"
#include "lan_str_table.h"
#include "equipment.h"
//#define LV_KEY_Q 113
//#define LV_KEY_W 119
char *list_title[16] = {"主题","亮度","蓝牙","其他\n设置","车辆\n信息","返回","1","2","3","4","5","6","7","8","9","10","11","12"};
char *theme_title[16] = {"主题\n设置","主题\n背景","返回","1","2","3","4","5","6","7","8","9","10","11","12"};
__attribute__((section("resource_section"))) static const lv_mainmenu_win_t mainmenu_page_group[MAINMENU_ITEM_ID_MAX] =
{
{MAINMENU_ITEM_ID_THEME, STR_ID_THEME, MAINMENU_ICON_ID_THEME, (void *)theme_create},
{MAINMENU_ITEM_ID_LIGHT, STR_ID_LIGHT, MAINMENU_ICON_ID_LIGHT, (void *)light_create},
{MAINMENU_ITEM_ID_BLUETOOTH, STR_ID_BLUETOOTH, MAINMENU_ICON_ID_BLUETOOTH, (void *)bluetooth_create},
{MAINMENU_ITEM_ID_OTHER, STR_ID_OTHER_SETTING, MAINMENU_ICON_ID_OTHER, (void *)other_create},
{MAINMENU_ITEM_ID_INFORMATION, STR_ID_INFORMATION, MAINMENU_ICON_ID_INFORMATION, (void *)information_create},
{MAINMENU_ITEM_ID_PRESSURE, STR_ID_PRESSURE, MAINMENU_ICON_ID_PRESSURE, (void *)pressure_create},
{MAINMENU_ITEM_ID_FAULT_CODE, STR_ID_FAULT_CODE, MAINMENU_ICON_ID_FAULT_CODE, (void *)fault_code_create},
{EQUIPMENT_ID_RETURN, STR_ID_RETURN, MAINMENU_ICON_ID_RETURN, (void *)demo_return},
};
const btn_event_func getDeviceEntryByStrId(const LAN_STR_ID str_id)
{
btn_event_func p_btn_func = NULL;
for (uint8_t i = MAINMENU_ITEM_ID_THEME; i < MAINMENU_ITEM_ID_MAX; i++)
{
// printf("mainmenu_page_group[i].str_id = %d ,str_id = %d ",mainmenu_page_group[i].str_id,str_id);
if (mainmenu_page_group[i].str_id == str_id)
{
p_btn_func = mainmenu_page_group[i].event_handler;
break;
}
}
if (p_btn_func != NULL)
{
p_btn_func(NULL);
}
else
{
LV_ASSERT(true);
}
return NULL;
}
ENUM_EQUIPMENT_ID get_menu_iconid_by_strid(const LAN_STR_ID str_id)
{
for (uint8_t i = EQUIPMENT_ID_THEME; i < EQUIPMENT_ID_MAX; i++)
{
if (mainmenu_page_group[i].str_id == str_id)
return mainmenu_page_group[i].mainmenu_icon_id;
}
return EQUIPMENT_ID_MAX;
}
LAN_STR_ID list_str[16] = {
STR_ID_THEME,
STR_ID_LIGHT,
STR_ID_BLUETOOTH,
STR_ID_OTHER_SETTING,
STR_ID_INFORMATION,
STR_ID_PRESSURE,
STR_ID_FAULT_CODE,
STR_ID_RETURN,
STR_ID_RETURN,
STR_ID_RETURN,
STR_ID_RETURN,
STR_ID_RETURN,
STR_ID_RETURN,
STR_ID_RETURN,
STR_ID_RETURN,
STR_ID_RETURN,
STR_ID_RETURN,
};
//lan_str_table[STR_ID_FOCUS_BREATHING][1]
mainmenu_tile_t mainmenu_tile[]=
{
[MAINMENU_TILE_ZERO] = {.window_obj = NULL, .col_id = 0, .row_id = 0, .dir = LV_DIR_HOR, .Init = init_tile_common}, // <20><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>
[MAINMENU_TILE_ONE] = {.window_obj = NULL, .col_id = 1, .row_id = 0, .dir = LV_DIR_HOR, .Init = init_tile_common},
[MAINMENU_TILE_TWO] = {.window_obj = NULL, .col_id = 2, .row_id = 0, .dir = LV_DIR_HOR, .Init = init_tile_common},
};
/*
LV_ATTRIBUTE_LARGE_CONST static const lv_img_dsc_t* test_list[4] =
{
IMG_DM1_OIL,
IMG_DM1_TCS,
IMG_DM1_TEMP,
IMG_DM1_NULL,
};
*/
uint32_t mainmenu_item_process(uint32_t dis_item_arr[MAINMENU_TILE_END][COMMON_PER_PAGE_NUM],
uint32_t *page_num, uint32_t *last_item_pos)
{
uint32_t mainmenu_item_sum = 0;
// calculate how many devices need display
for (uint8_t i = EQUIPMENT_ID_THEME; i < EQUIPMENT_ID_MAX; i++)
{
if (get_equipment_is_display(i))
mainmenu_item_sum++;
}
//mainmenu_item_sum++; // add device manage item
// calculate page_num according to mainmenu_item_sum
*page_num = mainmenu_item_sum / COMMON_PER_PAGE_NUM;
if (mainmenu_item_sum % COMMON_PER_PAGE_NUM != 0)
(*page_num)++;
// Store the device str_id to be displayed into an array in order
*last_item_pos = mainmenu_item_sum % COMMON_PER_PAGE_NUM;
get_display_equipment_str(dis_item_arr);
*last_item_pos == 0 ? (dis_item_arr[(*page_num) - 1][COMMON_PER_PAGE_NUM - 1] = STR_ID_RETURN) : (dis_item_arr[(*page_num) - 1][(*last_item_pos) - 1] = STR_ID_RETURN);
return mainmenu_item_sum;
}
void enter_mainmenu_win(lv_obj_t *parent)
{
lv_obj_t *mainmenu_win = lv_obj_create(parent);
lv_obj_set_style_bg_color(mainmenu_win, lv_color_make(0x00, 0x00, 0x00), 0);
lv_obj_set_scrollbar_mode(mainmenu_win, LV_SCROLLBAR_MODE_OFF);
lv_obj_set_size(mainmenu_win, LV_PCT(100), LV_PCT(100));
lv_obj_set_style_pad_all(mainmenu_win, 0, 0);
lv_obj_set_style_radius(mainmenu_win, 0, 0);
lv_obj_set_style_border_width(mainmenu_win, 0, LV_PART_MAIN);
// lv_obj_set_style_border_color(mainmenu_win, lv_color_black(), 0);
lv_obj_set_style_bg_color(mainmenu_win, lv_color_hex(0x5E5E5E), NULL);
lv_obj_clear_flag(mainmenu_win, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_t *demo_group = get_key_group();
lv_group_add_obj(demo_group, mainmenu_win);
lv_obj_t *mainmenu_tile_win = lv_tileview_create(mainmenu_win);
lv_obj_set_style_bg_color(mainmenu_tile_win, lv_color_black(), 0);
lv_obj_clear_flag(mainmenu_tile_win, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_clear_flag(mainmenu_tile_win, LV_OBJ_FLAG_EVENT_BUBBLE);
lv_obj_set_scrollbar_mode(mainmenu_tile_win, LV_SCROLLBAR_MODE_OFF);
lv_obj_set_scroll_dir(mainmenu_tile_win, LV_DIR_HOR);
lv_obj_clear_flag(mainmenu_tile_win, LV_OBJ_FLAG_SCROLL_ELASTIC);
lv_obj_add_flag(mainmenu_tile_win, LV_OBJ_FLAG_SCROLL_MOMENTUM);
lv_obj_add_flag(mainmenu_tile_win, LV_OBJ_FLAG_SCROLL_ONE);
lv_obj_set_size(mainmenu_tile_win, LV_PCT(100), LV_PCT(100));
lv_obj_set_style_radius(mainmenu_tile_win, 0, 0);
lv_obj_set_style_pad_all(mainmenu_tile_win, 0, 0);
lv_obj_set_style_border_width(mainmenu_tile_win, 0, LV_PART_MAIN);
// lv_obj_set_style_border_color(mainmenu_tile_win, lv_color_black(), 0);
lv_obj_set_style_bg_color(mainmenu_tile_win, lv_color_hex(0x5E5E5E), NULL);
uint32_t page_num = 3; // sum of mainmenu pages
uint32_t tile_item_count = 3; // number of items per page
uint32_t last_item_pos = 0;
uint8_t cal_check_page = 0;
// uint8_t cal_check_item = 0;
uint32_t dis_item_arr[MAINMENU_TILE_END][COMMON_PER_PAGE_NUM];
memset(dis_item_arr, 0, sizeof(dis_item_arr));
uint32_t btn_totalnum = mainmenu_item_process(dis_item_arr, &page_num, &last_item_pos);
printf("btn_totalnum = %d .\n",btn_totalnum);
printf("page_num = %d last_num = %d .\n",page_num,last_item_pos);
// Loop create tile
for (uint8_t i = MAINMENU_TILE_ZERO; i < page_num; i++)
{
// calculate number of items on the last page
if ((i == page_num - 1) && (last_item_pos))
tile_item_count = last_item_pos;
// add tile
mainmenu_tile[i].window_obj = lv_tileview_add_tile(mainmenu_tile_win, mainmenu_tile[i].col_id, mainmenu_tile[i].row_id, mainmenu_tile[i].dir);
if (i == cal_check_page)
((mainmenu_tile_t *)&mainmenu_tile[i])->Init(mainmenu_tile[i].window_obj, dis_item_arr[i], i, tile_item_count);
else
((mainmenu_tile_t *)&mainmenu_tile[i])->Init(mainmenu_tile[i].window_obj, dis_item_arr[i], i, tile_item_count);
}
lv_obj_set_tile_id(mainmenu_tile_win, mainmenu_tile[cal_check_page].col_id, mainmenu_tile[cal_check_page].row_id, LV_ANIM_ON);
lv_obj_add_event_cb(mainmenu_win, key_event_handler, LV_EVENT_KEY, NULL);
uint32_t btn_count = 0;
uint32_t page_count = 0;
lv_obj_t *tile_display = NULL;
lv_obj_t *mainmenu_btn_win = lv_tileview_get_tile_act(mainmenu_tile_win); // get display tile
for (uint32_t i = 0; i < lv_obj_get_child_cnt(mainmenu_btn_win); i++)
{
lv_obj_t *child = lv_obj_get_child(mainmenu_btn_win, i);
if (lv_obj_has_state(child, LV_STATE_FOCUS_KEY))
btn_count = i;
}
lv_obj_t *mainmenu_button_cur = lv_obj_get_child(mainmenu_btn_win, btn_count); // get checked item obj
switch(Get_UI_page_id()){
case 0:
case 1:
case 2:
case 3:
case 4:
break;
case 5:
case 6:
case 7:
//page_count = (uint32_t)lv_obj_get_child_id(mainmenu_btn_win); // get display tile index
//printf("page_count === %d .\r\n",page_count );
page_count=1;
printf("tile_page >> page_count === %d .\r\n",page_count );
tile_display = lv_obj_get_child(mainmenu_tile_win, page_count);
lv_obj_set_tile(mainmenu_tile_win, tile_display, LV_ANIM_ON);
break;
case 8:
case 9:
case 10:
//page_count = (uint32_t)lv_obj_get_child_id(mainmenu_btn_win); // get display tile index
page_count=2;
printf("tile_page >> page_count === %d .\r\n",page_count );
tile_display = lv_obj_get_child(mainmenu_tile_win, page_count);
lv_obj_set_tile(mainmenu_tile_win, tile_display, LV_ANIM_ON);
break;
default:
break;
}
app_menu_comm_entry(mainmenu_win,PAGE_MAINMENU_WIN_ID,false);
}
static void key_event_handler(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *mainmenu_win = lv_event_get_target(e);
lv_obj_t *mainmenu_tile_win = lv_obj_get_child(mainmenu_win, 0);
lv_obj_t *mainmenu_btn_win = lv_tileview_get_tile_act(mainmenu_tile_win); // get display tile
lv_obj_t *img_side = lv_obj_get_child(mainmenu_win, 1);
if (code == LV_EVENT_KEY)
{
uint32_t *key = lv_event_get_param(e);
uint8_t key_code = (uint8_t)*key;
uint32_t page_count = 0; // display tile index
uint32_t btn_count = 0; // checked item index
uint32_t page_num = 0; // sum of mainmenu pages
uint32_t last_item_pos = 0; // last item index of his page
uint32_t dis_item_arr[MAINMENU_TILE_END][COMMON_PER_PAGE_NUM];
memset(dis_item_arr, 0, sizeof(dis_item_arr));
uint32_t btn_totalnum = mainmenu_item_process(dis_item_arr, &page_num, &last_item_pos);
bool check = false;
// MAINMENU_ICON_ID_ENUM menu_id = MAINMENU_ICON_ID_MAX;
// ENUM_MAINMENU_ITEM_ID item_id = MAINMENU_ITEM_ID_MAX;
// uint8_t curItemState = 0;
// get focus item index
for (uint32_t i = 0; i < lv_obj_get_child_cnt(mainmenu_btn_win); i++)
{
lv_obj_t *child = lv_obj_get_child(mainmenu_btn_win, i);
if (lv_obj_has_state(child, LV_STATE_FOCUS_KEY))
btn_count = i;
}
lv_obj_t *mainmenu_button_cur = lv_obj_get_child(mainmenu_btn_win, btn_count); // get checked item obj
page_count = (uint32_t)lv_obj_get_child_id(mainmenu_btn_win); // get display tile index
check = lv_obj_get_child_cnt(mainmenu_btn_win) > 1 ? true : false;
switch (key_code)
{
case LV_KEY_Q:
lv_obj_clear_state(mainmenu_button_cur, LV_STATE_FOCUS_KEY);
if(btn_totalnum ==btn_count+1+page_count*3){//最后一个按钮
printf("2---------count = %d.\n",btn_count+1+page_count*3);
page_count =0;
btn_count =0;
lv_obj_t *tile_display = lv_obj_get_child(mainmenu_tile_win, page_count);
lv_obj_set_tile(mainmenu_tile_win, tile_display, LV_ANIM_ON);
mainmenu_btn_win = lv_tileview_get_tile_act(mainmenu_tile_win);
lv_obj_t *mainmenu_next_button = lv_obj_get_child(mainmenu_btn_win, btn_count);
lv_obj_add_state(mainmenu_next_button, LV_STATE_FOCUS_KEY);
printf("LV_KEY_Q page_count = %d ,btn_count = %d\n",page_count,btn_count);
break;
}
if(btn_count==2)
{
btn_count =0;
page_count++;
lv_obj_t *tile_display = lv_obj_get_child(mainmenu_tile_win, page_count);
lv_obj_set_tile(mainmenu_tile_win, tile_display, LV_ANIM_ON);
}
else
btn_count++;
mainmenu_btn_win = lv_tileview_get_tile_act(mainmenu_tile_win);
lv_obj_t *mainmenu_next_button = lv_obj_get_child(mainmenu_btn_win, btn_count);
lv_obj_add_state(mainmenu_next_button, LV_STATE_FOCUS_KEY);
printf("LV_KEY_Q page_count = %d ,btn_count = %d\n",page_count,btn_count);
break;
case LV_KEY_W:
printf("LV_KEY_W page_count = %d ,btn_count = %d,",page_count,btn_count);
printf("count = %d.\n",btn_count+1+page_count*3);
// ENUM_MAINMENU_ITEM_ID item_id = get_mainmenu_item_id_by_strid(dis_item_arr[page_count][btn_count]);
// Set_check_menu_item(item_id);
close_all_win();
SubmenuBtnEnter(get_root_win(), page_count, btn_count);
break;
default:
// printf("other key:%d\r\n", key_code);
break;
}
}
}
void init_tile_common(lv_obj_t *mainmenu_btn_win, uint32_t str_arr[], uint8_t page_num, uint8_t cur_tile_item)
{
printf("page_num = %d, cur_tile_item = %d\n",page_num,cur_tile_item);
lv_obj_t *mainmenu_tile_win = lv_obj_get_parent(mainmenu_btn_win);
lv_obj_t *mainmenu_win = lv_obj_get_parent(mainmenu_tile_win);
lv_obj_t *img_side = lv_obj_get_child(mainmenu_win, 1);
uint32_t x1 = 0, y1 = 0, x2 = 0, y2 = 0;
uint32_t page_id = lv_obj_get_child_id(mainmenu_btn_win);
lv_obj_set_style_pad_all(mainmenu_btn_win, 0, 0);
lv_obj_set_style_opa(mainmenu_btn_win, LV_OPA_100, 0);
lv_obj_set_scrollbar_mode(mainmenu_btn_win, LV_SCROLLBAR_MODE_ACTIVE);
lv_obj_clear_flag(mainmenu_btn_win, LV_OBJ_FLAG_SCROLL_ELASTIC);
lv_obj_set_size(mainmenu_btn_win, LV_PCT(100), LV_PCT(100));
lv_obj_set_style_radius(mainmenu_btn_win, 0, 0);
lv_obj_set_style_bg_color(mainmenu_btn_win, lv_color_hex(0x7000BB), 0);
for (uint8_t i = 0; i < cur_tile_item; i++)
{
lv_obj_t *imgbtn = lv_btn_create(mainmenu_btn_win);
lv_obj_set_style_bg_opa(imgbtn, LV_OPA_0, 0);
uint32_t child_id = lv_obj_get_child_id(imgbtn);
switch (child_id)
{
case 0:
x1 = ICON_IMG_1_X;
x2 = ICON_RING_1_X;
break;
case 1:
x1 = ICON_IMG_2_X;
x2 = ICON_RING_2_X;
break;
default:
x1 = ICON_IMG_3_X;
x2 = ICON_RING_3_X;
break;
}
y1 = ICON_IMG_Y;
lv_obj_set_size(imgbtn, MAINMENU_ICON_WIDTH_UNCHECK, MAINMENU_ICON_HEIGHT_UNCHECK);
lv_obj_set_pos(imgbtn, x1, y1);
LAN_STR_ID str_id = (LAN_STR_ID)str_arr[i];
ENUM_EQUIPMENT_ID cur_menu_id = get_menu_iconid_by_strid(str_id);
if (cur_menu_id == MAINMENU_ICON_ID_MAX)
continue;
switch(Get_UI_page_id()){
case 0://demo
case 1://list
case 2://theme
if(page_id == 0 && i==0){
lv_obj_add_state(imgbtn, LV_STATE_FOCUS_KEY);
}
break;
case 3://
if(page_id == 0 && i==1){
lv_obj_add_state(imgbtn, LV_STATE_FOCUS_KEY);
}
break;
case 4:
if(page_id == 0 && i==2){
lv_obj_add_state(imgbtn, LV_STATE_FOCUS_KEY);
}
break;
case 5:
if(page_id == 1 && i==0){
lv_obj_add_state(imgbtn, LV_STATE_FOCUS_KEY);
}
break;
case 6:
if(page_id == 1 && i==1){
lv_obj_add_state(imgbtn, LV_STATE_FOCUS_KEY);
}
break;
case 7:
if(page_id == 1 && i==2){
lv_obj_add_state(imgbtn, LV_STATE_FOCUS_KEY);
}
break;
case 8:
if(page_id == 2 && i==0){
lv_obj_add_state(imgbtn, LV_STATE_FOCUS_KEY);
}
break;
case 9:
if(page_id == 2 && i==1){
lv_obj_add_state(imgbtn, LV_STATE_FOCUS_KEY);
}
break;
case 10:
if(page_id == 2 && i==2){
lv_obj_add_state(imgbtn, LV_STATE_FOCUS_KEY);
}
break;
default:
if(page_id == 0 && i==0){
lv_obj_add_state(imgbtn, LV_STATE_FOCUS_KEY);
}
break;
}
lv_obj_t * label = lv_label_create(imgbtn);
const LAN_STR_ID Str_id = get_equipment_is_str(cur_menu_id);
lv_label_set_text_fmt(label, "%s",lan_str_table[Str_id][Get_sys_language()]);
lv_obj_center(label);
}
lv_obj_clear_flag(mainmenu_btn_win, LV_OBJ_FLAG_SCROLL_ELASTIC);
lv_obj_clear_flag(mainmenu_btn_win, LV_OBJ_FLAG_GESTURE_BUBBLE);
}
ENUM_MAINMENU_ITEM_ID Get_menu_btn_item(uint32_t btn_count)
{
switch(btn_count)
{
case 0:
break;
case 1:
break;
case 2:
break;
default:
break;
}
return MAINMENU_ITEM_ID_MAX;
}
ENUM_MAINMENU_ITEM_ID Get_menu_item(uint32_t page_count ,uint32_t btn_count)
{
switch(page_count)
{
case 0:
break;
case 1:
break;
case 2:
break;
default:
break;
}
return MAINMENU_ITEM_ID_MAX;
}
void SubmenuBtnEnter(lv_obj_t * scr_parent_main , uint32_t page_count ,uint32_t btn_count)
{
uint8_t mainmenu_item_sum = 0;
uint8_t page_num = 0;
uint8_t tile_item_count = COMMON_PER_PAGE_NUM;
lv_obj_t *submenu_win = lv_obj_create(scr_parent_main);
lv_obj_set_scrollbar_mode(submenu_win, LV_SCROLLBAR_MODE_OFF);
lv_obj_set_size(submenu_win, LV_PCT(100), LV_PCT(100));
lv_obj_set_style_pad_all(submenu_win, 0, 0);
lv_obj_set_style_radius(submenu_win, 0, 0);
lv_obj_set_style_border_width(submenu_win, 0, LV_PART_MAIN);
lv_obj_set_style_border_color(submenu_win, lv_color_black(), 0);
lv_obj_clear_flag(submenu_win, LV_OBJ_FLAG_SCROLLABLE);
// ENUM_MAINMENU_ITEM_ID page_type = Get_menu_item(page_count,btn_count);
// printf("SubmenuBtnEnter ====== page_count = %d ,btn_count = %d .page_type = %d\n",page_count,btn_count,page_type);
//
// uint32_t last_item_pos = mainmenu_item_sum % COMMON_PER_PAGE_NUM;
uint32_t dis_item_arr[MAINMENU_TILE_END][COMMON_PER_PAGE_NUM];
memset(dis_item_arr, 0, sizeof(dis_item_arr));
get_display_equipment_str(dis_item_arr);
// last_item_pos == 0 ? \
// (dis_item_arr[page_num-1][COMMON_PER_PAGE_NUM-1]=STR_ID_DEVICE_MANAGE) : \
// (dis_item_arr[page_num-1][last_item_pos-1]=STR_ID_DEVICE_MANAGE);
getDeviceEntryByStrId(dis_item_arr[page_count][btn_count]);
// printf("dis_item_arr = %d \n",dis_item_arr[page_count][btn_count]);
}
/**************************************************************************************/
static void scroll_begin_event(lv_event_t * e)
{
/*Disable the scroll animations. Triggered when a tab button is clicked */
if(lv_event_get_code(e) == LV_EVENT_SCROLL_BEGIN) {
lv_anim_t * a = lv_event_get_param(e);
if(a) a->time = 0;
}
}
static void scroll_event_cb(lv_event_t * e)
{
lv_obj_t * cont = lv_event_get_target(e);
lv_area_t cont_a;
lv_obj_get_coords(cont, &cont_a);
lv_coord_t cont_y_center = cont_a.y1 + lv_area_get_height(&cont_a) / 2;
lv_coord_t r = lv_obj_get_height(cont) * 7 / 10;
uint32_t i;
uint32_t child_cnt = lv_obj_get_child_cnt(cont);
for(i = 0; i < child_cnt; i++) {
lv_obj_t * child = lv_obj_get_child(cont, i);
lv_area_t child_a;
lv_obj_get_coords(child, &child_a);
lv_coord_t child_y_center = child_a.y1 + lv_area_get_height(&child_a) / 2;
lv_coord_t diff_y = child_y_center - cont_y_center;
diff_y = LV_ABS(diff_y);
/*Get the x of diff_y on a circle.*/
lv_coord_t x;
/*If diff_y is out of the circle use the last point of the circle (the radius)*/
if(diff_y >= r) {
x = r;
} else {
/*Use Pythagoras theorem to get x from radius and y*/
uint32_t x_sqr = r * r - diff_y * diff_y;
lv_sqrt_res_t res;
lv_sqrt(x_sqr, &res, 0x8000); /*Use lvgl's built in sqrt root function*/
x = r - res.i;
}
/*Translate the item by the calculated X coordinate*/
lv_obj_set_style_translate_x(child, x, 0);
/*Use some opacity with larger translations*/
lv_opa_t opa = lv_map(x, 0, r, LV_OPA_TRANSP, LV_OPA_COVER);
lv_obj_set_style_opa(child, LV_OPA_COVER - opa, 0);
}
}
void test(lv_obj_t* parent)
{
lv_obj_t *mainmenu_win = lv_obj_create(parent);
lv_obj_set_style_bg_color(mainmenu_win, lv_color_make(0x00, 0x00, 0x00), 0);
lv_obj_set_scrollbar_mode(mainmenu_win, LV_SCROLLBAR_MODE_OFF);
lv_obj_set_size(mainmenu_win, LV_PCT(100), LV_PCT(100));
lv_obj_set_style_pad_all(mainmenu_win, 0, 0);
lv_obj_set_style_radius(mainmenu_win, 0, 0);
lv_obj_set_style_border_width(mainmenu_win, 0, LV_PART_MAIN);
lv_obj_set_style_border_color(mainmenu_win, lv_color_black(), 0);
lv_obj_clear_flag(mainmenu_win, LV_OBJ_FLAG_SCROLLABLE);
// lv_obj_t *mainmenu_win = NULL;
// gui_create_new_window(mainmenu_win);
Set_UI_page_id(PAGE_MAINMENU_WIN_ID);
// app_menu_comm_entry(mainmenu_win,PAGE_MAINMENU_WIN_ID,false);
// #if !MMI_WIN32_SIM
// lv_group_t *g = lv_get_keypad_group();
// lv_group_remove_all_objs(g);
// lv_group_add_obj(g, mainmenu_win);
// #endif
uint8_t style_num =1;
lv_obj_t * cont = NULL;
lv_obj_t * cont_parent = NULL;
uint8_t i =0;
static lv_style_t style;
lv_obj_t *tabview;
switch(style_num)
{
case 0:
/*Create a Tab view object*/
tabview = lv_tabview_create(lv_scr_act(), LV_DIR_LEFT, 100);
lv_obj_add_event_cb(lv_tabview_get_content(tabview), scroll_begin_event, LV_EVENT_SCROLL_BEGIN, NULL);
lv_obj_set_style_bg_color(tabview, lv_palette_lighten(LV_PALETTE_RED, 2), 0);
lv_obj_t * tab_btns = lv_tabview_get_tab_btns(tabview);
lv_obj_set_style_bg_color(tab_btns, lv_palette_darken(LV_PALETTE_GREY, 3), 0);
lv_obj_set_style_text_color(tab_btns, lv_palette_lighten(LV_PALETTE_GREY, 5), 0);
lv_obj_set_style_border_side(tab_btns, LV_BORDER_SIDE_RIGHT, LV_PART_ITEMS | LV_STATE_CHECKED);
/*Add 3 tabs (the tabs are page (lv_page) and can be scrolled*/
lv_obj_t *tab1 = lv_tabview_add_tab(tabview, "Tab 1");
lv_obj_set_size(tab1, LV_PCT(100), LV_PCT(100));
lv_obj_t *tab2 = lv_tabview_add_tab(tabview, "Tab 2");
lv_obj_set_size(tab2, LV_PCT(100), LV_PCT(100));
lv_obj_t *tab3 = lv_tabview_add_tab(tabview, "Tab 3");
lv_obj_set_size(tab3, LV_PCT(100), LV_PCT(100));
lv_obj_t *tab4 = lv_tabview_add_tab(tabview, "Tab 4");
lv_obj_set_size(tab4, LV_PCT(100), LV_PCT(100));
lv_obj_t *tab5 = lv_tabview_add_tab(tabview, "Tab 5");
lv_obj_set_size(tab5, LV_PCT(100), LV_PCT(100));
lv_obj_set_style_bg_color(tab2, lv_palette_lighten(LV_PALETTE_AMBER, 3), 0);
lv_obj_set_style_bg_opa(tab2, LV_OPA_COVER, 0);
/*Add content to the tabs*/
lv_obj_t * label = lv_label_create(tab1);
lv_label_set_text(label, "First tab 1111111111111111");
label = lv_label_create(tab2);
lv_label_set_text(label, "Second tab 2222222222222222");
label = lv_label_create(tab3);
lv_label_set_text(label, "Third tab 333333333333333333333");
label = lv_label_create(tab4);
lv_label_set_text(label, "Forth tab 444");
label = lv_label_create(tab5);
lv_label_set_text(label, "Fifth tab 5");
// lv_obj_clear_flag(lv_tabview_get_content(tabview), LV_OBJ_FLAG_SCROLLABLE);
// //横向按钮列表
// cont = lv_obj_create(mainmenu_win);
// lv_obj_set_size(cont, lv_pct(100), lv_pct(100));
// lv_obj_center(cont);
// lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW );
// lv_obj_add_event_cb(cont, scroll_event_cb, LV_EVENT_SCROLL, NULL);
// lv_obj_set_style_radius(cont, LV_RADIUS_CIRCLE, 0);//圆弧框
// lv_obj_set_style_clip_corner(cont, true, 0);//隐藏四个角落
// lv_obj_set_scroll_dir(cont, LV_DIR_VER);
// lv_obj_set_scroll_snap_y(cont, LV_SCROLL_SNAP_CENTER);
// lv_obj_set_scrollbar_mode(cont, LV_SCROLLBAR_MODE_OFF);
// lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
//
// for(i = 0; i < 7; i++) {
// lv_obj_t * btn = lv_btn_create(cont);
// lv_obj_set_width(btn, 100);
// lv_obj_set_height(btn, lv_pct(70));
//
// lv_obj_t * label = lv_label_create(btn);
// lv_label_set_text_fmt(label, "%d", i);
// }
//
// lv_event_send(cont, LV_EVENT_SCROLL, NULL);
//
// lv_obj_scroll_to_view(lv_obj_get_child(cont, 0), LV_ANIM_OFF);
break;
case 1:
//弧形按钮列表
cont_parent = lv_obj_create(mainmenu_win);
lv_obj_set_size(cont_parent, 180, lv_pct(100));
lv_obj_align(cont_parent,LV_ALIGN_TOP_LEFT, 0, 0);
lv_obj_set_style_bg_color(cont_parent, lv_color_hex(0xff0000), 0);
lv_obj_clear_flag(cont_parent, LV_OBJ_FLAG_SCROLLABLE);
cont = lv_obj_create(cont_parent);
lv_obj_set_size(cont, 150, 150);
lv_obj_center(cont);
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
lv_obj_add_event_cb(cont, scroll_event_cb, LV_EVENT_SCROLL, NULL);
lv_obj_set_style_radius(cont, LV_RADIUS_CIRCLE, 0);//圆弧框
lv_obj_set_style_clip_corner(cont, true, 0);//隐藏四个角落
lv_obj_set_scroll_dir(cont, LV_DIR_VER);
lv_obj_set_scroll_snap_y(cont, LV_SCROLL_SNAP_CENTER);
lv_obj_set_scrollbar_mode(cont, LV_SCROLLBAR_MODE_OFF);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
for(i = 0; i < 7; i++) {
lv_obj_t * btn = lv_btn_create(cont);
lv_obj_set_width(btn, lv_pct(90));
lv_obj_set_height(btn, lv_pct(70));
lv_obj_t * label = lv_label_create(btn);
lv_label_set_text_fmt(label, "%d", i);
}
lv_event_send(cont, LV_EVENT_SCROLL, NULL);
lv_obj_scroll_to_view(lv_obj_get_child(cont, 0), LV_ANIM_OFF);
break;
case 2:
//循环滚动列表
lv_style_init(&style);
lv_style_set_bg_color(&style, lv_color_black());
lv_style_set_text_color(&style, lv_color_hex(0x5e0000));
lv_style_set_border_width(&style, 0);
lv_style_set_pad_all(&style, 0);
lv_obj_add_style(mainmenu_win, &style, 0);
lv_obj_t *roller1 = lv_roller_create(mainmenu_win);
lv_obj_add_style(roller1, &style, 0);
// lv_obj_set_style_bg_opa(roller1, LV_OPA_TRANSP, LV_PART_SELECTED);
lv_roller_set_options(roller1,
"January\n"
"February\n"
"March\n"
"April\n"
"May\n"
"June\n"
"July\n"
"August\n"
"September\n"
"October\n"
"November\n"
"December",
LV_ROLLER_MODE_INFINITE);
lv_obj_center(roller1);
lv_roller_set_visible_row_count(roller1, 3);
break;
}
}