TextEdit focus issues
This commit is contained in:
+9
-9
@@ -45,11 +45,11 @@ void BitmapBuffer::drawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t p
|
|||||||
{
|
{
|
||||||
APPLY_OFFSET();
|
APPLY_OFFSET();
|
||||||
|
|
||||||
if (y >= height || y >= ymax || y < ymin)
|
if (y >= _height || y >= ymax || y < ymin)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (x+w > width) {
|
if (x + w > _width) {
|
||||||
w = width - x;
|
w = _width - x;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_t * p = getPixelPtr(x, y);
|
pixel_t * p = getPixelPtr(x, y);
|
||||||
@@ -89,7 +89,7 @@ void BitmapBuffer::drawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (y < ymin) {
|
if (y < ymin) {
|
||||||
h += y-ymin;
|
h += y - ymin;
|
||||||
y = ymin;
|
y = ymin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ void BitmapBuffer::drawSolidFilledRect(coord_t x, coord_t y, coord_t w, coord_t
|
|||||||
if (!data || h<=0 || w<=0)
|
if (!data || h<=0 || w<=0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DMAFillRect(data, width, height, x, y, w, h, lcdColorTable[COLOR_IDX(flags)]);
|
DMAFillRect(data, _width, _height, x, y, w, h, lcdColorTable[COLOR_IDX(flags)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitmapBuffer::drawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat, LcdFlags att)
|
void BitmapBuffer::drawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat, LcdFlags att)
|
||||||
@@ -315,8 +315,8 @@ void BitmapBuffer::drawMask(coord_t x, coord_t y, const BitmapBuffer * mask, Lcd
|
|||||||
|
|
||||||
APPLY_OFFSET();
|
APPLY_OFFSET();
|
||||||
|
|
||||||
coord_t w = mask->getWidth();
|
coord_t w = mask->width();
|
||||||
coord_t height = mask->getHeight();
|
coord_t height = mask->height();
|
||||||
|
|
||||||
if (!width || width > w) {
|
if (!width || width > w) {
|
||||||
width = w;
|
width = w;
|
||||||
@@ -602,7 +602,7 @@ BitmapBuffer * BitmapBuffer::loadMask(const char * filename)
|
|||||||
BitmapBuffer * bitmap = BitmapBuffer::loadBitmap(filename);
|
BitmapBuffer * bitmap = BitmapBuffer::loadBitmap(filename);
|
||||||
if (bitmap) {
|
if (bitmap) {
|
||||||
pixel_t * p = bitmap->getPixelPtr(0, 0);
|
pixel_t * p = bitmap->getPixelPtr(0, 0);
|
||||||
for (int i = bitmap->getWidth() * bitmap->getHeight(); i > 0; i--) {
|
for (int i = bitmap->width() * bitmap->height(); i > 0; i--) {
|
||||||
*((uint8_t *)p) = OPACITY_MAX - ((*p) >> 12);
|
*((uint8_t *)p) = OPACITY_MAX - ((*p) >> 12);
|
||||||
MOVE_TO_NEXT_RIGHT_PIXEL(p);
|
MOVE_TO_NEXT_RIGHT_PIXEL(p);
|
||||||
}
|
}
|
||||||
@@ -615,7 +615,7 @@ BitmapBuffer * BitmapBuffer::loadMaskOnBackground(const char * filename, LcdFlag
|
|||||||
BitmapBuffer * result = nullptr;
|
BitmapBuffer * result = nullptr;
|
||||||
BitmapBuffer * mask = BitmapBuffer::loadMask(filename);
|
BitmapBuffer * mask = BitmapBuffer::loadMask(filename);
|
||||||
if (mask) {
|
if (mask) {
|
||||||
result = new BitmapBuffer(BMP_RGB565, mask->getWidth(), mask->getHeight());
|
result = new BitmapBuffer(BMP_RGB565, mask->width(), mask->height());
|
||||||
if (result) {
|
if (result) {
|
||||||
result->clear(background);
|
result->clear(background);
|
||||||
result->drawMask(0, 0, mask, foreground);
|
result->drawMask(0, 0, mask, foreground);
|
||||||
|
|||||||
+35
-35
@@ -58,8 +58,8 @@ class BitmapBufferBase
|
|||||||
public:
|
public:
|
||||||
BitmapBufferBase(uint8_t format, uint16_t width, uint16_t height, T * data):
|
BitmapBufferBase(uint8_t format, uint16_t width, uint16_t height, T * data):
|
||||||
format(format),
|
format(format),
|
||||||
width(width),
|
_width(width),
|
||||||
height(height),
|
_height(height),
|
||||||
xmax(width),
|
xmax(width),
|
||||||
ymax(height),
|
ymax(height),
|
||||||
data(data),
|
data(data),
|
||||||
@@ -69,21 +69,21 @@ class BitmapBufferBase
|
|||||||
|
|
||||||
BitmapBufferBase(uint8_t format, T * data):
|
BitmapBufferBase(uint8_t format, T * data):
|
||||||
format(format),
|
format(format),
|
||||||
width(*((uint16_t*)data)),
|
_width(*((uint16_t*)data)),
|
||||||
height(*(((uint16_t*)data) + 1)),
|
_height(*(((uint16_t*)data) + 1)),
|
||||||
xmax(width),
|
xmax(_width),
|
||||||
ymax(height),
|
ymax(_height),
|
||||||
data(data + 2),
|
data(data + 2),
|
||||||
data_end(data + 2 + (width * height))
|
data_end(data + 2 + (_width * _height))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void clearClippingRect()
|
inline void clearClippingRect()
|
||||||
{
|
{
|
||||||
xmin = 0;
|
xmin = 0;
|
||||||
xmax = width;
|
xmax = _width;
|
||||||
ymin = 0;
|
ymin = 0;
|
||||||
ymax = height;
|
ymax = _height;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setClippingRect(coord_t xmin, coord_t xmax, coord_t ymin, coord_t ymax)
|
inline void setClippingRect(coord_t xmin, coord_t xmax, coord_t ymin, coord_t ymax)
|
||||||
@@ -123,14 +123,14 @@ class BitmapBufferBase
|
|||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint16_t getWidth() const
|
inline uint16_t width() const
|
||||||
{
|
{
|
||||||
return width;
|
return _width;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint16_t getHeight() const
|
inline uint16_t height() const
|
||||||
{
|
{
|
||||||
return height;
|
return _height;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline T * getData() const
|
inline T * getData() const
|
||||||
@@ -140,7 +140,7 @@ class BitmapBufferBase
|
|||||||
|
|
||||||
uint32_t getDataSize() const
|
uint32_t getDataSize() const
|
||||||
{
|
{
|
||||||
return width * height * sizeof(T);
|
return _width * _height * sizeof(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const pixel_t * getPixelPtr(coord_t x, coord_t y) const
|
inline const pixel_t * getPixelPtr(coord_t x, coord_t y) const
|
||||||
@@ -149,13 +149,13 @@ class BitmapBufferBase
|
|||||||
x = width - x - 1;
|
x = width - x - 1;
|
||||||
y = height - y - 1;
|
y = height - y - 1;
|
||||||
#endif
|
#endif
|
||||||
return &data[y*width + x];
|
return &data[y * _width + x];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t format;
|
uint8_t format;
|
||||||
coord_t width;
|
coord_t _width;
|
||||||
coord_t height;
|
coord_t _height;
|
||||||
coord_t xmin = 0;
|
coord_t xmin = 0;
|
||||||
coord_t xmax;
|
coord_t xmax;
|
||||||
coord_t ymin = 0;
|
coord_t ymin = 0;
|
||||||
@@ -175,9 +175,9 @@ class RLEBitmap:
|
|||||||
RLEBitmap(uint8_t format, const uint8_t* rle_data) :
|
RLEBitmap(uint8_t format, const uint8_t* rle_data) :
|
||||||
BitmapBufferBase<uint16_t>(format, 0, 0, nullptr)
|
BitmapBufferBase<uint16_t>(format, 0, 0, nullptr)
|
||||||
{
|
{
|
||||||
width = *((uint16_t *)rle_data);
|
_width = *((uint16_t *)rle_data);
|
||||||
height = *(((uint16_t *)rle_data)+1);
|
_height = *(((uint16_t *)rle_data)+1);
|
||||||
uint32_t pixels = width * height;
|
uint32_t pixels = _width * _height;
|
||||||
data = (uint16_t*)malloc(pixels * sizeof(uint16_t));
|
data = (uint16_t*)malloc(pixels * sizeof(uint16_t));
|
||||||
decode((uint8_t *)data, pixels * sizeof(uint16_t), rle_data+4);
|
decode((uint8_t *)data, pixels * sizeof(uint16_t), rle_data+4);
|
||||||
data_end = data + pixels;
|
data_end = data + pixels;
|
||||||
@@ -265,7 +265,7 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
|
|||||||
|
|
||||||
inline void clear(LcdFlags flags=0)
|
inline void clear(LcdFlags flags=0)
|
||||||
{
|
{
|
||||||
drawSolidFilledRect(0, 0, width - offsetX, height - offsetY, flags);
|
drawSolidFilledRect(0, 0, _width - offsetX, _height - offsetY, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void drawPixel(pixel_t * p, pixel_t value)
|
inline void drawPixel(pixel_t * p, pixel_t value)
|
||||||
@@ -287,7 +287,7 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
|
|||||||
x = width - x - 1;
|
x = width - x - 1;
|
||||||
y = height - y - 1;
|
y = height - y - 1;
|
||||||
#endif
|
#endif
|
||||||
return &data[y*width + x];
|
return &data[y * _width + x];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline pixel_t * getPixelPtr(coord_t x, coord_t y)
|
inline pixel_t * getPixelPtr(coord_t x, coord_t y)
|
||||||
@@ -296,7 +296,7 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
|
|||||||
x = width - x - 1;
|
x = width - x - 1;
|
||||||
y = height - y - 1;
|
y = height - y - 1;
|
||||||
#endif
|
#endif
|
||||||
return &data[y*width + x];
|
return &data[y * _width + x];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void drawPixel(coord_t x, coord_t y, pixel_t value)
|
inline void drawPixel(coord_t x, coord_t y, pixel_t value)
|
||||||
@@ -387,8 +387,8 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
|
|||||||
if (!data || !bmp)
|
if (!data || !bmp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
coord_t srcw = bmp->getWidth();
|
coord_t srcw = bmp->width();
|
||||||
coord_t srch = bmp->getHeight();
|
coord_t srch = bmp->height();
|
||||||
|
|
||||||
if (w == 0)
|
if (w == 0)
|
||||||
w = srcw;
|
w = srcw;
|
||||||
@@ -432,20 +432,20 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
|
|||||||
h = height - y;
|
h = height - y;
|
||||||
}*/
|
}*/
|
||||||
if (bmp->getFormat() == BMP_ARGB4444) {
|
if (bmp->getFormat() == BMP_ARGB4444) {
|
||||||
DMACopyAlphaBitmap(data, width, height, x, y, bmp->getData(), srcw, srch, srcx, srcy, w, h);
|
DMACopyAlphaBitmap(data, _width, _height, x, y, bmp->getData(), srcw, srch, srcx, srcy, w, h);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DMACopyBitmap(data, width, height, x, y, bmp->getData(), srcw, srch, srcx, srcy, w, h);
|
DMACopyBitmap(data, _width, _height, x, y, bmp->getData(), srcw, srch, srcx, srcy, w, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int scaledw = w * scale;
|
int scaledw = w * scale;
|
||||||
int scaledh = h * scale;
|
int scaledh = h * scale;
|
||||||
|
|
||||||
if (x + scaledw > width)
|
if (x + scaledw > _width)
|
||||||
scaledw = width - x;
|
scaledw = _width - x;
|
||||||
if (y + scaledh > height)
|
if (y + scaledh > _height)
|
||||||
scaledh = height - y;
|
scaledh = _height - y;
|
||||||
|
|
||||||
for (int i = 0; i < scaledh; i++) {
|
for (int i = 0; i < scaledh; i++) {
|
||||||
pixel_t * p = getPixelPtr(x, y + i);
|
pixel_t * p = getPixelPtr(x, y + i);
|
||||||
@@ -469,12 +469,12 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
|
|||||||
template<class T>
|
template<class T>
|
||||||
void drawScaledBitmap(const T * bitmap, coord_t x, coord_t y, coord_t w, coord_t h)
|
void drawScaledBitmap(const T * bitmap, coord_t x, coord_t y, coord_t w, coord_t h)
|
||||||
{
|
{
|
||||||
float vscale = float(h) / bitmap->getHeight();
|
float vscale = float(h) / bitmap->height();
|
||||||
float hscale = float(w) / bitmap->getWidth();
|
float hscale = float(w) / bitmap->width();
|
||||||
float scale = vscale < hscale ? vscale : hscale;
|
float scale = vscale < hscale ? vscale : hscale;
|
||||||
|
|
||||||
int xshift = (w - (bitmap->getWidth() * scale)) / 2;
|
int xshift = (w - (bitmap->width() * scale)) / 2;
|
||||||
int yshift = (h - (bitmap->getHeight() * scale)) / 2;
|
int yshift = (h - (bitmap->height() * scale)) / 2;
|
||||||
drawBitmap(x + xshift, y + yshift, bitmap, 0, 0, 0, 0, scale);
|
drawBitmap(x + xshift, y + yshift, bitmap, 0, 0, 0, 0, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
@@ -60,6 +60,12 @@ class FormField: public Window {
|
|||||||
editMode = newEditMode;
|
editMode = newEditMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onFocusLost() override
|
||||||
|
{
|
||||||
|
editMode = false;
|
||||||
|
Window::onFocusLost();
|
||||||
|
}
|
||||||
|
|
||||||
inline static void link(FormField * previous, FormField * next)
|
inline static void link(FormField * previous, FormField * next)
|
||||||
{
|
{
|
||||||
previous->setNextField(next);
|
previous->setNextField(next);
|
||||||
|
|||||||
@@ -95,6 +95,7 @@
|
|||||||
#define DISABLE_COLOR COLOR(DISABLE_COLOR_INDEX)
|
#define DISABLE_COLOR COLOR(DISABLE_COLOR_INDEX)
|
||||||
#define HIGHLIGHT_COLOR COLOR(HIGHLIGHT_COLOR_INDEX)
|
#define HIGHLIGHT_COLOR COLOR(HIGHLIGHT_COLOR_INDEX)
|
||||||
#define CHECKBOX_COLOR COLOR(CHECKBOX_COLOR_INDEX)
|
#define CHECKBOX_COLOR COLOR(CHECKBOX_COLOR_INDEX)
|
||||||
|
#define SCROLLBAR_COLOR COLOR(SCROLLBAR_COLOR_INDEX)
|
||||||
#define MENU_COLOR COLOR(MENU_COLOR_INDEX)
|
#define MENU_COLOR COLOR(MENU_COLOR_INDEX)
|
||||||
#define MENU_BGCOLOR COLOR(MENU_BGCOLOR_INDEX)
|
#define MENU_BGCOLOR COLOR(MENU_BGCOLOR_INDEX)
|
||||||
#define CUSTOM_COLOR COLOR(CUSTOM_COLOR_INDEX)
|
#define CUSTOM_COLOR COLOR(CUSTOM_COLOR_INDEX)
|
||||||
|
|||||||
+20
-3
@@ -62,6 +62,16 @@ void TextEdit::paint(BitmapBuffer * dc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEdit::trim()
|
||||||
|
{
|
||||||
|
for (int i = length - 1; i >= 0; i--) {
|
||||||
|
if (value[i] == ' ' || value[i] == '\0')
|
||||||
|
value[i] = '\0';
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TextEdit::onEvent(event_t event)
|
void TextEdit::onEvent(event_t event)
|
||||||
{
|
{
|
||||||
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
|
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
|
||||||
@@ -111,7 +121,7 @@ void TextEdit::onEvent(event_t event)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case EVT_KEY_BREAK(KEY_RIGHT):
|
case EVT_KEY_BREAK(KEY_RIGHT):
|
||||||
if (cursorPos < length - 1) {
|
if (cursorPos < length - 1 && value[cursorPos + 1] != '\0') {
|
||||||
cursorPos++;
|
cursorPos++;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
@@ -120,15 +130,19 @@ void TextEdit::onEvent(event_t event)
|
|||||||
case EVT_KEY_BREAK(KEY_ENTER):
|
case EVT_KEY_BREAK(KEY_ENTER):
|
||||||
if (cursorPos < length - 1) {
|
if (cursorPos < length - 1) {
|
||||||
cursorPos++;
|
cursorPos++;
|
||||||
|
if (value[cursorPos] == '\0')
|
||||||
|
value[cursorPos] = ' ';
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
trim();
|
||||||
FormField::onEvent(event);
|
FormField::onEvent(event);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVT_KEY_BREAK(KEY_EXIT):
|
case EVT_KEY_BREAK(KEY_EXIT):
|
||||||
cursorPos = 0;
|
cursorPos = 0;
|
||||||
|
trim();
|
||||||
FormField::onEvent(event);
|
FormField::onEvent(event);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -191,12 +205,15 @@ bool TextEdit::onTouchEnd(coord_t x, coord_t y)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SOFTWARE_KEYBOARD)
|
|
||||||
void TextEdit::onFocusLost()
|
void TextEdit::onFocusLost()
|
||||||
{
|
{
|
||||||
|
#if defined(SOFTWARE_KEYBOARD)
|
||||||
TextKeyboard::hide();
|
TextKeyboard::hide();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
trim();
|
||||||
|
cursorPos = 0;
|
||||||
|
|
||||||
// TODO storageDirty(...);
|
// TODO storageDirty(...);
|
||||||
FormField::onFocusLost();
|
FormField::onFocusLost();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|||||||
+2
-2
@@ -58,15 +58,15 @@ class TextEdit : public FormField {
|
|||||||
bool onTouchEnd(coord_t x, coord_t y) override;
|
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SOFTWARE_KEYBOARD)
|
|
||||||
void onFocusLost() override;
|
void onFocusLost() override;
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
char * value;
|
char * value;
|
||||||
uint8_t length;
|
uint8_t length;
|
||||||
uint8_t cursorPos = 0;
|
uint8_t cursorPos = 0;
|
||||||
|
|
||||||
|
void trim();
|
||||||
|
|
||||||
static uint8_t getNextChar(uint8_t c)
|
static uint8_t getNextChar(uint8_t c)
|
||||||
{
|
{
|
||||||
if (c == ' ' || c == 0)
|
if (c == ' ' || c == 0)
|
||||||
|
|||||||
+1
-1
@@ -418,6 +418,6 @@ void Window::drawVerticalScrollbar(BitmapBuffer * dc)
|
|||||||
yofs = innerHeight - y - yhgt;
|
yofs = innerHeight - y - yhgt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dc->drawSolidFilledRect(x-1, y + yofs, 3, yhgt, CHECKBOX_COLOR);
|
dc->drawSolidFilledRect(x-1, y + yofs, 3, yhgt, SCROLLBAR_COLOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user