fix(textarea): fix the issue of textarea placeholder (#9621)
Arduino Lint / lint (push) Has been cancelled
Build Examples with C++ Compiler / build-examples (push) Has been cancelled
MicroPython CI / Build esp32 port (push) Has been cancelled
MicroPython CI / Build rp2 port (push) Has been cancelled
MicroPython CI / Build stm32 port (push) Has been cancelled
MicroPython CI / Build unix port (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_NORMAL_8BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_SDL - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build ESP IDF ESP32S3 (push) Has been cancelled
C/C++ CI / Run tests with 32bit build (push) Has been cancelled
C/C++ CI / Run tests with 64bit build (push) Has been cancelled
BOM Check / bom-check (push) Has been cancelled
Verify that lv_conf_internal.h matches repository state / verify-conf-internal (push) Has been cancelled
Verify GDB constants are up-to-date / verify-gdb-consts (push) Has been cancelled
Verify the widget property name / verify-property-name (push) Has been cancelled
Verify code formatting / verify-formatting (push) Has been cancelled
Compare file templates with file names / template-check (push) Has been cancelled
Build docs / build-and-deploy (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
Install LVGL using CMake / build-examples (push) Has been cancelled
Check Makefile / Build using Makefile (push) Has been cancelled
Check Makefile for UEFI / Build using Makefile for UEFI (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/benchmark_results_comment/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/filter_docker_logs/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/serialize_results/test.sh) (push) Has been cancelled
Hardware Performance Test / Hardware Performance Benchmark (push) Has been cancelled
Hardware Performance Test / HW Benchmark - Save PR Number (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_32B - Ubuntu (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_64B - Ubuntu (push) Has been cancelled
Port repo release update / run-release-branch-updater (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 32b - lv_conf_perf32b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 64b - lv_conf_perf64b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Save PR Number (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled

Signed-off-by: liujp <liujp@xiaomi.com>
This commit is contained in:
Lemon
2026-04-03 19:02:04 +08:00
committed by GitHub
parent 0194f6942a
commit 6324efbf3b
47 changed files with 409 additions and 11 deletions
+31 -11
View File
@@ -68,6 +68,8 @@ static void lv_textarea_scroll_to_cusor_pos(lv_obj_t * obj, int32_t pos);
static lv_result_t add_char(lv_obj_t * obj, uint32_t c);
static void add_text(lv_obj_t * obj, const char * txt);
static void set_cursor_pos_internal(lv_obj_t * obj, int32_t pos);
static void calc_placeholder_text_size(lv_obj_t * obj);
/**********************
* STATIC VARIABLES
**********************/
@@ -360,6 +362,8 @@ void lv_textarea_set_placeholder_text(lv_obj_t * obj, const char * txt)
lv_strcpy(ta->placeholder_txt, txt);
ta->placeholder_txt[txt_len] = '\0';
calc_placeholder_text_size(obj);
}
lv_obj_invalidate(obj);
@@ -418,7 +422,6 @@ void lv_textarea_set_password_mode(lv_obj_t * obj, bool en)
void lv_textarea_set_password_bullet(lv_obj_t * obj, const char * bullet)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
LV_ASSERT_NULL(bullet);
lv_textarea_t * ta = (lv_textarea_t *)obj;
@@ -467,6 +470,9 @@ void lv_textarea_set_one_line(lv_obj_t * obj, bool en)
}
lv_obj_scroll_to(obj, 0, 0, LV_ANIM_OFF);
/* update placeholder text size */
calc_placeholder_text_size(obj);
}
void lv_textarea_set_accepted_chars(lv_obj_t * obj, const char * list)
@@ -1310,18 +1316,15 @@ static void draw_placeholder(lv_event_t * e)
if(ta->one_line) ph_dsc.flag |= LV_TEXT_FLAG_EXPAND;
int32_t left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
int32_t right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
int32_t top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
int32_t bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
int32_t border_width = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
lv_obj_t * label = ta->label;
int32_t left = lv_obj_get_style_pad_left(label, LV_PART_TEXTAREA_PLACEHOLDER);
int32_t top = lv_obj_get_style_pad_top(label, LV_PART_TEXTAREA_PLACEHOLDER);
lv_area_t ph_coords;
lv_area_copy(&ph_coords, &obj->coords);
ph_coords.x1 += left + border_width;
ph_coords.x2 -= right + border_width;
ph_coords.y1 += top + border_width;
ph_coords.y2 -= bottom + border_width;
lv_area_copy(&ph_coords, &label->coords);
lv_area_move(&ph_coords, left, top);
ph_dsc.text = ta->placeholder_txt;
ph_dsc.text_size = ta->placeholder_txt_size;
lv_draw_label(layer, &ph_dsc, &ph_coords);
}
}
@@ -1564,4 +1567,21 @@ static lv_result_t add_char(lv_obj_t * obj, uint32_t c)
return LV_RESULT_OK;
}
static void calc_placeholder_text_size(lv_obj_t * obj)
{
lv_textarea_t * ta = (lv_textarea_t *)obj;
if(!ta->placeholder_txt) return;
lv_draw_label_dsc_t ph_dsc;
lv_draw_label_dsc_init(&ph_dsc);
lv_obj_init_draw_label_dsc(obj, LV_PART_TEXTAREA_PLACEHOLDER, &ph_dsc);
ph_dsc.text = ta->placeholder_txt;
ph_dsc.font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
if(ta->one_line) ph_dsc.flag |= LV_TEXT_FLAG_EXPAND;
lv_text_get_size(&ta->placeholder_txt_size, ph_dsc.text, ph_dsc.font, ph_dsc.letter_space, ph_dsc.line_space,
LV_COORD_MAX,
ph_dsc.flag);
}
#endif
@@ -32,6 +32,7 @@ struct _lv_textarea_t {
lv_obj_t obj;
lv_obj_t * label; /**< Label of the text area */
char * placeholder_txt; /**< Place holder label. only visible if text is an empty string */
lv_point_t placeholder_txt_size; /**Size of the placeholder text */
char * pwd_tmp; /**< Used to store the original text in password mode */
char * pwd_bullet; /**< Replacement characters displayed in password mode */
char * accepted_chars; /**< Only these characters will be accepted. NULL: accept all */
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

@@ -8,6 +8,52 @@ static lv_obj_t * active_screen = NULL;
static lv_obj_t * textarea = NULL;
static const char * textarea_default_text = "";
static char insert_replace_text[10] = "123";
static void event_handler(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
if(code == LV_EVENT_INSERT) {
const char * txt = lv_event_get_param(e);
if(txt && txt[0] >= '0' && txt[0] <= '9') {
/* insert */
}
else {
lv_obj_t * obj = lv_event_get_target(e);
lv_textarea_set_insert_replace(obj, insert_replace_text);
}
}
}
static bool test_font_get_glyph_dsc(const lv_font_t * font,
lv_font_glyph_dsc_t * dsc_out,
uint32_t unicode_letter,
uint32_t unicode_letter_next)
{
LV_UNUSED(font);
LV_UNUSED(unicode_letter_next);
if(unicode_letter >= 0x20 && unicode_letter <= 0x7E) {
dsc_out->adv_w = 10;
dsc_out->box_w = 8;
dsc_out->box_h = 12;
return true;
}
return false;
}
const void * test_font_get_glyph_bitmap(lv_font_glyph_dsc_t * g_dsc, lv_draw_buf_t * draw_buf)
{
LV_UNUSED(g_dsc);
LV_UNUSED(draw_buf);
return NULL;
}
static lv_font_t test_font_no_bullet = {
.get_glyph_dsc = test_font_get_glyph_dsc,
.get_glyph_bitmap = test_font_get_glyph_bitmap,
.line_height = 14,
.base_line = 12,
};
void setUp(void)
{
@@ -40,6 +86,8 @@ void test_textarea_should_return_actual_text_when_password_mode_is_enabled(void)
TEST_ASSERT_TRUE(lv_textarea_get_password_mode(textarea));
TEST_ASSERT_EQUAL_STRING(text, lv_textarea_get_text(textarea));
lv_textarea_set_password_mode(textarea, false);
}
void test_textarea_should_update_label_style_with_one_line_enabled(void)
@@ -314,4 +362,333 @@ void test_textarea_set_text_should_emit_value_changed_event_only_once(void)
TEST_ASSERT_EQUAL_UINT32(0U, event_count);
}
void test_textarea_set_max_length(void)
{
lv_textarea_set_max_length(textarea, 8);
lv_textarea_add_text(textarea, "1234567890");
TEST_ASSERT_EQUAL_STRING("12345678", lv_textarea_get_text(textarea));
}
void test_textarea_set_insert_replace(void)
{
lv_textarea_set_text(textarea, "1234567890");
lv_obj_add_event_cb(textarea, event_handler, LV_EVENT_INSERT, NULL);
lv_textarea_add_text(textarea, "abc");
TEST_ASSERT_EQUAL_STRING("1234567890123", lv_textarea_get_text(textarea));
lv_memset(insert_replace_text, 0, sizeof(insert_replace_text));
lv_textarea_add_text(textarea, "abc");
TEST_ASSERT_EQUAL_STRING("1234567890123", lv_textarea_get_text(textarea));
}
void test_textarea_placeholder_text_show_one_line(void)
{
lv_textarea_set_one_line(textarea, true);
lv_textarea_set_placeholder_text(textarea, "1234567890");
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_placeholder_show.png");
}
void test_textarea_password_mode(void)
{
lv_textarea_set_one_line(textarea, false);
lv_textarea_set_text(textarea, "123456");
lv_textarea_set_password_mode(textarea, true);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_password_mode.png");
lv_textarea_set_password_mode(textarea, false);
lv_textarea_set_text(textarea, "123456789");
lv_textarea_set_password_mode(textarea, true);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_password_mode_update.png");
lv_textarea_set_password_mode(textarea, false);
lv_textarea_add_text(textarea, "abc");
lv_textarea_set_password_mode(textarea, true);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_password_mode_add_text.png");
lv_textarea_set_password_mode(textarea, false);
lv_textarea_add_char(textarea, 'a');
lv_textarea_set_password_mode(textarea, true);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_password_mode_add_char.png");
lv_textarea_set_password_mode(textarea, false);
lv_textarea_delete_char(textarea);
lv_textarea_set_password_mode(textarea, true);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_password_mode_delete_char.png");
lv_textarea_set_password_mode(textarea, false);
lv_textarea_set_text(textarea, "1234567890");
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_normal_mode.png");
}
void test_textarea_password_mode_hide_char(void)
{
lv_textarea_set_one_line(textarea, false);
lv_textarea_set_password_mode(textarea, true);
lv_textarea_set_password_show_time(textarea, 0);
lv_textarea_add_char(textarea, 'a');
lv_test_wait(50);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_password_mode_hide_char_one.png");
lv_textarea_set_password_show_time(textarea, 500);
lv_textarea_add_char(textarea, 'b');
lv_test_wait(550);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_password_mode_hide_char_two.png");
lv_textarea_add_char(textarea, 'c');
lv_textarea_set_password_mode(textarea, false);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_password_mode_to_normal_mode.png");
lv_textarea_set_text(textarea, "");
}
void test_textarea_set_password_bullet(void)
{
lv_textarea_set_one_line(textarea, false);
lv_textarea_set_text(textarea, "1234567890");
lv_textarea_set_password_mode(textarea, true);
lv_obj_set_style_text_font(textarea, &test_font_no_bullet, 0);
TEST_ASSERT_EQUAL_STRING("*", lv_textarea_get_password_bullet(textarea));
lv_textarea_set_password_bullet(textarea, "*");
TEST_ASSERT_EQUAL_STRING("*", lv_textarea_get_password_bullet(textarea));
lv_textarea_set_password_bullet(textarea, NULL);
TEST_ASSERT_EQUAL_STRING("*", lv_textarea_get_password_bullet(textarea));
lv_textarea_set_password_mode(textarea, false);
lv_textarea_set_text(textarea, "");
}
void test_textarea_delete_char(void)
{
lv_textarea_set_one_line(textarea, false);
lv_textarea_set_text(textarea, "1234567890");
lv_textarea_delete_char(textarea);
}
void test_textarea_delete_char_forward(void)
{
lv_textarea_set_one_line(textarea, false);
lv_textarea_set_text(textarea, "1234567890");
lv_textarea_delete_char_forward(textarea);
}
void test_textarea_set_text_selection(void)
{
lv_textarea_set_one_line(textarea, false);
lv_textarea_set_text(textarea, "1234567890");
lv_textarea_set_text_selection(textarea, true);
TEST_ASSERT_EQUAL(1U, lv_textarea_get_text_selection(textarea));
lv_obj_t * label = lv_textarea_get_label(textarea);
lv_label_set_text_selection_start(label, 0);
lv_label_set_text_selection_end(label, 10);
TEST_ASSERT_EQUAL(1U, lv_textarea_text_is_selected(textarea));
lv_textarea_clear_selection(textarea);
TEST_ASSERT_EQUAL(0U, lv_textarea_text_is_selected(textarea));
}
void test_textarea_set_password_show_time(void)
{
lv_textarea_set_password_show_time(textarea, 1000);
TEST_ASSERT_EQUAL_UINT32(1000, lv_textarea_get_password_show_time(textarea));
}
void test_textarea_set_align(void)
{
lv_textarea_set_align(textarea, LV_TEXT_ALIGN_CENTER);
lv_textarea_set_text(textarea, "1234567890");
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_align_center.png");
lv_textarea_set_align(textarea, LV_TEXT_ALIGN_LEFT);
lv_textarea_set_text(textarea, "1234567890");
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_align_left.png");
lv_textarea_set_align(textarea, LV_TEXT_ALIGN_RIGHT);
lv_textarea_set_text(textarea, "1234567890");
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_align_right.png");
}
void test_textarea_cursor_show(void)
{
lv_textarea_set_password_show_time(textarea, 1000);
lv_obj_send_event(textarea, LV_EVENT_FOCUSED, NULL);
lv_test_wait(1000);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_cursor_show.png");
}
void test_textarea_set_cursor_pos(void)
{
lv_obj_set_size(textarea, 100, 60);
lv_textarea_set_one_line(textarea, false);
lv_textarea_set_text(textarea, "123456789012345678901234567890123456789012345678901");
lv_textarea_set_cursor_pos(textarea, 0);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_cursor_pos_top.png");
lv_textarea_set_cursor_pos(textarea, 50);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_cursor_pos_bottom.png");
lv_textarea_set_one_line(textarea, true);
lv_textarea_set_text(textarea, "123456789012345678901234567890123456789012345678901");
lv_textarea_set_cursor_pos(textarea, 0);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_cursor_pos_left.png");
lv_textarea_set_cursor_pos(textarea, 50);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_cursor_pos_right.png");
lv_textarea_set_one_line(textarea, false);
lv_textarea_set_text(textarea, "123456789012345678901234567890123456789012345678901");
lv_obj_set_size(lv_textarea_get_label(textarea), 100, 200);
lv_obj_scroll_to_y(textarea, 300, LV_ANIM_OFF);
lv_textarea_set_cursor_pos(textarea, 4);
lv_test_wait(500);
TEST_ASSERT_EQUAL_UINT32(0, lv_obj_get_scroll_y(textarea));
lv_textarea_set_one_line(textarea, true);
lv_textarea_set_cursor_pos(textarea, 50);
lv_test_wait(100);
lv_textarea_set_cursor_pos(textarea, 10);
lv_test_wait(100);
TEST_ASSERT_EQUAL_UINT32(10, lv_textarea_get_cursor_pos(textarea));
}
void test_textarea_get_current_char(void)
{
lv_textarea_set_one_line(textarea, false);
lv_textarea_set_text(textarea, "1234567890");
lv_textarea_set_cursor_pos(textarea, 2);
TEST_ASSERT_EQUAL_INT('2', lv_textarea_get_current_char(textarea));
lv_textarea_set_cursor_pos(textarea, 0);
TEST_ASSERT_EQUAL_INT(0, lv_textarea_get_current_char(textarea));
}
void test_textarea_cursor_position_on_click(void)
{
lv_textarea_set_one_line(textarea, true);
lv_textarea_set_text(textarea, "Hello World");
lv_obj_set_size(textarea, 200, 100);
lv_textarea_set_cursor_click_pos(textarea, true);
lv_test_mouse_click_at(5, 15);
TEST_ASSERT_EQUAL_UINT32(0, lv_textarea_get_cursor_pos(textarea));
lv_test_mouse_click_at(180, 15);
TEST_ASSERT_EQUAL_UINT32(11, lv_textarea_get_cursor_pos(textarea));
int32_t label_width = lv_obj_get_width(lv_textarea_get_label(textarea));
lv_test_mouse_click_at(label_width + 20, 15);
TEST_ASSERT_EQUAL_UINT32(11, lv_textarea_get_cursor_pos(textarea));
lv_textarea_set_text_selection(textarea, true);
lv_test_mouse_click_at(40, 15);
lv_test_mouse_press();
lv_test_wait(100);
lv_test_mouse_move_to(100, 15);
lv_test_wait(100);
lv_test_mouse_release();
TEST_ASSERT_EQUAL_UINT32(11, lv_textarea_get_cursor_pos(textarea));
lv_test_mouse_click_at(40, 15);
lv_test_mouse_press();
lv_test_wait(100);
lv_test_mouse_move_to(5, 15);
lv_test_wait(100);
lv_test_mouse_release();
TEST_ASSERT_EQUAL_UINT32(0, lv_textarea_get_cursor_pos(textarea));
lv_textarea_set_text_selection(textarea, false);
lv_test_mouse_click_at(5, 15);
TEST_ASSERT_EQUAL_UINT32(0, lv_textarea_get_cursor_pos(textarea));
lv_textarea_set_cursor_click_pos(textarea, false);
uint32_t pos_before = lv_textarea_get_cursor_pos(textarea);
lv_test_mouse_click_at(50, 15);
TEST_ASSERT_EQUAL_UINT32(pos_before, lv_textarea_get_cursor_pos(textarea));
}
void test_textarea_key_event(void)
{
lv_textarea_set_text(textarea, "Hello World");
lv_textarea_set_cursor_pos(textarea, 11);
uint32_t key = LV_KEY_BACKSPACE;
lv_obj_send_event(textarea, LV_EVENT_KEY, (void *) &key);
TEST_ASSERT_EQUAL_STRING("Hello Worl", lv_textarea_get_text(textarea));
lv_textarea_set_text(textarea, "Hello World");
lv_textarea_set_cursor_pos(textarea, 0);
key = LV_KEY_DEL;
lv_obj_send_event(textarea, LV_EVENT_KEY, (void *) &key);
TEST_ASSERT_EQUAL_STRING("ello World", lv_textarea_get_text(textarea));
key = LV_KEY_HOME;
lv_textarea_set_cursor_pos(textarea, 10);
lv_obj_send_event(textarea, LV_EVENT_KEY, (void *) &key);
TEST_ASSERT_EQUAL_UINT32(0, lv_textarea_get_cursor_pos(textarea));
key = LV_KEY_END;
lv_textarea_set_cursor_pos(textarea, 0);
lv_obj_send_event(textarea, LV_EVENT_KEY, (void *) &key);
TEST_ASSERT_EQUAL_UINT32(10, lv_textarea_get_cursor_pos(textarea));
lv_obj_set_size(textarea, 100, 40);
lv_textarea_set_one_line(textarea, false);
lv_textarea_set_text(textarea, "Hello World, this is a test for the key event");
lv_textarea_set_cursor_pos(textarea, 0);
key = LV_KEY_DOWN;
lv_obj_send_event(textarea, LV_EVENT_KEY, (void *) &key);
lv_test_wait(100);
TEST_ASSERT_EQUAL_UINT32(6, lv_textarea_get_cursor_pos(textarea));
lv_textarea_set_text(textarea, "Hello World");
lv_textarea_set_cursor_pos(textarea, 11);
key = 49;
lv_obj_send_event(textarea, LV_EVENT_KEY, (void *) &key);
TEST_ASSERT_EQUAL_STRING("Hello World1", lv_textarea_get_text(textarea));
}
void test_textarea_check_placeholder_text_position(void)
{
lv_textarea_set_placeholder_text(textarea, "Placeholder");
lv_textarea_set_one_line(textarea, true);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_placeholder_center.png");
lv_textarea_set_one_line(textarea, false);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_placeholder_top.png");
lv_obj_set_style_align(lv_textarea_get_label(textarea), LV_ALIGN_LEFT_MID, LV_PART_MAIN);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_placeholder_left_mid.png");
lv_obj_set_style_align(lv_textarea_get_label(textarea), LV_ALIGN_TOP_LEFT, LV_PART_MAIN);
lv_obj_set_style_pad_top(lv_textarea_get_label(textarea), 50, LV_PART_TEXTAREA_PLACEHOLDER);
lv_obj_set_style_pad_left(lv_textarea_get_label(textarea), 50, LV_PART_TEXTAREA_PLACEHOLDER);
TEST_ASSERT_EQUAL_SCREENSHOT("textarea_placeholder_pad_left_top_50.png");
}
#endif