fix encoder editing in textedit. also fixed cursor and text positioning
This commit is contained in:
committed by
Raphael Coeffic
parent
22619d7a0a
commit
f3f816d75b
+4
-5
@@ -20,7 +20,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "form.h"
|
#include "form.h"
|
||||||
#include "bitmapbuffer.h"
|
#include "strhelpers.h"
|
||||||
|
|
||||||
class BaseNumberEdit: public FormField
|
class BaseNumberEdit: public FormField
|
||||||
{
|
{
|
||||||
@@ -83,7 +83,7 @@ class BaseNumberEdit: public FormField
|
|||||||
auto newValue = limit(vmin, value, vmax);
|
auto newValue = limit(vmin, value, vmax);
|
||||||
if (newValue != currentValue) {
|
if (newValue != currentValue) {
|
||||||
currentValue = newValue;
|
currentValue = newValue;
|
||||||
if (instantChange) {
|
if (instantChange && _setValue != nullptr) {
|
||||||
_setValue(currentValue);
|
_setValue(currentValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,9 +91,8 @@ class BaseNumberEdit: public FormField
|
|||||||
if (displayFunction != nullptr) {
|
if (displayFunction != nullptr) {
|
||||||
lv_textarea_set_text(lvobj, displayFunction(currentValue).c_str());
|
lv_textarea_set_text(lvobj, displayFunction(currentValue).c_str());
|
||||||
} else {
|
} else {
|
||||||
char s[50];
|
auto dispString = formatNumberAsString(currentValue, textFlags, 0, prefix.c_str(), suffix.c_str());
|
||||||
BitmapBuffer::formatNumberAsString(s, 49, currentValue, textFlags, 0, prefix.c_str(), suffix.c_str());
|
lv_textarea_set_text(lvobj, dispString.c_str());
|
||||||
lv_textarea_set_text(lvobj, s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-30
@@ -61,6 +61,7 @@ TextEdit::TextEdit(Window *parent, const rect_t &rect, char *value,
|
|||||||
lv_textarea_set_text(lvobj, value);
|
lv_textarea_set_text(lvobj, value);
|
||||||
lv_textarea_set_placeholder_text(lvobj, "---");
|
lv_textarea_set_placeholder_text(lvobj, "---");
|
||||||
lv_textarea_set_max_length(lvobj, length);
|
lv_textarea_set_max_length(lvobj, length);
|
||||||
|
lv_textarea_set_cursor_pos(lvobj, 0);
|
||||||
|
|
||||||
// LV_PART_MAIN
|
// LV_PART_MAIN
|
||||||
lv_style_init(&style_main);
|
lv_style_init(&style_main);
|
||||||
@@ -68,9 +69,10 @@ TextEdit::TextEdit(Window *parent, const rect_t &rect, char *value,
|
|||||||
lv_style_set_border_color(&style_main, makeLvColor(COLOR_THEME_SECONDARY2));
|
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_color(&style_main, makeLvColor(COLOR_THEME_PRIMARY2));
|
||||||
lv_style_set_bg_opa(&style_main, LV_OPA_COVER);
|
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_roboto_13);
|
lv_style_set_text_font(&style_main, &lv_font_roboto_13);
|
||||||
lv_style_set_text_color(&style_main, makeLvColor(COLOR_THEME_SECONDARY1));
|
lv_style_set_text_color(&style_main, makeLvColor(COLOR_THEME_SECONDARY1));
|
||||||
|
lv_style_set_pad_left(&style_main, FIELD_PADDING_LEFT);
|
||||||
|
lv_style_set_pad_top(&style_main, FIELD_PADDING_TOP);
|
||||||
lv_obj_add_style(lvobj, &style_main, LV_PART_MAIN);
|
lv_obj_add_style(lvobj, &style_main, LV_PART_MAIN);
|
||||||
|
|
||||||
// LV_STATE_FOCUSED
|
// LV_STATE_FOCUSED
|
||||||
@@ -86,18 +88,16 @@ TextEdit::TextEdit(Window *parent, const rect_t &rect, char *value,
|
|||||||
// Show Cursor in "Edit" mode
|
// Show Cursor in "Edit" mode
|
||||||
lv_style_init(&style_edit);
|
lv_style_init(&style_edit);
|
||||||
lv_style_set_opa(&style_edit, LV_OPA_COVER);
|
lv_style_set_opa(&style_edit, LV_OPA_COVER);
|
||||||
lv_style_set_bg_opa(&style_edit, LV_OPA_COVER);
|
lv_style_set_bg_opa(&style_edit, LV_OPA_50);
|
||||||
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);
|
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 TextEdit::setCursorPos(int cursorPos)
|
||||||
|
{
|
||||||
|
lv_textarea_set_cursor_pos(lvobj, cursorPos);
|
||||||
|
}
|
||||||
|
|
||||||
void TextEdit::trim()
|
void TextEdit::trim()
|
||||||
{
|
{
|
||||||
for (int i = length - 1; i >= 0; i--) {
|
for (int i = length - 1; i >= 0; i--) {
|
||||||
@@ -141,15 +141,13 @@ void TextEdit::onEvent(event_t event)
|
|||||||
|
|
||||||
case EVT_KEY_BREAK(KEY_LEFT):
|
case EVT_KEY_BREAK(KEY_LEFT):
|
||||||
if (cursorPos > 0) {
|
if (cursorPos > 0) {
|
||||||
cursorPos--;
|
setCursorPos(cursorPos - 1);
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVT_KEY_BREAK(KEY_RIGHT):
|
case EVT_KEY_BREAK(KEY_RIGHT):
|
||||||
if (cursorPos < length - 1 && value[cursorPos + 1] != '\0') {
|
if (cursorPos < length - 1 && value[cursorPos + 1] != '\0') {
|
||||||
cursorPos++;
|
setCursorPos(cursorPos + 1);
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -164,7 +162,8 @@ void TextEdit::onEvent(event_t event)
|
|||||||
value[cursorPos] = ' ';
|
value[cursorPos] = ' ';
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
invalidate();
|
lv_textarea_set_text(lvobj, value);
|
||||||
|
setCursorPos(cursorPos);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
changeEnd();
|
changeEnd();
|
||||||
@@ -225,7 +224,8 @@ void TextEdit::onEvent(event_t event)
|
|||||||
if (cursorPos > 0 && value[cursorPos] == '\0') {
|
if (cursorPos > 0 && value[cursorPos] == '\0') {
|
||||||
cursorPos = cursorPos - 1;
|
cursorPos = cursorPos - 1;
|
||||||
}
|
}
|
||||||
invalidate();
|
lv_textarea_set_text(lvobj, value);
|
||||||
|
setCursorPos(cursorPos);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -233,12 +233,13 @@ void TextEdit::onEvent(event_t event)
|
|||||||
if (c != v) {
|
if (c != v) {
|
||||||
// TRACE("value[%d] = %d", cursorPos, v);
|
// TRACE("value[%d] = %d", cursorPos, v);
|
||||||
value[cursorPos] = v;
|
value[cursorPos] = v;
|
||||||
invalidate();
|
lv_textarea_set_text(lvobj, value);
|
||||||
|
setCursorPos(cursorPos);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cursorPos = 0;
|
setCursorPos(0);
|
||||||
FormField::onEvent(event);
|
FormField::onEvent(event);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -255,23 +256,12 @@ bool TextEdit::onTouchEnd(coord_t x, coord_t y)
|
|||||||
setFocus(SET_FOCUS_DEFAULT);
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cursorPos = lv_textarea_get_cursor_pos(lvobj);
|
||||||
|
|
||||||
#if defined(SOFTWARE_KEYBOARD)
|
#if defined(SOFTWARE_KEYBOARD)
|
||||||
TextKeyboard::show(this);
|
TextKeyboard::show(this);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// coord_t rest = x;
|
|
||||||
// for (cursorPos = 0; cursorPos < length; cursorPos++) {
|
|
||||||
// char c = value[cursorPos];
|
|
||||||
// if (c == '\0')
|
|
||||||
// break;
|
|
||||||
// uint8_t w = getCharWidth(c, fontspecsTable[0]) + 1;
|
|
||||||
// if (rest < w)
|
|
||||||
// break;
|
|
||||||
// rest -= w;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// invalidate();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+3
-1
@@ -56,6 +56,8 @@ class TextEdit : public FormField {
|
|||||||
|
|
||||||
virtual void paint(BitmapBuffer* dc) override {};
|
virtual void paint(BitmapBuffer* dc) override {};
|
||||||
|
|
||||||
|
void setCursorPos(int cursorPos);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
char * value;
|
char * value;
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
@@ -70,7 +72,7 @@ class TextEdit : public FormField {
|
|||||||
if (lvobj != nullptr)
|
if (lvobj != nullptr)
|
||||||
strncpy(value, lv_textarea_get_text(lvobj), length);
|
strncpy(value, lv_textarea_get_text(lvobj), length);
|
||||||
|
|
||||||
cursorPos = 0;
|
setCursorPos(0);
|
||||||
if (changed || forceChanged) {
|
if (changed || forceChanged) {
|
||||||
changed = false;
|
changed = false;
|
||||||
trim();
|
trim();
|
||||||
|
|||||||
+4
-1
@@ -76,7 +76,10 @@ static void window_event_cb(lv_event_t * e)
|
|||||||
TRACE_WINDOWS("PRESSED: %s", window->getWindowDebugString().c_str());
|
TRACE_WINDOWS("PRESSED: %s", window->getWindowDebugString().c_str());
|
||||||
|
|
||||||
lv_indev_t *click_source = (lv_indev_t *)lv_event_get_param(e);
|
lv_indev_t *click_source = (lv_indev_t *)lv_event_get_param(e);
|
||||||
if (click_source == NULL || is_scrolling) return;
|
if (click_source == NULL || is_scrolling) {
|
||||||
|
TRACE_WINDOWS("CLICK WHILE SCROLLING");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Exclude keyboard ?
|
// Exclude keyboard ?
|
||||||
// if(lv_indev_get_type(click_source) == LV_INDEV_TYPE_KEYPAD ||
|
// if(lv_indev_get_type(click_source) == LV_INDEV_TYPE_KEYPAD ||
|
||||||
|
|||||||
Reference in New Issue
Block a user