@zr #include "lvgl.h"
#include "stdlib.h"
#include "stdio.h"
#include "gui_guider.h"
#include "ui_manager.h"
#include "ble_handle.h"
#include "key_handle.h"
#include "func.h"
#include <math.h>
#define BTN_HEIGHT 32 // 按键高度(固定,可根据需求调整)
#define BTN_WIDTH 200 // 按键宽度
#define PAGE_MAX_BTN 5 // 页面最大按钮数
#define BTN_MAX_NUM 5 // 总共按钮数
static const char *btn_text[] = {
"device",
"Relief",
"20min",
"Favorite",
"Start",
};
static void update_channel_info(void);
static uint8_t mainChoose_start_index = 0; // 主界面起始选项起始下标
static lv_coord_t btn_y[BTN_MAX_NUM] = {45, 79, 114, 149, 184};
static lv_coord_t btn_width[BTN_MAX_NUM] = {164, 200, 195, 149, 124};
static lv_style_t choose_btn;
static lv_style_t nochoose_btn;
static lv_style_t startnochoose_btn;
static lv_style_t style_arrow;
static lv_style_t nostyle_arrow;
static lv_obj_t *btn[BTN_MAX_NUM];
static lv_obj_t *btn_num_label[BTN_MAX_NUM] = {NULL}; // 数字标签指针
static lv_obj_t *btn_text_label[BTN_MAX_NUM] = {NULL}; // 文本标签指针(全部按钮)
static lv_obj_t *sym[BTN_MAX_NUM] = {NULL};
//static lv_obj_t *label;
static const lv_img_dsc_t * line_img[4] = {&_01_alpha_196x4, &_02_alpha_210x4, &_03_alpha_202x4, &_04_alpha_160x4};
const lv_img_dsc_t * device_icon[3] = {&_menu_device1_alpha_27x27, &_menu_device2_alpha_27x27, &_device_all_alpha_64x27};
static uint8_t last_index = 0;
static void btn_eventKey_callback(lv_event_t *e)
{
lv_obj_t *btn = lv_event_get_target(e);
lv_event_code_t code = lv_event_get_code(e);
uint32_t key = lv_event_get_key(e);
uint8_t connect_status, num = (uint8_t)(uintptr_t)lv_obj_get_user_data(btn);
lv_ui *ui = lv_event_get_user_data(e);
struct DEVINFO *dev = get_dev();
struct OUTINFO * current_out = get_out(dev->currentch);
if (ui->choose_page == NULL)
return;
if (code == LV_EVENT_KEY)
{
switch(key)
{
case LV_KEY_ENTER:
switch(num)
{
case 1: // 小模式
{
last_index = num;
ui_manager_switch(SLAVEMODE_SCREEN, UI_ANIM_NONE, NULL);
break;
}
case 3: // 喜爱模式
{
last_index = num;
ui_manager_switch(FAVORITE_CHOOSE_SCREEN, UI_ANIM_NONE, NULL);
break;
}
case 4: // 启动
{
last_index = num;
ui_manager_switch(CONTROL_SCREEN, UI_ANIM_NONE, NULL);
break;
}
default:
break;
}
break;
case LV_KEY_LEFT:
switch(num)
{
case 0: // 设备
{
connect_status = get_hosts_status(STATUS_TYPE_CONNECT);
if (connect_status == 0x03)
{
dev->currentch = get_nextDeviceId(dev->currentch, 1);
update_channel_info();
}
else if(connect_status && (dev->currentch == MAX_CHANNEL))
{
if (connect_status == 0x01)
{
dev->currentch = 0;
}
else
{
dev->currentch = 1;
}
update_channel_info();
}
break;
}
case 1: // 小模式
{
if (current_out->slave_mode > MIN_SLAVE_MODE)
current_out->slave_mode--;
else
current_out->slave_mode = MAX_SLAVE_MODE - 1;
device_set_mode(current_out, current_out->master_mode, current_out->slave_mode);
mainPage_slavemode_update(current_out->master_mode, current_out->slave_mode);
// mainPage_strength_update(current_out->strength);
packet_ble_txdata(RUN_DPID, get_dev()->currentch == MAX_CHANNEL ? SYNC_DEVICE_ID : current_out->channel);
break;
}
case 2: // 时间
{
// ========== 减少5分钟(结果对齐到5的倍数) ==========
if (current_out->worktime > MIN_WORK_TIME)
{
// 先转成分钟(向上取整),再对齐到5的倍数,最后减5
uint8_t minutes = (current_out->worktime + 59) / 60;
minutes = ((minutes + 4) / 5) * 5; // 向上对齐到5的倍数
if (minutes > 5)
{
current_out->setworktime = current_out->worktime = (minutes - 5) * 60;
}
else
{
current_out->setworktime = current_out->worktime = MAX_WORK_TIME; // 回绕
}
}
else
{
current_out->setworktime = current_out->worktime = MAX_WORK_TIME;
}
mainPage_worktime_update(current_out->worktime);
packet_ble_txdata(TIME_DPID, get_dev()->currentch == MAX_CHANNEL ? SYNC_DEVICE_ID : current_out->channel);
break;
}
// case 4: // 强度
// {
// if (device_dec_strength(current_out))
// {
// mainPage_strength_update(current_out->strength);
// packet_ble_txdata(RUN_DPID, get_dev()->currentch == MAX_CHANNEL ? SYNC_DEVICE_ID : current_out->channel);
// }
// else // 没有处理任何操作直接return,防止调用sync_setChannelInfo
// return;
// break;
// }
default:
break;
}
break;
case LV_KEY_RIGHT:
{
switch(num)
{
case 0: // 设备
{
connect_status = get_hosts_status(STATUS_TYPE_CONNECT);
if (connect_status == 0x03)
{
dev->currentch = get_nextDeviceId(dev->currentch, 0);
update_channel_info();
}
else if(connect_status && (dev->currentch == MAX_CHANNEL))
{
if (connect_status == 0x01)
{
dev->currentch = 0;
}
else
{
dev->currentch = 1;
}
update_channel_info();
}
break;
}
case 1: // 小模式
{
current_out->slave_mode++;
current_out->slave_mode = current_out->slave_mode % MAX_SLAVE_MODE;
device_set_mode(current_out, current_out->master_mode, current_out->slave_mode);
mainPage_slavemode_update(current_out->master_mode, current_out->slave_mode);
// mainPage_strength_update(current_out->strength);
packet_ble_txdata(RUN_DPID, get_dev()->currentch == MAX_CHANNEL ? SYNC_DEVICE_ID : current_out->channel);
break;
}
case 2: // 时间
{
// ========== 增加5分钟(结果对齐到5的倍数) ==========
if (current_out->worktime < MAX_WORK_TIME)
{
// 先转成分钟(向上取整),再对齐到5的倍数,再加5
uint8_t minutes = (current_out->worktime + 59) / 60;
minutes = (minutes / 5) * 5; // 向上对齐到5的倍数
if (minutes <= (MAX_WORK_TIME / 60 - 5))
{
current_out->setworktime = current_out->worktime = (minutes + 5) * 60;
}
else
{
current_out->setworktime = current_out->worktime = MIN_WORK_TIME; // 回绕
}
}
else
{
current_out->setworktime = current_out->worktime = MIN_WORK_TIME;
}
mainPage_worktime_update(current_out->worktime);
packet_ble_txdata(TIME_DPID, get_dev()->currentch == MAX_CHANNEL ? SYNC_DEVICE_ID : current_out->channel);
break;
}
// case 4: // 强度
// {
// if (device_add_strength(current_out))
// {
// mainPage_strength_update(current_out->strength);
// packet_ble_txdata(RUN_DPID, get_dev()->currentch == MAX_CHANNEL ? SYNC_DEVICE_ID : current_out->channel);
// }
// else // 没有处理任何操作直接return,防止调用sync_setChannelInfo
// return;
// break;
// }
default:
break;
}
break;
}
case LV_KEY_DOUBLE:
{
current_out->pause = !current_out->pause;
packet_ble_txdata(RUN_DPID, get_dev()->currentch == MAX_CHANNEL ? SYNC_DEVICE_ID : current_out->channel);
mainPage_pause_update(current_out->pause);
break;
}
default:
return;
}
if (dev->currentch == MAX_CHANNEL && (num != 0 || key == LV_KEY_DOUBLE)) // 同步通道下调整了设置,自动进入同步模式(设备切换除外)
sync_setChannelInfo();
else if (dev->currentch != MAX_CHANNEL && (num != 0 || key == LV_KEY_DOUBLE)) // 独立通道下调整了设置,自动退出同步模式(设备切换除外)
exit_syncMode();
}
}
void mainPage_device_update(uint8_t channel)
{
if (guider_ui.choose_page == NULL)
return;
lv_img_set_src(sym[0], device_icon[channel]);
}
void mainPage_slavemode_update(uint8_t masterMode, uint8_t slaveMode)
{
if (guider_ui.choose_page == NULL)
return;
lv_label_set_text(btn_text_label[1], slave_btn_text[slaveMode]);
}
void mainPage_worktime_update(uint16_t time)
{
uint8_t min = (time - 1) / 60 + 1;
if (guider_ui.choose_page == NULL || btn_num_label[2] == NULL)
return;
lv_label_set_text_fmt(btn_num_label[2], "%02d", min);
}
void mainPage_mode_update(uint8_t slave_mode)
{
if (guider_ui.choose_page == NULL)
return;
mainPage_slavemode_update(0, slave_mode);
}
// void mainPage_strength_update(uint16_t strength)
// {
// if (guider_ui.choose_page == NULL)
// return;
// lv_label_set_text_fmt(btn_num_label[4], "%02d", strength);
// }
void mainPage_pause_update(uint8_t pause)
{
if (guider_ui.choose_page == NULL)
return;
if (pause)
{
lv_img_set_src(sym[2], &_pause_alpha_18x18);
lv_obj_set_style_img_recolor_opa(sym[2], LV_OPA_0, 0);
}
else
{
lv_img_set_src(sym[2], &_time_alpha_18x18);
lv_obj_set_style_img_recolor_opa(sym[2], LV_OPA_COVER, 0);
}
}
// CHOOSE_MENU的style初始化
static void style_init(void)
{
lv_style_init(&choose_btn);
lv_style_set_radius(&choose_btn, 50);
lv_style_set_bg_color(&choose_btn, lv_color_hex(UI_MAIN_COLOR));
lv_style_set_bg_opa(&choose_btn, 255);
lv_style_set_height(&choose_btn, BTN_HEIGHT);
lv_style_set_text_align(&choose_btn, LV_TEXT_ALIGN_CENTER);
lv_style_set_text_color(&choose_btn, lv_color_hex(0x000000));
lv_style_set_shadow_opa(&choose_btn, LV_OPA_TRANSP); // 阴影透明
lv_style_set_shadow_width(&choose_btn, 0); // 阴影宽度0
lv_style_set_border_opa(&choose_btn, 0);
// 关闭过渡动画(关键)
lv_style_set_transition(&choose_btn, NULL);
lv_style_init(&nochoose_btn);
lv_style_set_radius(&nochoose_btn, 50);
lv_style_set_bg_color(&nochoose_btn, lv_color_hex(0x000000));
lv_style_set_bg_opa(&nochoose_btn, 0);
lv_style_set_height(&nochoose_btn, BTN_HEIGHT);
lv_style_set_text_align(&nochoose_btn, LV_TEXT_ALIGN_CENTER);
lv_style_set_text_color(&nochoose_btn, lv_color_hex(UI_MAIN_COLOR));
lv_style_set_shadow_opa(&nochoose_btn, LV_OPA_TRANSP); // 阴影透明
lv_style_set_shadow_width(&nochoose_btn, 0); // 阴影宽度0
lv_style_set_border_opa(&nochoose_btn, 0);
// 关闭过渡动画(关键)
lv_style_set_transition(&nochoose_btn, NULL);
lv_style_init(&startnochoose_btn);
lv_style_set_radius(&startnochoose_btn, 50);
lv_style_set_bg_color(&startnochoose_btn, lv_color_hex(0x000000));
lv_style_set_bg_opa(&startnochoose_btn, 0);
lv_style_set_height(&startnochoose_btn, BTN_HEIGHT);
lv_style_set_text_align(&startnochoose_btn, LV_TEXT_ALIGN_CENTER);
lv_style_set_text_color(&startnochoose_btn, lv_color_hex(UI_MAIN_COLOR));
lv_style_set_shadow_opa(&startnochoose_btn, LV_OPA_TRANSP); // 阴影透明
lv_style_set_shadow_width(&startnochoose_btn, 0); // 阴影宽度0
lv_style_set_border_color(&startnochoose_btn, lv_color_hex(UI_MAIN_COLOR));
lv_style_set_border_width(&startnochoose_btn, 2);
lv_style_set_border_opa(&startnochoose_btn, 255);
// 关闭过渡动画(关键)
lv_style_set_transition(&startnochoose_btn, NULL);
lv_style_init(&style_arrow);
lv_style_set_text_opa(&style_arrow, 255);
// 关闭过渡动画(关键)
lv_style_set_transition(&style_arrow, NULL);
lv_style_init(&nostyle_arrow);
lv_style_set_text_opa(&nostyle_arrow, 0);
// 关闭过渡动画(关键)
lv_style_set_transition(&nostyle_arrow, NULL);
}
static void refresh_all_btn_pos(lv_ui *ui)
{
uint8_t index = 0;
// 重置按钮位置
for (index = 0; index < BTN_MAX_NUM; index++)
{
if (index >= (mainChoose_start_index + PAGE_MAX_BTN) || index < mainChoose_start_index)
{ // 超出屏幕显示数量的按钮放到屏幕外面
lv_obj_set_size(btn[index], btn_width[index], 33);
lv_obj_align(btn[index], LV_ALIGN_TOP_MID, 0, 0);
lv_obj_set_y(btn[index], 250);
}
else
{
lv_obj_set_size(btn[index], btn_width[index - mainChoose_start_index], 33);
lv_obj_align(btn[index], LV_ALIGN_TOP_MID, 0, 0);
lv_obj_set_y(btn[index], btn_y[index - mainChoose_start_index]);
}
}
}
// 更新子对象状态
static void sync_focus_state_to_children(lv_obj_t *parent, lv_ui *ui) {
// 判断父对象是否处于聚焦状态
uint8_t index = 0;
uint8_t num = 0;
bool is_focused = lv_obj_has_state(parent, LV_STATE_FOCUSED);
co_printf("sync_focus_state_to_children\r\n");
// 遍历父对象的所有子对象(箭头、文字等)
lv_obj_t *child = lv_obj_get_child(parent, 0);
num = (uint8_t)(uintptr_t)lv_obj_get_user_data(parent);
while(child != NULL) {
if(is_focused) {
// 子对象添加聚焦状态
lv_obj_add_state(child, LV_STATE_FOCUSED);
last_index = num;
if (sym[num] != NULL)
lv_obj_set_style_img_recolor(sym[num], lv_color_hex(0x000000), 0);
} else {
// 子对象清除聚焦状态
lv_obj_clear_state(child, LV_STATE_FOCUSED);
if (sym[num] != NULL)
lv_obj_set_style_img_recolor(sym[num], lv_color_hex(UI_MAIN_COLOR), 0);
}
// 切换到下一个子对象
child = lv_obj_get_child(parent, lv_obj_get_child_id(child) + 1);
}
if (is_focused)
{ // 获取当前焦点下标
num = (uint8_t)(uintptr_t)lv_obj_get_user_data(parent);
// 根据当前焦点的下标判断是否移动起始下标
if (num < mainChoose_start_index)
{
mainChoose_start_index--;
refresh_all_btn_pos(ui);
}
else if (num >= (mainChoose_start_index + PAGE_MAX_BTN))
{
mainChoose_start_index++;
refresh_all_btn_pos(ui);
}
}
for (index = 0; index < 3; index++)
{
// 隐藏当前选项的上一线条
if ((num - mainChoose_start_index) == index)
lv_obj_add_flag(ui->choose_page_img[index], LV_OBJ_FLAG_HIDDEN);
else
lv_obj_clear_flag(ui->choose_page_img[index], LV_OBJ_FLAG_HIDDEN);
}
}
// 按钮状态变化事件回调
static void btn_state_change_cb(lv_event_t *e) {
lv_obj_t *btn = lv_event_get_target(e);
lv_event_code_t code = lv_event_get_code(e);
lv_ui *ui = lv_event_get_user_data(e);
if (ui->choose_page == NULL)
return;
sync_focus_state_to_children(btn, ui);
}
static void update_channel_info(void)
{
struct OUTINFO * current_out = get_out(get_dev()->currentch);
uint8_t min = (current_out->worktime - 1) / 60 + 1;
lv_img_set_src(sym[0], device_icon[get_dev()->currentch]);
lv_label_set_text(btn_text_label[1], slave_btn_text[current_out->slave_mode]);
mainPage_pause_update(current_out->pause);
lv_label_set_text_fmt(btn_num_label[2], "%02d", min);
lv_label_set_text(btn_text_label[2], "min");
}
void create_mainChoose_page(lv_ui *ui)
{
uint8_t index = 0;
struct OUTINFO * current_out = get_out(get_dev()->currentch);
uint8_t min = (current_out->worktime - 1) / 60 + 1;
const lv_coord_t line_x[4] = {23, 16, 20, 41};
const lv_coord_t line_y[4] = {78, 112, 147, 182};
co_printf("enter create_mainChoose_page\r\n");
style_init();
//Write codes choose_page
ui->choose_page = lv_obj_create(lv_scr_act());
lv_obj_remove_style_all(ui->choose_page);
lv_obj_set_size(ui->choose_page, 240, 240);
lv_obj_set_scrollbar_mode(ui->choose_page, LV_SCROLLBAR_MODE_OFF);
//Write style for choose_page, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
lv_obj_set_style_bg_opa(ui->choose_page, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_bg_color(ui->choose_page, lv_color_hex(0x000000), LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_bg_grad_dir(ui->choose_page, LV_GRAD_DIR_NONE, LV_PART_MAIN|LV_STATE_DEFAULT);
//Write codes choose_page_img
for (index = 0; index < 3; index++)
{
ui->choose_page_img[index] = lv_img_create(ui->choose_page);
lv_obj_add_flag(ui->choose_page_img[index], LV_OBJ_FLAG_CLICKABLE);
lv_img_set_src(ui->choose_page_img[index], line_img[index]);
lv_img_set_pivot(ui->choose_page_img[index], 50,50);
lv_img_set_angle(ui->choose_page_img[index], 0);
lv_obj_set_pos(ui->choose_page_img[index], line_x[index], line_y[index]);
lv_obj_set_size(ui->choose_page_img[index], line_img[index]->header.w, line_img[index]->header.h);
//Write style for choose_page_img, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
lv_obj_set_style_img_recolor_opa(ui->choose_page_img[index], 0, LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_img_opa(ui->choose_page_img[index], 255, LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_radius(ui->choose_page_img[index], 0, LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_set_style_clip_corner(ui->choose_page_img[index], true, LV_PART_MAIN|LV_STATE_DEFAULT);
}
lv_obj_clear_flag(ui->choose_page, LV_OBJ_FLAG_SCROLLABLE);
for (index = 0; index < BTN_MAX_NUM; index++)
{
/**************
** 按键初始化(保持不变)
**************/
btn[index] = lv_btn_create(ui->choose_page);
lv_obj_set_style_outline_width(btn[index], 0, LV_STATE_FOCUS_KEY);
lv_obj_set_size(btn[index], btn_width[index - mainChoose_start_index], 33);
lv_obj_align(btn[index], LV_ALIGN_TOP_MID, 0, 0);
lv_obj_remove_style(btn[index], NULL, LV_STATE_PRESSED); // 移除按下时的缩放动画
if (index >= (mainChoose_start_index + PAGE_MAX_BTN) || index < mainChoose_start_index)
lv_obj_set_y(btn[index], 250);
else
lv_obj_set_y(btn[index], btn_y[index - mainChoose_start_index]);
lv_obj_set_user_data(btn[index], (void *)(uintptr_t)index);
// lv_obj_add_style(btn[index], &choose_btn, LV_STATE_FOCUSED); // 不能在这里设置样式,切换界面时选项会闪烁
if (index == 4)
{
lv_obj_add_style(btn[index], &startnochoose_btn, LV_STATE_DEFAULT);
}
else
{
lv_obj_add_style(btn[index], &nochoose_btn, LV_STATE_DEFAULT);
}
// 设置flex布局(所有按钮统一用 SPACE_BETWEEN,保证左右箭头贴边)
lv_obj_set_flex_flow(btn[index], LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(btn[index], LV_FLEX_ALIGN_SPACE_BETWEEN,
LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_style_pad_left(btn[index], 5, LV_STATE_DEFAULT);
lv_obj_set_style_pad_right(btn[index], 5, LV_STATE_DEFAULT);
// 添加事件回调(保持不变)
lv_obj_add_event_cb(btn[index], btn_state_change_cb, LV_EVENT_FOCUSED, ui);
lv_obj_add_event_cb(btn[index], btn_state_change_cb, LV_EVENT_DEFOCUSED, ui);
lv_obj_add_event_cb(btn[index], btn_eventKey_callback, LV_EVENT_KEY, ui);
/**************
** 左箭头(所有按钮都有)
**************/
lv_obj_t *arrow_left = lv_label_create(btn[index]);
lv_label_set_text(arrow_left, "\xE2\x97\x80");
lv_obj_set_style_text_font(arrow_left, &lv_font_SourceHanSerifSC_Regular_16, LV_STATE_DEFAULT);
lv_obj_add_style(arrow_left, &style_arrow, LV_STATE_FOCUSED);
lv_obj_add_style(arrow_left, &nostyle_arrow, LV_STATE_DEFAULT);
if ((index == 3) || (index == 4))
{
lv_obj_add_style(arrow_left, &nostyle_arrow, LV_STATE_FOCUSED);
}
/**************
** 中间内容区(区分处理)
**************/
if (index == 0)
{
lv_obj_t *mid = lv_obj_create(btn[index]);
lv_obj_remove_style_all(mid); // 去掉默认边框、背景
lv_obj_set_size(mid, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_flex_grow(mid, 1); // 占据中间所有剩余空间
lv_obj_set_flex_flow(mid, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(mid, LV_FLEX_ALIGN_CENTER, // 水平居中
LV_FLEX_ALIGN_CENTER, // 垂直居中
LV_FLEX_ALIGN_CENTER);
sym[index] = lv_img_create(mid);
lv_img_set_src(sym[index], device_icon[get_dev()->currentch]);
// 重新着色
set_img_recolor(sym[index], UI_MAIN_COLOR);
// lv_obj_set_style_img_recolor(sym[index], lv_color_hex(UI_MAIN_COLOR), 0);
// lv_obj_set_style_img_recolor_opa(sym[index], LV_OPA_COVER, 0);
}
else if (index == 2)
{
// 特殊按钮:左箭头 | [符号 数字 文本] | 右箭头
// 中间整体用一个容器包裹,内部居中对齐
lv_obj_t *mid = lv_obj_create(btn[index]);
lv_obj_remove_style_all(mid); // 去掉默认边框、背景
lv_obj_set_size(mid, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_flex_grow(mid, 1); // 占据中间所有剩余空间
lv_obj_set_flex_flow(mid, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(mid, LV_FLEX_ALIGN_CENTER, // 水平居中
LV_FLEX_ALIGN_CENTER, // 垂直居中
LV_FLEX_ALIGN_CENTER);
lv_obj_set_style_pad_column(mid, 3, 0); // 符号/数字/文本之间的间距
// 1) 符号
sym[index] = lv_img_create(mid);//lv_label_create(mid);
// 重新着色
set_img_recolor(sym[index], UI_MAIN_COLOR);
if ((index == 2))
{
mainPage_pause_update(current_out->pause);
}
// lv_obj_set_style_img_recolor(sym[index], lv_color_hex(UI_MAIN_COLOR), 0);
// lv_obj_set_style_img_recolor_opa(sym[index], LV_OPA_COVER, 0);
// 2) 数字(可变,保存指针方便后续更新)
if (index == 2) // 时间初始值
{
btn_num_label[index] = lv_label_create(mid);
lv_obj_set_style_text_font(btn_num_label[index], &lv_font_arialbd_20, 0);
lv_label_set_text_fmt(btn_num_label[index], "%02d", min);
}
// 3) 单位文本
if ((index == 2))
{
btn_text_label[index] = lv_label_create(mid);
lv_obj_set_style_text_font(btn_text_label[index], &lv_font_Arial_16, 0);
lv_label_set_text(btn_text_label[index], "min");
}
}
else
{
// 普通按钮:左箭头 | 文本 | 右箭头
btn_text_label[index] = lv_label_create(btn[index]);
switch(index)
{
case 1:
lv_label_set_text(btn_text_label[index], slave_btn_text[current_out->slave_mode]);
break;
default:
lv_label_set_text(btn_text_label[index], btn_text[index]);
break;
}
lv_obj_set_style_text_font(btn_text_label[index], &lv_font_arialbd_20, LV_STATE_DEFAULT);
if (index != 4)
{ // 除最后一项收藏按钮只有文本外,其余选项均采用flex布局
lv_obj_set_flex_grow(btn_text_label[index], 1); // 文本标签占据按钮内所有剩余空间
// lv_label_set_long_mode(btn_text_label[index], LV_LABEL_LONG_SCROLL);
// 普通按钮文本在flex_grow后自然占据中间,配合SPACE_BETWEEN即可
}
}
/**************
** 右箭头(所有按钮都有)
**************/
lv_obj_t *arrow_right = lv_label_create(btn[index]);
lv_label_set_text(arrow_right, "\xE2\x96\xB6");
lv_obj_set_style_text_font(arrow_right, &lv_font_SourceHanSerifSC_Regular_16, LV_STATE_DEFAULT);
lv_obj_add_style(arrow_right, &style_arrow, LV_STATE_FOCUSED);
lv_obj_add_style(arrow_right, &nostyle_arrow, LV_STATE_DEFAULT);
// 收藏按钮不需要左右箭头直接隐藏
if ((index == 3) || (index == 4))
{
lv_obj_add_style(arrow_right, &nostyle_arrow, LV_STATE_FOCUSED);
}
if ((index == 3) || (index == 4))
{
lv_obj_add_style(arrow_right, &nostyle_arrow, LV_STATE_FOCUSED);
}
}
lv_group_set_wrap(lv_group_get_default(), false);
lv_group_focus_obj(btn[last_index]);
for (index = 0; index < BTN_MAX_NUM; index++)
{
lv_obj_add_style(btn[index], &choose_btn, LV_STATE_FOCUSED);
}
co_printf("exit create_mainChoose_page\r\n");
lv_obj_update_layout(ui->choose_page);
}
/// 创建开机页面UI
static lv_obj_t *ui_mainChoose_create(void)
{
create_mainChoose_page(&guider_ui);
return guider_ui.choose_page;
}
/// 进入开机页面
static void ui_mainChoose_enter(void* param)
{
(void)param;
}
/// 退出开机页面
static void ui_mainChoose_exit(void)
{
uint8_t i = 0;
get_guiderUi_struct()->choose_page = NULL; //切换页面,置为NULL后续此界面的回调函数全停止处理防止读取到以及释放的资源
lv_style_reset(&choose_btn);
lv_style_reset(&nochoose_btn);
lv_style_reset(&style_arrow);
lv_style_reset(&nostyle_arrow);
for (i = 0; i < BTN_MAX_NUM; i++)
{
if (sym[i] != NULL)
{
lv_obj_del(sym[i]);
sym[i] = NULL;
}
if (btn_num_label[i] != NULL)
{
lv_obj_del(btn_num_label[i]);
btn_num_label[i] = NULL;
}
if (btn_text_label[i] != NULL)
{
lv_obj_del(btn_text_label[i]);
btn_text_label[i] = NULL;
}
if (btn[i] != NULL)
{
lv_obj_del(btn[i]);
btn[i] = NULL;
}
}
}
/// 销毁开机页面
static void ui_mainChoose_destroy(void)
{
// lv_obj_del(label);
}
/// 开机页面操作函数表
const ui_page_ops_t ui_mainChoose_ops = {
.create = ui_mainChoose_create,
.enter = ui_mainChoose_enter,
.exit = ui_mainChoose_exit,
.destroy = ui_mainChoose_destroy
};
[16:11:18.388]收←◆enter create_mainChoose_page
[16:11:18.771]收←◆sync_focus_state_to_children
[16:11:18.995]收←◆sync_focus_state_to_children
[16:11:19.043]收←◆exit create_mainChoose_page
LVGL生成一帧内部耗时太长,请问可以怎么改进优化,芯片FR800GP-U