added factory code, and the beginnings of styling
This commit is contained in:
committed by
Raphael Coeffic
parent
3d2b5bf460
commit
2a85442708
+30
-31
@@ -48,15 +48,13 @@ 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 {
|
||||
/*Create a keyboard*/
|
||||
if (kb == nullptr) {
|
||||
kb = lv_keyboard_create(lv_scr_act());
|
||||
lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
|
||||
lv_keyboard_set_textarea(kb, ta);
|
||||
}
|
||||
|
||||
if(kb != NULL)
|
||||
lv_keyboard_set_textarea(kb, ta);
|
||||
}
|
||||
else if (code == LV_EVENT_DEFOCUSED) {
|
||||
if (kb != nullptr) {
|
||||
@@ -64,47 +62,48 @@ static void ta_event_cb(lv_event_t * e)
|
||||
kb = nullptr;
|
||||
}
|
||||
}
|
||||
else if(code == LV_EVENT_READY) {
|
||||
LV_LOG_USER("Ready, current text: %s", lv_textarea_get_text(ta));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LvglWidgetFactory textEditFactory = LvglWidgetFactory(
|
||||
[] (lv_obj_t *parent) {
|
||||
return lv_textarea_create(parent);
|
||||
},
|
||||
[] (LvglWidgetFactory *factory) {
|
||||
lv_style_set_border_width(&factory->style, 1);
|
||||
lv_style_set_radius(&factory->style, 0);
|
||||
lv_style_set_pad_top(&factory->style, 2);
|
||||
lv_style_set_pad_bottom(&factory->style, 2);
|
||||
lv_style_set_pad_left(&factory->style, 2);
|
||||
lv_style_set_pad_right(&factory->style, 2);
|
||||
lv_style_set_text_font(&factory->style, &lv_font_montserrat_14);
|
||||
lv_style_set_text_line_space(&factory->style, 0);
|
||||
|
||||
lv_style_set_bg_color(&factory->style, lv_color_make(10,10,10));
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
TextEdit::TextEdit(Window * parent, const rect_t & rect, char * value, uint8_t length,
|
||||
LcdFlags windowFlags, const char * _extra_chars) :
|
||||
FormField(parent, rect, windowFlags),
|
||||
FormField(parent, rect, windowFlags, 0, &textEditFactory),
|
||||
value(value),
|
||||
length(length)
|
||||
{
|
||||
if (getLvObj() != nullptr) {
|
||||
lv_obj_del(lvobj);
|
||||
}
|
||||
|
||||
lvobj = lv_textarea_create(parent->getLvObj());
|
||||
lv_obj_add_event_cb(lvobj, ta_event_cb, LV_EVENT_ALL, NULL);
|
||||
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
||||
lv_obj_set_size(lvobj, rect.w, rect.h);
|
||||
lv_obj_add_style(lvobj, &textEditFactory.style, LV_PART_MAIN);
|
||||
|
||||
lv_obj_set_style_bg_color(lvobj, lv_color_make(255,10,10), LV_PART_MAIN);
|
||||
|
||||
lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF);
|
||||
lv_obj_set_style_border_width(lvobj, 0, LV_PART_MAIN);
|
||||
lv_obj_set_style_radius(lvobj, 0, LV_PART_MAIN);
|
||||
lv_obj_set_style_pad_top(lvobj, 2, LV_PART_MAIN);
|
||||
lv_obj_set_style_pad_bottom(lvobj, 2, LV_PART_MAIN);
|
||||
lv_obj_set_style_pad_left(lvobj, 4, LV_PART_MAIN);
|
||||
lv_obj_set_style_pad_right(lvobj, 4, LV_PART_MAIN);
|
||||
|
||||
|
||||
lv_textarea_set_password_mode(lvobj, false);
|
||||
lv_textarea_set_one_line(lvobj, true);
|
||||
lv_textarea_set_text(lvobj, value);
|
||||
lv_textarea_set_placeholder_text(lvobj, "---");
|
||||
lv_textarea_set_max_length(lvobj, length);
|
||||
|
||||
lv_obj_set_style_text_font(lvobj, &lv_font_montserrat_12, LV_PART_MAIN);
|
||||
lv_obj_set_style_text_line_space(lvobj, 0, LV_PART_MAIN);
|
||||
|
||||
auto color = COLOR_VAL(COLOR_THEME_SECONDARY1);
|
||||
auto label = lv_textarea_get_label(lvobj);
|
||||
lv_obj_set_style_text_color(label, lv_color_make(GET_RED(color), GET_GREEN(color), GET_BLUE(color)), LV_PART_MAIN);
|
||||
|
||||
lv_obj_set_style_text_color(label, makeLvColor(COLOR_THEME_SECONDARY1), LV_PART_MAIN);
|
||||
extra_chars = (_extra_chars) ? _extra_chars : extra_chars_default;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user