#include "../../lv_examples.h"
#if LV_USE_LABEL && LV_BUILD_EXAMPLES
typedef struct btn_usr_data
{
lv_obj_t* obj_ta_blue;
}btn_usr_data_t;
// 按键回调函数
static void btn_event_callback(lv_event_t* event)
{
lv_obj_t* btn = lv_event_get_target(event);
if (event == NULL)
{
printf("[%s:%d] event is NULL\n", __FUNCTION__, __LINE__);
return;
}
lv_event_code_t code = lv_event_get_code(event);
if (code == LV_EVENT_CLICKED)
{
btn_usr_data_t* data = (btn_usr_data_t*)lv_event_get_user_data(event);
if (data == NULL)
{
return;
}
unsigned int red = 0, green = 0, blue = 0;
char* r = lv_textarea_get_text(data->obj_ta_blue);
lv_obj_t* label = lv_obj_get_child(btn, 0);
lv_label_set_text_fmt(label, "Button: %d", atoi(r));
}
}
void lv_example_label_1(void)
{
lv_obj_t* btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/
lv_obj_set_pos(btn, 10, 10); /*Set its position*/
lv_obj_set_size(btn, 120, 50); /*Set its size*/
lv_obj_t* label = lv_label_create(btn); /*Add a label to the button*/
lv_label_set_text(label, "Button"); /*Set the labels text*/
lv_obj_center(label);
/
//创建文本输入框
lv_obj_t* obj_ta_blue = lv_textarea_create(lv_scr_act());
if (obj_ta_blue == NULL)
{
printf("[%s:%d] obj_ta_blue create failed !!!\n", __FUNCTION__, __LINE__);
return;
}
static btn_usr_data_t data = { 0 };
lv_textarea_set_one_line(obj_ta_blue, true); // 设置文本输入框为1行
lv_textarea_set_text_selection(obj_ta_blue, true); // 设置文本框可选中
lv_textarea_set_accepted_chars(obj_ta_blue, "0123456789"); // 设置文本输入框可输入的字符
lv_textarea_set_max_length(obj_ta_blue, 3); // 设置文本输入框可输入的字符最大长度
lv_obj_set_style_radius(obj_ta_blue, 0, 0); //圆角大小
lv_obj_set_size(obj_ta_blue, 150, 50);
lv_obj_align(obj_ta_blue, LV_ALIGN_TOP_LEFT, 330, 0);
lv_obj_set_style_text_font(obj_ta_blue, (const lv_font_t*)&lv_font_montserrat_20, 0); // 文本字体大小
data.obj_ta_blue = obj_ta_blue;
lv_obj_add_event_cb(btn, btn_event_callback, LV_EVENT_CLICKED, (void*)&data);
}
#endif
LVGL 输入框 登录 获取输入框字符串
最新推荐文章于 2024-07-03 17:21:32 发布