TextEdit focus issues

This commit is contained in:
Bertrand Songis
2019-10-28 15:05:58 +01:00
parent 7fc7e89b85
commit 5447a23af1
7 changed files with 74 additions and 50 deletions
+9 -9
View File
@@ -45,11 +45,11 @@ void BitmapBuffer::drawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t p
{
APPLY_OFFSET();
if (y >= height || y >= ymax || y < ymin)
if (y >= _height || y >= ymax || y < ymin)
return;
if (x+w > width) {
w = width - x;
if (x + w > _width) {
w = _width - x;
}
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) {
h += y-ymin;
h += 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)
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)
@@ -315,8 +315,8 @@ void BitmapBuffer::drawMask(coord_t x, coord_t y, const BitmapBuffer * mask, Lcd
APPLY_OFFSET();
coord_t w = mask->getWidth();
coord_t height = mask->getHeight();
coord_t w = mask->width();
coord_t height = mask->height();
if (!width || width > w) {
width = w;
@@ -602,7 +602,7 @@ BitmapBuffer * BitmapBuffer::loadMask(const char * filename)
BitmapBuffer * bitmap = BitmapBuffer::loadBitmap(filename);
if (bitmap) {
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);
MOVE_TO_NEXT_RIGHT_PIXEL(p);
}
@@ -615,7 +615,7 @@ BitmapBuffer * BitmapBuffer::loadMaskOnBackground(const char * filename, LcdFlag
BitmapBuffer * result = nullptr;
BitmapBuffer * mask = BitmapBuffer::loadMask(filename);
if (mask) {
result = new BitmapBuffer(BMP_RGB565, mask->getWidth(), mask->getHeight());
result = new BitmapBuffer(BMP_RGB565, mask->width(), mask->height());
if (result) {
result->clear(background);
result->drawMask(0, 0, mask, foreground);
+35 -35
View File
@@ -58,8 +58,8 @@ class BitmapBufferBase
public:
BitmapBufferBase(uint8_t format, uint16_t width, uint16_t height, T * data):
format(format),
width(width),
height(height),
_width(width),
_height(height),
xmax(width),
ymax(height),
data(data),
@@ -69,21 +69,21 @@ class BitmapBufferBase
BitmapBufferBase(uint8_t format, T * data):
format(format),
width(*((uint16_t*)data)),
height(*(((uint16_t*)data) + 1)),
xmax(width),
ymax(height),
_width(*((uint16_t*)data)),
_height(*(((uint16_t*)data) + 1)),
xmax(_width),
ymax(_height),
data(data + 2),
data_end(data + 2 + (width * height))
data_end(data + 2 + (_width * _height))
{
}
inline void clearClippingRect()
{
xmin = 0;
xmax = width;
xmax = _width;
ymin = 0;
ymax = height;
ymax = _height;
}
inline void setClippingRect(coord_t xmin, coord_t xmax, coord_t ymin, coord_t ymax)
@@ -123,14 +123,14 @@ class BitmapBufferBase
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
@@ -140,7 +140,7 @@ class BitmapBufferBase
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
@@ -149,13 +149,13 @@ class BitmapBufferBase
x = width - x - 1;
y = height - y - 1;
#endif
return &data[y*width + x];
return &data[y * _width + x];
}
protected:
uint8_t format;
coord_t width;
coord_t height;
coord_t _width;
coord_t _height;
coord_t xmin = 0;
coord_t xmax;
coord_t ymin = 0;
@@ -175,9 +175,9 @@ class RLEBitmap:
RLEBitmap(uint8_t format, const uint8_t* rle_data) :
BitmapBufferBase<uint16_t>(format, 0, 0, nullptr)
{
width = *((uint16_t *)rle_data);
height = *(((uint16_t *)rle_data)+1);
uint32_t pixels = width * height;
_width = *((uint16_t *)rle_data);
_height = *(((uint16_t *)rle_data)+1);
uint32_t pixels = _width * _height;
data = (uint16_t*)malloc(pixels * sizeof(uint16_t));
decode((uint8_t *)data, pixels * sizeof(uint16_t), rle_data+4);
data_end = data + pixels;
@@ -265,7 +265,7 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
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)
@@ -287,7 +287,7 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
x = width - x - 1;
y = height - y - 1;
#endif
return &data[y*width + x];
return &data[y * _width + x];
}
inline pixel_t * getPixelPtr(coord_t x, coord_t y)
@@ -296,7 +296,7 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
x = width - x - 1;
y = height - y - 1;
#endif
return &data[y*width + x];
return &data[y * _width + x];
}
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)
return;
coord_t srcw = bmp->getWidth();
coord_t srch = bmp->getHeight();
coord_t srcw = bmp->width();
coord_t srch = bmp->height();
if (w == 0)
w = srcw;
@@ -432,20 +432,20 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
h = height - y;
}*/
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 {
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 {
int scaledw = w * scale;
int scaledh = h * scale;
if (x + scaledw > width)
scaledw = width - x;
if (y + scaledh > height)
scaledh = height - y;
if (x + scaledw > _width)
scaledw = _width - x;
if (y + scaledh > _height)
scaledh = _height - y;
for (int i = 0; i < scaledh; i++) {
pixel_t * p = getPixelPtr(x, y + i);
@@ -469,12 +469,12 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
template<class T>
void drawScaledBitmap(const T * bitmap, coord_t x, coord_t y, coord_t w, coord_t h)
{
float vscale = float(h) / bitmap->getHeight();
float hscale = float(w) / bitmap->getWidth();
float vscale = float(h) / bitmap->height();
float hscale = float(w) / bitmap->width();
float scale = vscale < hscale ? vscale : hscale;
int xshift = (w - (bitmap->getWidth() * scale)) / 2;
int yshift = (h - (bitmap->getHeight() * scale)) / 2;
int xshift = (w - (bitmap->width() * scale)) / 2;
int yshift = (h - (bitmap->height() * scale)) / 2;
drawBitmap(x + xshift, y + yshift, bitmap, 0, 0, 0, 0, scale);
}
+6
View File
@@ -60,6 +60,12 @@ class FormField: public Window {
editMode = newEditMode;
}
void onFocusLost() override
{
editMode = false;
Window::onFocusLost();
}
inline static void link(FormField * previous, FormField * next)
{
previous->setNextField(next);
@@ -95,6 +95,7 @@
#define DISABLE_COLOR COLOR(DISABLE_COLOR_INDEX)
#define HIGHLIGHT_COLOR COLOR(HIGHLIGHT_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_BGCOLOR COLOR(MENU_BGCOLOR_INDEX)
#define CUSTOM_COLOR COLOR(CUSTOM_COLOR_INDEX)
+20 -3
View File
@@ -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)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
@@ -111,7 +121,7 @@ void TextEdit::onEvent(event_t event)
break;
case EVT_KEY_BREAK(KEY_RIGHT):
if (cursorPos < length - 1) {
if (cursorPos < length - 1 && value[cursorPos + 1] != '\0') {
cursorPos++;
invalidate();
}
@@ -120,15 +130,19 @@ void TextEdit::onEvent(event_t event)
case EVT_KEY_BREAK(KEY_ENTER):
if (cursorPos < length - 1) {
cursorPos++;
if (value[cursorPos] == '\0')
value[cursorPos] = ' ';
invalidate();
}
else {
trim();
FormField::onEvent(event);
}
break;
case EVT_KEY_BREAK(KEY_EXIT):
cursorPos = 0;
trim();
FormField::onEvent(event);
break;
@@ -191,12 +205,15 @@ bool TextEdit::onTouchEnd(coord_t x, coord_t y)
}
#endif
#if defined(SOFTWARE_KEYBOARD)
void TextEdit::onFocusLost()
{
#if defined(SOFTWARE_KEYBOARD)
TextKeyboard::hide();
#endif
trim();
cursorPos = 0;
// TODO storageDirty(...);
FormField::onFocusLost();
}
#endif
+2 -2
View File
@@ -58,15 +58,15 @@ class TextEdit : public FormField {
bool onTouchEnd(coord_t x, coord_t y) override;
#endif
#if defined(SOFTWARE_KEYBOARD)
void onFocusLost() override;
#endif
protected:
char * value;
uint8_t length;
uint8_t cursorPos = 0;
void trim();
static uint8_t getNextChar(uint8_t c)
{
if (c == ' ' || c == 0)
+1 -1
View File
@@ -418,6 +418,6 @@ void Window::drawVerticalScrollbar(BitmapBuffer * dc)
yofs = innerHeight - y - yhgt;
}
}
dc->drawSolidFilledRect(x-1, y + yofs, 3, yhgt, CHECKBOX_COLOR);
dc->drawSolidFilledRect(x-1, y + yofs, 3, yhgt, SCROLLBAR_COLOR);
}
}