fix(color): long press key handling, curve preview not updating (#5107)
This commit is contained in:
+3
-10
@@ -58,8 +58,6 @@ ButtonBase::ButtonBase(Window* parent, const rect_t& rect,
|
||||
objConstruct ? objConstruct : lv_btn_create),
|
||||
pressHandler(std::move(pressHandler))
|
||||
{
|
||||
lv_obj_add_event_cb(lvobj, ButtonBase::long_pressed, LV_EVENT_LONG_PRESSED,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
void ButtonBase::check(bool checked)
|
||||
@@ -81,13 +79,15 @@ bool ButtonBase::checked() const
|
||||
|
||||
void ButtonBase::onPress() { check(pressHandler && pressHandler()); }
|
||||
|
||||
void ButtonBase::onLongPress()
|
||||
bool ButtonBase::onLongPress()
|
||||
{
|
||||
if (longPressHandler) {
|
||||
check(longPressHandler());
|
||||
lv_obj_clear_state(lvobj, LV_STATE_PRESSED);
|
||||
lv_indev_wait_release(lv_indev_get_act());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ButtonBase::onClicked() { onPress(); }
|
||||
@@ -98,13 +98,6 @@ void ButtonBase::checkEvents()
|
||||
if (checkHandler) checkHandler();
|
||||
}
|
||||
|
||||
void ButtonBase::long_pressed(lv_event_t* e)
|
||||
{
|
||||
auto obj = lv_event_get_target(e);
|
||||
auto btn = (ButtonBase*)lv_obj_get_user_data(obj);
|
||||
if (obj) btn->onLongPress();
|
||||
}
|
||||
|
||||
TextButton::TextButton(Window* parent, const rect_t& rect, std::string text,
|
||||
std::function<uint8_t(void)> pressHandler) :
|
||||
ButtonBase(parent, rect, pressHandler, button_create),
|
||||
|
||||
+1
-3
@@ -36,7 +36,7 @@ class ButtonBase : public FormField
|
||||
#endif
|
||||
|
||||
virtual void onPress();
|
||||
virtual void onLongPress();
|
||||
bool onLongPress() override;
|
||||
|
||||
void onClicked() override;
|
||||
void checkEvents() override;
|
||||
@@ -63,8 +63,6 @@ class ButtonBase : public FormField
|
||||
std::function<uint8_t(void)> pressHandler;
|
||||
std::function<uint8_t(void)> longPressHandler;
|
||||
std::function<void(void)> checkHandler;
|
||||
|
||||
static void long_pressed(lv_event_t* e);
|
||||
};
|
||||
|
||||
class Button : public ButtonBase
|
||||
|
||||
+4
-27
@@ -110,8 +110,7 @@ Choice::Choice(Window* parent, const rect_t& rect, int vmin, int vmax,
|
||||
vmax(vmax),
|
||||
menuTitle(title),
|
||||
_getValue(std::move(_getValue)),
|
||||
_setValue(std::move(_setValue)),
|
||||
longPressData({})
|
||||
_setValue(std::move(_setValue))
|
||||
{
|
||||
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
}
|
||||
@@ -124,8 +123,7 @@ Choice::Choice(Window* parent, const rect_t& rect, const char* const values[],
|
||||
vmax(vmax),
|
||||
menuTitle(title),
|
||||
_getValue(std::move(_getValue)),
|
||||
_setValue(std::move(_setValue)),
|
||||
longPressData({})
|
||||
_setValue(std::move(_setValue))
|
||||
{
|
||||
setValues(values);
|
||||
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
@@ -141,8 +139,7 @@ Choice::Choice(Window* parent, const rect_t& rect,
|
||||
vmax(vmax),
|
||||
menuTitle(title),
|
||||
_getValue(std::move(_getValue)),
|
||||
_setValue(std::move(_setValue)),
|
||||
longPressData({})
|
||||
_setValue(std::move(_setValue))
|
||||
{
|
||||
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
}
|
||||
@@ -179,7 +176,7 @@ void Choice::setValue(int val)
|
||||
|
||||
void Choice::onClicked()
|
||||
{
|
||||
if (!longPressData.isLongPressed) openMenu();
|
||||
openMenu();
|
||||
}
|
||||
|
||||
void Choice::fillMenu(Menu* menu, const FilterFct& filter)
|
||||
@@ -235,23 +232,3 @@ void Choice::openMenu()
|
||||
|
||||
menu->setCloseHandler([=]() { setEditMode(false); });
|
||||
}
|
||||
|
||||
static void localLongPressHandler(lv_event_t* e)
|
||||
{
|
||||
lv_eventData_t* ld = (lv_eventData_t*)lv_event_get_user_data(e);
|
||||
ld->isLongPressed = true;
|
||||
ld->lv_LongPressHandler(ld->userData);
|
||||
}
|
||||
|
||||
void Choice::set_lv_LongPressHandler(lvHandler_t longPressHandler, void* data)
|
||||
{
|
||||
TRACE("longPressHandler=%p", longPressHandler);
|
||||
|
||||
if (longPressHandler) {
|
||||
longPressData.userData = data;
|
||||
longPressData.lv_LongPressHandler = longPressHandler;
|
||||
lv_obj_add_event_cb(lvobj, localLongPressHandler, LV_EVENT_LONG_PRESSED,
|
||||
&longPressData);
|
||||
lv_obj_add_event_cb(lvobj, ClickHandler, LV_EVENT_CLICKED, this);
|
||||
}
|
||||
}
|
||||
|
||||
-19
@@ -22,14 +22,6 @@
|
||||
|
||||
#include "form.h"
|
||||
|
||||
typedef void (*lvHandler_t)(void *);
|
||||
|
||||
typedef struct {
|
||||
void *userData;
|
||||
bool isLongPressed;
|
||||
lvHandler_t lv_LongPressHandler;
|
||||
} lv_eventData_t;
|
||||
|
||||
class Menu;
|
||||
|
||||
enum ChoiceType {
|
||||
@@ -153,8 +145,6 @@ class Choice : public ChoiceBase
|
||||
|
||||
std::string getString(int val) { return values[val]; }
|
||||
|
||||
void set_lv_LongPressHandler(lvHandler_t longPressHandler, void *data);
|
||||
|
||||
int selectedIx0 = 0;
|
||||
|
||||
protected:
|
||||
@@ -177,13 +167,4 @@ class Choice : public ChoiceBase
|
||||
void fillMenu(Menu *menu, const FilterFct &filter = nullptr);
|
||||
|
||||
virtual void openMenu();
|
||||
|
||||
lv_eventData_t longPressData;
|
||||
std::function<void(event_t)> longPressHandler = nullptr;
|
||||
|
||||
static void ClickHandler(lv_event_t *e)
|
||||
{
|
||||
auto ch = (Choice *)lv_event_get_user_data(e);
|
||||
if (ch) ch->longPressData.isLongPressed = false;
|
||||
}
|
||||
};
|
||||
|
||||
-21
@@ -91,9 +91,6 @@ class MenuBody : public TableField
|
||||
});
|
||||
lv_group_set_editing(g, true);
|
||||
}
|
||||
|
||||
lv_obj_add_event_cb(lvobj, MenuBody::localLongPressHandler,
|
||||
LV_EVENT_LONG_PRESSED, this);
|
||||
}
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
@@ -219,13 +216,6 @@ class MenuBody : public TableField
|
||||
isLongPressed = false;
|
||||
}
|
||||
|
||||
void longPress()
|
||||
{
|
||||
isLongPressed = true;
|
||||
Menu* menu = getParentMenu();
|
||||
if (menu) menu->longPress();
|
||||
}
|
||||
|
||||
void onDrawBegin(uint16_t row, uint16_t col,
|
||||
lv_obj_draw_part_dsc_t* dsc) override
|
||||
{
|
||||
@@ -284,12 +274,6 @@ class MenuBody : public TableField
|
||||
int selectedIndex = 0;
|
||||
|
||||
Menu* getParentMenu() { return static_cast<Menu*>(getParent()->getParent()); }
|
||||
|
||||
static void localLongPressHandler(lv_event_t* e)
|
||||
{
|
||||
MenuBody* menuBody = (MenuBody*)lv_event_get_user_data(e);
|
||||
if (menuBody) menuBody->longPress();
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -451,11 +435,6 @@ void Menu::onCancel()
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
void Menu::longPress()
|
||||
{
|
||||
if (toolbar) toolbar->longPress();
|
||||
}
|
||||
|
||||
void Menu::setCancelHandler(std::function<void()> handler)
|
||||
{
|
||||
cancelHandler = std::move(handler);
|
||||
|
||||
-2
@@ -83,8 +83,6 @@ class Menu : public ModalWindow
|
||||
}
|
||||
}
|
||||
|
||||
void longPress();
|
||||
|
||||
protected:
|
||||
bool multiple;
|
||||
MenuWindowContent *content;
|
||||
|
||||
+2
-5
@@ -22,9 +22,6 @@
|
||||
#include "themes/etx_lv_theme.h"
|
||||
#include "translations.h"
|
||||
|
||||
constexpr uint32_t MENUS_TOOLBAR_BUTTON_WIDTH = 36;
|
||||
constexpr uint32_t MENUS_TOOLBAR_BUTTON_HEIGHT = 32;
|
||||
|
||||
static const lv_obj_class_t menu_button_class = {
|
||||
.base_class = &button_class,
|
||||
.constructor_cb = nullptr,
|
||||
@@ -116,13 +113,13 @@ rect_t MenuToolbar::getButtonRect(bool wideButton)
|
||||
coord_t x =
|
||||
(nxtBtnPos % filterColumns) * (MENUS_TOOLBAR_BUTTON_WIDTH + PAD_SMALL);
|
||||
coord_t y =
|
||||
(nxtBtnPos / filterColumns) * (MENUS_TOOLBAR_BUTTON_HEIGHT + PAD_SMALL);
|
||||
(nxtBtnPos / filterColumns) * (EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_SMALL);
|
||||
coord_t w = wideButton ? (MENUS_TOOLBAR_BUTTON_WIDTH + PAD_SMALL) *
|
||||
(filterColumns - 1) +
|
||||
MENUS_TOOLBAR_BUTTON_WIDTH
|
||||
: MENUS_TOOLBAR_BUTTON_WIDTH;
|
||||
nxtBtnPos += wideButton ? filterColumns : 1;
|
||||
return {x, y, w, MENUS_TOOLBAR_BUTTON_HEIGHT};
|
||||
return {x, y, w, EdgeTxStyles::UI_ELEMENT_HEIGHT};
|
||||
}
|
||||
|
||||
bool MenuToolbar::filterMenu(MenuToolbarButton* btn, int16_t filtermin,
|
||||
|
||||
+2
-7
@@ -45,13 +45,8 @@ class MenuToolbar : public Window
|
||||
|
||||
virtual void longPress() {}
|
||||
|
||||
static LAYOUT_VAL(MENUS_TOOLBAR_BUTTON_WIDTH, 32, 32)
|
||||
|
||||
#if PORTRAIT_LCD
|
||||
static constexpr coord_t MENUS_MAX_HEIGHT = (ListBox::MENUS_LINE_HEIGHT * 10);
|
||||
#else
|
||||
static constexpr coord_t MENUS_MAX_HEIGHT = (ListBox::MENUS_LINE_HEIGHT * 7) + 8;
|
||||
#endif
|
||||
static LAYOUT_VAL(MENUS_TOOLBAR_BUTTON_WIDTH, 36, 36)
|
||||
static LAYOUT_VAL(MENUS_MAX_HEIGHT, ListBox::MENUS_LINE_HEIGHT * 7 + 8, ListBox::MENUS_LINE_HEIGHT * 10)
|
||||
|
||||
protected:
|
||||
Choice* choice;
|
||||
|
||||
+12
-3
@@ -45,6 +45,14 @@ class NumberArea : public FormField
|
||||
|
||||
lv_obj_add_event_cb(lvobj, NumberArea::numberedit_cb, LV_EVENT_KEY, this);
|
||||
|
||||
setFocusHandler([=](bool focus) {
|
||||
if (!focus && editMode) {
|
||||
setEditMode(false);
|
||||
hide();
|
||||
lv_obj_clear_state(parent->getLvObj(), LV_STATE_FOCUSED);
|
||||
}
|
||||
});
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -150,6 +158,7 @@ class NumberArea : public FormField
|
||||
setEditMode(true);
|
||||
} else {
|
||||
FormField::onClicked();
|
||||
if (!editMode) changeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,12 +325,12 @@ void NumberEdit::openEdit()
|
||||
this->vmin, this->vmax, _getValue, _setValue, textFlags);
|
||||
edit->setChangeHandler([=]() {
|
||||
update();
|
||||
lv_group_focus_obj(lvobj);
|
||||
if (edit->hasFocus())
|
||||
lv_group_focus_obj(lvobj);
|
||||
edit->hide();
|
||||
});
|
||||
edit->setCancelHandler([=]() {
|
||||
lv_group_focus_obj(lvobj);
|
||||
edit->hide();
|
||||
edit->onClicked();
|
||||
});
|
||||
}
|
||||
edit->setTextFlag(textFlags);
|
||||
|
||||
+69
-51
@@ -24,6 +24,7 @@
|
||||
#include "themes/etx_lv_theme.h"
|
||||
|
||||
std::list<Window *> Window::trash;
|
||||
bool Window::_longPressed = false;
|
||||
|
||||
const lv_obj_class_t window_base_class = {
|
||||
.base_class = &lv_obj_class,
|
||||
@@ -43,49 +44,60 @@ lv_obj_t *window_create(lv_obj_t *parent)
|
||||
}
|
||||
|
||||
void Window::window_event_cb(lv_event_t *e)
|
||||
{
|
||||
Window *window = (Window *)lv_obj_get_user_data(lv_event_get_target(e));
|
||||
if (window)
|
||||
window->eventHandler(e);
|
||||
}
|
||||
|
||||
void Window::eventHandler(lv_event_t *e)
|
||||
{
|
||||
lv_obj_t *target = lv_event_get_target(e);
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
|
||||
Window *window = (Window *)lv_obj_get_user_data(target);
|
||||
if (window) {
|
||||
if (code == LV_EVENT_DELETE || window->deleted()) return;
|
||||
if (code == LV_EVENT_DELETE || deleted()) return;
|
||||
|
||||
switch (code) {
|
||||
case LV_EVENT_SCROLL: {
|
||||
// exclude pointer based scrolling (only focus scrolling)
|
||||
if (!lv_obj_is_scrolling(target)) {
|
||||
lv_point_t *p = (lv_point_t *)lv_event_get_param(e);
|
||||
lv_coord_t scroll_bottom = lv_obj_get_scroll_bottom(target);
|
||||
switch (code) {
|
||||
case LV_EVENT_SCROLL: {
|
||||
// exclude pointer based scrolling (only focus scrolling)
|
||||
if (!lv_obj_is_scrolling(target)) {
|
||||
lv_point_t *p = (lv_point_t *)lv_event_get_param(e);
|
||||
lv_coord_t scroll_bottom = lv_obj_get_scroll_bottom(target);
|
||||
|
||||
lv_coord_t scroll_y = lv_obj_get_scroll_y(target);
|
||||
TRACE("SCROLL[x=%d;y=%d;top=%d;bottom=%d]", p->x, p->y, scroll_y,
|
||||
scroll_bottom);
|
||||
lv_coord_t scroll_y = lv_obj_get_scroll_y(target);
|
||||
TRACE("SCROLL[x=%d;y=%d;top=%d;bottom=%d]", p->x, p->y, scroll_y,
|
||||
scroll_bottom);
|
||||
|
||||
if (scroll_y <= 45 && p->y > 0) {
|
||||
lv_obj_scroll_by(target, 0, scroll_y, LV_ANIM_OFF);
|
||||
} else if (scroll_bottom <= 16 && p->y < 0) {
|
||||
lv_obj_scroll_by(target, 0, -scroll_bottom, LV_ANIM_OFF);
|
||||
}
|
||||
if (scroll_y <= 45 && p->y > 0) {
|
||||
lv_obj_scroll_by(target, 0, scroll_y, LV_ANIM_OFF);
|
||||
} else if (scroll_bottom <= 16 && p->y < 0) {
|
||||
lv_obj_scroll_by(target, 0, -scroll_bottom, LV_ANIM_OFF);
|
||||
}
|
||||
} break;
|
||||
case LV_EVENT_CLICKED:
|
||||
TRACE("CLICKED[%p]", window);
|
||||
window->onClicked();
|
||||
break;
|
||||
case LV_EVENT_CANCEL:
|
||||
TRACE("CANCEL[%p]", window);
|
||||
window->onCancel();
|
||||
break;
|
||||
case LV_EVENT_FOCUSED:
|
||||
if (window->focusHandler) window->focusHandler(true);
|
||||
break;
|
||||
case LV_EVENT_DEFOCUSED:
|
||||
if (window->focusHandler) window->focusHandler(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case LV_EVENT_CLICKED:
|
||||
if (!_longPressed) {
|
||||
TRACE("CLICKED[%p]", this);
|
||||
onClicked();
|
||||
}
|
||||
_longPressed = false;
|
||||
break;
|
||||
case LV_EVENT_CANCEL:
|
||||
TRACE("CANCEL[%p]", this);
|
||||
onCancel();
|
||||
break;
|
||||
case LV_EVENT_FOCUSED:
|
||||
if (focusHandler) focusHandler(true);
|
||||
break;
|
||||
case LV_EVENT_DEFOCUSED:
|
||||
if (focusHandler) focusHandler(false);
|
||||
break;
|
||||
case LV_EVENT_LONG_PRESSED:
|
||||
TRACE("LONG PRESS[%p]", this);
|
||||
_longPressed = onLongPress();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,23 +307,25 @@ void Window::onEvent(event_t event)
|
||||
{
|
||||
TRACE_WINDOWS("%s received event 0x%X",
|
||||
Window::getWindowDebugString("Window").c_str(), event);
|
||||
if (parent) {
|
||||
if (parent)
|
||||
parent->onEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::onClicked()
|
||||
{
|
||||
if (parent && !(windowFlags & OPAQUE)) {
|
||||
if (parent && !(windowFlags & OPAQUE))
|
||||
parent->onClicked();
|
||||
}
|
||||
}
|
||||
|
||||
void Window::onCancel()
|
||||
{
|
||||
if (parent) {
|
||||
if (parent)
|
||||
parent->onCancel();
|
||||
}
|
||||
}
|
||||
|
||||
bool Window::onLongPress()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Window::addChild(Window *window)
|
||||
@@ -355,21 +369,25 @@ FormLine *Window::newLine(FlexGridLayout &layout)
|
||||
|
||||
void Window::show(bool visible)
|
||||
{
|
||||
if (lv_obj_has_flag(lvobj, LV_OBJ_FLAG_HIDDEN) == visible) {
|
||||
if (visible)
|
||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_HIDDEN);
|
||||
else
|
||||
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_HIDDEN);
|
||||
if (!_deleted && lvobj) {
|
||||
if (lv_obj_has_flag(lvobj, LV_OBJ_FLAG_HIDDEN) == visible) {
|
||||
if (visible)
|
||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_HIDDEN);
|
||||
else
|
||||
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Window::enable(bool enabled)
|
||||
{
|
||||
if (lv_obj_has_state(lvobj, LV_STATE_DISABLED) == enabled) {
|
||||
if (enabled)
|
||||
lv_obj_clear_state(lvobj, LV_STATE_DISABLED);
|
||||
else
|
||||
lv_obj_add_state(lvobj, LV_STATE_DISABLED);
|
||||
if (!_deleted && lvobj) {
|
||||
if (lv_obj_has_state(lvobj, LV_STATE_DISABLED) == enabled) {
|
||||
if (enabled)
|
||||
lv_obj_clear_state(lvobj, LV_STATE_DISABLED);
|
||||
else
|
||||
lv_obj_add_state(lvobj, LV_STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -144,6 +144,7 @@ class Window
|
||||
virtual void onEvent(event_t event);
|
||||
virtual void onClicked();
|
||||
virtual void onCancel();
|
||||
virtual bool onLongPress();
|
||||
|
||||
void invalidate();
|
||||
|
||||
@@ -192,6 +193,7 @@ class Window
|
||||
LcdFlags textFlags = 0;
|
||||
|
||||
bool _deleted = false;
|
||||
static bool _longPressed;
|
||||
|
||||
std::function<void()> closeHandler;
|
||||
std::function<void(bool)> focusHandler;
|
||||
@@ -201,6 +203,7 @@ class Window
|
||||
virtual void addChild(Window *window);
|
||||
void removeChild(Window *window);
|
||||
|
||||
void eventHandler(lv_event_t *e);
|
||||
static void window_event_cb(lv_event_t *e);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user