Exemple #1
0
/**
 * Handle the drawing related tasks of the scrollable object
 * @param scrl pointer to an object
 * @param mask the object will be drawn only in this area
 * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
 *                                  (return 'true' if yes)
 *             LV_DESIGN_DRAW: draw the object (always return 'true')
 *             LV_DESIGN_DRAW_POST: drawing after every children are drawn
 * @param return true/false, depends on 'mode'
 */
static bool lv_scrl_design(lv_obj_t * scrl, const lv_area_t * mask, lv_design_mode_t mode)
{
    if(mode == LV_DESIGN_COVER_CHK) {
        return ancestor_design(scrl, mask, mode);
    } else if(mode == LV_DESIGN_DRAW_MAIN) {
#if USE_LV_GROUP
        /* If the page is the active in a group and
         * the background (page) is not visible (transparent or empty)
         * then activate the style of the scrollable*/
        lv_style_t * style_ori = lv_obj_get_style(scrl);
        lv_obj_t * page = lv_obj_get_parent(scrl);
        lv_style_t * style_page = lv_obj_get_style(page);
        lv_group_t * g = lv_obj_get_group(page);
        if(style_page->body.empty != 0 || style_page->body.opa == LV_OPA_TRANSP) { /*Background is visible?*/
            if(lv_group_get_focused(g) == page) {
                lv_style_t * style_mod;
                style_mod = lv_group_mod_style(g, style_ori);
                scrl->style_p = style_mod;  /*Temporally change the style to the activated */
            }
        }
#endif
        ancestor_design(scrl, mask, mode);

#if USE_LV_GROUP
        scrl->style_p = style_ori;  /*Revert the style*/
#endif
    } else if(mode == LV_DESIGN_DRAW_POST) {
        ancestor_design(scrl, mask, mode);
    }

    return true;
}
Exemple #2
0
/**
 * Signal function of the scrollable part of the roller.
 * @param roller_scrl ointer to the scrollable part of roller (page)
 * @param sign a signal type from lv_signal_t enum
 * @param param pointer to a signal specific variable
 * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
 */
static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param)
{
    lv_res_t res;

    /* Include the ancient signal function */
    res = ancestor_scrl_signal(roller_scrl, sign, param);
    if(res != LV_RES_OK) return res;

    lv_indev_t * indev = lv_indev_get_act();
    int32_t id = -1;
    lv_obj_t * roller = lv_obj_get_parent(roller_scrl);
    lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);

    if(ext->ddlist.label == NULL) return LV_RES_INV;    /*On delete the ddlist signal deletes the label so nothing left to do here*/

    lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
    const lv_font_t * font = style_label->text.font;
    lv_coord_t font_h = lv_font_get_height_scale(font);

    if(sign == LV_SIGNAL_DRAG_END) {
        /*If dragged then align the list to there be an element in the middle*/
        lv_coord_t label_y1 = ext->ddlist.label->coords.y1 - roller->coords.y1;
        lv_coord_t label_unit = font_h + style_label->text.line_space;
        lv_coord_t mid = (roller->coords.y2 - roller->coords.y1) / 2;
        id = (mid - label_y1 + style_label->text.line_space / 2) / label_unit;
        if(id < 0) id = 0;
        if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1;
        ext->ddlist.sel_opt_id = id;
        if(ext->ddlist.action) ext->ddlist.action(roller);
    }
    else if(sign == LV_SIGNAL_RELEASED) {
        /*If picked an option by clicking then set it*/
        if(!lv_indev_is_dragging(indev)) {
            lv_point_t p;
            lv_indev_get_point(indev, &p);
            p.y = p.y - ext->ddlist.label->coords.y1;
            id = p.y / (font_h + style_label->text.line_space);
            if(id < 0) id = 0;
            if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1;
            ext->ddlist.sel_opt_id = id;
            if(ext->ddlist.action) ext->ddlist.action(roller);
        }
    }

    /*Position the scrollable according to the new selected option*/
    if(id != -1) {
        refr_position(roller, true);
    }

    return res;
}
Exemple #3
0
static lv_res_t keyboard_open_close(lv_obj_t * text_area)
{
    lv_obj_t * parent = lv_obj_get_parent(lv_obj_get_parent(ta));   /*Test area is on the scrollabe part of the page but we need the page itself*/

    if(kb) {
        return keyboard_hide_action(kb);
    } else {

        kb = lv_kb_create(parent, NULL);
        lv_obj_set_size(kb, lv_page_get_scrl_width(parent), lv_obj_get_height(parent) / 2);
        lv_obj_align(kb, ta, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
        lv_kb_set_ta(kb, ta);
        lv_kb_set_style(kb, LV_KB_STYLE_BG, &style_kb);
        lv_kb_set_style(kb, LV_KB_STYLE_BTN_REL, &style_kb_rel);
        lv_kb_set_style(kb, LV_KB_STYLE_BTN_PR, &style_kb_pr);
        lv_kb_set_hide_action(kb, keyboard_hide_action);
        lv_kb_set_ok_action(kb, keyboard_hide_action);

#if USE_LV_ANIMATION
        lv_obj_animate(kb, LV_ANIM_FLOAT_BOTTOM | LV_ANIM_IN, 300, 0, NULL);
#endif
        return LV_RES_OK;
    }
}
Exemple #4
0
/**
 * Signal function of the drop down list's scrollable part
 * @param scrl pointer to a drop down list's scrollable part
 * @param sign a signal type from lv_signal_t enum
 * @param param pointer to a signal specific variable
 * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
 */
static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
{
    lv_res_t res;

    /* Include the ancient signal function */
    res = ancestor_scrl_signal(scrl, sign, param);
    if(res != LV_RES_OK) return res;

    lv_obj_t *ddlist = lv_obj_get_parent(scrl);

    if(sign == LV_SIGNAL_REFR_EXT_SIZE) {
        /* Because of the wider selected rectangle ext. size
         * In this way by dragging the scrollable part the wider rectangle area can be redrawn too*/
        lv_style_t *style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG);
        if(scrl->ext_size < style->body.padding.hor) scrl->ext_size = style->body.padding.hor;
    }
    else if(sign == LV_SIGNAL_CLEANUP) {
        lv_ddlist_ext_t *ext = lv_obj_get_ext_attr(ddlist);
        ext->label = NULL;      /*The label is already deleted*/
    }

    return res;
}
Exemple #5
0
/**
 * Refresh the label with its text stored in its extended data
 * @param label pointer to a label object
 */
