update obejcts with the new event system

This commit is contained in:
Gabor Kiss-Vamosi
2019-02-26 16:07:40 +01:00
parent 50e69bab6b
commit dc0ce46b0c
18 changed files with 193 additions and 111 deletions

View File

@@ -385,7 +385,7 @@ static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode
lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG);
lv_style_t style_tmp;
lv_style_copy(&style_tmp, style_bg);
style_tmp.body.empty = 1;
style_tmp.body.opa = LV_OPA_TRANSP;
style_tmp.body.shadow.width = 0;
lv_draw_rect(&bar->coords, mask, &style_tmp, opa_scale);
}

View File

@@ -273,13 +273,13 @@ static bool lv_bullet_design(lv_obj_t * bullet, const lv_area_t * mask, lv_desig
} else if(mode == LV_DESIGN_DRAW_MAIN) {
#if USE_LV_GROUP
/* If the check box is the active in a group and
* the background is not visible (transparent or empty)
* the background is not visible (transparent)
* then activate the style of the bullet*/
lv_style_t * style_ori = lv_obj_get_style(bullet);
lv_obj_t * bg = lv_obj_get_parent(bullet);
lv_style_t * style_page = lv_obj_get_style(bg);
lv_group_t * g = lv_obj_get_group(bg);
if(style_page->body.empty != 0 || style_page->body.opa == LV_OPA_TRANSP) { /*Background is visible?*/
if(style_page->body.opa == LV_OPA_TRANSP) { /*Is the Background visible?*/
if(lv_group_get_focused(g) == bg) {
lv_style_t * style_mod;
style_mod = lv_group_mod_style(g, style_ori);

View File

@@ -674,7 +674,6 @@ static void lv_chart_draw_points(lv_obj_t * chart, const lv_area_t * mask)
lv_style_copy(&style_point, &lv_style_plain);
style_point.body.border.width = 0;
style_point.body.empty = 0;
style_point.body.radius = LV_RADIUS_CIRCLE;
style_point.body.opa = ext->series.opa;
style_point.body.radius = ext->series.width;
@@ -725,7 +724,6 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const lv_area_t * mask)
lv_style_copy(&rects, &lv_style_plain);
rects.body.border.width = 0;
rects.body.empty = 0;
rects.body.radius = 0;
rects.body.opa = ext->series.opa;

View File

@@ -93,6 +93,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy)
ext->anim_time = LV_DDLIST_ANIM_TIME;
ext->sel_style = &lv_style_plain_color;
ext->draw_arrow = 0; /*Do not draw arrow by default*/
ext->stay_open = 1;
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_cb(new_ddlist, lv_ddlist_signal);
@@ -103,7 +104,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy)
if(copy == NULL) {
lv_obj_t * scrl = lv_page_get_scrl(new_ddlist);
lv_obj_set_drag(scrl, false);
lv_page_set_scrl_fit2(new_ddlist, LV_FIT_TIGHT, LV_FIT_TIGHT);
lv_page_set_scrl_fit2(new_ddlist, LV_FIT_FLOOD, LV_FIT_TIGHT);
ext->label = lv_label_create(new_ddlist, NULL);
lv_cont_set_fit2(new_ddlist, LV_FIT_TIGHT, LV_FIT_NONE);
@@ -151,19 +152,6 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy)
* Setter functions
*====================*/
/**
* Set arrow draw in a drop down list
* @param ddlist pointer to drop down list object
* @param en enable/disable a arrow draw. E.g. "true" for draw.
*/
void lv_ddlist_set_draw_arrow(lv_obj_t * ddlist, bool en)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
/*Set the flag*/
ext->draw_arrow = en;
}
/**
* Set the options in a drop down list from a string
* @param ddlist pointer to drop down list object
@@ -226,13 +214,40 @@ void lv_ddlist_set_fix_height(lv_obj_t * ddlist, lv_coord_t h)
* @param ddlist pointer to a drop down list
* @param fit fit mode fron `lv_fit_t` (Typically `LV_FIT_NONE` or `LV_FIT_TIGHT`)
*/
void lv_ddlist_set_hor_fit(lv_obj_t * ddlist, lv_fit_t fit)
void lv_ddlist_set_fit(lv_obj_t * ddlist, lv_fit_t fit)
{
lv_cont_set_fit2(ddlist, fit, lv_cont_get_fit_top(ddlist));
lv_cont_set_fit2(ddlist, fit, LV_FIT_NONE);
lv_ddlist_refr_size(ddlist, false);
}
/**
* Set arrow draw in a drop down list
* @param ddlist pointer to drop down list object
* @param en enable/disable a arrow draw. E.g. "true" for draw.
*/
void lv_ddlist_set_draw_arrow(lv_obj_t * ddlist, bool en)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
/*Set the flag*/
ext->draw_arrow = en ? 1 : 0;
}
/**
* Leave the list opened when a new value is selected
* @param ddlist pointer to drop down list object
* @param en enable/disable "stay open" feature
*/
void lv_ddlist_set_stay_open(lv_obj_t * ddlist, bool en)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
/*Set the flag*/
ext->stay_open = en ? 1 : 0;
}
/**
* Set the open/close animation time.
* @param ddlist pointer to a drop down list
@@ -283,16 +298,6 @@ void lv_ddlist_set_align(lv_obj_t *ddlist, lv_label_align_t align)
* Getter functions
*====================*/
/**
* Get arrow draw in a drop down list
* @param ddlist pointer to drop down list object
*/
bool lv_ddlist_get_draw_arrow(lv_obj_t * ddlist)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
return ext->draw_arrow;
}
/**
* Get the options of a drop down list
@@ -353,6 +358,28 @@ lv_coord_t lv_ddlist_get_fix_height(const lv_obj_t * ddlist)
return ext->fix_height;
}
/**
* Get arrow draw in a drop down list
* @param ddlist pointer to drop down list object
*/
bool lv_ddlist_get_draw_arrow(lv_obj_t * ddlist)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
return ext->draw_arrow ? true : false;
}
/**
* Get whether the drop down list stay open after selecting a value or not
* @param ddlist pointer to drop down list object
*/
bool lv_ddlist_get_stay_open(lv_obj_t * ddlist)
{
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
return ext->stay_open ? true : false;
}
/**
* Get the open/close animation time.
* @param ddlist pointer to a drop down list
@@ -720,7 +747,9 @@ static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void *
if(scrl->ext_size < style->body.padding.hor) scrl->ext_size = style->body.padding.hor;
}
else if(sign == LV_SIGNAL_RELEASED) {
release_handler(ddlist);
if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
release_handler(ddlist);
}
}
else if(sign == LV_SIGNAL_CLEANUP) {
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
@@ -742,9 +771,8 @@ static lv_res_t release_handler(lv_obj_t * ddlist)
if(ext->opened == 0) { /*Open the list*/
ext->opened = 1;
lv_obj_set_drag(lv_page_get_scrl(ddlist), true);
lv_ddlist_refr_size(ddlist, true);
} else {
ext->opened = 0;
lv_obj_set_drag(lv_page_get_scrl(ddlist), false);
/*Search the clicked option*/
lv_indev_t * indev = lv_indev_get_act();
@@ -768,8 +796,15 @@ static lv_res_t release_handler(lv_obj_t * ddlist)
ext->sel_opt_id = new_opt;
lv_obj_send_event(ddlist, LV_EVENT_VALUE_CHANGED);
if(ext->stay_open == 0) {
ext->opened = 0;
lv_obj_set_drag(lv_page_get_scrl(ddlist), false);
lv_ddlist_refr_size(ddlist, true);
} else {
lv_obj_invalidate(ddlist);
}
}
lv_ddlist_refr_size(ddlist, true);
return LV_RES_OK;

