/** * Create a label objects * @param par pointer to an object, it will be the parent of the new label * @param copy pointer to a button object, if not NULL then the new object will be copied from it * @return pointer to the created button */ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy) { /*Create a basic object*/ lv_obj_t * new_label = lv_obj_create(par, copy); lv_mem_assert(new_label); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_label); /*Extend the basic object to a label object*/ lv_obj_allocate_ext_attr(new_label, sizeof(lv_label_ext_t)); lv_label_ext_t * ext = lv_obj_get_ext_attr(new_label); lv_mem_assert(ext); ext->text = NULL; ext->static_txt = 0; ext->recolor = 0; ext->no_break = 0; ext->body_draw = 0; ext->align = LV_LABEL_ALIGN_LEFT; ext->dot_end = LV_LABEL_DOT_END_INV; ext->long_mode = LV_LABEL_LONG_EXPAND; ext->anim_speed = LV_LABEL_SCROLL_SPEED; ext->offset.x = 0; ext->offset.y = 0; lv_obj_set_design_func(new_label, lv_label_design); lv_obj_set_signal_func(new_label, lv_label_signal); /*Init the new label*/ if(copy == NULL) { lv_obj_set_click(new_label, false); lv_label_set_long_mode(new_label, LV_LABEL_LONG_EXPAND); lv_label_set_text(new_label, "Text"); lv_label_set_style(new_label, NULL); /*Inherit parent's style*/ } /*Copy 'copy' if not NULL*/ else { lv_label_ext_t * copy_ext = lv_obj_get_ext_attr(copy); lv_label_set_long_mode(new_label, lv_label_get_long_mode(copy)); lv_label_set_recolor(new_label, lv_label_get_recolor(copy)); lv_label_set_body_draw(new_label, lv_label_get_body_draw(copy)); lv_label_set_align(new_label, lv_label_get_align(copy)); if(copy_ext->static_txt == 0) lv_label_set_text(new_label, lv_label_get_text(copy)); else lv_label_set_static_text(new_label, lv_label_get_text(copy)); /*In DOT mode save the text byte-to-byte because a '\0' can be in the middle*/ if(copy_ext->long_mode == LV_LABEL_LONG_DOT) { ext->text = lv_mem_realloc(ext->text, lv_mem_get_size(copy_ext->text)); memcpy(ext->text, copy_ext->text, lv_mem_get_size(copy_ext->text)); } memcpy(ext->dot_tmp, copy_ext->dot_tmp, sizeof(ext->dot_tmp)); ext->dot_end = copy_ext->dot_end; /*Refresh the style with new signal function*/ lv_obj_refresh_style(new_label); } return new_label; }
/** * Open a terminal * @return pointer to the terminal window */ lv_obj_t * terminal_create(void) { static lv_style_t style_bg; lv_style_copy(&style_bg, &lv_style_pretty); style_bg.body.main_color = LV_COLOR_MAKE(0x30, 0x30, 0x30); style_bg.body.grad_color = LV_COLOR_MAKE(0x30, 0x30, 0x30); style_bg.body.border.color = LV_COLOR_WHITE; style_bg.text.color = LV_COLOR_MAKE(0xE0, 0xE0, 0xE0); win = lv_win_create(lv_scr_act(), NULL); lv_win_set_style(win, LV_WIN_STYLE_BG, &style_bg); lv_obj_set_size(win, TERMINAL_WIDTH, TERMINAL_HEIGHT); lv_win_set_sb_mode(win, LV_SB_MODE_AUTO); lv_win_add_btn(win, SYMBOL_CLOSE, win_close_action); /*Make the window's content responsive*/ lv_win_set_layout(win, LV_LAYOUT_PRETTY); /*Create a label for the text of the terminal*/ label = lv_label_create(win, NULL); lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); lv_obj_set_width(label, lv_win_get_width(win)); lv_label_set_static_text(label, txt_log); /*Use the text array directly*/ /*Create a clear button*/ clr_btn = lv_btn_create(win, NULL); lv_cont_set_fit(clr_btn, true, true); lv_btn_set_action(clr_btn, LV_BTN_ACTION_CLICK, clr_click_action); lv_obj_t * btn_label = lv_label_create(clr_btn, NULL); lv_label_set_text(btn_label, "Clear"); return win; }
static void ssd1306_task(void *pvParameters) { printf("%s: Started user interface task\n", __FUNCTION__); vTaskDelay(SECOND); ssd1306_set_whole_display_lighting(&dev, false); //Set a style for the obj lv_style_copy(&style, &lv_style_transp); style.text.font = &lv_font_dejavu_10; /*Unicode and symbol fonts already assigned by the library*/ style.text.color.full = 1; style.text.opa = 255; style.body.main_color.full = 0; style.body.grad_color.full = 0; style.body.shadow.color.full = 0; style.body.border.color.full = 0; style.body.empty = 1; style.image.color.full = 1; style.image.intense = 255; style.image.opa = 255; style.line.color.full = 1; style.line.opa = 255; style.line.width = 1; style.line.rounded = false; //Create main screen obj lv_obj_t * scr = lv_obj_create(NULL, NULL); lv_scr_load(scr); lv_obj_set_style(scr, &style); //Create a simple label label = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style(label, &style); lv_obj_align(label, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0); lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); lv_label_set_text(label, "lvgl work with esp-open-rtos"); lv_obj_set_width(label, LV_HOR_RES); while (1) { /*draw system call */ lv_task_handler(); vTaskDelay(1); } }