Description
I try to make my code into several blocks to make it more clear to understand. So I create a function to initial my keyboard style. Then I put the funciton into another file, but it can’t work.
What MCU/Processor/Board and compiler are you using?
What do you experience?
Give a detailed description. “It doesn’t work” is not enough information for us to diagnose the issue.
What do you expect?
To make code more clear.
Code to reproduce
version A, this version achieve my expect and is an original version.
...
static lv_style_t style_kb;
static lv_style_t style_kb_rel;
static lv_style_t style_kb_pr;
static void create_keyboard(lv_obj_t* parent)
{
/* 键盘样式 */
//KeyBoard_Style_Init();
lv_style_copy(&style_kb, &lv_style_plain);
style_kb.body.opa = LV_OPA_70;
style_kb.body.main_color = lv_color_hex3(0x333);
style_kb.body.grad_color = lv_color_hex3(0x333);
style_kb.body.padding.left = 0;
style_kb.body.padding.right = 0;
style_kb.body.padding.top = 0;
style_kb.body.padding.bottom = 0;
style_kb.body.padding.inner = 0;
lv_style_copy(&style_kb_rel, &lv_style_plain);
style_kb_rel.body.opa = LV_OPA_TRANSP;
style_kb_rel.body.radius = 0;
style_kb_rel.body.border.width = 1;
style_kb_rel.body.border.color = LV_COLOR_SILVER;
style_kb_rel.body.border.opa = LV_OPA_50;
style_kb_rel.body.main_color = lv_color_hex3(0x333); /*Recommended if LV_VDB_SIZE == 0 and bpp > 1 fonts are used*/
style_kb_rel.body.grad_color = lv_color_hex3(0x333);
style_kb_rel.text.color = LV_COLOR_WHITE;
lv_style_copy(&style_kb_pr, &lv_style_plain);
style_kb_pr.body.radius = 0;
style_kb_pr.body.opa = LV_OPA_50;
style_kb_pr.body.main_color = LV_COLOR_WHITE;
style_kb_pr.body.grad_color = LV_COLOR_WHITE;
style_kb_pr.body.border.width = 1;
style_kb_pr.body.border.color = LV_COLOR_SILVER;
keyboard = lv_kb_create(parent, NULL);
lv_obj_set_size(keyboard, 800, 150);
lv_obj_align(keyboard, parent, LV_ALIGN_IN_BOTTOM_MID, 0, -10);
lv_kb_set_style(keyboard, LV_KB_STYLE_BG, &style_kb);
lv_kb_set_style(keyboard, LV_KB_STYLE_BTN_REL, &style_kb_rel);
lv_kb_set_style(keyboard, LV_KB_STYLE_BTN_PR, &style_kb_pr);
lv_obj_set_event_cb(keyboard, keyboard_event_cb);
/* 隐藏键盘,只有在选中文本框的时候才打开键盘 */
lv_obj_set_hidden(keyboard, true);
}
version B, I create a function “KeyBoard_Style_Init()” to initial keyboard style, but put it in another file, just call A.c, and give the API interface in the A.h, also, the static variate put into the A.h
static lv_style_t style_kb;
static lv_style_t style_kb_rel;
static lv_style_t style_kb_pr;
bool KeyBoard_Style_Init(void)
{
lv_style_copy(&style_kb, &lv_style_plain);
style_kb.body.opa = LV_OPA_70;
style_kb.body.main_color = lv_color_hex3(0x333);
style_kb.body.grad_color = lv_color_hex3(0x333);
style_kb.body.padding.left = 0;
style_kb.body.padding.right = 0;
style_kb.body.padding.top = 0;
style_kb.body.padding.bottom = 0;
style_kb.body.padding.inner = 0;
lv_style_copy(&style_kb_rel, &lv_style_plain);
style_kb_rel.body.opa = LV_OPA_TRANSP;
style_kb_rel.body.radius = 0;
style_kb_rel.body.border.width = 1;
style_kb_rel.body.border.color = LV_COLOR_SILVER;
style_kb_rel.body.border.opa = LV_OPA_50;
style_kb_rel.body.main_color = lv_color_hex3(0x333); /*Recommended if LV_VDB_SIZE == 0 and bpp > 1 fonts are used*/
style_kb_rel.body.grad_color = lv_color_hex3(0x333);
style_kb_rel.text.color = LV_COLOR_WHITE;
lv_style_copy(&style_kb_pr, &lv_style_plain);
style_kb_pr.body.radius = 0;
style_kb_pr.body.opa = LV_OPA_50;
style_kb_pr.body.main_color = LV_COLOR_WHITE;
style_kb_pr.body.grad_color = LV_COLOR_WHITE;
style_kb_pr.body.border.width = 1;
style_kb_pr.body.border.color = LV_COLOR_SILVER
}
then the code change to like this
static void create_keyboard(lv_obj_t* parent)
{
/* 键盘样式 */
KeyBoard_Style_Init();
keyboard = lv_kb_create(parent, NULL);
lv_obj_set_size(keyboard, 800, 150);
lv_obj_align(keyboard, parent, LV_ALIGN_IN_BOTTOM_MID, 0, -10);
lv_kb_set_style(keyboard, LV_KB_STYLE_BG, &style_kb);
lv_kb_set_style(keyboard, LV_KB_STYLE_BTN_REL, &style_kb_rel);
lv_kb_set_style(keyboard, LV_KB_STYLE_BTN_PR, &style_kb_pr);
lv_obj_set_event_cb(keyboard, keyboard_event_cb);
/* 隐藏键盘,只有在选中文本框的时候才打开键盘 */
lv_obj_set_hidden(keyboard, true);
}
I think it the same to version A, but it don’t work.
Screenshot and/or video
If possible, add screenshots and/or videos about the current issue.