当前位置:网站首页>LVGL 8.2 Textarea
LVGL 8.2 Textarea
2022-07-25 04:18:00 【Fairy sword love】
Simple Text area
static void textarea_event_handler(lv_event_t* e)
{
lv_obj_t* ta = lv_event_get_target(e);
LV_LOG_USER("Enter was pressed. The current text is: %s", lv_textarea_get_text(ta));
}
static void btnm_event_handler(lv_event_t* e)
{
lv_obj_t* obj = lv_event_get_target(e);
lv_obj_t* ta = lv_event_get_user_data(e);
const char* txt = lv_btnmatrix_get_btn_text(obj, lv_btnmatrix_get_selected_btn(obj));
if (strcmp(txt, LV_SYMBOL_BACKSPACE) == 0) lv_textarea_del_char(ta);
else if (strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) lv_event_send(ta, LV_EVENT_READY, NULL);
else lv_textarea_add_text(ta, txt);
}
static void lv_example_textarea_1(void)
{
lv_obj_t* ta = lv_textarea_create(lv_scr_act());
lv_textarea_set_one_line(ta, true);
lv_obj_align(ta, LV_ALIGN_TOP_MID, 0, 10);
lv_obj_add_event_cb(ta, textarea_event_handler, LV_EVENT_READY, ta);
lv_obj_add_state(ta, LV_STATE_FOCUSED); /*To be sure the cursor is visible*/
static const char* btnm_map[] = {
"1", "2", "3", "\n",
"4", "5", "6", "\n",
"7", "8", "9", "\n",
LV_SYMBOL_BACKSPACE, "0", LV_SYMBOL_NEW_LINE, ""
};
lv_obj_t* btnm = lv_btnmatrix_create(lv_scr_act());
lv_obj_set_size(btnm, 200, 150);
lv_obj_align(btnm, LV_ALIGN_BOTTOM_MID, 0, -10);
lv_obj_add_event_cb(btnm, btnm_event_handler, LV_EVENT_VALUE_CHANGED, ta);
lv_obj_clear_flag(btnm, LV_OBJ_FLAG_CLICK_FOCUSABLE); /*To keep the text area focused on button clicks*/
lv_btnmatrix_set_map(btnm, btnm_map);
}
- Running effect