static void lv_label_refr_text(lv_obj_t * label)
{
    lv_label_ext_t * ext = lv_obj_get_ext_attr(label);

    if(ext->text == NULL) return;

    lv_coord_t max_w = lv_obj_get_width(label);
    lv_style_t * style = lv_obj_get_style(label);
    const lv_font_t * font = style->text.font;

    /*If the width will be expanded set the max length to very big */
    if(ext->long_mode == LV_LABEL_LONG_EXPAND ||
       ext->long_mode == LV_LABEL_LONG_SCROLL) {
        max_w = LV_COORD_MAX;
    }

    /*Calc. the height and longest line*/
    lv_point_t size;
    lv_txt_flag_t flag = LV_TXT_FLAG_NONE;
    if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
    if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
    if(ext->no_break != 0) flag |= LV_TXT_FLAG_NO_BREAK;
    lv_txt_get_size(&size, ext->text, font, style->text.letter_space, style->text.line_space, max_w, flag);

    /*Set the full size in expand mode*/
    if(ext->long_mode == LV_LABEL_LONG_EXPAND || ext->long_mode == LV_LABEL_LONG_SCROLL) {
        lv_obj_set_size(label, size.x, size.y);

        /*Start scrolling if the label is greater then its parent*/
        if(ext->long_mode == LV_LABEL_LONG_SCROLL) {
#if USE_LV_ANIMATION
            lv_obj_t * parent = lv_obj_get_parent(label);

            /*Delete the potential previous scroller animations*/
            lv_anim_del(label, (lv_anim_fp_t) lv_obj_set_x);
            lv_anim_del(label, (lv_anim_fp_t) lv_obj_set_y);

            lv_anim_t anim;
            anim.var = label;
            anim.repeat = 1;
            anim.playback = 1;
            anim.start = lv_font_get_width(font, ' ');
            anim.act_time = 0;
            anim.end_cb = NULL;
            anim.path = lv_anim_path_linear;

            anim.playback_pause = (((lv_font_get_width(style->text.font, ' ') +
                                    style->text.letter_space) * 1000) / ext->anim_speed) * ANIM_WAIT_CHAR_COUNT;
            anim.repeat_pause = anim.playback_pause;

            if(lv_obj_get_width(label) > lv_obj_get_width(parent)) {
                anim.end = lv_obj_get_width(parent) - lv_obj_get_width(label) - lv_font_get_width(font, ' ');
                anim.fp = (lv_anim_fp_t) lv_obj_set_x;
                anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end);
                lv_anim_create(&anim);
            } else if(lv_obj_get_height(label) > lv_obj_get_height(parent)) {
                anim.end =  lv_obj_get_height(parent) - lv_obj_get_height(label) - lv_font_get_height(font);
                anim.fp = (lv_anim_fp_t)lv_obj_set_y;
                anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end);
                lv_anim_create(&anim);
            }
#endif
        }
    }
    /*In roll mode keep the size but start offset animations*/
    else if(ext->long_mode == LV_LABEL_LONG_ROLL) {
#if USE_LV_ANIMATION
        lv_anim_t anim;
        anim.var = label;
        anim.repeat = 1;
        anim.playback = 1;
        anim.start = lv_font_get_width(font, ' ');
        anim.act_time = 0;
        anim.end_cb = NULL;
        anim.path = lv_anim_path_linear;
        anim.playback_pause =  (((lv_font_get_width(style->text.font, ' ') + style->text.letter_space) * 1000) / ext->anim_speed) * ANIM_WAIT_CHAR_COUNT;;
        anim.repeat_pause =  anim.playback_pause;

        bool hor_anim = false;
        if(size.x > lv_obj_get_width(label)) {
            anim.end = lv_obj_get_width(label) - size.x - lv_font_get_width(font, ' ');
            anim.fp = (lv_anim_fp_t) lv_label_set_offset_x;
            anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end);
            lv_anim_create(&anim);
            hor_anim = true;
        } else {
            /*Delete the offset animation if not required*/
            lv_anim_del(label, (lv_anim_fp_t) lv_label_set_offset_x);
            ext->offset.x = 0;
        }

        if(size.y > lv_obj_get_height(label) && hor_anim == false) {
            anim.end =  lv_obj_get_height(label) - size.y - (lv_font_get_height(font));
            anim.fp = (lv_anim_fp_t)lv_label_set_offset_y;
            anim.time = lv_anim_speed_to_time(ext->anim_speed, anim.start, anim.end);
            lv_anim_create(&anim);
        } else {
            /*Delete the offset animation if not required*/
            lv_anim_del(label, (lv_anim_fp_t) lv_label_set_offset_y);
            ext->offset.y = 0;
        }
