feat(textarea) remove the need of lv_textarea_set_align

It was used to position the text in one line text areas where the label is shorter then the text area itself.
However, setting min_width=100% in case of one line text area ensures that the label is at least as wide as
the text area. This way the normal text_align style property can be used too.

Fixes https://forum.lvgl.io/t/spinbox-text-centering-not-working-as-intended-expected/6762/4
This commit is contained in:
Gabor Kiss-Vamosi
2021-09-13 20:09:09 +02:00
parent 26e15fa577
commit 56ebb1a4c8
3 changed files with 4 additions and 5 deletions

View File

@@ -74,11 +74,6 @@ In password mode `lv_textarea_get_text(textarea)` returns the actual text entere
The visibility time can be adjusted with `LV_TEXTAREA_DEF_PWD_SHOW_TIME)` in `lv_conf.h`. The visibility time can be adjusted with `LV_TEXTAREA_DEF_PWD_SHOW_TIME)` in `lv_conf.h`.
### Text alignment
To align the text in the Text area ` lv_textarea_set_align(textarea, LV_TEXT_ALIGN_LEFT/RIGHT/CENTER)` needs to be used instead of setting the `text_align` style property.
### Accepted characters ### Accepted characters
You can set a list of accepted characters with `lv_textarea_set_accepted_chars(textarea, "0123456789.+-")`. You can set a list of accepted characters with `lv_textarea_set_accepted_chars(textarea, "0123456789.+-")`.
Other characters will be ignored. Other characters will be ignored.

View File

@@ -489,6 +489,7 @@ void lv_textarea_set_one_line(lv_obj_t * obj, bool en)
if(en) { if(en) {
ta->one_line = 1; ta->one_line = 1;
lv_obj_set_width(ta->label, LV_SIZE_CONTENT); lv_obj_set_width(ta->label, LV_SIZE_CONTENT);
lv_obj_set_style_min_width(ta->label, lv_pct(100), 0);
lv_obj_set_height(obj, LV_SIZE_CONTENT); lv_obj_set_height(obj, LV_SIZE_CONTENT);
lv_obj_scroll_to(obj, 0, 0, LV_ANIM_OFF); lv_obj_scroll_to(obj, 0, 0, LV_ANIM_OFF);
@@ -496,6 +497,7 @@ void lv_textarea_set_one_line(lv_obj_t * obj, bool en)
else { else {
ta->one_line = 0; ta->one_line = 0;
lv_obj_set_width(ta->label, lv_pct(100)); lv_obj_set_width(ta->label, lv_pct(100));
lv_obj_set_style_min_width(ta->label, 0, 0);
lv_obj_remove_local_style_prop(obj, LV_STYLE_HEIGHT, LV_PART_MAIN); lv_obj_remove_local_style_prop(obj, LV_STYLE_HEIGHT, LV_PART_MAIN);
lv_obj_scroll_to(obj, 0, 0, LV_ANIM_OFF); lv_obj_scroll_to(obj, 0, 0, LV_ANIM_OFF);
} }
@@ -553,6 +555,7 @@ void lv_textarea_set_password_show_time(lv_obj_t * obj, uint16_t time)
void lv_textarea_set_align(lv_obj_t * obj, lv_text_align_t align) void lv_textarea_set_align(lv_obj_t * obj, lv_text_align_t align)
{ {
LV_LOG_WARN("Deprecated: use the normal text_align style property instead");
lv_obj_set_style_text_align(obj, align, 0); lv_obj_set_style_text_align(obj, align, 0);
switch(align) { switch(align) {

View File

@@ -199,6 +199,7 @@ void lv_textarea_set_text_selection(lv_obj_t * obj, bool en);
void lv_textarea_set_password_show_time(lv_obj_t * obj, uint16_t time); void lv_textarea_set_password_show_time(lv_obj_t * obj, uint16_t time);
/** /**
* Deprecated: use the normal text_align style property instead
* Set the label's alignment. * Set the label's alignment.
* It sets where the label is aligned (in one line mode it can be smaller than the text area) * It sets where the label is aligned (in one line mode it can be smaller than the text area)
* and how the lines of the area align in case of multiline text area * and how the lines of the area align in case of multiline text area