Text area with password field
static void ta_event_cb(lv_event_t* e);
static lv_obj_t* kb;
static void lv_example_textarea_2(void)
{
/*Create the password box*/
lv_obj_t* pwd_ta = lv_textarea_create(lv_scr_act());
lv_textarea_set_text(pwd_ta, "");
lv_textarea_set_password_mode(pwd_ta, true);
lv_textarea_set_one_line(pwd_ta, true);
lv_obj_set_width(pwd_ta, lv_pct(40));
lv_obj_set_pos(pwd_ta, 5, 20);
lv_obj_add_event_cb(pwd_ta, ta_event_cb, LV_EVENT_ALL, NULL);
/*Create a label and position it above the text box*/
lv_obj_t* pwd_label = lv_label_create(lv_scr_act());
lv_label_set_text(pwd_label, "Password:");
lv_obj_align_to(pwd_label, pwd_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
/*Create the one-line mode text area*/
lv_obj_t* text_ta = lv_textarea_create(lv_scr_act());
lv_textarea_set_one_line(text_ta, true);
lv_textarea_set_password_mode(text_ta, false);
lv_obj_set_width(text_ta, lv_pct(40));
lv_obj_add_event_cb(text_ta, ta_event_cb, LV_EVENT_ALL, NULL);
lv_obj_align(text_ta, LV_ALIGN_TOP_RIGHT, -5, 20);
/*Create a label and position it above the text box*/
lv_obj_t* oneline_label = lv_label_create(lv_scr_act());
lv_label_set_text(oneline_label, "Text:");
lv_obj_align_to(oneline_label, text_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
/*Create a keyboard*/
kb = lv_keyboard_create(lv_scr_act());
lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
lv_keyboard_set_textarea(kb, pwd_ta); /*Focus it on one of the text areas to start*/
}
static void ta_event_cb(lv_event_t* e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t* ta = lv_event_get_target(e);
if (code == LV_EVENT_CLICKED || code == LV_EVENT_FOCUSED) {
/*Focus on the clicked text area*/
if (kb != NULL) lv_keyboard_set_textarea(kb, ta);
}
else if (code == LV_EVENT_READY) {
LV_LOG_USER("Ready, current text: %s", lv_textarea_get_text(ta));
}
}
- Running effect

Text auto-formatting
static void ta_event_cb(lv_event_t* e);
static lv_obj_t* kb;
/** * Automatically format text like a clock. E.g. "12:34" * Add the ':' automatically. */
static void lv_example_textarea_3(void)
{
/*Create the text area*/
lv_obj_t* ta = lv_textarea_create(lv_scr_act());
lv_obj_add_event_cb(ta, ta_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
lv_textarea_set_accepted_chars(ta, "0123456789:");
lv_textarea_set_max_length(ta, 5);
lv_textarea_set_one_line(ta, true);
lv_textarea_set_text(ta, "");
/*Create a keyboard*/
kb = lv_keyboard_create(lv_scr_act());
lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUMBER);
lv_keyboard_set_textarea(kb, ta);
}
static void ta_event_cb(lv_event_t* e)
{
lv_obj_t* ta = lv_event_get_target(e);
const char* txt = lv_textarea_get_text(ta);
if (txt[0] >= '0' && txt[0] <= '9' &&
txt[1] >= '0' && txt[1] <= '9' &&
txt[2] != ':') {
lv_textarea_set_cursor_pos(ta, 2);
lv_textarea_add_char(ta, ':');
}
}
- Running effect

边栏推荐
- Sales system of infant products based on SSH
- Top101 [linked list] must be applied for interview
- Chapter 3 business function development (modify the remarks of market activities)
- Operations in shell
- An article takes you quickly to learn flex layout
- Chapter 18 request matcher serverwebexchangematcher of oauth2loginauthenticationwebfilter
- Traditional architecture of enterprise digital transformation to medium platform micro service architecture
- After the failure of listing in Hong Kong, tuba rabbit terminated its gem IPO, and the founder responded
- Detailed explanation of kubernetes network plug-in - flannel chapter
- Deeply understand the connection state and reliable mechanism of TCP protocol
猜你喜欢

Behind Senma's LP, "Wenzhou Department" is running into the venture capital circle

Visual studio 2019 installation and uninstallation problems

DIY can decorate the mall system, you can also have!

Bond network card mode setting

Student thinking vs workplace thinking

Penetration test target combat SQL injection getshell

Wechat applet experiment case: simple idiom dictionary
![[interview must brush 101] greedy algorithm, simulation, string](/img/ac/32f249c1884965710d82b8aca0c851.png)
[interview must brush 101] greedy algorithm, simulation, string

Eve-ng lab simulator Cisco, H3C test host alias

Application of AI in testing
随机推荐
DNS domain name resolution service
TS learning (VII): interface and type compatibility of TS
SQL comment
Use "display: flex; justify content: Center; align items: Center;" Solve the problem that the streaming grid layout cannot be centered
Spire. Office for net 7.7.2 and news
Oracle uses FY_ recover_ Data recover truncate deleted data
有个问题想请教下,我想用来同步数据库,但我看他是根据mysql 的binlog同步的,如果是大表,一
Solve "nothing added to commit but untracked files present"“
Interview question 05.06. integer conversion
Typical data Lake application cases
Implementing DDD based on ABP -- domain logic and application logic
Preparation for Android development in big companies
Win11 experience
Shell string
01_ Education 2
01_ Education 3
Installation and tutorial of MATLAB curling simulation game
Pandora IOT development board learning (RT thread) - Experiment 16 WiFi module experiment (learning notes)
Yuntu says digital asset chain: your God of digital asset property protection
Original | record a loophole excavation in Colleges and Universities