Example #1
0
/**
 * 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;
}
Example #2
0
/**
 * Create a roller object
 * @param par pointer to an object, it will be the parent of the new roller
 * @param copy pointer to a roller object, if not NULL then the new object will be copied from it
 * @return pointer to the created roller
 */
lv_obj_t * lv_roller_create(lv_obj_t * par, lv_obj_t * copy)
{
    /*Create the ancestor of roller*/
	lv_obj_t * new_roller = lv_ddlist_create(par, copy);
    lv_mem_assert(new_roller);
    if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_roller));
    if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_roller);
    
    /*Allocate the roller type specific extended data*/
    lv_roller_ext_t * ext = lv_obj_allocate_ext_attr(new_roller, sizeof(lv_roller_ext_t));
    lv_mem_assert(ext);

    /*The signal and design functions are not copied so set them here*/
    lv_obj_set_signal_func(new_roller, lv_roller_signal);
    lv_obj_set_design_func(new_roller, lv_roller_design);

    /*Init the new roller roller*/
    if(copy == NULL) {
        lv_obj_t * scrl = lv_page_get_scrl(new_roller);
        lv_obj_set_drag(scrl, true);                        /*In ddlist is might be disabled*/
        lv_page_set_rel_action(new_roller, NULL);       /*Roller don't uses it (like ddlist)*/
        lv_page_set_scrl_fit(new_roller, true, false);      /*Height is specified directly*/
        lv_ddlist_open(new_roller, false);
        lv_ddlist_set_anim_time(new_roller, LV_ROLLER_ANIM_TIME);
        lv_roller_set_visible_row_count(new_roller, 3);
        lv_label_set_align(ext->ddlist.label, LV_LABEL_ALIGN_CENTER);

        lv_obj_set_signal_func(scrl, lv_roller_scrl_signal);

        /*Set the default styles*/
        lv_theme_t *th = lv_theme_get_current();
        if(th) {
            lv_roller_set_style(new_roller, LV_ROLLER_STYLE_BG, th->roller.bg);
            lv_roller_set_style(new_roller, LV_ROLLER_STYLE_SEL, th->roller.sel);
        } else {
            /*Let the ddlist's style*/
            lv_obj_refresh_style(new_roller);                /*To set scrollable size automatically*/
        }
    }
    /*Copy an existing roller*/
    else {
        lv_obj_t * scrl = lv_page_get_scrl(new_roller);
        lv_ddlist_open(new_roller, false);
        lv_obj_set_signal_func(scrl, lv_roller_scrl_signal);

        lv_obj_refresh_style(new_roller);        /*Refresh the style with new signal function*/
    }
    
    return new_roller;
}
Example #3
0
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);
    }
}