mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(obj) save self_size in the obejct to save a lot of recalculations
This commit is contained in:
parent
ff2c2e5d33
commit
1b93668df7
@ -8,7 +8,6 @@ static void set_value(void * indic, int32_t v)
|
||||
lv_meter_set_indicator_end_value(meter, indic, v);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A clock from a meter
|
||||
*/
|
||||
|
@ -285,7 +285,7 @@ static bool event_is_bubbled(lv_event_code_t e)
|
||||
case LV_EVENT_CHILD_CHANGED:
|
||||
case LV_EVENT_SIZE_CHANGED:
|
||||
case LV_EVENT_STYLE_CHANGED:
|
||||
case LV_EVENT_GET_SELF_SIZE:
|
||||
case LV_EVENT_REFR_SELF_SIZE:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
|
@ -76,7 +76,7 @@ typedef enum {
|
||||
LV_EVENT_SIZE_CHANGED, /**< Object coordinates/size have changed*/
|
||||
LV_EVENT_STYLE_CHANGED, /**< Object's style has changed*/
|
||||
LV_EVENT_BASE_DIR_CHANGED, /**< The base dir has changed*/
|
||||
LV_EVENT_GET_SELF_SIZE, /**< Get the internal size of a widget*/
|
||||
LV_EVENT_REFR_SELF_SIZE, /**< Get the internal size of a widget*/
|
||||
|
||||
_LV_EVENT_LAST /** Number of default events*/
|
||||
}lv_event_code_t;
|
||||
|
@ -164,6 +164,7 @@ typedef struct _lv_obj_t {
|
||||
void * user_data;
|
||||
#endif
|
||||
lv_area_t coords;
|
||||
lv_point_t self_size;
|
||||
lv_obj_flag_t flags;
|
||||
lv_state_t state;
|
||||
uint16_t layout_inv :1;
|
||||
|
@ -592,23 +592,20 @@ void lv_obj_get_content_coords(const lv_obj_t * obj, lv_area_t * area)
|
||||
|
||||
lv_coord_t lv_obj_get_self_width(struct _lv_obj_t * obj)
|
||||
{
|
||||
lv_point_t p = {0, LV_COORD_MIN};
|
||||
lv_event_send((lv_obj_t * )obj, LV_EVENT_GET_SELF_SIZE, &p);
|
||||
return p.x;
|
||||
return obj->self_size.x;
|
||||
}
|
||||
|
||||
lv_coord_t lv_obj_get_self_height(struct _lv_obj_t * obj)
|
||||
{
|
||||
lv_point_t p = {LV_COORD_MIN, 0};
|
||||
lv_event_send((lv_obj_t * )obj, LV_EVENT_GET_SELF_SIZE, &p);
|
||||
return p.y;
|
||||
return obj->self_size.y;
|
||||
}
|
||||
|
||||
bool lv_obj_handle_self_size_chg(struct _lv_obj_t * obj)
|
||||
bool lv_obj_refresh_self_size(struct _lv_obj_t * obj)
|
||||
{
|
||||
lv_coord_t w_set = lv_obj_get_style_width(obj, LV_PART_MAIN);
|
||||
lv_coord_t h_set = lv_obj_get_style_height(obj, LV_PART_MAIN);
|
||||
if(w_set != LV_SIZE_CONTENT && h_set != LV_SIZE_CONTENT) return false;
|
||||
lv_obj_update_layout(obj);
|
||||
obj->self_size.x = 0;
|
||||
obj->self_size.y = 0;
|
||||
lv_event_send(obj, LV_EVENT_REFR_SELF_SIZE, &obj->self_size);
|
||||
|
||||
lv_obj_refr_size(obj);
|
||||
return true;
|
||||
|
@ -293,7 +293,7 @@ lv_coord_t lv_obj_get_self_height(struct _lv_obj_t * obj);
|
||||
* @param obj pointer to an object
|
||||
* @return false: nothing happened; true: refresh happened
|
||||
*/
|
||||
bool lv_obj_handle_self_size_chg(struct _lv_obj_t * obj);
|
||||
bool lv_obj_refresh_self_size(struct _lv_obj_t * obj);
|
||||
|
||||
void lv_obj_refr_pos(struct _lv_obj_t * obj);
|
||||
|
||||
|
@ -299,10 +299,12 @@ void lv_obj_scroll_to_x(lv_obj_t * obj, lv_coord_t x, lv_anim_enable_t anim_en)
|
||||
|
||||
/*Don't let scroll more then naturally possible by the size of the content*/
|
||||
if(x < 0) x = 0;
|
||||
lv_coord_t scroll_max = lv_obj_get_scroll_left(obj) + lv_obj_get_scroll_right(obj);
|
||||
if(scroll_max < 0) scroll_max = 0;
|
||||
if(x > 0) {
|
||||
lv_coord_t scroll_max = lv_obj_get_scroll_left(obj) + lv_obj_get_scroll_right(obj);
|
||||
if(scroll_max < 0) scroll_max = 0;
|
||||
|
||||
if(x > scroll_max) x = scroll_max;
|
||||
if(x > scroll_max) x = scroll_max;
|
||||
}
|
||||
|
||||
lv_coord_t scroll_x = lv_obj_get_scroll_x(obj);
|
||||
lv_coord_t diff = -x + scroll_x;
|
||||
@ -316,9 +318,11 @@ void lv_obj_scroll_to_y(lv_obj_t * obj, lv_coord_t y, lv_anim_enable_t anim_en)
|
||||
|
||||
/*Don't let scroll more then naturally possible by the size of the content*/
|
||||
if(y < 0) y = 0;
|
||||
lv_coord_t scroll_max = lv_obj_get_scroll_top(obj) + lv_obj_get_scroll_bottom(obj);
|
||||
if(scroll_max < 0) scroll_max = 0;
|
||||
if(y > scroll_max) y = scroll_max;
|
||||
if(y > 0) {
|
||||
lv_coord_t scroll_max = lv_obj_get_scroll_top(obj) + lv_obj_get_scroll_bottom(obj);
|
||||
if(scroll_max < 0) scroll_max = 0;
|
||||
if(y > scroll_max) y = scroll_max;
|
||||
}
|
||||
|
||||
lv_coord_t scroll_y = lv_obj_get_scroll_y(obj);
|
||||
lv_coord_t diff = -y + scroll_y;
|
||||
|
@ -61,7 +61,6 @@ void lv_draw_img_dsc_init(lv_draw_img_dsc_t * dsc)
|
||||
dsc->opa = LV_OPA_COVER;
|
||||
dsc->zoom = LV_IMG_ZOOM_NONE;
|
||||
dsc->antialias = LV_COLOR_DEPTH > 8 ? 1 : 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,6 +196,7 @@ void lv_chart_set_zoom_x(lv_obj_t * obj, uint16_t zoom_x)
|
||||
if(chart->zoom_x == zoom_x) return;
|
||||
|
||||
chart->zoom_x = zoom_x;
|
||||
lv_obj_refresh_self_size(obj);
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
|
||||
@ -207,6 +208,7 @@ void lv_chart_set_zoom_y(lv_obj_t * obj, uint16_t zoom_y)
|
||||
if(chart->zoom_y == zoom_y) return;
|
||||
|
||||
chart->zoom_y = zoom_y;
|
||||
lv_obj_refresh_self_size(obj);
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
|
||||
@ -645,7 +647,7 @@ static void lv_chart_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
lv_coord_t * s = lv_event_get_param(e);
|
||||
*s = LV_MAX4(*s, chart->tick[LV_CHART_AXIS_X].draw_size,
|
||||
chart->tick[LV_CHART_AXIS_PRIMARY_Y].draw_size, chart->tick[LV_CHART_AXIS_SECONDARY_Y].draw_size);
|
||||
} else if(code == LV_EVENT_GET_SELF_SIZE) {
|
||||
} else if(code == LV_EVENT_REFR_SELF_SIZE) {
|
||||
lv_point_t * p = lv_event_get_param(e);
|
||||
p->x = (lv_obj_get_content_width(obj) * chart->zoom_x) >> 8;
|
||||
p->y = (lv_obj_get_content_height(obj) * chart->zoom_y) >> 8;
|
||||
|
@ -82,7 +82,7 @@ void lv_checkbox_set_text(lv_obj_t * obj, const char * txt)
|
||||
|
||||
cb->static_txt = 0;
|
||||
|
||||
lv_obj_handle_self_size_chg(obj);
|
||||
lv_obj_refresh_self_size(obj);
|
||||
}
|
||||
|
||||
void lv_checkbox_set_text_static(lv_obj_t * obj, const char * txt)
|
||||
@ -94,7 +94,7 @@ void lv_checkbox_set_text_static(lv_obj_t * obj, const char * txt)
|
||||
cb->txt = (char*)txt;
|
||||
cb->static_txt = 1;
|
||||
|
||||
lv_obj_handle_self_size_chg(obj);
|
||||
lv_obj_refresh_self_size(obj);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
@ -155,7 +155,7 @@ static void lv_checkbox_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
if (code == LV_EVENT_PRESSED || code == LV_EVENT_RELEASED) {
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
else if (code == LV_EVENT_GET_SELF_SIZE) {
|
||||
else if (code == LV_EVENT_REFR_SELF_SIZE) {
|
||||
lv_point_t * p = lv_event_get_param(e);
|
||||
lv_checkbox_t * cb = (lv_checkbox_t *)obj;
|
||||
|
||||
|
@ -658,10 +658,14 @@ static void lv_dropdown_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
}
|
||||
else if(code == LV_EVENT_STYLE_CHANGED) {
|
||||
lv_obj_refresh_self_size(obj);
|
||||
}
|
||||
else if(code == LV_EVENT_SIZE_CHANGED) {
|
||||
lv_obj_refresh_self_size(obj);
|
||||
if(dropdown->list) lv_dropdown_close(obj);
|
||||
}
|
||||
else if(code == LV_EVENT_GET_SELF_SIZE) {
|
||||
else if(code == LV_EVENT_REFR_SELF_SIZE) {
|
||||
lv_point_t * p = lv_event_get_param(e);
|
||||
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
|
||||
p->y = lv_font_get_line_height(font);
|
||||
|
@ -149,7 +149,7 @@ void lv_img_set_src(lv_obj_t * obj, const void * src)
|
||||
img->pivot.x = header.w / 2;
|
||||
img->pivot.y = header.h / 2;
|
||||
|
||||
lv_obj_handle_self_size_chg(obj);
|
||||
lv_obj_refresh_self_size(obj);
|
||||
|
||||
/*Provide enough room for the rotated corners*/
|
||||
if(img->angle || img->zoom != LV_IMG_ZOOM_NONE) lv_obj_refresh_ext_draw_size(obj);
|
||||
@ -471,7 +471,7 @@ static void lv_img_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
info->result = _lv_area_is_point_on(&a, info->point, 0);
|
||||
}
|
||||
}
|
||||
else if(code == LV_EVENT_GET_SELF_SIZE) {
|
||||
else if(code == LV_EVENT_REFR_SELF_SIZE) {
|
||||
lv_point_t * p = lv_event_get_param(e);;
|
||||
p->x = img->w;
|
||||
p->y = img->h;
|
||||
|
@ -763,7 +763,7 @@ static void lv_label_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
lv_label_revert_dots(obj);
|
||||
lv_label_refr_text(obj);
|
||||
}
|
||||
else if(code == LV_EVENT_GET_SELF_SIZE) {
|
||||
else if(code == LV_EVENT_REFR_SELF_SIZE) {
|
||||
lv_point_t size;
|
||||
lv_label_t * label = (lv_label_t *)obj;
|
||||
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
|
||||
@ -905,7 +905,7 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
|
||||
lv_txt_get_size(&size, label->text, font, letter_space, line_space, max_w, flag);
|
||||
|
||||
lv_obj_handle_self_size_chg(obj);
|
||||
lv_obj_refresh_self_size(obj);
|
||||
|
||||
/*In scroll mode start an offset animations*/
|
||||
if(label->long_mode == LV_LABEL_LONG_SCROLL) {
|
||||
@ -1079,7 +1079,7 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
}
|
||||
}
|
||||
else if(label->long_mode == LV_LABEL_LONG_DOT) {
|
||||
lv_obj_handle_self_size_chg(obj);
|
||||
lv_obj_refresh_self_size(obj);
|
||||
if(size.y <= lv_area_get_height(&txt_coords)) { /*No dots are required, the text is short enough*/
|
||||
label->dot_end = LV_LABEL_DOT_END_INV;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ void lv_line_set_points(lv_obj_t * obj, const lv_point_t points[], uint16_t poin
|
||||
line->point_array = points;
|
||||
line->point_num = point_num;
|
||||
|
||||
lv_obj_handle_self_size_chg(obj);
|
||||
lv_obj_refresh_self_size(obj);
|
||||
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
@ -138,7 +138,7 @@ static void lv_line_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
lv_coord_t * s = lv_event_get_param(e);
|
||||
if(*s < line_width) *s = line_width;
|
||||
}
|
||||
else if(code == LV_EVENT_GET_SELF_SIZE) {
|
||||
else if(code == LV_EVENT_REFR_SELF_SIZE) {
|
||||
lv_line_t * line = (lv_line_t *)obj;
|
||||
|
||||
lv_point_t * p = lv_event_get_param(e);
|
||||
|
@ -317,7 +317,7 @@ static void lv_roller_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
lv_roller_t * roller = (lv_roller_t*)obj;
|
||||
|
||||
if(code == LV_EVENT_GET_SELF_SIZE) {
|
||||
if(code == LV_EVENT_REFR_SELF_SIZE) {
|
||||
lv_point_t * p = lv_event_get_param(e);
|
||||
p->x = get_selected_label_width(obj);
|
||||
}
|
||||
@ -325,7 +325,7 @@ static void lv_roller_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
lv_obj_t * label = get_label(obj);
|
||||
/*Be sure the label's style is updated before processing the roller*/
|
||||
if(label) lv_event_send(label, LV_EVENT_STYLE_CHANGED, NULL);
|
||||
lv_obj_handle_self_size_chg(obj);
|
||||
lv_obj_refresh_self_size(obj);
|
||||
refr_position(obj, false);
|
||||
}
|
||||
else if(code == LV_EVENT_SIZE_CHANGED) {
|
||||
|
@ -476,7 +476,7 @@ static void lv_table_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
if(code == LV_EVENT_STYLE_CHANGED) {
|
||||
refr_size(obj, 0);
|
||||
}
|
||||
else if(code == LV_EVENT_GET_SELF_SIZE) {
|
||||
else if(code == LV_EVENT_REFR_SELF_SIZE) {
|
||||
lv_point_t * p = lv_event_get_param(e);
|
||||
uint32_t i;
|
||||
lv_coord_t w = 0;
|
||||
@ -779,7 +779,7 @@ static void refr_size(lv_obj_t * obj, uint32_t strat_row)
|
||||
table->row_h[i] = LV_CLAMP(minh, table->row_h[i], maxh);
|
||||
}
|
||||
|
||||
lv_obj_handle_self_size_chg(obj) ;
|
||||
lv_obj_refresh_self_size(obj) ;
|
||||
}
|
||||
|
||||
static lv_coord_t get_row_height(lv_obj_t * obj, uint16_t row_id, const lv_font_t * font,
|
||||
|
Loading…
x
Reference in New Issue
Block a user