View File

@@ -54,7 +54,7 @@ typedef struct
uint16_t anim_time; /*Open/Close animation time [ms]*/
uint8_t opened :1; /*1: The list is opened (handled by the library)*/
uint8_t draw_arrow :1; /*1: Draw arrow*/
uint8_t stay_open :1; /*1: Don't close the list when a new item is selected*/
lv_coord_t fix_height; /*Height of the ddlist when opened. (0: auto-size)*/
} lv_ddlist_ext_t;
@@ -80,13 +80,6 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy);
* Setter functions
*====================*/
/**
* Set arrow draw in a drop down list
* @param ddlist pointer to drop down list object
* @param en enable/disable a arrow draw. E.g. "true" for draw.
*/
void lv_ddlist_set_draw_arrow(lv_obj_t * ddlist, bool en);
/**
* Set the options in a drop down list from a string
* @param ddlist pointer to drop down list object
@@ -115,7 +108,21 @@ void lv_ddlist_set_fix_height(lv_obj_t * ddlist, lv_coord_t h);
* @param ddlist pointer to a drop down list
* @param fit fit mode fron `lv_fit_t` (Typically `LV_FIT_NONE` or `LV_FIT_TIGHT`)
*/
void lv_ddlist_set_hor_fit(lv_obj_t * ddlist, lv_fit_t fit);
void lv_ddlist_set_fit(lv_obj_t * ddlist, lv_fit_t fit);
/**
* Set arrow draw in a drop down list
* @param ddlist pointer to drop down list object
* @param en enable/disable a arrow draw. E.g. "true" for draw.
*/
void lv_ddlist_set_draw_arrow(lv_obj_t * ddlist, bool en);
/**
* Leave the list opened when a new value is selected
* @param ddlist pointer to drop down list object
* @param en enable/disable "stay open" feature
*/
void lv_ddlist_set_stay_open(lv_obj_t * ddlist, bool en);
/**
* Set the scroll bar mode of a drop down list
@@ -154,11 +161,6 @@ void lv_ddlist_set_align(lv_obj_t *ddlist, lv_label_align_t align);
* Getter functions
*====================*/
/**
* Get arrow draw in a drop down list
* @param ddlist pointer to drop down list object
*/
bool lv_ddlist_get_draw_arrow(lv_obj_t * ddlist);
/**
* Get the options of a drop down list
@@ -189,6 +191,18 @@ void lv_ddlist_get_selected_str(const lv_obj_t * ddlist, char * buf);
*/
lv_coord_t lv_ddlist_get_fix_height(const lv_obj_t * ddlist);
/**
* Get arrow draw in a drop down list
* @param ddlist pointer to drop down list object
*/
bool lv_ddlist_get_draw_arrow(lv_obj_t * ddlist);
/**
* Get whether the drop down list stay open after selecting a value or not
* @param ddlist pointer to drop down list object
*/
bool lv_ddlist_get_stay_open(lv_obj_t * ddlist);
/**
* Get the scroll bar mode of a drop down list
* @param ddlist pointer to a drop down list object

View File

@@ -585,12 +585,12 @@ static bool lv_page_design(lv_obj_t * page, const lv_area_t * mask, lv_design_mo
/*Draw only a border*/
lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG);
lv_coord_t shadow_width_tmp = style->body.shadow.width;
uint8_t empty_tmp = style->body.empty;
lv_opa_t opa_tmp = style->body.opa;
style->body.shadow.width = 0;
style->body.empty = 1;
style->body.opa = LV_OPA_TRANSP;
lv_draw_rect(&page->coords, mask, style, lv_obj_get_opa_scale(page));
style->body.shadow.width = shadow_width_tmp;
style->body.empty = empty_tmp;
style->body.opa = opa_tmp;
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
@@ -677,16 +677,24 @@ static bool lv_scrl_design(lv_obj_t * scrl, const lv_area_t * mask, lv_design_mo
} else if(mode == LV_DESIGN_DRAW_MAIN) {
#if USE_LV_GROUP
/* If the page is focused in a group and
* the background object is not visible (transparent or empty)
* the background object is not visible (transparent)
* then "activate" the style of the scrollable*/
lv_style_t * style_scrl_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 || style_page->body.opa == LV_OPA_TRANSP) && style_page->body.border.width == 0) { /*Is the background visible?*/
if((style_page->body.opa == LV_OPA_TRANSP) && style_page->body.border.width == 0) { /*Is the background visible?*/
if(lv_group_get_focused(g) == page) {
lv_style_t * style_mod;
style_mod = lv_group_mod_style(g, style_scrl_ori);
/*If still not visible modify the style a littel bit*/
if((style_mod->body.opa == LV_OPA_TRANSP) && style_mod->body.border.width == 0) {
style_mod->body.opa = LV_OPA_50;
style_mod->body.border.width = 1;
style_mod = lv_group_mod_style(g, style_mod);
}
scrl->style_p = style_mod; /*Temporally change the style to the activated */
}
}
@@ -729,10 +737,10 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
/*Reposition the child to take padding into account*/
lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_SCRL);
child->coords.x1 += style->body.padding.hor;
child->coords.x2 += style->body.padding.hor;
child->coords.y1 += style->body.padding.ver;
child->coords.y2 += style->body.padding.ver;
tmp->coords.x1 += style->body.padding.hor;
tmp->coords.x2 += style->body.padding.hor;
tmp->coords.y1 += style->body.padding.ver;
tmp->coords.y2 += style->body.padding.ver;
lv_obj_set_parent(tmp, ext->scrl);
} else {

View File

@@ -87,6 +87,7 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy)
lv_page_set_scrl_fit2(new_roller, LV_FIT_TIGHT, LV_FIT_NONE); /*Height is specified directly*/
lv_ddlist_open(new_roller, false);
lv_ddlist_set_anim_time(new_roller, LV_ROLLER_ANIM_TIME);
lv_ddlist_set_stay_open(new_roller, true);
lv_roller_set_visible_row_count(new_roller, 3);
lv_label_set_align(ext->ddlist.label, LV_LABEL_ALIGN_CENTER);

