changes for keyboard processing. It is pretty good now. The next thing will be to do the numeric keyboard. Stay tuned

This commit is contained in:
kkoenig1@optonline.com
2022-06-11 15:13:11 +02:00
committed by Raphael Coeffic
parent a6a387a87c
commit 684a004f9e
9 changed files with 274 additions and 243 deletions
+2 -2
View File
@@ -77,9 +77,9 @@ class FormField: public Window
virtual void setEditMode(bool newEditMode) virtual void setEditMode(bool newEditMode)
{ {
editMode = newEditMode; editMode = newEditMode;
if (editMode) { if (editMode && lvobj != nullptr) {
lv_obj_add_state(lvobj, LV_STATE_EDITED | LV_STATE_FOCUSED); lv_obj_add_state(lvobj, LV_STATE_EDITED | LV_STATE_FOCUSED);
} else { } else if (lvobj != nullptr) {
lv_obj_clear_state(lvobj, LV_STATE_EDITED); lv_obj_clear_state(lvobj, LV_STATE_EDITED);
} }
invalidate(); invalidate();
+10 -2
View File
@@ -18,6 +18,9 @@
*/ */
#include "keyboard_base.h" #include "keyboard_base.h"
Keyboard * Keyboard::activeKeyboard = nullptr;
lv_obj_t *Keyboard::keyboard = nullptr;
coord_t calcScrollOffsetForField(FormField *newField, Window *topWindow) coord_t calcScrollOffsetForField(FormField *newField, Window *topWindow)
{ {
// now we need to calculate the offset of the field in the fields scroll container // now we need to calculate the offset of the field in the fields scroll container
@@ -32,7 +35,7 @@ coord_t calcScrollOffsetForField(FormField *newField, Window *topWindow)
// try and place it in the middle of the screen. The containing window MUST have // try and place it in the middle of the screen. The containing window MUST have
// already been resized // already been resized
return offsetY - topWindow->height() / 2; return offsetY - topWindow->height() * 2 / 7;
} }
bool Keyboard::attachKeyboard() bool Keyboard::attachKeyboard()
@@ -99,7 +102,10 @@ void Keyboard::setField(FormField* newField)
#endif #endif
// scroll the header of the window out of view to get more space to // scroll the header of the window out of view to get more space to
// see the field being edited // see the field being edited
lv_obj_scroll_to_y(fieldContainer->getLvObj(), fields->top(), LV_ANIM_OFF);
// TODO: this no longer works. we need to figure out something else
//lv_obj_scroll_to_y(fieldContainer->getLvObj(), fields->top(), LV_ANIM_OFF);
oldHeight = fields->height(); oldHeight = fields->height();
fields->setHeight(newHeight); fields->setHeight(newHeight);
@@ -113,6 +119,8 @@ void Keyboard::setField(FormField* newField)
invalidate(); invalidate();
newField->setEditMode(true); newField->setEditMode(true);
lv_keyboard_set_textarea(keyboard, newField->getLvObj());
field = newField; field = newField;
} else { } else {
clearField(); clearField();
+11 -1
View File
@@ -25,13 +25,21 @@
class Keyboard: public FormWindow class Keyboard: public FormWindow
{ {
public: public:
explicit Keyboard(coord_t height) : FormWindow(nullptr, {0, LCD_H - height, LCD_W, height}, OPAQUE) explicit Keyboard(coord_t height) :
FormWindow(nullptr, {0, LCD_H - height, LCD_W, height}, OPAQUE)
{ {
// set the background of the window and opacity to 100%
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY1), LV_PART_MAIN);
lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_PART_MAIN);
} }
void clearField() void clearField()
{ {
TRACE("CLEAR FIELD"); TRACE("CLEAR FIELD");
if (keyboard != nullptr) {
lv_obj_add_flag(keyboard, LV_OBJ_FLAG_HIDDEN);
}
detach(); detach();
if (fields) { if (fields) {
fields->setHeight(oldHeight); fields->setHeight(oldHeight);
@@ -59,6 +67,8 @@ class Keyboard: public FormWindow
protected: protected:
static Keyboard * activeKeyboard; static Keyboard * activeKeyboard;
static lv_obj_t * keyboard;
FormField *field = nullptr; FormField *field = nullptr;
Window *fieldContainer = nullptr; Window *fieldContainer = nullptr;
FormWindow *fields = nullptr; FormWindow *fields = nullptr;
+215 -210
View File
@@ -22,283 +22,288 @@
#include "textedit.h" #include "textedit.h"
#include "font.h" #include "font.h"
constexpr coord_t KEYBOARD_HEIGHT = 160; constexpr coord_t KEYBOARD_HEIGHT = LCD_H * 2 / 5;
TextKeyboard * TextKeyboard::_instance = nullptr; TextKeyboard * TextKeyboard::_instance = nullptr;
const uint8_t LBM_KEY_UPPERCASE[] = { // const uint8_t LBM_KEY_UPPERCASE[] = {
#include "mask_key_uppercase.lbm" // #include "mask_key_uppercase.lbm"
}; // };
const uint8_t LBM_KEY_LOWERCASE[] = { // const uint8_t LBM_KEY_LOWERCASE[] = {
#include "mask_key_lowercase.lbm" // #include "mask_key_lowercase.lbm"
}; // };
const uint8_t LBM_KEY_BACKSPACE[] = { // const uint8_t LBM_KEY_BACKSPACE[] = {
#include "mask_key_backspace.lbm" // #include "mask_key_backspace.lbm"
}; // };
const uint8_t LBM_KEY_LETTERS[] = { // const uint8_t LBM_KEY_LETTERS[] = {
#include "mask_key_letters.lbm" // #include "mask_key_letters.lbm"
}; // };
const uint8_t LBM_KEY_NUMBERS[] = { // const uint8_t LBM_KEY_NUMBERS[] = {
#include "mask_key_numbers.lbm" // #include "mask_key_numbers.lbm"
}; // };
const uint8_t LBM_KEY_SPACEBAR[] = { // const uint8_t LBM_KEY_SPACEBAR[] = {
#include "mask_key_spacebar.lbm" // #include "mask_key_spacebar.lbm"
}; // };
const uint8_t * const LBM_SPECIAL_KEYS[] = { // const uint8_t * const LBM_SPECIAL_KEYS[] = {
LBM_KEY_BACKSPACE, // LBM_KEY_BACKSPACE,
LBM_KEY_UPPERCASE, // LBM_KEY_UPPERCASE,
LBM_KEY_LOWERCASE, // LBM_KEY_LOWERCASE,
LBM_KEY_LETTERS, // LBM_KEY_LETTERS,
LBM_KEY_NUMBERS, // LBM_KEY_NUMBERS,
}; // };
const char * const KEYBOARD_LOWERCASE[] = { // const char * const KEYBOARD_LOWERCASE[] = {
"qwertyuiop", // "qwertyuiop",
" asdfghjkl", // " asdfghjkl",
KEYBOARD_SET_UPPERCASE "zxcvbnm" KEYBOARD_BACKSPACE, // KEYBOARD_SET_UPPERCASE "zxcvbnm" KEYBOARD_BACKSPACE,
KEYBOARD_SET_NUMBERS KEYBOARD_SPACE KEYBOARD_ENTER // KEYBOARD_SET_NUMBERS KEYBOARD_SPACE KEYBOARD_ENTER
}; // };
const char * const KEYBOARD_UPPERCASE[] = { // const char * const KEYBOARD_UPPERCASE[] = {
"QWERTYUIOP", // "QWERTYUIOP",
" ASDFGHJKL", // " ASDFGHJKL",
KEYBOARD_SET_LOWERCASE "ZXCVBNM" KEYBOARD_BACKSPACE, // KEYBOARD_SET_LOWERCASE "ZXCVBNM" KEYBOARD_BACKSPACE,
KEYBOARD_SET_NUMBERS KEYBOARD_SPACE KEYBOARD_ENTER // KEYBOARD_SET_NUMBERS KEYBOARD_SPACE KEYBOARD_ENTER
}; // };
const char * const KEYBOARD_NUMBERS[] = { // const char * const KEYBOARD_NUMBERS[] = {
"1234567890", // "1234567890",
"_-", // "_-",
" " KEYBOARD_BACKSPACE, // " " KEYBOARD_BACKSPACE,
KEYBOARD_SET_LETTERS KEYBOARD_SPACE KEYBOARD_ENTER // KEYBOARD_SET_LETTERS KEYBOARD_SPACE KEYBOARD_ENTER
}; // };
#define NUMBER_OF_KEYBOARD_LAYOUTS 4 // #define NUMBER_OF_KEYBOARD_LAYOUTS 4
const char * const * const KEYBOARD_LAYOUTS[NUMBER_OF_KEYBOARD_LAYOUTS] = { // const char * const * const KEYBOARD_LAYOUTS[NUMBER_OF_KEYBOARD_LAYOUTS] = {
KEYBOARD_UPPERCASE, // KEYBOARD_UPPERCASE,
KEYBOARD_LOWERCASE, // KEYBOARD_LOWERCASE,
KEYBOARD_LOWERCASE, // KEYBOARD_LOWERCASE,
KEYBOARD_NUMBERS, // KEYBOARD_NUMBERS,
}; // };
TextKeyboard::TextKeyboard(): TextKeyboard::TextKeyboard():
Keyboard(KEYBOARD_HEIGHT), Keyboard(KEYBOARD_HEIGHT)
layout(KEYBOARD_LOWERCASE) // layout(KEYBOARD_LOWERCASE)
{ {
if (keyboard == nullptr) {
keyboard = lv_keyboard_create(lv_scr_act());
lv_obj_set_size(keyboard, LCD_W, LCD_H * 2 / 5);
lv_obj_clear_flag(keyboard, LV_OBJ_FLAG_HIDDEN);
}
} }
TextKeyboard::~TextKeyboard() TextKeyboard::~TextKeyboard()
{ {
_instance = nullptr; _instance = nullptr;
} }
int TextKeyboard::getCharWidth(const char c) int TextKeyboard::getCharWidth(const char c)
{ {
if (int8_t(c) < 0) return KEYBOARD_BITMAP_WIDTH; // if (int8_t(c) < 0) return KEYBOARD_BITMAP_WIDTH;
switch (c) // switch (c)
{ // {
case ' ': return 15; // case ' ': return 15;
case KEYBOARD_SPACE[0]: return KEYBOARD_SPACE_WIDTH; // case KEYBOARD_SPACE[0]: return KEYBOARD_SPACE_WIDTH;
case KEYBOARD_ENTER[0]: return KEYBOARD_ENTER_WIDTH; // case KEYBOARD_ENTER[0]: return KEYBOARD_ENTER_WIDTH;
default: return KEYBOARD_CHAR_WIDTH; // default: return KEYBOARD_CHAR_WIDTH;
} // }
} }
int TextKeyboard::calculateMaxWidth() int TextKeyboard::calculateMaxWidth()
{ {
int maxWidth = 0; // int maxWidth = 0;
for (uint8_t i = 0; i < NUMBER_OF_KEYBOARD_LAYOUTS; i++) { // for (uint8_t i = 0; i < NUMBER_OF_KEYBOARD_LAYOUTS; i++) {
int lineWidth = 0; // int lineWidth = 0;
const char * c = layout[i]; // const char * c = layout[i];
while (*c) { // while (*c) {
lineWidth += getCharWidth(*c); // lineWidth += getCharWidth(*c);
maxWidth = max(lineWidth, maxWidth); // maxWidth = max(lineWidth, maxWidth);
c++; // c++;
} // }
} // }
return maxWidth; // return maxWidth;
} }
void TextKeyboard::paint(BitmapBuffer * dc) void TextKeyboard::paint(BitmapBuffer * dc)
{ {
lcdSetColor(RGB(0xE0, 0xE0, 0xE0)); // lcdSetColor(RGB(0xE0, 0xE0, 0xE0));
dc->clear(CUSTOM_COLOR); // dc->clear(CUSTOM_COLOR);
// center the keyboard // // center the keyboard
coord_t start_x = (dc->width() - calculateMaxWidth()) / 2; // coord_t start_x = (dc->width() - calculateMaxWidth()) / 2;
for (uint8_t i = 0; i < NUMBER_OF_KEYBOARD_LAYOUTS; i++) { // for (uint8_t i = 0; i < NUMBER_OF_KEYBOARD_LAYOUTS; i++) {
coord_t y = KEYBOARD_OFFSET_Y + i * KEYBOARD_ROW_HEIGHT; // coord_t y = KEYBOARD_OFFSET_Y + i * KEYBOARD_ROW_HEIGHT;
coord_t x = start_x; // coord_t x = start_x;
const char * c = layout[i]; // const char * c = layout[i];
while (*c) { // while (*c) {
if (*c == KEYBOARD_SPACE[0]) { // if (*c == KEYBOARD_SPACE[0]) {
// spacebar // // spacebar
dc->drawBitmapPattern(x, y, LBM_KEY_SPACEBAR, COLOR_THEME_SECONDARY1); // dc->drawBitmapPattern(x, y, LBM_KEY_SPACEBAR, COLOR_THEME_SECONDARY1);
} // }
else if (*c == KEYBOARD_ENTER[0]) { // else if (*c == KEYBOARD_ENTER[0]) {
// enter // // enter
dc->drawSolidFilledRect(x, y - 2, KEYBOARD_ENTER_WIDTH, 25, COLOR_THEME_DISABLED); // dc->drawSolidFilledRect(x, y - 2, KEYBOARD_ENTER_WIDTH, 25, COLOR_THEME_DISABLED);
dc->drawText(x + KEYBOARD_ENTER_WIDTH / 2, y + 2, "ENTER", CENTERED); // dc->drawText(x + KEYBOARD_ENTER_WIDTH / 2, y + 2, "ENTER", CENTERED);
} // }
else if (int8_t(*c) < 0) { // else if (int8_t(*c) < 0) {
const uint8_t *pBitmap = LBM_SPECIAL_KEYS[uint8_t(*c - 128)]; // const uint8_t *pBitmap = LBM_SPECIAL_KEYS[uint8_t(*c - 128)];
uint8_t bitmapWidth = *pBitmap, bitmapHeight = *(pBitmap + 2); // uint8_t bitmapWidth = *pBitmap, bitmapHeight = *(pBitmap + 2);
if (touched && *c == touch_key) { // if (touched && *c == touch_key) {
dc->drawSolidFilledRect(x - 2, y + 3, bitmapWidth + 4, bitmapHeight + 4, COLOR_THEME_SECONDARY2); // dc->drawSolidFilledRect(x - 2, y + 3, bitmapWidth + 4, bitmapHeight + 4, COLOR_THEME_SECONDARY2);
} // }
dc->drawBitmapPattern(x, y + 5, pBitmap, COLOR_THEME_SECONDARY1); // dc->drawBitmapPattern(x, y + 5, pBitmap, COLOR_THEME_SECONDARY1);
} // }
else { // else {
if (touched && *c == touch_key) { // if (touched && *c == touch_key) {
dc->drawSolidFilledRect(x - KEYBOARD_CHAR_WIDTH / 2, y - ((KEYBOARD_ROW_HEIGHT - 16) / 2), KEYBOARD_CHAR_WIDTH, KEYBOARD_ROW_HEIGHT, COLOR_THEME_FOCUS); // dc->drawSolidFilledRect(x - KEYBOARD_CHAR_WIDTH / 2, y - ((KEYBOARD_ROW_HEIGHT - 16) / 2), KEYBOARD_CHAR_WIDTH, KEYBOARD_ROW_HEIGHT, COLOR_THEME_FOCUS);
} // }
dc->drawSizedText(x, y, c, 1, CENTERED); // dc->drawSizedText(x, y, c, 1, CENTERED);
} // }
x += getCharWidth(*c); // x += getCharWidth(*c);
c++; // c++;
} // }
} // }
} }
bool TextKeyboard::onTouchStart(coord_t x, coord_t y) bool TextKeyboard::onTouchStart(coord_t x, coord_t y)
{ {
// remove the centering. If x < 0 then this is an invalid touch event // // remove the centering. If x < 0 then this is an invalid touch event
x -= (this->width() - calculateMaxWidth()) / 2; // x -= (this->width() - calculateMaxWidth()) / 2;
if (x < 0) { // if (x < 0) {
if (touched) { // if (touched) {
touched = false; // touched = false;
invalidate(); // invalidate();
} // }
return true; // return true;
} // }
touched = false; // touched = false;
uint8_t row = max<coord_t>(0, y - 5) / KEYBOARD_ROW_HEIGHT; // uint8_t row = max<coord_t>(0, y - 5) / KEYBOARD_ROW_HEIGHT;
const char * key = layout[row]; // const char * key = layout[row];
while(*key) { // while(*key) {
if (*key == KEYBOARD_SPACE[0] && x <= KEYBOARD_SPACE_WIDTH) { // if (*key == KEYBOARD_SPACE[0] && x <= KEYBOARD_SPACE_WIDTH) {
touch_key = KEYBOARD_SPACE[0]; // touch_key = KEYBOARD_SPACE[0];
touched = true; // touched = true;
break; // break;
} // }
else if (*key == KEYBOARD_ENTER[0] && x <= KEYBOARD_ENTER_WIDTH) { // else if (*key == KEYBOARD_ENTER[0] && x <= KEYBOARD_ENTER_WIDTH) {
touch_key = KEYBOARD_ENTER[0]; // touch_key = KEYBOARD_ENTER[0];
touched = true; // touched = true;
break; // break;
} // }
else if (int8_t(*key) < 0 && x <= KEYBOARD_BITMAP_WIDTH) { // else if (int8_t(*key) < 0 && x <= KEYBOARD_BITMAP_WIDTH) {
if (uint8_t(*key) == 128) { // if (uint8_t(*key) == 128) {
touch_key = KEYBOARD_BACKSPACE[0]; // touch_key = KEYBOARD_BACKSPACE[0];
touched = true; // touched = true;
break; // break;
} else { // } else {
touched = false; // touched = false;
break; // break;
} // }
} // }
else if (*key != ' ' && (x >= -(KEYBOARD_CHAR_WIDTH / 2) && x <= KEYBOARD_CHAR_WIDTH / 2)) { // else if (*key != ' ' && (x >= -(KEYBOARD_CHAR_WIDTH / 2) && x <= KEYBOARD_CHAR_WIDTH / 2)) {
touch_key = *key; // touch_key = *key;
touched = true; // touched = true;
break; // break;
} // }
x -= getCharWidth(*key); // x -= getCharWidth(*key);
key++; // key++;
if (touched) { // if (touched) {
invalidate(); // invalidate();
break; // break;
} // }
} // }
return true; // return true;
} }
bool TextKeyboard::onTouchEnd(coord_t x, coord_t y) bool TextKeyboard::onTouchEnd(coord_t x, coord_t y)
{ {
// remove the centering width, if x < 0 then this is an invalid touch on a centered keyboard. // // remove the centering width, if x < 0 then this is an invalid touch on a centered keyboard.
x -= (this->width() - calculateMaxWidth()) / 2; // x -= (this->width() - calculateMaxWidth()) / 2;
if (x < 0) { // if (x < 0) {
touched = false; // touched = false;
return true; // return true;
} // }
onKeyPress(); // onKeyPress();
if (touched) // if (touched)
invalidate(); // invalidate();
touched = false; // touched = false;
uint8_t row = max<coord_t>(0, y - 5) / KEYBOARD_ROW_HEIGHT; // uint8_t row = max<coord_t>(0, y - 5) / KEYBOARD_ROW_HEIGHT;
const char * key = layout[row]; // const char * key = layout[row];
while (*key) { // while (*key) {
if (*key == KEYBOARD_SPACE[0]) { // if (*key == KEYBOARD_SPACE[0]) {
if (x <= KEYBOARD_SPACE_WIDTH) { // if (x <= KEYBOARD_SPACE_WIDTH) {
pushEvent(EVT_VIRTUAL_KEY(' ')); // pushEvent(EVT_VIRTUAL_KEY(' '));
return true; // return true;
} // }
} // }
else if (*key == KEYBOARD_ENTER[0]) { // else if (*key == KEYBOARD_ENTER[0]) {
if (x <= KEYBOARD_ENTER_WIDTH) { // if (x <= KEYBOARD_ENTER_WIDTH) {
pushEvent(EVT_VIRTUAL_KEY(KEYBOARD_ENTER[0])); // pushEvent(EVT_VIRTUAL_KEY(KEYBOARD_ENTER[0]));
// enter // // enter
hide(); // hide();
return true; // return true;
} // }
} // }
else if (int8_t(*key) < 0) { // else if (int8_t(*key) < 0) {
if (x <= KEYBOARD_BITMAP_WIDTH) { // if (x <= KEYBOARD_BITMAP_WIDTH) {
uint8_t specialKey = *key; // uint8_t specialKey = *key;
if (specialKey == 128) { // if (specialKey == 128) {
// backspace // // backspace
pushEvent(EVT_VIRTUAL_KEY(KEYBOARD_BACKSPACE[0])); // pushEvent(EVT_VIRTUAL_KEY(KEYBOARD_BACKSPACE[0]));
} // }
else { // else {
layout = KEYBOARD_LAYOUTS[specialKey - 129]; // layout = KEYBOARD_LAYOUTS[specialKey - 129];
invalidate(); // invalidate();
} // }
break; // break;
} // }
} // }
else { // else {
if (*key != ' ' && (x >= -(KEYBOARD_CHAR_WIDTH / 2) && x <= KEYBOARD_CHAR_WIDTH / 2)) { // if (*key != ' ' && (x >= -(KEYBOARD_CHAR_WIDTH / 2) && x <= KEYBOARD_CHAR_WIDTH / 2)) {
pushEvent(EVT_VIRTUAL_KEY(*key)); // pushEvent(EVT_VIRTUAL_KEY(*key));
return true; // return true;
} // }
} // }
x -= getCharWidth(*key); // x -= getCharWidth(*key);
key++; // key++;
} // }
return true; // return true;
} }
bool TextKeyboard::onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY) bool TextKeyboard::onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY)
{ {
if (touched) // if (touched)
invalidate(); // invalidate();
touched = false; // touched = false;
return false; // return false;
} }
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
void TextKeyboard::onEvent(event_t event) void TextKeyboard::onEvent(event_t event)
{ {
} }
#endif #endif
+2
View File
@@ -53,6 +53,8 @@ class TextKeyboard : public Keyboard {
{ {
if (!_instance) if (!_instance)
_instance = new TextKeyboard(); _instance = new TextKeyboard();
else
lv_obj_clear_flag(_instance->keyboard, LV_OBJ_FLAG_HIDDEN);
_instance->setField(field); _instance->setField(field);
} }
-1
View File
@@ -33,7 +33,6 @@ LvglWidgetFactory mainWindowFactory = LvglWidgetFactory([] (lv_obj_t *parent) {
#if defined(HARDWARE_TOUCH) #if defined(HARDWARE_TOUCH)
TouchState touchState; TouchState touchState;
Keyboard * Keyboard::activeKeyboard = nullptr;
#endif #endif
void MainWindow::emptyTrash() void MainWindow::emptyTrash()
+23 -23
View File
@@ -47,24 +47,24 @@ static lv_obj_t *virtual_kb = nullptr;
static void ta_event_cb(lv_event_t *e) static void ta_event_cb(lv_event_t *e)
{ {
lv_event_code_t code = lv_event_get_code(e); // lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *ta = lv_event_get_target(e); // lv_obj_t *ta = lv_event_get_target(e);
if (code == LV_EVENT_CLICKED) { // if (code == LV_EVENT_CLICKED) {
if (virtual_kb == nullptr) { // if (virtual_kb == nullptr) {
virtual_kb = lv_keyboard_create(lv_scr_act()); // virtual_kb = lv_keyboard_create(lv_scr_act());
lv_obj_set_size(virtual_kb, LV_HOR_RES, LV_VER_RES / 2); // lv_obj_set_size(virtual_kb, LV_HOR_RES, LV_VER_RES / 2);
} // }
if (virtual_kb != NULL) { // if (virtual_kb != NULL) {
lv_keyboard_set_textarea(virtual_kb, ta); // lv_keyboard_set_textarea(virtual_kb, ta);
lv_obj_add_state(ta, LV_STATE_EDITED); // lv_obj_add_state(ta, LV_STATE_EDITED);
} // }
} else if (code == LV_EVENT_DEFOCUSED || code == LV_EVENT_DELETE) { // } else if (code == LV_EVENT_DEFOCUSED || code == LV_EVENT_DELETE) {
if (virtual_kb != nullptr) { // if (virtual_kb != nullptr) {
lv_obj_del(virtual_kb); // lv_obj_del(virtual_kb);
virtual_kb = nullptr; // virtual_kb = nullptr;
} // }
} // }
} }
static lv_style_t style_main; static lv_style_t style_main;
@@ -339,9 +339,9 @@ bool TextEdit::onTouchEnd(coord_t x, coord_t y)
setFocus(SET_FOCUS_DEFAULT); setFocus(SET_FOCUS_DEFAULT);
} }
// #if defined(SOFTWARE_KEYBOARD) #if defined(SOFTWARE_KEYBOARD)
// TextKeyboard::show(this); TextKeyboard::show(this);
// #endif #endif
coord_t rest = x; coord_t rest = x;
for (cursorPos = 0; cursorPos < length; cursorPos++) { for (cursorPos = 0; cursorPos < length; cursorPos++) {
@@ -361,9 +361,9 @@ bool TextEdit::onTouchEnd(coord_t x, coord_t y)
void TextEdit::onFocusLost() void TextEdit::onFocusLost()
{ {
// #if defined(SOFTWARE_KEYBOARD) #if defined(SOFTWARE_KEYBOARD)
// TextKeyboard::hide(); TextKeyboard::hide();
// #endif #endif
changeEnd(); changeEnd();
FormField::onFocusLost(); FormField::onFocusLost();
-2
View File
@@ -208,8 +208,6 @@ void Window::attach(Window * newParent)
if (newParent) if (newParent)
{ {
newParent->addChild(this); newParent->addChild(this);
if(lvobj != nullptr)
lv_obj_set_parent(lvobj, newParent->lvobj);
} }
} }
+11 -2
View File
@@ -210,11 +210,12 @@ class Window
void setHeight(coord_t value) void setHeight(coord_t value)
{ {
rect.h = value; rect.h = value;
lv_obj_set_height(lvobj, rect.h); if (lvobj != nullptr)
lv_obj_set_height(lvobj, rect.h);
if (windowFlags & FORWARD_SCROLL) if (windowFlags & FORWARD_SCROLL)
innerHeight = value; innerHeight = value;
else if (innerHeight <= value) { else if (lvobj != nullptr && innerHeight <= value) {
lv_obj_scroll_to_y(lvobj, 0, LV_ANIM_OFF); lv_obj_scroll_to_y(lvobj, 0, LV_ANIM_OFF);
} }
invalidate(); invalidate();
@@ -436,6 +437,12 @@ class Window
void addChild(Window * window, bool front = false) void addChild(Window * window, bool front = false)
{ {
if (lv_obj_get_parent(window->lvobj) != nullptr) {
lv_obj_set_parent(window->lvobj, this->lvobj);
if (front)
lv_obj_move_to_index(window->lvobj, 0);
}
if (front) if (front)
children.push_front(window); children.push_front(window);
else else
@@ -445,6 +452,8 @@ class Window
void removeChild(Window * window) void removeChild(Window * window)
{ {
children.remove(window); children.remove(window);
if (window->lvobj != nullptr)
lv_obj_set_parent(window->lvobj, nullptr);
invalidate(); invalidate();
} }