1. basic changes to mirror libopnui window hierararchy to lvgl object hierarchy
2. basic scroll support 3. Basic layer support (still pretty broken), multiple screen support 4. Preliminary impelemntation of TextEdit using lvgl. 5. Preliminary implementation of StaticText using lvgl. 6. Preliminary implementation of TextButton using lvgl.
This commit is contained in:
committed by
Raphael Coeffic
parent
e538138ade
commit
6b70baf63a
+108
-41
@@ -42,44 +42,111 @@
|
||||
#include "clipboard.h"
|
||||
#endif
|
||||
|
||||
|
||||
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*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
else if (code == LV_EVENT_DEFOCUSED) {
|
||||
if (kb != nullptr) {
|
||||
lv_obj_del(kb);
|
||||
kb = nullptr;
|
||||
}
|
||||
}
|
||||
else if(code == LV_EVENT_READY) {
|
||||
LV_LOG_USER("Ready, current text: %s", lv_textarea_get_text(ta));
|
||||
}
|
||||
}
|
||||
|
||||
TextEdit::TextEdit(Window * parent, const rect_t & rect, char * value, uint8_t length,
|
||||
LcdFlags windowFlags, const char * _extra_chars) :
|
||||
FormField(parent, rect, windowFlags),
|
||||
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_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);
|
||||
|
||||
extra_chars = (_extra_chars) ? _extra_chars : extra_chars_default;
|
||||
}
|
||||
|
||||
|
||||
void TextEdit::paint(BitmapBuffer * dc)
|
||||
{
|
||||
FormField::paint(dc);
|
||||
// FormField::paint(dc);
|
||||
|
||||
if (editMode) {
|
||||
dc->drawSizedText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, length,
|
||||
COLOR_THEME_PRIMARY2);
|
||||
coord_t left = (cursorPos == 0 ? 0 : getTextWidth(value, cursorPos));
|
||||
#if defined(SOFTWARE_KEYBOARD)
|
||||
dc->drawSolidFilledRect(left + 2, 2, 2, height() - 4, COLOR_THEME_PRIMARY2);
|
||||
#else
|
||||
char s[] = {value[cursorPos], '\0'};
|
||||
dc->drawSolidFilledRect(FIELD_PADDING_LEFT + left - 1,
|
||||
FIELD_PADDING_TOP - 1, getTextWidth(s, 1) + 1,
|
||||
height() - 2, COLOR_THEME_PRIMARY2);
|
||||
dc->drawText(FIELD_PADDING_LEFT + left, FIELD_PADDING_TOP, s,
|
||||
COLOR_THEME_SECONDARY1);
|
||||
#endif
|
||||
} else {
|
||||
const char * displayedValue = value;
|
||||
LcdFlags textColor = COLOR_THEME_PRIMARY2;
|
||||
if (hasFocus()) {
|
||||
if (strlen(value) == 0) {
|
||||
displayedValue = "---";
|
||||
}
|
||||
textColor = COLOR_THEME_PRIMARY2;
|
||||
}
|
||||
else {
|
||||
if (strlen(value) == 0) {
|
||||
displayedValue = "---";
|
||||
textColor = COLOR_THEME_DISABLED;
|
||||
}
|
||||
else {
|
||||
textColor = COLOR_THEME_SECONDARY1;
|
||||
}
|
||||
}
|
||||
dc->drawSizedText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, displayedValue, length, textColor);
|
||||
}
|
||||
// if (editMode) {
|
||||
// dc->drawSizedText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, length,
|
||||
// COLOR_THEME_PRIMARY2);
|
||||
// coord_t left = (cursorPos == 0 ? 0 : getTextWidth(value, cursorPos));
|
||||
// #if defined(SOFTWARE_KEYBOARD)
|
||||
// dc->drawSolidFilledRect(left + 2, 2, 2, height() - 4, COLOR_THEME_PRIMARY2);
|
||||
// #else
|
||||
// char s[] = {value[cursorPos], '\0'};
|
||||
// dc->drawSolidFilledRect(FIELD_PADDING_LEFT + left - 1,
|
||||
// FIELD_PADDING_TOP - 1, getTextWidth(s, 1) + 1,
|
||||
// height() - 2, COLOR_THEME_PRIMARY2);
|
||||
// dc->drawText(FIELD_PADDING_LEFT + left, FIELD_PADDING_TOP, s,
|
||||
// COLOR_THEME_SECONDARY1);
|
||||
// #endif
|
||||
// } else {
|
||||
// const char * displayedValue = value;
|
||||
// LcdFlags textColor = COLOR_THEME_PRIMARY2;
|
||||
// if (hasFocus()) {
|
||||
// if (strlen(value) == 0) {
|
||||
// displayedValue = "---";
|
||||
// }
|
||||
// textColor = COLOR_THEME_PRIMARY2;
|
||||
// }
|
||||
// else {
|
||||
// if (strlen(value) == 0) {
|
||||
// displayedValue = "---";
|
||||
// textColor = COLOR_THEME_DISABLED;
|
||||
// }
|
||||
// else {
|
||||
// textColor = COLOR_THEME_SECONDARY1;
|
||||
// }
|
||||
// }
|
||||
// dc->drawSizedText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, displayedValue, length, textColor);
|
||||
// }
|
||||
}
|
||||
|
||||
void TextEdit::trim()
|
||||
@@ -254,9 +321,9 @@ bool TextEdit::onTouchEnd(coord_t x, coord_t y)
|
||||
setFocus(SET_FOCUS_DEFAULT);
|
||||
}
|
||||
|
||||
#if defined(SOFTWARE_KEYBOARD)
|
||||
TextKeyboard::show(this);
|
||||
#endif
|
||||
// #if defined(SOFTWARE_KEYBOARD)
|
||||
// TextKeyboard::show(this);
|
||||
// #endif
|
||||
|
||||
coord_t rest = x;
|
||||
for (cursorPos = 0; cursorPos < length; cursorPos++) {
|
||||
@@ -276,9 +343,9 @@ bool TextEdit::onTouchEnd(coord_t x, coord_t y)
|
||||
|
||||
void TextEdit::onFocusLost()
|
||||
{
|
||||
#if defined(SOFTWARE_KEYBOARD)
|
||||
TextKeyboard::hide();
|
||||
#endif
|
||||
// #if defined(SOFTWARE_KEYBOARD)
|
||||
// TextKeyboard::hide();
|
||||
// #endif
|
||||
|
||||
changeEnd();
|
||||
FormField::onFocusLost();
|
||||
|
||||
Reference in New Issue
Block a user