#endif
    }
    else if(ext->long_mode == LV_LABEL_LONG_DOT) {
       if(size.y <= lv_obj_get_height(label)) {                /*No dots are required, the text is short enough*/
           ext->dot_end = LV_LABEL_DOT_END_INV;
       } else if(lv_txt_get_length(ext->text) <= LV_LABEL_DOT_NUM) {     /*Don't turn to dots all the characters*/
           ext->dot_end = LV_LABEL_DOT_END_INV;
       } else {
           lv_point_t p;
           p.x = lv_obj_get_width(label) - (lv_font_get_width(style->text.font, '.') + style->text.letter_space) * LV_LABEL_DOT_NUM; /*Shrink with dots*/
           p.y = lv_obj_get_height(label);
           p.y -= p.y  % (lv_font_get_height(style->text.font) + style->text.line_space);   /*Round down to the last line*/
           p.y -= style->text.line_space;                                                      /*Trim the last line space*/
           uint32_t letter_id = lv_label_get_letter_on(label, &p);


#if LV_TXT_UTF8 == 0
           /*Save letters under the dots and replace them with dots*/
           uint8_t i;
           for(i = 0; i < LV_LABEL_DOT_NUM; i++)  {
               ext->dot_tmp[i] = ext->text[letter_id + i];
               ext->text[letter_id + i] = '.';
           }

           ext->dot_tmp[LV_LABEL_DOT_NUM] = ext->text[letter_id + LV_LABEL_DOT_NUM];
           ext->text[letter_id + LV_LABEL_DOT_NUM] = '\0';

           ext->dot_end = letter_id + LV_LABEL_DOT_NUM;
#else
           /*Save letters under the dots and replace them with dots*/
           uint32_t i;
           uint32_t byte_id = txt_utf8_get_byte_id(ext->text, letter_id);
           uint32_t byte_id_ori = byte_id;
           uint8_t len = 0;
           for(i = 0; i <= LV_LABEL_DOT_NUM; i++)  {
               len += lv_txt_utf8_size(ext->text[byte_id]);
               lv_txt_utf8_next(ext->text, &byte_id);
           }

           memcpy(ext->dot_tmp, &ext->text[byte_id_ori], len);
           ext->dot_tmp[len] = '\0';       /*Close with a zero*/

           for(i = 0; i < LV_LABEL_DOT_NUM; i++) {
               ext->text[byte_id_ori + i] = '.';
           }
           ext->text[byte_id_ori + LV_LABEL_DOT_NUM] = '\0';

           ext->dot_end = letter_id + LV_LABEL_DOT_NUM;
#endif

       }
   }
    /*In break mode only the height can change*/
    else if (ext->long_mode == LV_LABEL_LONG_BREAK) {
        lv_obj_set_height(label, size.y);
    }


    lv_obj_invalidate(label);
}
Exemple #6
0
/**
 * Signal function of the scrollable part of a page
 * @param scrl pointer to the scrollable object
 * @param sign a signal type from lv_signal_t enum
 * @param param pointer to a signal specific variable
 * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
 */
