/** * Get a style of a roller * @param roller pointer to a roller object * @param type which style should be get * @return style pointer to a style * */ lv_style_t * lv_roller_get_style(lv_obj_t *roller, lv_roller_style_t type) { switch (type) { case LV_ROLLER_STYLE_BG: return lv_obj_get_style(roller); case LV_ROLLER_STYLE_SEL: return lv_ddlist_get_style(roller, LV_DDLIST_STYLE_SEL); default: return NULL; } /*To avoid warning*/ return NULL; }
/** * 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; }
/** * Handle the drawing related tasks of the drop down lists * @param ddlist 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_ddlist_design(lv_obj_t * ddlist, const lv_area_t * mask, lv_design_mode_t mode) { /*Return false if the object is not covers the mask_p area*/ if(mode == LV_DESIGN_COVER_CHK) { return ancestor_design(ddlist, mask, mode); } /*Draw the object*/ else if(mode == LV_DESIGN_DRAW_MAIN) { ancestor_design(ddlist, mask, mode); lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); /*If the list is opened draw a rectangle under the selected item*/ if(ext->opened != 0) { lv_style_t *style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); const lv_font_t * font = style->text.font; lv_coord_t font_h = lv_font_get_height(font); /*Draw the selected*/ lv_area_t rect_area; rect_area.y1 = ext->label->coords.y1; rect_area.y1 += ext->sel_opt_id * (font_h + style->text.line_space); rect_area.y1 -= style->text.line_space / 2; rect_area.y2 = rect_area.y1 + font_h + style->text.line_space; rect_area.x1 = ddlist->coords.x1; rect_area.x2 = ddlist->coords.x2; lv_draw_rect(&rect_area, mask, ext->sel_style); } } /*Post draw when the children are drawn*/ else if(mode == LV_DESIGN_DRAW_POST) { ancestor_design(ddlist, mask, mode); /*Redraw the text on the selected area with a different color*/ lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); /*Redraw only in opened state*/ if(ext->opened == 0) return true; lv_style_t *style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); const lv_font_t * font = style->text.font; lv_coord_t font_h = lv_font_get_height(font); lv_area_t area_sel; area_sel.y1 = ext->label->coords.y1; area_sel.y1 += ext->sel_opt_id * (font_h + style->text.line_space); area_sel.y1 -= style->text.line_space / 2; area_sel.y2 = area_sel.y1 + font_h + style->text.line_space; area_sel.x1 = ddlist->coords.x1; area_sel.x2 = ddlist->coords.x2; lv_area_t mask_sel; bool area_ok; area_ok = lv_area_union(&mask_sel, mask, &area_sel); if(area_ok) { lv_style_t *sel_style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_SEL); lv_style_t new_style; lv_style_copy(&new_style, style); new_style.text.color = sel_style->text.color; new_style.text.opa = sel_style->text.opa; lv_draw_label(&ext->label->coords, &mask_sel, &new_style, lv_label_get_text(ext->label), LV_TXT_FLAG_NONE, NULL); } } return true; }