keyboard changes
make window honor no focus.
This commit is contained in:
committed by
Raphael Coeffic
parent
551d7ae766
commit
0284a520fa
+44
-4
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "form.h"
|
||||
#include "bitmapbuffer.h"
|
||||
|
||||
class BaseNumberEdit: public FormField
|
||||
{
|
||||
@@ -76,11 +77,40 @@ class BaseNumberEdit: public FormField
|
||||
|
||||
void setValue(int value)
|
||||
{
|
||||
currentValue = limit(vmin, value, vmax);
|
||||
if (instantChange) {
|
||||
_setValue(currentValue);
|
||||
auto newValue = limit(vmin, value, vmax);
|
||||
if (newValue != currentValue) {
|
||||
currentValue = newValue;
|
||||
if (instantChange) {
|
||||
_setValue(currentValue);
|
||||
}
|
||||
}
|
||||
invalidate();
|
||||
if (lvobj != nullptr) {
|
||||
if (displayFunction != nullptr) {
|
||||
lv_textarea_set_text(lvobj, displayFunction(currentValue).c_str());
|
||||
} else {
|
||||
char s[50];
|
||||
BitmapBuffer::formatNumberAsString(s, 49, currentValue, textFlags, 0, prefix.c_str(), suffix.c_str());
|
||||
lv_textarea_set_text(lvobj, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setPrefix(std::string value)
|
||||
{
|
||||
prefix = std::move(value);
|
||||
setValue(currentValue);
|
||||
}
|
||||
|
||||
void setSuffix(std::string value)
|
||||
{
|
||||
suffix = std::move(value);
|
||||
setValue(currentValue);
|
||||
}
|
||||
|
||||
void setZeroText(std::string value)
|
||||
{
|
||||
zeroText = std::move(value);
|
||||
setValue(currentValue);
|
||||
}
|
||||
|
||||
void enableInstantChange(bool value)
|
||||
@@ -117,6 +147,12 @@ class BaseNumberEdit: public FormField
|
||||
}
|
||||
}
|
||||
|
||||
void setDisplayHandler(std::function<std::string(int value)> function)
|
||||
{
|
||||
displayFunction = std::move(function);
|
||||
setValue(currentValue);
|
||||
}
|
||||
|
||||
protected:
|
||||
int vdefault = 0;
|
||||
int vmin;
|
||||
@@ -124,6 +160,10 @@ class BaseNumberEdit: public FormField
|
||||
int step = 1;
|
||||
int currentValue;
|
||||
bool instantChange = true;
|
||||
std::string prefix;
|
||||
std::string suffix;
|
||||
std::string zeroText;
|
||||
std::function<int()> _getValue;
|
||||
std::function<void(int)> _setValue;
|
||||
std::function<std::string(int)> displayFunction;
|
||||
};
|
||||
|
||||
+7
-12
@@ -25,19 +25,14 @@
|
||||
void Button::onPress()
|
||||
{
|
||||
bool check = (pressHandler && pressHandler());
|
||||
if (check != bool(windowFlags & BUTTON_CHECKED)) {
|
||||
windowFlags ^= BUTTON_CHECKED;
|
||||
windowFlags = check ? windowFlags | BUTTON_CHECKED : windowFlags & ~BUTTON_CHECKED;
|
||||
if(lvobj == nullptr)
|
||||
return;
|
||||
|
||||
if(lvobj == nullptr)
|
||||
return;
|
||||
|
||||
if (! (windowFlags & BUTTON_CHECKED))
|
||||
lv_obj_clear_state(lvobj, LV_STATE_CHECKED);
|
||||
else
|
||||
lv_obj_add_state(lvobj, LV_STATE_CHECKED);
|
||||
|
||||
// invalidate();
|
||||
}
|
||||
if (! (windowFlags & BUTTON_CHECKED))
|
||||
lv_obj_clear_state(lvobj, LV_STATE_CHECKED);
|
||||
else
|
||||
lv_obj_add_state(lvobj, LV_STATE_CHECKED);
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
|
||||
+10
-12
@@ -17,9 +17,9 @@
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
#include "keyboard_base.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
Keyboard * Keyboard::activeKeyboard = nullptr;
|
||||
lv_obj_t *Keyboard::keyboard = nullptr;
|
||||
|
||||
static void keyboard_event_cb(lv_event_t * e)
|
||||
{
|
||||
@@ -33,20 +33,18 @@ static void keyboard_event_cb(lv_event_t * e)
|
||||
|
||||
|
||||
Keyboard::Keyboard(coord_t height) :
|
||||
FormWindow(nullptr, {0, LCD_H - height, LCD_W, height}, OPAQUE)
|
||||
FormWindow(MainWindow::instance(), {0, LCD_H - height, LCD_W, height}, OPAQUE)
|
||||
{
|
||||
// set the background of the window and opacity to 100%
|
||||
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY1), LV_PART_MAIN);
|
||||
lv_obj_set_parent(lvobj, lv_layer_top()); // the keyboard is always on top
|
||||
lv_obj_set_style_bg_color(lvobj, lv_color_make(0xE0, 0xE0, 0xE0), LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_PART_MAIN);
|
||||
|
||||
if (keyboard == nullptr) {
|
||||
keyboard = lv_keyboard_create(lv_scr_act());
|
||||
lv_obj_add_event_cb(keyboard, keyboard_event_cb, LV_EVENT_ALL, this);
|
||||
|
||||
|
||||
lv_obj_set_size(keyboard, LCD_W, LCD_H * 2 / 5);
|
||||
lv_obj_clear_flag(keyboard, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
keyboard = lv_keyboard_create(this->getLvObj());
|
||||
lv_obj_add_event_cb(keyboard, keyboard_event_cb, LV_EVENT_ALL, this);
|
||||
lv_obj_set_pos(keyboard, 0, 0);
|
||||
lv_obj_set_size(keyboard, LCD_W, height);
|
||||
lv_obj_clear_flag(keyboard, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
void Keyboard::clearField()
|
||||
@@ -76,6 +74,7 @@ void Keyboard::hide()
|
||||
{
|
||||
if (activeKeyboard) {
|
||||
activeKeyboard->clearField();
|
||||
lv_obj_add_flag(activeKeyboard->lvobj, LV_OBJ_FLAG_HIDDEN);
|
||||
activeKeyboard = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -106,7 +105,6 @@ bool Keyboard::attachKeyboard()
|
||||
}
|
||||
|
||||
activeKeyboard = this;
|
||||
attach(MainWindow::instance());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -19,7 +19,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "form.h"
|
||||
|
||||
class Keyboard: public FormWindow
|
||||
@@ -31,7 +30,7 @@ class Keyboard: public FormWindow
|
||||
|
||||
protected:
|
||||
static Keyboard * activeKeyboard;
|
||||
static lv_obj_t * keyboard;
|
||||
lv_obj_t * keyboard = nullptr;
|
||||
|
||||
FormField *field = nullptr;
|
||||
Window *fieldContainer = nullptr;
|
||||
|
||||
+42
-40
@@ -27,53 +27,55 @@ NumberKeyboard * NumberKeyboard::_instance = nullptr;
|
||||
NumberKeyboard::NumberKeyboard() :
|
||||
Keyboard(KEYBOARD_HEIGHT)
|
||||
{
|
||||
// new TextButton(this, {LCD_W / 2 - 115, 10, 50, 30}, "<<",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_BACKWARD);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
lv_obj_add_flag(keyboard, LV_OBJ_FLAG_HIDDEN); // ToDo: for now we are still using the old keyboard
|
||||
|
||||
// new TextButton(this, {LCD_W / 2 - 55, 10, 50, 30}, "-",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_MINUS);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
new TextButton(this, {LCD_W / 2 - 115, 10, 50, 30}, "<<",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_BACKWARD);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
// new TextButton(this, {LCD_W / 2 + 5, 10, 50, 30}, "+",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_PLUS);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
new TextButton(this, {LCD_W / 2 - 55, 10, 50, 30}, "-",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_MINUS);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
// new TextButton(this, {LCD_W / 2 + 65, 10, 50, 30}, ">>",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_FORWARD);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
new TextButton(this, {LCD_W / 2 + 5, 10, 50, 30}, "+",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_PLUS);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
// new TextButton(this, {LCD_W / 2 - 115, 50, 50, 30}, "MIN",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_MIN);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
new TextButton(this, {LCD_W / 2 + 65, 10, 50, 30}, ">>",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_FORWARD);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
// new TextButton(this, {LCD_W / 2 + 65, 50, 50, 30}, "MAX",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_MAX);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
new TextButton(this, {LCD_W / 2 - 115, 50, 50, 30}, "MIN",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_MIN);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
// new TextButton(this, { LCD_W/2 - 55, 50, 50, 30 }, "DEF",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_DEFAULT);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
new TextButton(this, {LCD_W / 2 + 65, 50, 50, 30}, "MAX",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_MAX);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
new TextButton(this, { LCD_W/2 - 55, 50, 50, 30 }, "DEF",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_DEFAULT);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
|
||||
// new TextButton(this, { LCD_W/2 + 5, 50, 50, 30 }, "+/-",
|
||||
// [=]() -> uint8_t {
|
||||
// pushEvent(EVT_VIRTUAL_KEY_SIGN);
|
||||
// return 0;
|
||||
// }, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
new TextButton(this, { LCD_W/2 + 5, 50, 50, 30 }, "+/-",
|
||||
[=]() -> uint8_t {
|
||||
pushEvent(EVT_VIRTUAL_KEY_SIGN);
|
||||
return 0;
|
||||
}, BUTTON_BACKGROUND | OPAQUE | NO_FOCUS);
|
||||
}
|
||||
|
||||
NumberKeyboard::~NumberKeyboard()
|
||||
|
||||
+9
-3
@@ -38,10 +38,16 @@ class NumberKeyboard : public Keyboard {
|
||||
{
|
||||
if (!_instance)
|
||||
_instance = new NumberKeyboard();
|
||||
else
|
||||
lv_obj_clear_flag(_instance->keyboard, LV_OBJ_FLAG_HIDDEN);
|
||||
// else
|
||||
// lv_obj_clear_flag(_instance->keyboard, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
// lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_NUMBER);
|
||||
|
||||
lv_obj_clear_flag(_instance->lvobj, LV_OBJ_FLAG_HIDDEN);
|
||||
// lv_obj_clear_flag(_instance->keyboard, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_keyboard_set_mode(_instance->keyboard, LV_KEYBOARD_MODE_NUMBER);
|
||||
lv_obj_move_foreground(_instance->getLvObj());
|
||||
|
||||
lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_NUMBER);
|
||||
_instance->setField(field);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -53,10 +53,10 @@ class TextKeyboard : public Keyboard {
|
||||
{
|
||||
if (!_instance)
|
||||
_instance = new TextKeyboard();
|
||||
else
|
||||
lv_obj_clear_flag(_instance->keyboard, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_TEXT_LOWER);
|
||||
lv_obj_clear_flag(_instance->lvobj, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(_instance->keyboard, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_keyboard_set_mode(_instance->keyboard, LV_KEYBOARD_MODE_TEXT_LOWER);
|
||||
_instance->setField(field);
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -35,11 +35,9 @@ NumberEdit::NumberEdit(Window * parent, const rect_t & rect, int vmin, int vmax,
|
||||
lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF);
|
||||
lv_textarea_set_password_mode(lvobj, false);
|
||||
lv_textarea_set_one_line(lvobj, true);
|
||||
lv_textarea_set_accepted_chars(lvobj, "0123456789");
|
||||
|
||||
auto value = _getValue();
|
||||
auto strValue = std::to_string(value);
|
||||
lv_textarea_set_text(lvobj, strValue.c_str());
|
||||
this->setValue(value);
|
||||
|
||||
// LV_PART_MAIN
|
||||
lv_style_init(&style_main);
|
||||
|
||||
-24
@@ -39,26 +39,6 @@ class NumberEdit : public BaseNumberEdit
|
||||
isValueAvailable = std::move(handler);
|
||||
}
|
||||
|
||||
void setPrefix(std::string value)
|
||||
{
|
||||
prefix = std::move(value);
|
||||
}
|
||||
|
||||
void setSuffix(std::string value)
|
||||
{
|
||||
suffix = std::move(value);
|
||||
}
|
||||
|
||||
void setZeroText(std::string value)
|
||||
{
|
||||
zeroText = std::move(value);
|
||||
}
|
||||
|
||||
void setDisplayHandler(std::function<void(BitmapBuffer *, LcdFlags, int)> function)
|
||||
{
|
||||
displayFunction = std::move(function);
|
||||
}
|
||||
|
||||
void onEvent(event_t event) override;
|
||||
void onFocusLost() override;
|
||||
|
||||
@@ -67,10 +47,6 @@ class NumberEdit : public BaseNumberEdit
|
||||
#endif
|
||||
|
||||
protected:
|
||||
std::function<void(BitmapBuffer *, LcdFlags, int)> displayFunction;
|
||||
std::string prefix;
|
||||
std::string suffix;
|
||||
std::string zeroText;
|
||||
std::function<bool(int)> isValueAvailable;
|
||||
};
|
||||
|
||||
|
||||
+5
-2
@@ -147,6 +147,11 @@ Window::Window(Window *parent, const rect_t &rect, WindowFlags windowFlags,
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
// honor the no focus flag of libopenui
|
||||
if (this->windowFlags & NO_FOCUS) {
|
||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
|
||||
}
|
||||
}
|
||||
extern lv_obj_t * canvas;
|
||||
Window::~Window()
|
||||
@@ -181,8 +186,6 @@ void Window::detach()
|
||||
if (parent) {
|
||||
parent->removeChild(this);
|
||||
parent = nullptr;
|
||||
if(lvobj != nullptr)
|
||||
lv_obj_set_parent(lvobj, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user