mirror of
https://github.com/lvgl/lvgl.git
synced 2026-09-22 19:26:06 +08:00
feat(label) update long modes and use LV_SIZE_CONTENT
This commit is contained in:
@@ -49,7 +49,11 @@ props = [
|
||||
|
||||
{'name': 'ANIM_TIME',
|
||||
'style_type': 'num', 'var_type': 'uint32_t' , 'default':0, 'inherited': 0, 'layout': 0, 'ext_draw': 0,
|
||||
'dsc': "The animation time in milliseconds. It's meaning is widget specific. E.g. blink time of the cursor on the text area or scroll speed of a roller. See the widgets' documentation to learn more."},
|
||||
'dsc': "The animation time in milliseconds. It's meaning is widget specific. E.g. blink time of the cursor on the text area or scroll time of a roller. See the widgets' documentation to learn more."},
|
||||
|
||||
{'name': 'ANIM_SPEED',
|
||||
'style_type': 'num', 'var_type': 'uint32_t' , 'default':0, 'inherited': 0, 'layout': 0, 'ext_draw': 0,
|
||||
'dsc': "The animation speed in pixel/sec. It's meaning is widget specific. E.g. scroll speed of label. See the widgets' documentation to learn more."},
|
||||
|
||||
{'name': 'TRANSITION',
|
||||
'style_type': 'ptr', 'var_type': 'const lv_style_transition_dsc_t *' , 'default':0, 'inherited': 0, 'layout': 0, 'ext_draw': 0,
|
||||
|
||||
@@ -70,6 +70,12 @@ static inline uint32_t lv_obj_get_style_anim_time(const struct _lv_obj_t * obj,
|
||||
return (uint32_t)v.num;
|
||||
}
|
||||
|
||||
static inline uint32_t lv_obj_get_style_anim_speed(const struct _lv_obj_t * obj, uint32_t part)
|
||||
{
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ANIM_SPEED);
|
||||
return (uint32_t)v.num;
|
||||
}
|
||||
|
||||
static inline const lv_style_transition_dsc_t * lv_obj_get_style_transition(const struct _lv_obj_t * obj, uint32_t part)
|
||||
{
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION);
|
||||
@@ -616,6 +622,14 @@ static inline void lv_obj_set_style_anim_time(struct _lv_obj_t * obj, uint32_t v
|
||||
lv_obj_set_local_style_prop(obj, LV_STYLE_ANIM_TIME, v, selector);
|
||||
}
|
||||
|
||||
static inline void lv_obj_set_style_anim_speed(struct _lv_obj_t * obj, uint32_t value, lv_style_selector_t selector)
|
||||
{
|
||||
lv_style_value_t v = {
|
||||
.num = (int32_t)value
|
||||
};
|
||||
lv_obj_set_local_style_prop(obj, LV_STYLE_ANIM_SPEED, v, selector);
|
||||
}
|
||||
|
||||
static inline void lv_obj_set_style_transition(struct _lv_obj_t * obj, const lv_style_transition_dsc_t * value, lv_style_selector_t selector)
|
||||
{
|
||||
lv_style_value_t v = {
|
||||
|
||||
@@ -49,6 +49,10 @@ void lv_style_init(lv_style_t * style)
|
||||
#if LV_USE_ASSERT_STYLE
|
||||
style->sentinel = LV_STYLE_SENTINEL_VALUE;
|
||||
#endif
|
||||
|
||||
static int cnt = 0;
|
||||
cnt++;
|
||||
printf("%d\n", cnt);
|
||||
}
|
||||
|
||||
void lv_style_reset(lv_style_t * style)
|
||||
|
||||
+2
-1
@@ -125,7 +125,8 @@ typedef enum {
|
||||
LV_STYLE_COLOR_FILTER_DSC = 10,
|
||||
LV_STYLE_COLOR_FILTER_OPA = 11,
|
||||
LV_STYLE_ANIM_TIME = 12,
|
||||
LV_STYLE_TRANSITION = 13,
|
||||
LV_STYLE_ANIM_SPEED = 12,
|
||||
LV_STYLE_TRANSITION = 14,
|
||||
LV_STYLE_BLEND_MODE = 15,
|
||||
|
||||
/*Group 1*/
|
||||
|
||||
@@ -94,6 +94,14 @@ static inline void lv_style_set_anim_time(lv_style_t * style, uint32_t value)
|
||||
lv_style_set_prop(style, LV_STYLE_ANIM_TIME, v);
|
||||
}
|
||||
|
||||
static inline void lv_style_set_anim_speed(lv_style_t * style, uint32_t value)
|
||||
{
|
||||
lv_style_value_t v = {
|
||||
.num = (int32_t)value
|
||||
};
|
||||
lv_style_set_prop(style, LV_STYLE_ANIM_SPEED, v);
|
||||
}
|
||||
|
||||
static inline void lv_style_set_transition(lv_style_t * style, const lv_style_transition_dsc_t * value)
|
||||
{
|
||||
lv_style_value_t v = {
|
||||
|
||||
+39
-31
@@ -23,7 +23,8 @@
|
||||
*********************/
|
||||
#define MY_CLASS &lv_label_class
|
||||
|
||||
#define LV_LABEL_DEF_SCROLL_SPEED 25
|
||||
#define LV_LABEL_DEF_SCROLL_SPEED (lv_disp_get_dpi(lv_obj_get_disp(obj)) / 3)
|
||||
#define LV_LABEL_SCROLL_DELAY 300
|
||||
#define LV_LABEL_DOT_END_INV 0xFFFFFFFF
|
||||
#define LV_LABEL_HINT_HEIGHT_LIMIT 1024 /*Enable "hint" to buffer info about labels larger than this. (Speed up drawing)*/
|
||||
|
||||
@@ -56,6 +57,8 @@ const lv_obj_class_t lv_label_class = {
|
||||
.constructor_cb = lv_label_constructor,
|
||||
.destructor_cb = lv_label_destructor,
|
||||
.event_cb = lv_label_event,
|
||||
.width_def = LV_SIZE_CONTENT,
|
||||
.height_def = LV_SIZE_CONTENT,
|
||||
.instance_size = sizeof(lv_label_t),
|
||||
.base_class = &lv_obj_class
|
||||
};
|
||||
@@ -319,7 +322,7 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t
|
||||
|
||||
if(label->recolor != 0) flag |= LV_TEXT_FLAG_RECOLOR;
|
||||
if(label->expand != 0) flag |= LV_TEXT_FLAG_EXPAND;
|
||||
if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TEXT_FLAG_FIT;
|
||||
if(label->long_mode == LV_LABEL_LONG_WRAP) flag |= LV_TEXT_FLAG_FIT;
|
||||
|
||||
uint32_t byte_id = _lv_txt_encoded_get_byte_id(txt, char_id);
|
||||
|
||||
@@ -417,7 +420,6 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in)
|
||||
|
||||
if(label->recolor != 0) flag |= LV_TEXT_FLAG_RECOLOR;
|
||||
if(label->expand != 0) flag |= LV_TEXT_FLAG_EXPAND;
|
||||
if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TEXT_FLAG_FIT;
|
||||
|
||||
lv_text_align_t align = lv_obj_get_style_text_align(obj, LV_PART_MAIN);
|
||||
|
||||
@@ -536,7 +538,6 @@ bool lv_label_is_char_under_pos(const lv_obj_t * obj, lv_point_t * pos)
|
||||
|
||||
if(label->recolor != 0) flag |= LV_TEXT_FLAG_RECOLOR;
|
||||
if(label->expand != 0) flag |= LV_TEXT_FLAG_EXPAND;
|
||||
if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TEXT_FLAG_FIT;
|
||||
|
||||
/*Search the line of the index letter*/;
|
||||
while(txt[line_start] != '\0') {
|
||||
@@ -703,7 +704,7 @@ static void lv_label_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
label->static_txt = 0;
|
||||
label->recolor = 0;
|
||||
label->dot_end = LV_LABEL_DOT_END_INV;
|
||||
label->long_mode = LV_LABEL_LONG_EXPAND;
|
||||
label->long_mode = LV_LABEL_LONG_WRAP;
|
||||
label->offset.x = 0;
|
||||
label->offset.y = 0;
|
||||
|
||||
@@ -721,7 +722,7 @@ static void lv_label_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
label->dot_tmp_alloc = 0;
|
||||
|
||||
lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_label_set_long_mode(obj, LV_LABEL_LONG_EXPAND);
|
||||
lv_label_set_long_mode(obj, LV_LABEL_LONG_WRAP);
|
||||
lv_label_set_text(obj, "Text");
|
||||
|
||||
|
||||
@@ -760,6 +761,25 @@ 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) {
|
||||
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);
|
||||
lv_coord_t letter_space = lv_obj_get_style_text_letter_space(obj, LV_PART_MAIN);
|
||||
lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
|
||||
lv_text_flag_t flag = LV_TEXT_FLAG_NONE;
|
||||
if(label->recolor != 0) flag |= LV_TEXT_FLAG_RECOLOR;
|
||||
if(label->expand != 0) flag |= LV_TEXT_FLAG_EXPAND;
|
||||
|
||||
lv_coord_t w = lv_obj_get_style_width(obj, LV_PART_MAIN);
|
||||
if(w == LV_SIZE_CONTENT) w = LV_COORD_MAX;
|
||||
|
||||
lv_txt_get_size(&size, label->text, font, letter_space, line_space, w, flag);
|
||||
|
||||
lv_point_t * self_size = lv_event_get_param(e);
|
||||
self_size->x = LV_MAX(self_size->x, size.x);
|
||||
self_size->y = LV_MAX(self_size->y, size.y);
|
||||
}
|
||||
else if(code == LV_EVENT_BASE_DIR_CHANGED) {
|
||||
#if LV_USE_BIDI
|
||||
lv_label_t * label = (lv_label_t *)obj;
|
||||
@@ -789,7 +809,6 @@ static void draw_main(lv_event_t * e)
|
||||
lv_text_flag_t flag = LV_TEXT_FLAG_NONE;
|
||||
if(label->recolor != 0) flag |= LV_TEXT_FLAG_RECOLOR;
|
||||
if(label->expand != 0) flag |= LV_TEXT_FLAG_EXPAND;
|
||||
if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TEXT_FLAG_FIT;
|
||||
|
||||
lv_draw_label_dsc_t label_draw_dsc;
|
||||
lv_draw_label_dsc_init(&label_draw_dsc);
|
||||
@@ -877,26 +896,19 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
lv_text_flag_t flag = LV_TEXT_FLAG_NONE;
|
||||
if(label->recolor != 0) flag |= LV_TEXT_FLAG_RECOLOR;
|
||||
if(label->expand != 0) flag |= LV_TEXT_FLAG_EXPAND;
|
||||
if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TEXT_FLAG_FIT;
|
||||
lv_txt_get_size(&size, label->text, font, letter_space, line_space, max_w, flag);
|
||||
|
||||
/*Set the full size in expand mode*/
|
||||
if(label->long_mode == LV_LABEL_LONG_EXPAND) {
|
||||
size.x += lv_obj_get_style_pad_left(obj, LV_PART_MAIN) + lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
size.y += lv_obj_get_style_pad_top(obj, LV_PART_MAIN) + lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
|
||||
lv_obj_set_size(obj, size.x, size.y);
|
||||
}
|
||||
/*In roll mode keep the size but start offset animations*/
|
||||
else if(label->long_mode == LV_LABEL_LONG_SCROLL) {
|
||||
uint16_t anim_speed = lv_obj_get_style_anim_time(obj, LV_PART_MAIN);
|
||||
lv_obj_handle_self_size_chg(obj)
|
||||
;
|
||||
/*In scroll mode start an offset animations*/
|
||||
if(label->long_mode == LV_LABEL_LONG_SCROLL) {
|
||||
uint16_t anim_speed = lv_obj_get_style_anim_speed(obj, LV_PART_MAIN);
|
||||
if(anim_speed == 0) anim_speed = LV_LABEL_DEF_SCROLL_SPEED;
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, obj);
|
||||
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
|
||||
lv_anim_set_playback_delay(&a, (((lv_font_get_glyph_width(font, ' ', ' ') + letter_space) * 1000) /
|
||||
anim_speed) *
|
||||
LV_LABEL_WAIT_CHAR_COUNT);
|
||||
lv_anim_set_playback_delay(&a, LV_LABEL_SCROLL_DELAY);
|
||||
lv_anim_set_repeat_delay(&a, a.playback_delay);
|
||||
|
||||
bool hor_anim = false;
|
||||
@@ -921,7 +933,6 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
#else
|
||||
lv_anim_set_values(&a, 0, lv_area_get_width(&txt_coords) - size.x);
|
||||
lv_anim_set_exec_cb(&a, set_ofs_x_anim);
|
||||
lv_anim_set_time(&a, lv_anim_speed_to_time(anim_speed, a.start_value, a.end_value));
|
||||
#endif
|
||||
lv_anim_set_exec_cb(&a, set_ofs_x_anim);
|
||||
|
||||
@@ -945,6 +956,8 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
}
|
||||
}
|
||||
|
||||
lv_anim_set_time(&a, lv_anim_speed_to_time(anim_speed, a.start_value, a.end_value));
|
||||
lv_anim_set_playback_time(&a, a.time);
|
||||
lv_anim_start(&a);
|
||||
hor_anim = true;
|
||||
}
|
||||
@@ -957,8 +970,6 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
if(size.y > lv_area_get_height(&txt_coords) && hor_anim == false) {
|
||||
lv_anim_set_values(&a, 0, lv_area_get_height(&txt_coords) - size.y - (lv_font_get_line_height(font)));
|
||||
lv_anim_set_exec_cb(&a, set_ofs_y_anim);
|
||||
lv_anim_set_time(&a, lv_anim_speed_to_time(anim_speed, a.start_value, a.end_value));
|
||||
lv_anim_set_playback_time(&a, a.time);
|
||||
|
||||
lv_anim_t * anim_cur = lv_anim_get(obj, set_ofs_y_anim);
|
||||
int32_t act_time = 0;
|
||||
@@ -980,6 +991,8 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
}
|
||||
}
|
||||
|
||||
lv_anim_set_time(&a, lv_anim_speed_to_time(anim_speed, a.start_value, a.end_value));
|
||||
lv_anim_set_playback_time(&a, a.time);
|
||||
lv_anim_start(&a);
|
||||
}
|
||||
else {
|
||||
@@ -990,7 +1003,7 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
}
|
||||
/*In roll inf. mode keep the size but start offset animations*/
|
||||
else if(label->long_mode == LV_LABEL_LONG_SCROLL_CIRCULAR) {
|
||||
uint16_t anim_speed = lv_obj_get_style_anim_time(obj, LV_PART_MAIN);
|
||||
uint16_t anim_speed = lv_obj_get_style_anim_speed(obj, LV_PART_MAIN);
|
||||
if(anim_speed == 0) anim_speed = LV_LABEL_DEF_SCROLL_SPEED;
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
@@ -1018,9 +1031,9 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
lv_anim_set_values(&a, start, end);
|
||||
#else
|
||||
lv_anim_set_values(&a, 0, -size.x - lv_font_get_glyph_width(font, ' ', ' ') * LV_LABEL_WAIT_CHAR_COUNT);
|
||||
#endif
|
||||
lv_anim_set_exec_cb(&a, set_ofs_x_anim);
|
||||
lv_anim_set_time(&a, lv_anim_speed_to_time(anim_speed, a.start_value, a.end_value));
|
||||
#endif
|
||||
|
||||
lv_anim_t * anim_cur = lv_anim_get(obj, set_ofs_x_anim);
|
||||
int32_t act_time = anim_cur ? anim_cur->act_time : 0;
|
||||
@@ -1059,6 +1072,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);
|
||||
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;
|
||||
}
|
||||
@@ -1111,12 +1125,6 @@ static void lv_label_refr_text(lv_obj_t * obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*In break mode only the height can change*/
|
||||
else if(label->long_mode == LV_LABEL_LONG_WRAP) {
|
||||
size.y += lv_obj_get_style_pad_top(obj, LV_PART_MAIN) + lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
|
||||
lv_obj_set_height(obj, size.y);
|
||||
}
|
||||
/*Do not set the size in Clip mode*/
|
||||
else if(label->long_mode == LV_LABEL_LONG_CLIP) {
|
||||
/*Do nothing*/
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ LV_EXPORT_CONST_INT(LV_LABEL_TEXT_SEL_OFF);
|
||||
|
||||
/** Long mode behaviors. Used in 'lv_label_ext_t'*/
|
||||
enum {
|
||||
LV_LABEL_LONG_EXPAND, /**< Expand the object size to the text size*/
|
||||
LV_LABEL_LONG_WRAP, /**< Keep the object width, wrap the too long lines and expand the object height*/
|
||||
LV_LABEL_LONG_DOT, /**< Keep the size and write dots at the end if the text is too long*/
|
||||
LV_LABEL_LONG_SCROLL, /**< Keep the size and roll the text back and forth*/
|
||||
|
||||
@@ -478,7 +478,7 @@ void lv_textarea_set_one_line(lv_obj_t * obj, bool en)
|
||||
|
||||
ta->one_line = 1;
|
||||
lv_obj_set_content_height(obj, font_h);
|
||||
lv_label_set_long_mode(ta->label, LV_LABEL_LONG_EXPAND);
|
||||
lv_label_set_long_mode(ta->label, LV_LABEL_LONG_WRAP);
|
||||
lv_obj_scroll_to(obj, 0, 0, LV_ANIM_OFF);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user