static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
{
    lv_res_t res;

    /* Include the ancient signal function */
    res = ancestor_signal(scrl, sign, param);
    if(res != LV_RES_OK) return res;

    lv_obj_t * page = lv_obj_get_parent(scrl);
    lv_style_t * page_style = lv_obj_get_style(page);
    lv_page_ext_t * page_ext = lv_obj_get_ext_attr(page);

    if(sign == LV_SIGNAL_CORD_CHG) {
        /*Be sure the width of the scrollable is correct*/
        if(lv_cont_get_hor_fit(scrl) == false) {
            lv_obj_set_width(scrl, lv_obj_get_width(page) - 2 * page_style->body.padding.hor);
        }

        /*Limit the position of the scrollable object to be always visible
         * (Do not let its edge inner then its parent respective edge)*/
        lv_coord_t new_x;
        lv_coord_t new_y;
        bool refr_x = false;
        bool refr_y = false;
        lv_area_t page_cords;
        lv_area_t scrl_cords;
        lv_coord_t hpad = page_style->body.padding.hor;
        lv_coord_t vpad = page_style->body.padding.ver;

        new_x = lv_obj_get_x(scrl);
        new_y = lv_obj_get_y(scrl);
        lv_obj_get_coords(scrl, &scrl_cords);
        lv_obj_get_coords(page, &page_cords);

        /*scrollable width smaller then page width? -> align to left*/
        if(lv_area_get_width(&scrl_cords) + 2 * hpad < lv_area_get_width(&page_cords)) {
            if(scrl_cords.x1 != page_cords.x1 + hpad) {
                new_x = hpad;
                refr_x = true;
            }
        } else {
            /*The edges of the scrollable can not be in the page (minus hpad) */
            if(scrl_cords.x2  < page_cords.x2 - hpad) {
               new_x =  lv_area_get_width(&page_cords) - lv_area_get_width(&scrl_cords) - hpad;   /* Right align */
               refr_x = true;
            }
            if (scrl_cords.x1 > page_cords.x1 + hpad) {
                new_x = hpad;  /*Left align*/
                refr_x = true;
            }
        }

        /*scrollable height smaller then page height? -> align to left*/
        if(lv_area_get_height(&scrl_cords) + 2 * vpad < lv_area_get_height(&page_cords)) {
            if(scrl_cords.y1 != page_cords.y1 + vpad) {
                new_y = vpad;
                refr_y = true;
            }
        } else {
            /*The edges of the scrollable can not be in the page (minus vpad) */
            if(scrl_cords.y2 < page_cords.y2 - vpad) {
               new_y =  lv_area_get_height(&page_cords) - lv_area_get_height(&scrl_cords) - vpad;   /* Bottom align */
               refr_y = true;
            }
            if (scrl_cords.y1  > page_cords.y1 + vpad) {
                new_y = vpad;  /*Top align*/
                refr_y = true;
            }
        }
        if(refr_x != false || refr_y != false) {
            lv_obj_set_pos(scrl, new_x, new_y);
        }

        lv_page_sb_refresh(page);
    }
    else if(sign == LV_SIGNAL_DRAG_END) {
        /*Hide scrollbars if required*/
        if(page_ext->sb.mode == LV_SB_MODE_DRAG) {
            lv_area_t sb_area_tmp;
            if(page_ext->sb.hor_draw) {
                lv_area_copy(&sb_area_tmp, &page_ext->sb.hor_area);
                sb_area_tmp.x1 += page->coords.x1;
                sb_area_tmp.y1 += page->coords.y1;
                sb_area_tmp.x2 += page->coords.x2;
                sb_area_tmp.y2 += page->coords.y2;
                lv_inv_area(&sb_area_tmp);
                page_ext->sb.hor_draw = 0;
            }
            if(page_ext->sb.ver_draw)  {
                lv_area_copy(&sb_area_tmp, &page_ext->sb.ver_area);
                sb_area_tmp.x1 += page->coords.x1;
                sb_area_tmp.y1 += page->coords.y1;
                sb_area_tmp.x2 += page->coords.x2;
                sb_area_tmp.y2 += page->coords.y2;
                lv_inv_area(&sb_area_tmp);
                page_ext->sb.ver_draw = 0;
            }
        }
    }
    else if(sign == LV_SIGNAL_PRESSED) {
        if(page_ext->pr_action != NULL) {
            page_ext->pr_action(page);
        }
    }
    else if(sign == LV_SIGNAL_RELEASED) {
        if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
            if(page_ext->rel_action != NULL) {
                page_ext->rel_action(page);
            }
        }
    }

    return res;
}