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