trying to fix scrolling to correct positon when keyboard pops up
This commit is contained in:
@@ -42,5 +42,6 @@ if(SOFTWARE_KEYBOARD)
|
|||||||
${LIBOPENUI_SRC}
|
${LIBOPENUI_SRC}
|
||||||
keyboard_text.cpp
|
keyboard_text.cpp
|
||||||
keyboard_number.cpp
|
keyboard_number.cpp
|
||||||
|
keyboard_base.cpp
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) OpenTX
|
||||||
|
*
|
||||||
|
* Source:
|
||||||
|
* https://github.com/opentx/libopenui
|
||||||
|
*
|
||||||
|
* This file is a part of libopenui library.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*/
|
||||||
|
#include "keyboard_base.h"
|
||||||
|
|
||||||
|
void Keyboard::hide()
|
||||||
|
{
|
||||||
|
if (activeKeyboard) {
|
||||||
|
activeKeyboard->clearField();
|
||||||
|
activeKeyboard = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Keyboard::clearField()
|
||||||
|
{
|
||||||
|
detach();
|
||||||
|
if (fields) {
|
||||||
|
fields->setHeight(oldHeight);
|
||||||
|
fields = nullptr;
|
||||||
|
}
|
||||||
|
if (fieldContainer) {
|
||||||
|
fieldContainer->setHeight(LCD_H - 0 - fieldContainer->top());
|
||||||
|
fieldContainer = nullptr;
|
||||||
|
}
|
||||||
|
if (field) {
|
||||||
|
field->setEditMode(false);
|
||||||
|
field = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Keyboard::setField(FormField* newField)
|
||||||
|
{
|
||||||
|
if (activeKeyboard) {
|
||||||
|
if (activeKeyboard == this) return;
|
||||||
|
activeKeyboard->clearField();
|
||||||
|
}
|
||||||
|
activeKeyboard = this;
|
||||||
|
attach(MainWindow::instance());
|
||||||
|
|
||||||
|
fieldContainer = getFieldContainer(newField);
|
||||||
|
if (fieldContainer) {
|
||||||
|
coord_t newWindowHeight = LCD_H - height();
|
||||||
|
|
||||||
|
fieldContainer->setHeight(newWindowHeight);
|
||||||
|
|
||||||
|
std::list<Window*> children = fieldContainer->getChildren();
|
||||||
|
fields = *std::next(children.begin());
|
||||||
|
|
||||||
|
rect_t scrollRect = {
|
||||||
|
fieldContainer->left(),
|
||||||
|
fields->top(), // this will remove the title from the screen to provide extra visible space.
|
||||||
|
fieldContainer->width(),
|
||||||
|
fieldContainer->height()
|
||||||
|
};
|
||||||
|
// both should be the same height as we are scrolled to the right position
|
||||||
|
fieldContainer->scrollTo(scrollRect);
|
||||||
|
oldHeight = fields->height();
|
||||||
|
fields->setHeight(newWindowHeight);
|
||||||
|
|
||||||
|
// now we need to calculate the offset of the field in the fields scroll container
|
||||||
|
coord_t offsetX = 0, offsetY = 0;
|
||||||
|
Window* parentWindow = newField->getParent();
|
||||||
|
while (parentWindow && parentWindow != fieldContainer) {
|
||||||
|
offsetX += parentWindow->left();
|
||||||
|
offsetY += parentWindow->top();
|
||||||
|
parentWindow = parentWindow->getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollRect = {
|
||||||
|
offsetX,
|
||||||
|
offsetY + 69,
|
||||||
|
fieldContainer->width(),
|
||||||
|
fieldContainer->height()
|
||||||
|
};
|
||||||
|
fields->scrollTo(scrollRect);
|
||||||
|
|
||||||
|
invalidate();
|
||||||
|
newField->setEditMode(true);
|
||||||
|
field = newField;
|
||||||
|
} else {
|
||||||
|
clearField();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Window* Keyboard::getFieldContainer(FormField* field)
|
||||||
|
{
|
||||||
|
return field->getFullScreenWindow();
|
||||||
|
}
|
||||||
+9
-49
@@ -25,61 +25,21 @@
|
|||||||
class Keyboard: public FormWindow
|
class Keyboard: public FormWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Keyboard(coord_t height):
|
explicit Keyboard(coord_t height) : FormWindow(nullptr, {0, LCD_H - height, LCD_W, height}, OPAQUE)
|
||||||
FormWindow(nullptr, {0, LCD_H - height, LCD_W, height}, OPAQUE)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hide()
|
static void hide();
|
||||||
{
|
|
||||||
if (activeKeyboard) {
|
|
||||||
activeKeyboard->clearField();
|
|
||||||
activeKeyboard = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static Keyboard * activeKeyboard;
|
static Keyboard * activeKeyboard;
|
||||||
FormField * field = nullptr;
|
FormField *field = nullptr;
|
||||||
Window * fieldContainer = nullptr;
|
Window *fieldContainer = nullptr;
|
||||||
|
Window *fields = nullptr;
|
||||||
|
coord_t oldHeight = 0;
|
||||||
|
|
||||||
void setField(FormField * newField)
|
void setField(FormField *newField);
|
||||||
{
|
void clearField();
|
||||||
if (activeKeyboard) {
|
Window *getFieldContainer(FormField * field);
|
||||||
if (activeKeyboard == this)
|
|
||||||
return;
|
|
||||||
activeKeyboard->clearField();
|
|
||||||
}
|
|
||||||
activeKeyboard = this;
|
|
||||||
attach(MainWindow::instance());
|
|
||||||
fieldContainer = getFieldContainer(newField);
|
|
||||||
if (fieldContainer) {
|
|
||||||
fieldContainer->setHeight(LCD_H - height() - fieldContainer->top());
|
|
||||||
fieldContainer->scrollTo(newField);
|
|
||||||
invalidate();
|
|
||||||
newField->setEditMode(true);
|
|
||||||
field = newField;
|
|
||||||
} else {
|
|
||||||
clearField();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearField()
|
|
||||||
{
|
|
||||||
detach();
|
|
||||||
if (fieldContainer) {
|
|
||||||
fieldContainer->setHeight(LCD_H - 0 - fieldContainer->top());
|
|
||||||
fieldContainer = nullptr;
|
|
||||||
}
|
|
||||||
if (field) {
|
|
||||||
field->setEditMode(false);
|
|
||||||
field = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Window * getFieldContainer(FormField * field)
|
|
||||||
{
|
|
||||||
return field->getFullScreenWindow();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ void NumberEdit::onEvent(event_t event)
|
|||||||
case EVT_KEY_FIRST(KEY_EXIT):
|
case EVT_KEY_FIRST(KEY_EXIT):
|
||||||
#if defined(SOFTWARE_KEYBOARD)
|
#if defined(SOFTWARE_KEYBOARD)
|
||||||
Keyboard::hide();
|
Keyboard::hide();
|
||||||
|
return;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -170,10 +170,12 @@ void TextEdit::onEvent(event_t event)
|
|||||||
|
|
||||||
case EVT_KEY_BREAK(KEY_EXIT):
|
case EVT_KEY_BREAK(KEY_EXIT):
|
||||||
changeEnd();
|
changeEnd();
|
||||||
|
FormField::onEvent(event);
|
||||||
|
|
||||||
#if defined(SOFTWARE_KEYBOARD)
|
#if defined(SOFTWARE_KEYBOARD)
|
||||||
Keyboard::hide();
|
Keyboard::hide();
|
||||||
#endif
|
#endif
|
||||||
FormField::onEvent(event);
|
setFocus(SET_FOCUS_DEFAULT, this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVT_KEY_LONG(KEY_ENTER):
|
case EVT_KEY_LONG(KEY_ENTER):
|
||||||
|
|||||||
+5
@@ -144,6 +144,11 @@ class Window
|
|||||||
focusHandler = std::move(handler);
|
focusHandler = std::move(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::list<Window *> getChildren()
|
||||||
|
{
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void deleteLater(bool detach = true, bool trash = true);
|
virtual void deleteLater(bool detach = true, bool trash = true);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user