keyboard changes
This commit is contained in:
committed by
Raphael Coeffic
parent
ca5b6a121c
commit
551d7ae766
+2
-2
@@ -25,8 +25,8 @@ class BaseNumberEdit: public FormField
|
||||
{
|
||||
public:
|
||||
BaseNumberEdit(Window * parent, const rect_t &rect, int vmin, int vmax,
|
||||
std::function<int()> getValue, std::function<void(int)> setValue = nullptr, WindowFlags windowFlags = 0, LcdFlags textFlags = 0):
|
||||
FormField(parent, rect, windowFlags, textFlags),
|
||||
std::function<int()> getValue, std::function<void(int)> setValue = nullptr, WindowFlags windowFlags = 0, LcdFlags textFlags = 0, LvglWidgetFactory *factory = nullptr):
|
||||
FormField(parent, rect, windowFlags, textFlags, factory),
|
||||
vmin(vmin),
|
||||
vmax(vmax),
|
||||
_getValue(std::move(getValue)),
|
||||
|
||||
@@ -21,6 +21,66 @@
|
||||
Keyboard * Keyboard::activeKeyboard = nullptr;
|
||||
lv_obj_t *Keyboard::keyboard = nullptr;
|
||||
|
||||
static void keyboard_event_cb(lv_event_t * e)
|
||||
{
|
||||
auto code = lv_event_get_code(e);
|
||||
Keyboard *kb = (Keyboard *) lv_event_get_user_data(e);
|
||||
if (code == LV_EVENT_READY) {
|
||||
pushEvent(EVT_VIRTUAL_KEY('\n'));
|
||||
kb->hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Keyboard::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);
|
||||
|
||||
if (keyboard == nullptr) {
|
||||
keyboard = lv_keyboard_create(lv_scr_act());
|
||||
lv_obj_add_event_cb(keyboard, keyboard_event_cb, LV_EVENT_ALL, this);
|
||||
|
||||
|
||||
lv_obj_set_size(keyboard, LCD_W, LCD_H * 2 / 5);
|
||||
lv_obj_clear_flag(keyboard, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
void Keyboard::clearField()
|
||||
{
|
||||
TRACE("CLEAR FIELD");
|
||||
if (keyboard != nullptr) {
|
||||
lv_obj_add_flag(keyboard, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
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->changeEnd();
|
||||
field = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Keyboard::hide()
|
||||
{
|
||||
if (activeKeyboard) {
|
||||
activeKeyboard->clearField();
|
||||
activeKeyboard = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
coord_t calcScrollOffsetForField(FormField *newField, Window *topWindow)
|
||||
{
|
||||
// now we need to calculate the offset of the field in the fields scroll container
|
||||
|
||||
+3
-39
@@ -25,45 +25,9 @@
|
||||
class Keyboard: public FormWindow
|
||||
{
|
||||
public:
|
||||
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()
|
||||
{
|
||||
TRACE("CLEAR FIELD");
|
||||
if (keyboard != nullptr) {
|
||||
lv_obj_add_flag(keyboard, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
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->changeEnd();
|
||||
field = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void hide()
|
||||
{
|
||||
if (activeKeyboard) {
|
||||
activeKeyboard->clearField();
|
||||
activeKeyboard = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
explicit Keyboard(coord_t height);
|
||||
void clearField();
|
||||
static void hide();
|
||||
|
||||
protected:
|
||||
static Keyboard * activeKeyboard;
|
||||
|
||||
+40
-46
@@ -22,59 +22,58 @@
|
||||
#include "libopenui_globals.h"
|
||||
|
||||
constexpr coord_t KEYBOARD_HEIGHT = 90;
|
||||
|
||||
NumberKeyboard * NumberKeyboard::_instance = nullptr;
|
||||
|
||||
NumberKeyboard::NumberKeyboard() :
|
||||
Keyboard(KEYBOARD_HEIGHT)
|
||||
{
|
||||
new TextButton(this, {LCD_W / 2 - 115, 10, 50, 30}, "<<",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_BACKWARD);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
// new TextButton(this, {LCD_W / 2 - 115, 10, 50, 30}, "<<",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_BACKWARD);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
new TextButton(this, {LCD_W / 2 - 55, 10, 50, 30}, "-",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_MINUS);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
// new TextButton(this, {LCD_W / 2 - 55, 10, 50, 30}, "-",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_MINUS);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
new TextButton(this, {LCD_W / 2 + 5, 10, 50, 30}, "+",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_PLUS);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
// new TextButton(this, {LCD_W / 2 + 5, 10, 50, 30}, "+",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_PLUS);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
new TextButton(this, {LCD_W / 2 + 65, 10, 50, 30}, ">>",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_FORWARD);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
// new TextButton(this, {LCD_W / 2 + 65, 10, 50, 30}, ">>",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_FORWARD);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
new TextButton(this, {LCD_W / 2 - 115, 50, 50, 30}, "MIN",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_MIN);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
// new TextButton(this, {LCD_W / 2 - 115, 50, 50, 30}, "MIN",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_MIN);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
new TextButton(this, {LCD_W / 2 + 65, 50, 50, 30}, "MAX",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_MAX);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
// new TextButton(this, {LCD_W / 2 + 65, 50, 50, 30}, "MAX",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_MAX);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
new TextButton(this, { LCD_W/2 - 55, 50, 50, 30 }, "DEF",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_DEFAULT);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
// new TextButton(this, { LCD_W/2 - 55, 50, 50, 30 }, "DEF",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_DEFAULT);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
new TextButton(this, { LCD_W/2 + 5, 50, 50, 30 }, "+/-",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_SIGN);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
// new TextButton(this, { LCD_W/2 + 5, 50, 50, 30 }, "+/-",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_SIGN);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
}
|
||||
|
||||
NumberKeyboard::~NumberKeyboard()
|
||||
@@ -82,8 +81,3 @@ NumberKeyboard::~NumberKeyboard()
|
||||
_instance = nullptr;
|
||||
}
|
||||
|
||||
void NumberKeyboard::paint(BitmapBuffer * dc)
|
||||
{
|
||||
lcdSetColor(RGB(0xE0, 0xE0, 0xE0));
|
||||
dc->clear(CUSTOM_COLOR);
|
||||
}
|
||||
|
||||
+4
-2
@@ -38,11 +38,13 @@ class NumberKeyboard : public Keyboard {
|
||||
{
|
||||
if (!_instance)
|
||||
_instance = new NumberKeyboard();
|
||||
else
|
||||
lv_obj_clear_flag(_instance->keyboard, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_NUMBER);
|
||||
_instance->setField(field);
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
protected:
|
||||
static NumberKeyboard * _instance;
|
||||
};
|
||||
|
||||
+1
-268
@@ -23,283 +23,16 @@
|
||||
#include "font.h"
|
||||
|
||||
constexpr coord_t KEYBOARD_HEIGHT = LCD_H * 2 / 5;
|
||||
|
||||
TextKeyboard * TextKeyboard::_instance = nullptr;
|
||||
|
||||
// const uint8_t LBM_KEY_UPPERCASE[] = {
|
||||
// #include "mask_key_uppercase.lbm"
|
||||
// };
|
||||
|
||||
// const uint8_t LBM_KEY_LOWERCASE[] = {
|
||||
// #include "mask_key_lowercase.lbm"
|
||||
// };
|
||||
|
||||
// const uint8_t LBM_KEY_BACKSPACE[] = {
|
||||
// #include "mask_key_backspace.lbm"
|
||||
// };
|
||||
|
||||
// const uint8_t LBM_KEY_LETTERS[] = {
|
||||
// #include "mask_key_letters.lbm"
|
||||
// };
|
||||
|
||||
// const uint8_t LBM_KEY_NUMBERS[] = {
|
||||
// #include "mask_key_numbers.lbm"
|
||||
// };
|
||||
|
||||
// const uint8_t LBM_KEY_SPACEBAR[] = {
|
||||
// #include "mask_key_spacebar.lbm"
|
||||
// };
|
||||
|
||||
// const uint8_t * const LBM_SPECIAL_KEYS[] = {
|
||||
// LBM_KEY_BACKSPACE,
|
||||
// LBM_KEY_UPPERCASE,
|
||||
// LBM_KEY_LOWERCASE,
|
||||
// LBM_KEY_LETTERS,
|
||||
// LBM_KEY_NUMBERS,
|
||||
// };
|
||||
|
||||
// const char * const KEYBOARD_LOWERCASE[] = {
|
||||
// "qwertyuiop",
|
||||
// " asdfghjkl",
|
||||
// KEYBOARD_SET_UPPERCASE "zxcvbnm" KEYBOARD_BACKSPACE,
|
||||
// KEYBOARD_SET_NUMBERS KEYBOARD_SPACE KEYBOARD_ENTER
|
||||
// };
|
||||
|
||||
// const char * const KEYBOARD_UPPERCASE[] = {
|
||||
// "QWERTYUIOP",
|
||||
// " ASDFGHJKL",
|
||||
// KEYBOARD_SET_LOWERCASE "ZXCVBNM" KEYBOARD_BACKSPACE,
|
||||
// KEYBOARD_SET_NUMBERS KEYBOARD_SPACE KEYBOARD_ENTER
|
||||
// };
|
||||
|
||||
// const char * const KEYBOARD_NUMBERS[] = {
|
||||
// "1234567890",
|
||||
// "_-",
|
||||
// " " KEYBOARD_BACKSPACE,
|
||||
// KEYBOARD_SET_LETTERS KEYBOARD_SPACE KEYBOARD_ENTER
|
||||
// };
|
||||
|
||||
// #define NUMBER_OF_KEYBOARD_LAYOUTS 4
|
||||
// const char * const * const KEYBOARD_LAYOUTS[NUMBER_OF_KEYBOARD_LAYOUTS] = {
|
||||
// KEYBOARD_UPPERCASE,
|
||||
// KEYBOARD_LOWERCASE,
|
||||
// KEYBOARD_LOWERCASE,
|
||||
// KEYBOARD_NUMBERS,
|
||||
// };
|
||||
|
||||
TextKeyboard::TextKeyboard():
|
||||
TextKeyboard::TextKeyboard() :
|
||||
Keyboard(KEYBOARD_HEIGHT)
|
||||
// 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()
|
||||
{
|
||||
_instance = nullptr;
|
||||
|
||||
}
|
||||
|
||||
int TextKeyboard::getCharWidth(const char c)
|
||||
{
|
||||
// if (int8_t(c) < 0) return KEYBOARD_BITMAP_WIDTH;
|
||||
|
||||
// switch (c)
|
||||
// {
|
||||
// case ' ': return 15;
|
||||
// case KEYBOARD_SPACE[0]: return KEYBOARD_SPACE_WIDTH;
|
||||
// case KEYBOARD_ENTER[0]: return KEYBOARD_ENTER_WIDTH;
|
||||
// default: return KEYBOARD_CHAR_WIDTH;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
int TextKeyboard::calculateMaxWidth()
|
||||
{
|
||||
// int maxWidth = 0;
|
||||
// for (uint8_t i = 0; i < NUMBER_OF_KEYBOARD_LAYOUTS; i++) {
|
||||
// int lineWidth = 0;
|
||||
// const char * c = layout[i];
|
||||
// while (*c) {
|
||||
// lineWidth += getCharWidth(*c);
|
||||
// maxWidth = max(lineWidth, maxWidth);
|
||||
// c++;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return maxWidth;
|
||||
}
|
||||
|
||||
void TextKeyboard::paint(BitmapBuffer * dc)
|
||||
{
|
||||
// lcdSetColor(RGB(0xE0, 0xE0, 0xE0));
|
||||
// dc->clear(CUSTOM_COLOR);
|
||||
|
||||
// // center the keyboard
|
||||
// coord_t start_x = (dc->width() - calculateMaxWidth()) / 2;
|
||||
|
||||
// for (uint8_t i = 0; i < NUMBER_OF_KEYBOARD_LAYOUTS; i++) {
|
||||
// coord_t y = KEYBOARD_OFFSET_Y + i * KEYBOARD_ROW_HEIGHT;
|
||||
// coord_t x = start_x;
|
||||
// const char * c = layout[i];
|
||||
|
||||
// while (*c) {
|
||||
// if (*c == KEYBOARD_SPACE[0]) {
|
||||
// // spacebar
|
||||
// dc->drawBitmapPattern(x, y, LBM_KEY_SPACEBAR, COLOR_THEME_SECONDARY1);
|
||||
// }
|
||||
// else if (*c == KEYBOARD_ENTER[0]) {
|
||||
// // enter
|
||||
// dc->drawSolidFilledRect(x, y - 2, KEYBOARD_ENTER_WIDTH, 25, COLOR_THEME_DISABLED);
|
||||
// dc->drawText(x + KEYBOARD_ENTER_WIDTH / 2, y + 2, "ENTER", CENTERED);
|
||||
// }
|
||||
// else if (int8_t(*c) < 0) {
|
||||
// const uint8_t *pBitmap = LBM_SPECIAL_KEYS[uint8_t(*c - 128)];
|
||||
// uint8_t bitmapWidth = *pBitmap, bitmapHeight = *(pBitmap + 2);
|
||||
// if (touched && *c == touch_key) {
|
||||
// dc->drawSolidFilledRect(x - 2, y + 3, bitmapWidth + 4, bitmapHeight + 4, COLOR_THEME_SECONDARY2);
|
||||
// }
|
||||
|
||||
// dc->drawBitmapPattern(x, y + 5, pBitmap, COLOR_THEME_SECONDARY1);
|
||||
// }
|
||||
// else {
|
||||
// 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->drawSizedText(x, y, c, 1, CENTERED);
|
||||
// }
|
||||
// x += getCharWidth(*c);
|
||||
// c++;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
bool TextKeyboard::onTouchStart(coord_t x, coord_t y)
|
||||
{
|
||||
// // remove the centering. If x < 0 then this is an invalid touch event
|
||||
// x -= (this->width() - calculateMaxWidth()) / 2;
|
||||
// if (x < 0) {
|
||||
// if (touched) {
|
||||
// touched = false;
|
||||
// invalidate();
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// touched = false;
|
||||
|
||||
// uint8_t row = max<coord_t>(0, y - 5) / KEYBOARD_ROW_HEIGHT;
|
||||
// const char * key = layout[row];
|
||||
|
||||
// while(*key) {
|
||||
// if (*key == KEYBOARD_SPACE[0] && x <= KEYBOARD_SPACE_WIDTH) {
|
||||
// touch_key = KEYBOARD_SPACE[0];
|
||||
// touched = true;
|
||||
// break;
|
||||
// }
|
||||
// else if (*key == KEYBOARD_ENTER[0] && x <= KEYBOARD_ENTER_WIDTH) {
|
||||
// touch_key = KEYBOARD_ENTER[0];
|
||||
// touched = true;
|
||||
// break;
|
||||
// }
|
||||
// else if (int8_t(*key) < 0 && x <= KEYBOARD_BITMAP_WIDTH) {
|
||||
// if (uint8_t(*key) == 128) {
|
||||
// touch_key = KEYBOARD_BACKSPACE[0];
|
||||
// touched = true;
|
||||
// break;
|
||||
// } else {
|
||||
// touched = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// else if (*key != ' ' && (x >= -(KEYBOARD_CHAR_WIDTH / 2) && x <= KEYBOARD_CHAR_WIDTH / 2)) {
|
||||
// touch_key = *key;
|
||||
// touched = true;
|
||||
// break;
|
||||
// }
|
||||
|
||||
// x -= getCharWidth(*key);
|
||||
// key++;
|
||||
|
||||
// if (touched) {
|
||||
// invalidate();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
}
|
||||
|
||||
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.
|
||||
// x -= (this->width() - calculateMaxWidth()) / 2;
|
||||
// if (x < 0) {
|
||||
// touched = false;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// onKeyPress();
|
||||
|
||||
// if (touched)
|
||||
// invalidate();
|
||||
// touched = false;
|
||||
|
||||
// uint8_t row = max<coord_t>(0, y - 5) / KEYBOARD_ROW_HEIGHT;
|
||||
|
||||
// const char * key = layout[row];
|
||||
// while (*key) {
|
||||
// if (*key == KEYBOARD_SPACE[0]) {
|
||||
// if (x <= KEYBOARD_SPACE_WIDTH) {
|
||||
// pushEvent(EVT_VIRTUAL_KEY(' '));
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// else if (*key == KEYBOARD_ENTER[0]) {
|
||||
// if (x <= KEYBOARD_ENTER_WIDTH) {
|
||||
// pushEvent(EVT_VIRTUAL_KEY(KEYBOARD_ENTER[0]));
|
||||
// // enter
|
||||
// hide();
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// else if (int8_t(*key) < 0) {
|
||||
// if (x <= KEYBOARD_BITMAP_WIDTH) {
|
||||
// uint8_t specialKey = *key;
|
||||
// if (specialKey == 128) {
|
||||
// // backspace
|
||||
// pushEvent(EVT_VIRTUAL_KEY(KEYBOARD_BACKSPACE[0]));
|
||||
// }
|
||||
// else {
|
||||
// layout = KEYBOARD_LAYOUTS[specialKey - 129];
|
||||
// invalidate();
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// if (*key != ' ' && (x >= -(KEYBOARD_CHAR_WIDTH / 2) && x <= KEYBOARD_CHAR_WIDTH / 2)) {
|
||||
// pushEvent(EVT_VIRTUAL_KEY(*key));
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// x -= getCharWidth(*key);
|
||||
// key++;
|
||||
// }
|
||||
|
||||
// return true;
|
||||
}
|
||||
|
||||
bool TextKeyboard::onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY)
|
||||
{
|
||||
// if (touched)
|
||||
// invalidate();
|
||||
|
||||
// touched = false;
|
||||
// return false;
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
|
||||
+2
-8
@@ -55,17 +55,11 @@ class TextKeyboard : public Keyboard {
|
||||
_instance = new TextKeyboard();
|
||||
else
|
||||
lv_obj_clear_flag(_instance->keyboard, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_TEXT_LOWER);
|
||||
_instance->setField(field);
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||
bool onTouchStart(coord_t x, coord_t y) override;
|
||||
bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY) override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void onEvent(event_t event) override;
|
||||
|
||||
+45
-34
@@ -23,46 +23,57 @@
|
||||
#include "keyboard_number.h"
|
||||
#endif
|
||||
|
||||
|
||||
static LvglWidgetFactory numberEditFactory = { lv_textarea_create, nullptr };
|
||||
static lv_style_t style_main;
|
||||
static lv_style_t style_edit;
|
||||
|
||||
NumberEdit::NumberEdit(Window * parent, const rect_t & rect, int vmin, int vmax, std::function<int()> getValue, std::function<void(int)> setValue, WindowFlags windowFlags, LcdFlags textFlags):
|
||||
BaseNumberEdit(parent, rect, vmin, vmax, std::move(getValue), std::move(setValue), windowFlags, textFlags)
|
||||
BaseNumberEdit(parent, rect, vmin, vmax, std::move(getValue), std::move(setValue), windowFlags, textFlags, &numberEditFactory)
|
||||
{
|
||||
}
|
||||
// properties
|
||||
lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF);
|
||||
lv_textarea_set_password_mode(lvobj, false);
|
||||
lv_textarea_set_one_line(lvobj, true);
|
||||
lv_textarea_set_accepted_chars(lvobj, "0123456789");
|
||||
|
||||
void NumberEdit::paint(BitmapBuffer * dc)
|
||||
{
|
||||
FormField::paint(dc);
|
||||
auto value = _getValue();
|
||||
auto strValue = std::to_string(value);
|
||||
lv_textarea_set_text(lvobj, strValue.c_str());
|
||||
|
||||
auto value = getValue();
|
||||
// LV_PART_MAIN
|
||||
lv_style_init(&style_main);
|
||||
lv_style_set_border_width(&style_main, 1);
|
||||
lv_style_set_border_color(&style_main, makeLvColor(COLOR_THEME_SECONDARY2));
|
||||
lv_style_set_bg_color(&style_main, makeLvColor(COLOR_THEME_PRIMARY2));
|
||||
lv_style_set_bg_opa(&style_main, LV_OPA_COVER);
|
||||
//lv_style_set_radius(&style_main, 0);
|
||||
lv_style_set_text_font(&style_main, &lv_font_montserrat_12);
|
||||
lv_style_set_text_color(&style_main, makeLvColor(COLOR_THEME_SECONDARY1));
|
||||
lv_obj_add_style(lvobj, &style_main, LV_PART_MAIN);
|
||||
|
||||
LcdFlags textColor;
|
||||
if (editMode)
|
||||
textColor = COLOR_THEME_PRIMARY2;
|
||||
else if (hasFocus())
|
||||
textColor = COLOR_THEME_PRIMARY2;
|
||||
// else if (enabled && (value != 0 || zeroText.empty()))
|
||||
// textColor = COLOR_THEME_SECONDARY1;
|
||||
else
|
||||
textColor = COLOR_THEME_SECONDARY1;
|
||||
// LV_STATE_FOCUSED
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_FOCUS),
|
||||
LV_PART_MAIN | LV_STATE_FOCUSED);
|
||||
|
||||
if (displayFunction) {
|
||||
displayFunction(dc, textColor, value);
|
||||
} else if (value == 0 && !zeroText.empty()) {
|
||||
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, zeroText.c_str(),
|
||||
textColor | textFlags);
|
||||
if (textFlags & RIGHT)
|
||||
dc->drawText(rect.w - FIELD_PADDING_LEFT, FIELD_PADDING_TOP,
|
||||
zeroText.c_str(), textColor | textFlags);
|
||||
else
|
||||
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, zeroText.c_str(),
|
||||
textColor | textFlags);
|
||||
} else {
|
||||
if (textFlags & RIGHT)
|
||||
dc->drawNumber(rect.w - FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value,
|
||||
textColor | textFlags, 0, prefix.c_str(), suffix.c_str());
|
||||
else
|
||||
dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value,
|
||||
textColor | textFlags, 0, prefix.c_str(), suffix.c_str());
|
||||
}
|
||||
lv_obj_set_style_text_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2),
|
||||
LV_PART_MAIN | LV_STATE_FOCUSED);
|
||||
|
||||
// Hide cursor
|
||||
lv_obj_set_style_opa(lvobj, 0, LV_PART_CURSOR);
|
||||
|
||||
// Show Cursor in "Edit" mode
|
||||
lv_style_init(&style_edit);
|
||||
lv_style_set_opa(&style_edit, LV_OPA_COVER);
|
||||
lv_style_set_bg_opa(&style_edit, LV_OPA_COVER);
|
||||
lv_style_set_pad_left(&style_edit, (lv_coord_t)-(FIELD_PADDING_LEFT+2));
|
||||
lv_style_set_pad_top(&style_edit, (lv_coord_t)-(FIELD_PADDING_TOP+2));
|
||||
lv_obj_add_style(lvobj, &style_edit, LV_PART_CURSOR | LV_STATE_EDITED);
|
||||
|
||||
// Text padding
|
||||
auto label = lv_textarea_get_label(lvobj);
|
||||
lv_obj_set_style_pad_left(label, FIELD_PADDING_LEFT, LV_PART_MAIN);
|
||||
lv_obj_set_style_pad_top(label, FIELD_PADDING_TOP, LV_PART_MAIN);
|
||||
}
|
||||
|
||||
void NumberEdit::onEvent(event_t event)
|
||||
|
||||
@@ -34,8 +34,6 @@ class NumberEdit : public BaseNumberEdit
|
||||
}
|
||||
#endif
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
void setAvailableHandler(std::function<bool(int)> handler)
|
||||
{
|
||||
isValueAvailable = std::move(handler);
|
||||
|
||||
+1
-83
@@ -42,31 +42,6 @@
|
||||
#include "clipboard.h"
|
||||
#endif
|
||||
|
||||
|
||||
static lv_obj_t *virtual_kb = nullptr;
|
||||
|
||||
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) {
|
||||
// if (virtual_kb == nullptr) {
|
||||
// virtual_kb = lv_keyboard_create(lv_scr_act());
|
||||
// lv_obj_set_size(virtual_kb, LV_HOR_RES, LV_VER_RES / 2);
|
||||
// }
|
||||
|
||||
// if (virtual_kb != NULL) {
|
||||
// lv_keyboard_set_textarea(virtual_kb, ta);
|
||||
// lv_obj_add_state(ta, LV_STATE_EDITED);
|
||||
// }
|
||||
// } else if (code == LV_EVENT_DEFOCUSED || code == LV_EVENT_DELETE) {
|
||||
// if (virtual_kb != nullptr) {
|
||||
// lv_obj_del(virtual_kb);
|
||||
// virtual_kb = nullptr;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
static lv_style_t style_main;
|
||||
static lv_style_t style_edit;
|
||||
static LvglWidgetFactory textEditFactory = { lv_textarea_create, nullptr };
|
||||
@@ -81,9 +56,6 @@ TextEdit::TextEdit(Window *parent, const rect_t &rect, char *value,
|
||||
{
|
||||
extra_chars = (_extra_chars) ? _extra_chars : extra_chars_default;
|
||||
|
||||
// callbacks
|
||||
lv_obj_add_event_cb(lvobj, ta_event_cb, LV_EVENT_ALL, NULL);
|
||||
|
||||
// properties
|
||||
lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF);
|
||||
lv_textarea_set_password_mode(lvobj, false);
|
||||
@@ -127,45 +99,6 @@ TextEdit::TextEdit(Window *parent, const rect_t &rect, char *value,
|
||||
lv_obj_set_style_pad_top(label, FIELD_PADDING_TOP, LV_PART_MAIN);
|
||||
}
|
||||
|
||||
void TextEdit::paint(BitmapBuffer * 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);
|
||||
// }
|
||||
}
|
||||
|
||||
void TextEdit::trim()
|
||||
{
|
||||
@@ -184,24 +117,9 @@ void TextEdit::onEvent(event_t event)
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
if (IS_VIRTUAL_KEY_EVENT(event)) {
|
||||
uint8_t c = event & 0xFF;
|
||||
if (c == (uint8_t)KEYBOARD_BACKSPACE[0]) {
|
||||
if (cursorPos > 0) {
|
||||
memmove(value + cursorPos - 1, value + cursorPos, length - cursorPos);
|
||||
value[length - 1] = '\0';
|
||||
--cursorPos;
|
||||
invalidate();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
else if (c == (uint8_t)KEYBOARD_ENTER[0]) {
|
||||
if (c == (uint8_t)KEYBOARD_ENTER[0]) {
|
||||
changeEnd();
|
||||
}
|
||||
else if (cursorPos < length) {
|
||||
memmove(value + cursorPos + 1, value + cursorPos, length - cursorPos - 1);
|
||||
value[cursorPos++] = c;
|
||||
invalidate();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+1
-2
@@ -46,8 +46,6 @@ class TextEdit : public FormField {
|
||||
return value;
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
void onEvent(event_t event) override;
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
@@ -67,6 +65,7 @@ class TextEdit : public FormField {
|
||||
|
||||
void changeEnd(bool forceChanged = false) override
|
||||
{
|
||||
strncpy(value, lv_textarea_get_text(lvobj), length);
|
||||
cursorPos = 0;
|
||||
if (changed || forceChanged) {
|
||||
changed = false;
|
||||
|
||||
Reference in New Issue
Block a user