/** * Get a style of a switch * @param sw pointer to a switch object * @param type which style should be get * @return style pointer to a style */ lv_style_t * lv_sw_get_style(const lv_obj_t * sw, lv_sw_style_t type) { lv_style_t * style = NULL; lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw); switch(type) { case LV_SW_STYLE_BG: style = lv_slider_get_style(sw, LV_SLIDER_STYLE_BG); break; case LV_SW_STYLE_INDIC: style = lv_slider_get_style(sw, LV_SLIDER_STYLE_INDIC); break; case LV_SW_STYLE_KNOB_OFF: style = ext->style_knob_off; break; case LV_SW_STYLE_KNOB_ON: style = ext->style_knob_on; break; default: style = NULL; break; } return style; }
/** * Handle the drawing related tasks of the sliders * @param slider 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_slider_design(lv_obj_t * slider, 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 false; } /*Draw the object*/ else if(mode == LV_DESIGN_DRAW_MAIN) { lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); lv_style_t * style_bg = lv_slider_get_style(slider, LV_SLIDER_STYLE_BG); lv_style_t * style_knob = lv_slider_get_style(slider, LV_SLIDER_STYLE_KNOB); lv_style_t * style_indic = lv_slider_get_style(slider, LV_SLIDER_STYLE_INDIC); lv_coord_t slider_w = lv_area_get_width(&slider->coords); lv_coord_t slider_h = lv_area_get_height(&slider->coords); /*Draw the bar*/ lv_area_t area_bg; lv_area_copy(&area_bg, &slider->coords); /*Be sure at least LV_SLIDER_SIZE_MIN size will remain*/ lv_coord_t pad_ver_bg = style_bg->body.padding.ver; lv_coord_t pad_hor_bg = style_bg->body.padding.hor; if(pad_ver_bg * 2 + LV_SLIDER_SIZE_MIN > lv_area_get_height(&area_bg)) { pad_ver_bg = (lv_area_get_height(&area_bg) - LV_SLIDER_SIZE_MIN) >> 1; }
/** * Get a style of a switch * @param sw pointer to a switch object * @param type which style should be get * @return style pointer to a style */ lv_style_t * lv_sw_get_style(lv_obj_t *sw, lv_sw_style_t type) { lv_sw_ext_t *ext = lv_obj_get_ext_attr(sw); switch (type) { case LV_SW_STYLE_BG: return lv_slider_get_style(sw, LV_SLIDER_STYLE_BG); case LV_SW_STYLE_INDIC: return lv_slider_get_style(sw, LV_SLIDER_STYLE_INDIC); case LV_SW_STYLE_KNOB_OFF: return ext->style_knob_off; case LV_SW_STYLE_KNOB_ON: return ext->style_knob_on; default: return NULL; } /*To avoid warning*/ return NULL; }