Focus issue on disabled form fields
This commit is contained in:
+3
-3
@@ -48,9 +48,9 @@ void Button::onEvent(event_t event)
|
|||||||
#if defined(HARDWARE_TOUCH)
|
#if defined(HARDWARE_TOUCH)
|
||||||
bool Button::onTouchEnd(coord_t x, coord_t y)
|
bool Button::onTouchEnd(coord_t x, coord_t y)
|
||||||
{
|
{
|
||||||
if (enabled()) {
|
if (enabled) {
|
||||||
if (!(windowFlags & NO_FOCUS)) {
|
if (!(windowFlags & NO_FOCUS)) {
|
||||||
setFocus();
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
}
|
}
|
||||||
onPress();
|
onPress();
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ void TextButton::paint(BitmapBuffer * dc)
|
|||||||
{
|
{
|
||||||
FormField::paint(dc);
|
FormField::paint(dc);
|
||||||
|
|
||||||
LcdFlags textColor = DEFAULT_COLOR;
|
auto textColor = DEFAULT_COLOR;
|
||||||
|
|
||||||
if (checked()) {
|
if (checked()) {
|
||||||
if (hasFocus()) {
|
if (hasFocus()) {
|
||||||
|
|||||||
+6
-25
@@ -22,10 +22,9 @@
|
|||||||
|
|
||||||
#include "form.h"
|
#include "form.h"
|
||||||
|
|
||||||
constexpr WindowFlags BUTTON_BACKGROUND = FORM_FLAGS_LAST << 1;
|
constexpr WindowFlags BUTTON_BACKGROUND = FORM_FLAGS_LAST << 1u;
|
||||||
constexpr WindowFlags BUTTON_CHECKED = FORM_FLAGS_LAST << 2;
|
constexpr WindowFlags BUTTON_CHECKED = FORM_FLAGS_LAST << 2u;
|
||||||
constexpr WindowFlags BUTTON_CHECKED_ON_FOCUS = FORM_FLAGS_LAST << 3;
|
constexpr WindowFlags BUTTON_CHECKED_ON_FOCUS = FORM_FLAGS_LAST << 3u;
|
||||||
constexpr WindowFlags BUTTON_DISABLED = FORM_FLAGS_LAST << 4;
|
|
||||||
|
|
||||||
class Button: public FormField {
|
class Button: public FormField {
|
||||||
public:
|
public:
|
||||||
@@ -42,19 +41,6 @@ class Button: public FormField {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void enable(bool enabled = true)
|
|
||||||
{
|
|
||||||
if (!enabled != bool(windowFlags & BUTTON_DISABLED)) {
|
|
||||||
windowFlags ^= BUTTON_DISABLED;
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void disable()
|
|
||||||
{
|
|
||||||
enable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void check(bool checked = true)
|
void check(bool checked = true)
|
||||||
{
|
{
|
||||||
if (checked != bool(windowFlags & BUTTON_CHECKED)) {
|
if (checked != bool(windowFlags & BUTTON_CHECKED)) {
|
||||||
@@ -63,12 +49,7 @@ class Button: public FormField {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool enabled()
|
bool checked() const
|
||||||
{
|
|
||||||
return !(windowFlags & BUTTON_DISABLED);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool checked()
|
|
||||||
{
|
{
|
||||||
if (windowFlags & BUTTON_CHECKED_ON_FOCUS)
|
if (windowFlags & BUTTON_CHECKED_ON_FOCUS)
|
||||||
return hasFocus();
|
return hasFocus();
|
||||||
@@ -106,7 +87,7 @@ class Button: public FormField {
|
|||||||
class TextButton: public Button {
|
class TextButton: public Button {
|
||||||
public:
|
public:
|
||||||
TextButton(FormGroup * parent, const rect_t & rect, std::string text, std::function<uint8_t(void)> pressHandler = nullptr, WindowFlags windowFlags = BUTTON_BACKGROUND):
|
TextButton(FormGroup * parent, const rect_t & rect, std::string text, std::function<uint8_t(void)> pressHandler = nullptr, WindowFlags windowFlags = BUTTON_BACKGROUND):
|
||||||
Button(parent, rect, pressHandler, windowFlags | OPAQUE),
|
Button(parent, rect, std::move(pressHandler), windowFlags | OPAQUE),
|
||||||
text(std::move(text))
|
text(std::move(text))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -135,7 +116,7 @@ class TextButton: public Button {
|
|||||||
class IconButton: public Button {
|
class IconButton: public Button {
|
||||||
public:
|
public:
|
||||||
IconButton(FormGroup * parent, const rect_t & rect, uint8_t icon, std::function<uint8_t(void)> pressHandler, WindowFlags flags = 0):
|
IconButton(FormGroup * parent, const rect_t & rect, uint8_t icon, std::function<uint8_t(void)> pressHandler, WindowFlags flags = 0):
|
||||||
Button(parent, rect, pressHandler, flags),
|
Button(parent, rect, std::move(pressHandler), flags),
|
||||||
icon(icon)
|
icon(icon)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ bool CheckBox::onTouchEnd(coord_t x, coord_t y)
|
|||||||
{
|
{
|
||||||
onKeyPress();
|
onKeyPress();
|
||||||
_setValue(!getValue());
|
_setValue(!getValue());
|
||||||
setFocus();
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
invalidate();
|
invalidate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -150,7 +150,7 @@ void Choice::openMenu()
|
|||||||
|
|
||||||
menu->setCloseHandler([=]() {
|
menu->setCloseHandler([=]() {
|
||||||
editMode = false;
|
editMode = false;
|
||||||
setFocus();
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
});
|
});
|
||||||
|
|
||||||
setEditMode(true);
|
setEditMode(true);
|
||||||
|
|||||||
+2
-2
@@ -25,7 +25,7 @@ DialogWindowContent::DialogWindowContent(Dialog * parent, const rect_t & rect):
|
|||||||
ModalWindowContent(parent, rect),
|
ModalWindowContent(parent, rect),
|
||||||
form(this, {0, POPUP_HEADER_HEIGHT, rect.w, coord_t(rect.h - POPUP_HEADER_HEIGHT)}, FORM_NO_BORDER)
|
form(this, {0, POPUP_HEADER_HEIGHT, rect.w, coord_t(rect.h - POPUP_HEADER_HEIGHT)}, FORM_NO_BORDER)
|
||||||
{
|
{
|
||||||
form.setFocus();
|
form.setFocus(SET_FOCUS_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -34,5 +34,5 @@ Dialog::Dialog(Window * parent, std::string title, const rect_t & rect):
|
|||||||
content(createDialogWindow(this, rect))
|
content(createDialogWindow(this, rect))
|
||||||
{
|
{
|
||||||
bringToTop();
|
bringToTop();
|
||||||
content->setTitle(title);
|
content->setTitle(std::move(title));
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ void ExpansionPanelHeader::onEvent(event_t event)
|
|||||||
bool ExpansionPanelHeader::onTouchEnd(coord_t, coord_t)
|
bool ExpansionPanelHeader::onTouchEnd(coord_t, coord_t)
|
||||||
{
|
{
|
||||||
static_cast<ExpansionPanel *>(parent)->toggle();
|
static_cast<ExpansionPanel *>(parent)->toggle();
|
||||||
setFocus();
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+4
-4
@@ -75,7 +75,7 @@ bool FileChoice::openMenu()
|
|||||||
files.emplace_back(fno.fname, fnLen);
|
files.emplace_back(fno.fname, fnLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (files.size() > 0) {
|
if (!files.empty()) {
|
||||||
// sort files
|
// sort files
|
||||||
files.sort(compare_nocase);
|
files.sort(compare_nocase);
|
||||||
|
|
||||||
@@ -102,8 +102,8 @@ bool FileChoice::openMenu()
|
|||||||
}
|
}
|
||||||
|
|
||||||
menu->setCloseHandler([=]() {
|
menu->setCloseHandler([=]() {
|
||||||
editMode = false;
|
editMode = false;
|
||||||
setFocus();
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -136,7 +136,7 @@ void FileChoice::onEvent(event_t event)
|
|||||||
bool FileChoice::onTouchEnd(coord_t, coord_t)
|
bool FileChoice::onTouchEnd(coord_t, coord_t)
|
||||||
{
|
{
|
||||||
openMenu();
|
openMenu();
|
||||||
setFocus();
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
setEditMode(true);
|
setEditMode(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-7
@@ -25,7 +25,7 @@ FormField::FormField(Window * parent, const rect_t & rect, WindowFlags windowFla
|
|||||||
Window(parent, rect, windowFlags, textFlags)
|
Window(parent, rect, windowFlags, textFlags)
|
||||||
{
|
{
|
||||||
if (!(windowFlags & NO_FOCUS)) {
|
if (!(windowFlags & NO_FOCUS)) {
|
||||||
FormGroup * form = dynamic_cast<FormGroup *>(parent);
|
auto * form = dynamic_cast<FormGroup *>(parent);
|
||||||
if (form) {
|
if (form) {
|
||||||
form->addField(this, windowFlags & PUSH_FRONT);
|
form->addField(this, windowFlags & PUSH_FRONT);
|
||||||
}
|
}
|
||||||
@@ -61,6 +61,23 @@ void FormField::onEvent(event_t event)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void FormField::setFocus(uint8_t flag)
|
||||||
|
{
|
||||||
|
if (!enabled) {
|
||||||
|
if (flag == SET_FOCUS_BACKWARD) {
|
||||||
|
if (previous)
|
||||||
|
previous->setFocus(flag);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (next)
|
||||||
|
next->setFocus(flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Window::setFocus(flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FormField::paint(BitmapBuffer * dc)
|
void FormField::paint(BitmapBuffer * dc)
|
||||||
{
|
{
|
||||||
if (editMode) {
|
if (editMode) {
|
||||||
@@ -101,7 +118,7 @@ void FormGroup::addField(FormField * field, bool front)
|
|||||||
link(last, first);
|
link(last, first);
|
||||||
}
|
}
|
||||||
if (!focusWindow && !(field->getWindowFlags() & FORM_FORWARD_FOCUS)) {
|
if (!focusWindow && !(field->getWindowFlags() & FORM_FORWARD_FOCUS)) {
|
||||||
field->setFocus();
|
field->setFocus(SET_FOCUS_DEFAULT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,21 +148,23 @@ void FormGroup::setFocus(uint8_t flag)
|
|||||||
|
|
||||||
case SET_FOCUS_FORWARD:
|
case SET_FOCUS_FORWARD:
|
||||||
if (focusWindow->isChild(last)) {
|
if (focusWindow->isChild(last)) {
|
||||||
if (next == this)
|
if (next == this) {
|
||||||
first->setFocus(SET_FOCUS_FORWARD);
|
first->setFocus(SET_FOCUS_FORWARD);
|
||||||
|
}
|
||||||
else if (next)
|
else if (next)
|
||||||
next->setFocus(SET_FOCUS_FORWARD);
|
next->setFocus(SET_FOCUS_FORWARD);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (first)
|
if (first) {
|
||||||
first->setFocus(SET_FOCUS_FORWARD);
|
first->setFocus(SET_FOCUS_FORWARD);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (focusWindow == previous) {
|
if (focusWindow == previous) {
|
||||||
if (first)
|
if (first)
|
||||||
first->setFocus();
|
first->setFocus(SET_FOCUS_DEFAULT);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (next)
|
if (next)
|
||||||
@@ -155,7 +174,7 @@ void FormGroup::setFocus(uint8_t flag)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
FormField::setFocus();
|
FormField::setFocus(SET_FOCUS_DEFAULT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,6 +228,6 @@ void FormWindow::onEvent(event_t event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::onEvent(event);
|
FormGroup::onEvent(event);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+20
-1
@@ -62,6 +62,24 @@ class FormField: public Window {
|
|||||||
editMode = newEditMode;
|
editMode = newEditMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enable(bool enabled)
|
||||||
|
{
|
||||||
|
this->enabled = enabled;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isEnabled() const
|
||||||
|
{
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void disable()
|
||||||
|
{
|
||||||
|
enable(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFocus(uint8_t flag) override;
|
||||||
|
|
||||||
void onFocusLost() override
|
void onFocusLost() override
|
||||||
{
|
{
|
||||||
editMode = false;
|
editMode = false;
|
||||||
@@ -84,6 +102,7 @@ class FormField: public Window {
|
|||||||
FormField * next = nullptr;
|
FormField * next = nullptr;
|
||||||
FormField * previous = nullptr;
|
FormField * previous = nullptr;
|
||||||
bool editMode = false;
|
bool editMode = false;
|
||||||
|
bool enabled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FormGroup: public FormField {
|
class FormGroup: public FormField {
|
||||||
@@ -107,7 +126,7 @@ class FormGroup: public FormField {
|
|||||||
last = nullptr;
|
last = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFocus(uint8_t flag = SET_FOCUS_DEFAULT) override;
|
void setFocus(uint8_t flag) override;
|
||||||
|
|
||||||
void addField(FormField * field, bool front = false);
|
void addField(FormField * field, bool front = false);
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -36,10 +36,10 @@ void MenuBody::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);
|
||||||
|
|
||||||
if (event == EVT_ROTARY_RIGHT) {
|
if (event == EVT_ROTARY_RIGHT) {
|
||||||
select((selectedIndex + 1) % lines.size());
|
select(int((selectedIndex + 1) % lines.size()));
|
||||||
}
|
}
|
||||||
else if (event == EVT_ROTARY_LEFT) {
|
else if (event == EVT_ROTARY_LEFT) {
|
||||||
select(selectedIndex == 0 ? lines.size() - 1 : selectedIndex - 1);
|
select(int(selectedIndex == 0 ? lines.size() - 1 : selectedIndex - 1));
|
||||||
}
|
}
|
||||||
else if (event == EVT_KEY_BREAK(KEY_ENTER)) {
|
else if (event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||||
if (selectedIndex < 0) {
|
if (selectedIndex < 0) {
|
||||||
@@ -99,7 +99,7 @@ MenuWindowContent::MenuWindowContent(Menu * parent):
|
|||||||
ModalWindowContent(parent, {(LCD_W - MENUS_WIDTH) / 2, (LCD_H - MENUS_WIDTH) / 2, MENUS_WIDTH, 0}),
|
ModalWindowContent(parent, {(LCD_W - MENUS_WIDTH) / 2, (LCD_H - MENUS_WIDTH) / 2, MENUS_WIDTH, 0}),
|
||||||
body(this, {0, 0, width(), height()})
|
body(this, {0, 0, width(), height()})
|
||||||
{
|
{
|
||||||
body.setFocus();
|
body.setFocus(SET_FOCUS_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuWindowContent::paint(BitmapBuffer * dc)
|
void MenuWindowContent::paint(BitmapBuffer * dc)
|
||||||
@@ -148,7 +148,7 @@ void Menu::addLine(const std::string & text, std::function<void()> onPress)
|
|||||||
|
|
||||||
void Menu::addCustomLine(std::function<void(BitmapBuffer * dc, coord_t x, coord_t y, LcdFlags flags)> drawLine, std::function<void()> onPress)
|
void Menu::addCustomLine(std::function<void(BitmapBuffer * dc, coord_t x, coord_t y, LcdFlags flags)> drawLine, std::function<void()> onPress)
|
||||||
{
|
{
|
||||||
content->body.addCustomLine(drawLine, std::move(onPress));
|
content->body.addCustomLine(std::move(drawLine), std::move(onPress));
|
||||||
updatePosition();
|
updatePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -47,7 +47,7 @@ class MenuToolbarButton: public Button {
|
|||||||
clearFocus();
|
clearFocus();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setFocus();
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
}
|
}
|
||||||
onPress();
|
onPress();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ class ModalWindow: public Window
|
|||||||
void deleteLater()
|
void deleteLater()
|
||||||
{
|
{
|
||||||
if (previousFocus) {
|
if (previousFocus) {
|
||||||
previousFocus->setFocus();
|
previousFocus->setFocus(SET_FOCUS_DEFAULT);
|
||||||
}
|
}
|
||||||
Window::deleteLater();
|
Window::deleteLater();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -127,7 +127,7 @@ bool NumberEdit::onTouchEnd(coord_t, coord_t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!hasFocus()) {
|
if (!hasFocus()) {
|
||||||
setFocus();
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
NumberKeyboard::show(this);
|
NumberKeyboard::show(this);
|
||||||
|
|||||||
@@ -37,11 +37,6 @@ class NumberEdit : public BaseNumberEdit {
|
|||||||
|
|
||||||
void paint(BitmapBuffer * dc) override;
|
void paint(BitmapBuffer * dc) override;
|
||||||
|
|
||||||
void enable(bool enabled)
|
|
||||||
{
|
|
||||||
this->enabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAvailableHandler(std::function<bool(int)> handler)
|
void setAvailableHandler(std::function<bool(int)> handler)
|
||||||
{
|
{
|
||||||
isValueAvailable = std::move(handler);
|
isValueAvailable = std::move(handler);
|
||||||
@@ -80,7 +75,6 @@ class NumberEdit : public BaseNumberEdit {
|
|||||||
std::string prefix;
|
std::string prefix;
|
||||||
std::string suffix;
|
std::string suffix;
|
||||||
std::string zeroText;
|
std::string zeroText;
|
||||||
bool enabled = true;
|
|
||||||
std::function<bool(int)> isValueAvailable;
|
std::function<bool(int)> isValueAvailable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ bool Slider::onTouchStart(coord_t x, coord_t y)
|
|||||||
{
|
{
|
||||||
if (!hasFocus()) {
|
if (!hasFocus()) {
|
||||||
onKeyPress();
|
onKeyPress();
|
||||||
setFocus();
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
}
|
}
|
||||||
sliding = (value(x) == getValue());
|
sliding = (value(x) == getValue());
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+1
-1
@@ -182,7 +182,7 @@ void TextEdit::onEvent(event_t event)
|
|||||||
bool TextEdit::onTouchEnd(coord_t x, coord_t y)
|
bool TextEdit::onTouchEnd(coord_t x, coord_t y)
|
||||||
{
|
{
|
||||||
if (!hasFocus()) {
|
if (!hasFocus()) {
|
||||||
setFocus();
|
setFocus(SET_FOCUS_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(SOFTWARE_KEYBOARD)
|
#if defined(SOFTWARE_KEYBOARD)
|
||||||
|
|||||||
+3
-3
@@ -158,11 +158,11 @@ class Window {
|
|||||||
|
|
||||||
static void clearFocus();
|
static void clearFocus();
|
||||||
|
|
||||||
virtual void setFocus(uint8_t flag = SET_FOCUS_DEFAULT);
|
virtual void setFocus(uint8_t flag);
|
||||||
|
|
||||||
void setRect(rect_t rect)
|
void setRect(rect_t value)
|
||||||
{
|
{
|
||||||
this->rect = rect;
|
rect = value;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user