textedit: removed useless code and added update()
This commit is contained in:
+111
-107
@@ -55,18 +55,22 @@ TextEdit::TextEdit(Window *parent, const rect_t &rect, char *value,
|
||||
lv_textarea_set_password_mode(lvobj, false);
|
||||
lv_textarea_set_one_line(lvobj, true);
|
||||
|
||||
// value may not be null-terminated
|
||||
std::string txt(value, length);
|
||||
lv_textarea_set_text(lvobj, txt.c_str());
|
||||
|
||||
lv_textarea_set_placeholder_text(lvobj, "---");
|
||||
lv_textarea_set_max_length(lvobj, length);
|
||||
|
||||
if (width() == 0) {
|
||||
lv_obj_set_width(lvobj, LV_DPI_DEF);
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void TextEdit::update()
|
||||
{
|
||||
// value may not be null-terminated
|
||||
std::string txt(value, length);
|
||||
lv_textarea_set_text(lvobj, txt.c_str());
|
||||
}
|
||||
|
||||
void TextEdit::setCursorPos(int cursorPos)
|
||||
{
|
||||
@@ -91,123 +95,123 @@ void TextEdit::onEvent(event_t event)
|
||||
|
||||
if (IS_VIRTUAL_KEY_EVENT(event)) {
|
||||
uint8_t c = event & 0xFF;
|
||||
if (c == (uint8_t)KEYBOARD_ENTER[0]) {
|
||||
if (c == LV_KEY_ENTER) {
|
||||
changeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
if (editMode) {
|
||||
int c = value[cursorPos];
|
||||
int v = c;
|
||||
// #if defined(HARDWARE_KEYS)
|
||||
// if (editMode) {
|
||||
// int c = value[cursorPos];
|
||||
// int v = c;
|
||||
|
||||
switch (event) {
|
||||
case EVT_ROTARY_RIGHT:
|
||||
for (int i = 0; i < ROTARY_ENCODER_SPEED(); i++) {
|
||||
v = getNextChar(v);
|
||||
}
|
||||
break;
|
||||
// switch (event) {
|
||||
// case EVT_ROTARY_RIGHT:
|
||||
// for (int i = 0; i < ROTARY_ENCODER_SPEED(); i++) {
|
||||
// v = getNextChar(v);
|
||||
// }
|
||||
// break;
|
||||
|
||||
case EVT_ROTARY_LEFT:
|
||||
for (int i = 0; i < ROTARY_ENCODER_SPEED(); i++) {
|
||||
v = getPreviousChar(v);
|
||||
}
|
||||
break;
|
||||
// case EVT_ROTARY_LEFT:
|
||||
// for (int i = 0; i < ROTARY_ENCODER_SPEED(); i++) {
|
||||
// v = getPreviousChar(v);
|
||||
// }
|
||||
// break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_LEFT):
|
||||
if (cursorPos > 0) {
|
||||
setCursorPos(cursorPos - 1);
|
||||
}
|
||||
break;
|
||||
// case EVT_KEY_BREAK(KEY_LEFT):
|
||||
// if (cursorPos > 0) {
|
||||
// setCursorPos(cursorPos - 1);
|
||||
// }
|
||||
// break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_RIGHT):
|
||||
if (cursorPos < length - 1 && value[cursorPos + 1] != '\0') {
|
||||
setCursorPos(cursorPos + 1);
|
||||
}
|
||||
break;
|
||||
// case EVT_KEY_BREAK(KEY_RIGHT):
|
||||
// if (cursorPos < length - 1 && value[cursorPos + 1] != '\0') {
|
||||
// setCursorPos(cursorPos + 1);
|
||||
// }
|
||||
// break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
if (cursorPos < length - 1) {
|
||||
if (value[cursorPos] == '\0') {
|
||||
value[cursorPos] = ' ';
|
||||
changed = true;
|
||||
}
|
||||
cursorPos++;
|
||||
if (value[cursorPos] == '\0') {
|
||||
value[cursorPos] = ' ';
|
||||
changed = true;
|
||||
}
|
||||
lv_textarea_set_text(lvobj, value);
|
||||
setCursorPos(cursorPos);
|
||||
}
|
||||
else {
|
||||
changeEnd();
|
||||
FormField::onEvent(event);
|
||||
}
|
||||
break;
|
||||
// case EVT_KEY_BREAK(KEY_ENTER):
|
||||
// if (cursorPos < length - 1) {
|
||||
// if (value[cursorPos] == '\0') {
|
||||
// value[cursorPos] = ' ';
|
||||
// changed = true;
|
||||
// }
|
||||
// cursorPos++;
|
||||
// if (value[cursorPos] == '\0') {
|
||||
// value[cursorPos] = ' ';
|
||||
// changed = true;
|
||||
// }
|
||||
// update();
|
||||
// setCursorPos(cursorPos);
|
||||
// }
|
||||
// else {
|
||||
// changeEnd();
|
||||
// FormField::onEvent(event);
|
||||
// }
|
||||
// break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
{
|
||||
killEvents(event);
|
||||
auto menu = new Menu(this);
|
||||
menu->setTitle(STR_EDIT);
|
||||
#if defined(CLIPBOARD)
|
||||
menu->addLine(STR_COPY, [=] {
|
||||
clipboard.write((uint8_t *)value, length, Clipboard::CONTENT_TEXT);
|
||||
});
|
||||
if (clipboard.contentType == Clipboard::CONTENT_TEXT) {
|
||||
menu->addLine(STR_PASTE, [=] {
|
||||
clipboard.read((uint8_t *)value, length);
|
||||
changeEnd(true);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
menu->addLine(STR_CLEAR, [=] {
|
||||
memset(value, 0, length);
|
||||
changeEnd(true);
|
||||
});
|
||||
break;
|
||||
}
|
||||
// case EVT_KEY_LONG(KEY_ENTER):
|
||||
// {
|
||||
// killEvents(event);
|
||||
// auto menu = new Menu(this);
|
||||
// menu->setTitle(STR_EDIT);
|
||||
// #if defined(CLIPBOARD)
|
||||
// menu->addLine(STR_COPY, [=] {
|
||||
// clipboard.write((uint8_t *)value, length, Clipboard::CONTENT_TEXT);
|
||||
// });
|
||||
// if (clipboard.contentType == Clipboard::CONTENT_TEXT) {
|
||||
// menu->addLine(STR_PASTE, [=] {
|
||||
// clipboard.read((uint8_t *)value, length);
|
||||
// changeEnd(true);
|
||||
// });
|
||||
// }
|
||||
// #endif
|
||||
// menu->addLine(STR_CLEAR, [=] {
|
||||
// memset(value, 0, length);
|
||||
// changeEnd(true);
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
|
||||
case EVT_KEY_BREAK(KEY_UP):
|
||||
v = toggleCase(v);
|
||||
break;
|
||||
// case EVT_KEY_BREAK(KEY_UP):
|
||||
// v = toggleCase(v);
|
||||
// break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_LEFT):
|
||||
case EVT_KEY_LONG(KEY_RIGHT):
|
||||
v = toggleCase(v);
|
||||
if (event == EVT_KEY_LONG(KEY_LEFT)) {
|
||||
killEvents(KEY_LEFT);
|
||||
}
|
||||
break;
|
||||
// case EVT_KEY_LONG(KEY_LEFT):
|
||||
// case EVT_KEY_LONG(KEY_RIGHT):
|
||||
// v = toggleCase(v);
|
||||
// if (event == EVT_KEY_LONG(KEY_LEFT)) {
|
||||
// killEvents(KEY_LEFT);
|
||||
// }
|
||||
// break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_PGDN):
|
||||
if (cursorPos < length) {
|
||||
memmove(&value[cursorPos], &value[cursorPos + 1], length - cursorPos - 1);
|
||||
value[length - 1] = '\0';
|
||||
changed = true;
|
||||
if (cursorPos > 0 && value[cursorPos] == '\0') {
|
||||
cursorPos = cursorPos - 1;
|
||||
}
|
||||
lv_textarea_set_text(lvobj, value);
|
||||
setCursorPos(cursorPos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// case EVT_KEY_BREAK(KEY_PGDN):
|
||||
// if (cursorPos < length) {
|
||||
// memmove(&value[cursorPos], &value[cursorPos + 1], length - cursorPos - 1);
|
||||
// value[length - 1] = '\0';
|
||||
// changed = true;
|
||||
// if (cursorPos > 0 && value[cursorPos] == '\0') {
|
||||
// cursorPos = cursorPos - 1;
|
||||
// }
|
||||
// update();
|
||||
// setCursorPos(cursorPos);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
|
||||
if (c != v) {
|
||||
// TRACE("value[%d] = %d", cursorPos, v);
|
||||
value[cursorPos] = v;
|
||||
lv_textarea_set_text(lvobj, value);
|
||||
setCursorPos(cursorPos);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
FormField::onEvent(event);
|
||||
setCursorPos(0);
|
||||
}
|
||||
#endif
|
||||
// if (c != v) {
|
||||
// // TRACE("value[%d] = %d", cursorPos, v);
|
||||
// value[cursorPos] = v;
|
||||
// update();
|
||||
// setCursorPos(cursorPos);
|
||||
// changed = true;
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// FormField::onEvent(event);
|
||||
// setCursorPos(0);
|
||||
// }
|
||||
// #endif
|
||||
}
|
||||
|
||||
void TextEdit::onClicked()
|
||||
|
||||
+4
-5
@@ -27,7 +27,8 @@ class TextEdit : public FormField {
|
||||
friend class TextKeyboard;
|
||||
|
||||
public:
|
||||
TextEdit(Window * parent, const rect_t & rect, char * value, uint8_t length, LcdFlags windowFlags = 0, const char * _extra_chars = nullptr);
|
||||
TextEdit(Window* parent, const rect_t& rect, char* value, uint8_t length,
|
||||
LcdFlags windowFlags = 0, const char* _extra_chars = nullptr);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override
|
||||
@@ -46,13 +47,11 @@ class TextEdit : public FormField {
|
||||
return value;
|
||||
}
|
||||
|
||||
void update();
|
||||
|
||||
void onEvent(event_t event) override;
|
||||
void onClicked() override;
|
||||
|
||||
// #if defined(HARDWARE_TOUCH)
|
||||
// bool onTouchEnd(coord_t x, coord_t y) override;
|
||||
// #endif
|
||||
|
||||
void onFocusLost() override;
|
||||
|
||||
virtual void paint(BitmapBuffer* dc) override {};
|
||||
|
||||
Reference in New Issue
Block a user