fix crash in number kebyoard when NumericKeyboard looses focus

This commit is contained in:
kevinkoenig
2021-09-03 09:47:39 +02:00
committed by Raphael Coeffic
parent 47585b8829
commit 2c5ed7e3ad
4 changed files with 41 additions and 11 deletions
+29 -10
View File
@@ -49,17 +49,25 @@ void Keyboard::attachKeyboard()
// this routine finds the window that is a FormWindow. This is the window
// that contains all of the editable fields. This is the window that needs
// to be scrolled into view.
FormWindow *Keyboard::findFormWindow()
FormWindow *Keyboard::findFormWindow(Window *parent)
{
if (fieldContainer) {
auto children = fieldContainer->getChildren();
auto k = children.begin();
while (k != children.end())
if (parent) {
auto children = parent->getChildren();
auto childIterator = children.begin();
while (childIterator != children.end())
{
FormWindow *a = dynamic_cast<FormWindow*>(*k);
if (a)
return a;
k++;
#if defined(DEBUG_WINDOWS)
std::string windowName;
Window *window = dynamic_cast<Window *>(*childIterator);
if (window)
windowName = window->getName();
#endif
FormWindow *formWindow = dynamic_cast<FormWindow*>(*childIterator);
if (formWindow)
return formWindow;
childIterator++;
}
}
@@ -72,11 +80,18 @@ void Keyboard::setField(FormField* newField)
fieldContainer = getFieldContainer(newField);
if (fieldContainer) {
#if defined(DEBUG_WINDOWS)
auto windowName = fieldContainer->getName();
#endif
coord_t newHeight = LCD_H - height();
fieldContainer->setHeight(newHeight);
fields = findFormWindow();
fields = findFormWindow(fieldContainer);
if (fields) {
#if defined(DEBUG_WINDOWS)
windowName = fields->getName();
#endif
// scroll the header of the window out of view to get more space to
// see the field being edited
fieldContainer->setScrollPositionY(fields->top());
@@ -85,6 +100,10 @@ void Keyboard::setField(FormField* newField)
coord_t offsetY = calcScrollOffsetForField(newField, fields);
fields->setScrollPositionY(offsetY);
} else {
// TODO: what happens if field container is null.
// we will need to interrogate the fieldContainer for its
// FormGroup. That is really how it should work anyway.
}
invalidate();
+1 -1
View File
@@ -65,6 +65,6 @@ class Keyboard: public FormWindow
void setField(FormField *newField);
Window *getFieldContainer(FormField * field);
void attachKeyboard();
FormWindow *findFormWindow();
FormWindow *findFormWindow(Window *parent);
};
+10
View File
@@ -150,6 +150,16 @@ void NumberEdit::onEvent(event_t event)
FormField::onEvent(event);
}
void NumberEdit::onFocusLost()
{
#if defined(SOFTWARE_KEYBOARD)
Keyboard::hide();
#endif
FormField::onFocusLost();
}
#if defined(HARDWARE_TOUCH)
bool NumberEdit::onTouchEnd(coord_t, coord_t)
{
+1
View File
@@ -62,6 +62,7 @@ class NumberEdit : public BaseNumberEdit
}
void onEvent(event_t event) override;
void onFocusLost() override;
#if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t x, coord_t y) override;