rever reset

This commit is contained in:
Gabor Kiss-Vamosi
2017-10-05 11:29:21 +02:00
parent d6ccc48963
commit c0715b4c63
26 changed files with 275 additions and 252 deletions

View File

@@ -70,7 +70,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
ext->opt_label = NULL;
ext->cb = NULL;
ext->opened = 0;
ext->auto_size = 0;
ext->fix_height = 0;
ext->sel_opt = 0;
ext->num_opt = 0;
ext->anim_time = LV_DDLIST_DEF_ANIM_TIME;
@@ -86,7 +86,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
if(copy == NULL) {
lv_obj_t * scrl = lv_page_get_scrl(new_ddlist);
lv_obj_set_drag(scrl, false);
lv_obj_set_style(scrl, lv_style_get(LV_STYLE_TRANSP, NULL));;
lv_obj_set_style(scrl, lv_style_get(LV_STYLE_TRANSP, NULL));
lv_cont_set_fit(scrl, true, true);
ext->opt_label = lv_label_create(new_ddlist, NULL);
@@ -102,7 +102,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
ext->opt_label = lv_label_create(new_ddlist, copy_ext->opt_label);
lv_label_set_text(ext->opt_label, lv_label_get_text(copy_ext->opt_label));
ext->sel_opt = copy_ext->sel_opt;
ext->auto_size = copy_ext->auto_size;
ext->fix_height = copy_ext->fix_height;
ext->cb = copy_ext->cb;
ext->num_opt = copy_ext->num_opt;
@@ -131,8 +131,6 @@ bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param)
* make the object specific signal handling */
if(valid != false) {
if(sign == LV_SIGNAL_STYLE_CHG) {
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
lv_obj_set_style(ext->opt_label, lv_obj_get_style(ddlist));
lv_ddlist_refr_size(ddlist, 0);
} else if(sign == LV_SIGNAL_FOCUS) {
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
@@ -195,8 +193,8 @@ void lv_ddlist_set_options(lv_obj_t * ddlist, const char ** options)
lv_label_set_text(ext->opt_label, "");
uint16_t i = 0;
while(options[i][0] != '\0') {
lv_label_append_text(ext->opt_label, options[i]);
if(options[i + 1][0] != '\0') lv_label_append_text(ext->opt_label, "\n");
lv_label_ins_text(ext->opt_label, LV_LABEL_POS_LAST, options[i]);
if(options[i + 1][0] != '\0') lv_label_ins_text(ext->opt_label, LV_LABEL_POS_LAST, "\n");
i++;
}
@@ -235,11 +233,13 @@ void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
ext->sel_opt = sel_opt;
ext->sel_opt = sel_opt < ext->num_opt ? sel_opt : ext->num_opt - 1;
/*Move the list to show the current option*/
if(ext->opened == 0) {
lv_ddlist_pos_act_option(ddlist);
} else {
lv_obj_inv(ddlist);
}
}
@@ -255,15 +255,16 @@ void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t cb)
}
/**
* Set the auto size attribute. If enabled the height will reduced to be visible on the parent.
* In this case the drop down list can be scrolled.
* Set the fix height value.
* If 0 then the opened ddlist will be auto. sized else the set height will be applied.
* @param ddlist pointer to a drop down list
* @param auto_size true: enable auto size, false: disable
* @param h the height when the list is opened (0: auto size)
*/
void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size)
void lv_ddlist_set_fix_height(lv_obj_t * ddlist, cord_t h)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
ext->auto_size = auto_size == false ? 0 : 1;
ext->fix_height = h;
lv_ddlist_refr_size(ddlist, 0);
}
/**
@@ -287,6 +288,20 @@ void lv_ddlist_set_style_select(lv_obj_t * ddlist, lv_style_t * style)
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
ext->style_sel = style;
}
/**
* Open or Collapse the drop down list
* @param ddlist pointer to drop down list object
* @param state true: open; false: collapse
* @param anim true: use animations; false: not use animations
*/
void lv_ddlist_open(lv_obj_t * ddlist, bool state, bool anim)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
ext->opened = state ? 1 : 0;
lv_ddlist_refr_size(ddlist, anim ? ext->anim_time : 0);
}
/*=====================
* Getter functions
@@ -341,14 +356,14 @@ void lv_ddlist_get_selected_str(lv_obj_t * ddlist, char * buf)
}
/**
* Get the auto size attribute.
* Get the fix height value.
* @param ddlist pointer to a drop down list object
* @return true: the auto_size is enabled, false: disabled
* @return the height if the ddlist is opened (0: auto size)
*/
bool lv_ddlist_get_auto_size(lv_obj_t * ddlist, bool auto_size)
cord_t lv_ddlist_get_fix_height(lv_obj_t * ddlist)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
return ext->auto_size == 0 ? false : true;
return ext->fix_height;
}
/**
@@ -469,7 +484,7 @@ static lv_action_res_t lv_ddlist_rel_action(lv_obj_t * ddlist, lv_dispi_t * disp
}
/**
* Refresh the size of drop down list according its status (open or closed)
* Refresh the size of drop down list according to its status (open or closed)
* @param ddlist pointer to a drop down list object
* @param anim_time animations time for open/close [ms]
*/
@@ -478,13 +493,9 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, uint16_t anim_time)
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
lv_style_t * style = lv_obj_get_style(ddlist);
cord_t new_height;
if(ext->opened != 0) { /*Open the list*/
new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->vpad;
lv_obj_t * parent = lv_obj_get_parent(ddlist);
/*Reduce the height if enabled and required*/
if(ext->auto_size != 0 && new_height + ddlist->cords.y1 > parent->cords.y2) {
new_height = parent->cords.y2 - ddlist->cords.y1;
}
if(ext->opened) { /*Open the list*/
if(ext->fix_height == 0) new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->vpad;
else new_height = ext->fix_height;
} else { /*Close the list*/
const font_t * font = style->font;
lv_style_t * label_style = lv_obj_get_style(ext->opt_label);
@@ -525,9 +536,11 @@ static void lv_ddlist_pos_act_option(lv_obj_t * ddlist)
cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS;
lv_style_t * label_style = lv_obj_get_style(ext->opt_label);
lv_obj_t * scrl = lv_page_get_scrl(ddlist);
lv_style_t * style_scrl = lv_obj_get_style(scrl);
lv_obj_set_y(scrl, -(ext->sel_opt * (font_h + label_style->line_space) - label_style->line_space) - style_scrl->hpad);
cord_t h = lv_obj_get_height(ddlist);
cord_t line_y1 = ext->sel_opt * (font_h + label_style->line_space) + ext->opt_label->cords.y1 - scrl->cords.y1;
lv_obj_set_y(scrl, - line_y1 + (h - font_h) / 2);
}