View File

@@ -104,7 +104,7 @@ void lv_roller_set_visible_row_count(lv_obj_t *roller, uint8_t row_cnt);
*/
static inline void lv_roller_set_hor_fit(lv_obj_t * roller, bool en)
{
lv_ddlist_set_hor_fit(roller, en);
lv_ddlist_set_fit(roller, en);
}
/**

View File

@@ -63,8 +63,6 @@ lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy)
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_spinbox);
/*Initialize the allocated 'ext'*/
ext->ta.one_line = 1;
ext->ta.pwd_mode = 0;
ext->ta.accapted_chars = "1234567890+-. ";
ext->value = 0;
@@ -77,6 +75,7 @@ lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy)
ext->value_changed_cb = NULL;
lv_ta_set_cursor_type(new_spinbox, LV_CURSOR_BLOCK | LV_CURSOR_HIDDEN); /*hidden by default*/
lv_ta_set_one_line(new_spinbox, true);
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_cb(new_spinbox, lv_spinbox_signal);

View File

@@ -106,8 +106,7 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy)
ext->tab_name_ptr[0] = "";
ext->tab_cnt = 0;
lv_disp_t * disp = lv_obj_get_disp(new_tabview);
lv_obj_set_size(new_tabview, lv_disp_get_hor_res(disp), lv_disp_get_ver_res(disp));
lv_obj_set_size(new_tabview, LV_DPI * 3, LV_DPI * 2);
ext->btns = lv_btnm_create(new_tabview, NULL);
lv_obj_set_height(ext->btns, 3 * LV_DPI / 4);

View File

@@ -105,7 +105,7 @@ lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy)
lv_win_set_style(new_win, LV_WIN_STYLE_BTN_PR, th->style.win.btn.pr);
} else {
lv_win_set_style(new_win, LV_WIN_STYLE_BG, &lv_style_plain);
lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_BG, &lv_style_plain);
lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_BG, &lv_style_transp_fit);
lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_SCRL, &lv_style_transp);
lv_win_set_style(new_win, LV_WIN_STYLE_HEADER, &lv_style_plain_color);
}
@@ -133,11 +133,11 @@ lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy)
}
lv_obj_set_signal_cb(new_win, lv_win_signal);
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_win);
}
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_win);
lv_win_realign(new_win);
LV_LOG_INFO("window created");