fix(color): long press key handling, curve preview not updating (#5107)

This commit is contained in:
philmoz
2024-06-07 15:43:58 +10:00
committed by GitHub
parent f8d542c5e2
commit 76dde34f19
33 changed files with 201 additions and 244 deletions
+9 -3
View File
@@ -66,11 +66,10 @@ static void copy_kb_data_backup(lv_indev_data_t* data)
memcpy(data, &kb_data_backup, sizeof(lv_indev_data_t));
}
constexpr event_t _KEY_PRESSED = _MSK_KEY_FLAGS & ~_MSK_KEY_BREAK;
static bool evt_to_indev_data(event_t evt, lv_indev_data_t *data)
{
event_t key = EVT_KEY_MASK(evt);
switch(key) {
case KEY_ENTER:
@@ -90,7 +89,8 @@ static bool evt_to_indev_data(event_t evt, lv_indev_data_t *data)
return false;
}
if (evt & _KEY_PRESSED) {
event_t flgs = evt & _MSK_KEY_FLAGS;
if (flgs != _MSK_KEY_BREAK && flgs != _MSK_KEY_LONG_BRK) {
data->state = LV_INDEV_STATE_PRESSED;
} else {
data->state = LV_INDEV_STATE_RELEASED;
@@ -122,6 +122,12 @@ static void keyboardDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)
if (isEvent()) { // event waiting
event_t evt = getEvent();
if ((evt & _MSK_KEY_FLAGS) == _MSK_KEY_LONG_BRK) {
data->state = LV_INDEV_STATE_RELEASED;
backup_kb_data(data);
return;
}
if(evt == EVT_KEY_FIRST(KEY_PAGEUP) ||
evt == EVT_KEY_FIRST(KEY_PAGEDN) ||
evt == EVT_KEY_FIRST(KEY_ENTER) ||
+31 -8
View File
@@ -46,9 +46,34 @@ void CurveParam::value_changed(lv_event_t* e)
param->update();
}
class CurveChoice : public Choice
{
public:
CurveChoice(Window* parent, CurveRef* ref, std::function<void(int32_t)> setRefValue, std::function<void(void)> refreshView) :
Choice(parent, rect_t{}, -MAX_CURVES, MAX_CURVES, GET_DEFAULT(ref->value), setRefValue),
ref(ref), refreshView(refreshView)
{
setTextHandler([](int value) { return getCurveString(value); });
}
bool onLongPress() override
{
if (modelCurvesEnabled()) {
if (ref->value) {
ModelCurvesPage::pushEditCurve(abs(ref->value) - 1, refreshView);
}
}
return true;
}
protected:
CurveRef* ref;
std::function<void(void)> refreshView;
};
CurveParam::CurveParam(Window* parent, const rect_t& rect, CurveRef* ref,
std::function<void(int32_t)> setRefValue) :
Window(parent, rect), ref(ref), setRefValue(setRefValue)
std::function<void(int32_t)> setRefValue, std::function<void(void)> refreshView) :
Window(parent, rect), ref(ref)
{
padAll(PAD_TINY);
lv_obj_set_flex_flow(lvobj, LV_FLEX_FLOW_ROW_WRAP);
@@ -67,18 +92,16 @@ CurveParam::CurveParam(Window* parent, const rect_t& rect, CurveRef* ref,
// CURVE_REF_DIFF
// CURVE_REF_EXPO
value_edit = new GVarNumberEdit(this, -100, 100, GET_DEFAULT(ref->value), setRefValue);
value_edit->setSuffix("%");
auto gv = new GVarNumberEdit(this, -100, 100, GET_DEFAULT(ref->value), setRefValue);
gv->setSuffix("%");
value_edit = gv;
// CURVE_REF_FUNC
func_choice = new Choice(this, rect_t{}, STR_VCURVEFUNC, 0, CURVE_BASE - 1,
GET_DEFAULT(ref->value), setRefValue);
// CURVE_REF_CUSTOM
cust_choice = new Choice(this, rect_t{}, -MAX_CURVES, MAX_CURVES,
GET_DEFAULT(ref->value), setRefValue);
cust_choice->setTextHandler([](int value) { return getCurveString(value); });
cust_choice->set_lv_LongPressHandler(LongPressHandler, &(ref->value));
cust_choice = new CurveChoice(this, ref, setRefValue, refreshView);
update();
}
+5 -9
View File
@@ -25,20 +25,15 @@
struct CurveRef;
class GVarNumberEdit;
class Choice;
class CurveParam : public Window
{
// Curve
CurveRef* ref;
std::function<void(int32_t)> setRefValue;
// Controls
GVarNumberEdit* value_edit;
Choice* func_choice;
Choice* cust_choice;
Window* value_edit;
Window* func_choice;
Window* cust_choice;
Window* act_field = nullptr;
void update();
@@ -47,5 +42,6 @@ class CurveParam : public Window
public:
CurveParam(Window* parent, const rect_t& rect, CurveRef* ref,
std::function<void(int32_t)> setRefValue);
std::function<void(int32_t)> setRefValue,
std::function<void(void)> refreshView = nullptr);
};
+8 -2
View File
@@ -240,8 +240,8 @@ void CurveEdit::checkEvents()
Window::checkEvents();
}
CurveEditWindow::CurveEditWindow(uint8_t index) :
Page(ICON_MODEL_CURVES, PAD_ZERO), index(index)
CurveEditWindow::CurveEditWindow(uint8_t index, std::function<void(void)> refreshView) :
Page(ICON_MODEL_CURVES, PAD_ZERO), index(index), refreshView(refreshView)
{
buildBody(body);
buildHeader(header);
@@ -392,3 +392,9 @@ void CurveEditWindow::buildBody(Window* window)
curveDataEdit->setCurveEdit(curveEdit);
}
void CurveEditWindow::onCancel()
{
if (refreshView) refreshView();
Page::onCancel();
}
+4 -1
View File
@@ -82,13 +82,16 @@ class CurveDataEdit : public Window
class CurveEditWindow : public Page
{
public:
CurveEditWindow(uint8_t index);
CurveEditWindow(uint8_t index, std::function<void(void)> refreshView = nullptr);
protected:
uint8_t index;
CurveEdit * curveEdit = nullptr;
CurveDataEdit * curveDataEdit = nullptr;
std::function<void(void)> refreshView = nullptr;
void buildHeader(Window * window);
void buildBody(Window * window);
void onCancel() override;
};
+4 -10
View File
@@ -74,8 +74,6 @@ FullScreenDialog::FullScreenDialog(
build();
lv_obj_add_event_cb(lvobj, FullScreenDialog::long_pressed,
LV_EVENT_LONG_PRESSED, nullptr);
lv_obj_add_event_cb(lvobj, FullScreenDialog::on_draw,
LV_EVENT_DRAW_MAIN_BEGIN, nullptr);
}
@@ -164,15 +162,11 @@ void FullScreenDialog::closeDialog()
deleteLater();
}
void FullScreenDialog::long_pressed(lv_event_t* e)
bool FullScreenDialog::onLongPress()
{
auto obj = lv_event_get_target(e);
auto fs = (FullScreenDialog*)lv_obj_get_user_data(obj);
if (fs) {
fs->closeDialog();
lv_indev_wait_release(lv_indev_get_act());
}
closeDialog();
lv_indev_wait_release(lv_indev_get_act());
return false;
}
void FullScreenDialog::onEvent(event_t event)
+1 -1
View File
@@ -43,6 +43,7 @@ class FullScreenDialog : public Window
void onEvent(event_t event) override;
void onCancel() override;
bool onLongPress() override;
void deleteLater(bool detach = true, bool trash = true) override;
@@ -71,6 +72,5 @@ class FullScreenDialog : public Window
virtual void delayedInit() {}
void build();
static void long_pressed(lv_event_t* e);
static void on_draw(lv_event_t* e);
};
+9 -5
View File
@@ -135,11 +135,15 @@ void InputEditWindow::buildBody(Window* form)
line = form->newLine(grid);
new StaticText(line, rect_t{}, STR_CURVE);
auto param =
new CurveParam(line, rect_t{}, &input->curve, [=](int32_t newValue) {
input->curve.value = newValue;
preview->update();
SET_DIRTY();
});
new CurveParam(line, rect_t{}, &input->curve,
[=](int32_t newValue) {
input->curve.value = newValue;
preview->update();
SET_DIRTY();
},
[=]() {
preview->update();
});
lv_obj_set_style_grid_cell_x_align(param->getLvObj(), LV_GRID_ALIGN_STRETCH,
0);
+4 -13
View File
@@ -23,14 +23,6 @@
#include "libopenui.h"
// TODO:
// - split this into 2 handlers:
// - key_cb: PRESSED / LONG_PRESSED (always on)
// - focus_cb: for FOCUSED / DEFOCUSED (only w/ 'auto-edit' mode)
// - add 'auto-edit' mode (add / remove 'focus_cb')
// - when turned on, ESC gets out of the edit-mode
// and ENTER gets into edit-mode
//
void ListBox::event_cb(lv_event_t* e)
{
static bool _nested = false;
@@ -51,10 +43,6 @@ void ListBox::event_cb(lv_event_t* e)
_nested = true;
lv_group_set_editing((lv_group_t*)lv_obj_get_group(obj), false);
_nested = false;
} else if (code == LV_EVENT_LONG_PRESSED) {
lb->onLongPressed();
lv_obj_clear_state(obj, LV_STATE_PRESSED);
lv_indev_wait_release(lv_indev_get_act());
}
}
@@ -180,12 +168,15 @@ void ListBox::onPress(uint16_t row, uint16_t col)
}
}
void ListBox::onLongPressed()
bool ListBox::onLongPress()
{
TRACE("LONG_PRESS");
if (longPressHandler) {
longPressHandler();
lv_indev_wait_release(lv_indev_get_act());
return false;
}
return true;
}
// TODO: !auto-edit
+1 -1
View File
@@ -95,7 +95,7 @@ class ListBox : public TableField
bool smallSelectMarker = false;
void onPress(uint16_t row, uint16_t col) override;
void onLongPressed();
bool onLongPress() override;
void onClicked() override;
void onCancel() override;
+2 -2
View File
@@ -122,7 +122,7 @@ ModelCurvesPage::ModelCurvesPage() : PageTab(STR_MENUCURVES, ICON_MODEL_CURVES)
// can be called from any other screen to edit a curve.
// currently called from model_mixes.cpp on longpress.
void ModelCurvesPage::pushEditCurve(int index)
void ModelCurvesPage::pushEditCurve(int index, std::function<void(void)> refreshView)
{
if (!isCurveUsed(index)) {
CurveHeader &curve = g_model.curves[index];
@@ -130,7 +130,7 @@ void ModelCurvesPage::pushEditCurve(int index)
initPoints(curve, points);
}
new CurveEditWindow(index);
new CurveEditWindow(index, refreshView);
}
void ModelCurvesPage::rebuild(Window *window)
+1 -1
View File
@@ -28,7 +28,7 @@ class ModelCurvesPage : public PageTab
{
public:
ModelCurvesPage();
static void pushEditCurve(int index);
static void pushEditCurve(int index, std::function<void(void)> refreshView = nullptr);
bool isVisible() const override { return modelCurvesEnabled(); }
+6 -10
View File
@@ -149,16 +149,14 @@ class SourceChoiceMenuToolbar : public MenuToolbar
#endif
};
void SourceChoice::LongPressHandler(void* data)
bool SourceChoice::onLongPress()
{
SourceChoice* src = (SourceChoice*)data;
if (src && src->canInvert) {
int16_t val = src->_getValue();
if (src->isValueAvailable && src->isValueAvailable(-val)) {
src->setValue(-val);
src->invalidate();
}
if (canInvert) {
int16_t val = _getValue();
if (isValueAvailable && isValueAvailable(-val))
setValue(-val);
}
return true;
}
void SourceChoice::setValue(int value)
@@ -234,7 +232,5 @@ SourceChoice::SourceChoice(Window *parent, const rect_t &rect, int16_t vmin,
return std::string(getSourceString(value));
});
set_lv_LongPressHandler(LongPressHandler, this);
setAvailableHandler([](int v) { return isSourceAvailable(v); });
}
+1 -2
View File
@@ -35,8 +35,6 @@ class SourceChoice : public Choice
std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue, bool allowInvert = false);
static void LongPressHandler(void* data);
protected:
friend SourceChoiceMenuToolbar;
@@ -45,6 +43,7 @@ class SourceChoice : public Choice
void setValue(int value) override;
int getIntValue() const override;
bool onLongPress() override;
void invertChoice();
+5 -9
View File
@@ -103,14 +103,12 @@ class SwitchChoiceMenuToolbar : public MenuToolbar
#endif
};
void SwitchChoice::LongPressHandler(void* data)
bool SwitchChoice::onLongPress()
{
SwitchChoice* swch = (SwitchChoice*)data;
if (!swch) return;
int16_t val = swch->_getValue();
if (swch->isValueAvailable && swch->isValueAvailable(-val)) {
swch->setValue(-val);
}
int16_t val = _getValue();
if (isValueAvailable && isValueAvailable(-val))
setValue(-val);
return true;
}
void SwitchChoice::setValue(int value)
@@ -182,7 +180,5 @@ SwitchChoice::SwitchChoice(Window* parent, const rect_t& rect, int vmin,
return std::string(getSwitchPositionName(value));
});
set_lv_LongPressHandler(LongPressHandler, this);
setAvailableHandler(isSwitchAvailableInMixes);
}
+1 -2
View File
@@ -33,8 +33,6 @@ class SwitchChoice : public Choice
std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue);
static void LongPressHandler(void* data);
protected:
friend SwitchChoiceMenuToolbar;
@@ -42,6 +40,7 @@ class SwitchChoice : public Choice
void setValue(int value) override;
int getIntValue() const override;
bool onLongPress() override;
void invertChoice();
+2 -13
View File
@@ -85,8 +85,6 @@ ViewMain::ViewMain() :
lv_obj_add_event_cb(tile_view, tile_view_scroll, LV_EVENT_SCROLL, nullptr);
lv_obj_add_event_cb(tile_view, tile_view_scroll, LV_EVENT_SCROLL_END,
nullptr);
lv_obj_add_event_cb(lvobj, ViewMain::long_pressed, LV_EVENT_LONG_PRESSED,
nullptr);
// create last to be on top
topbar = TopbarFactory::create(this);
@@ -342,7 +340,7 @@ void ViewMain::ws_timer(lv_timer_t* t)
view->enableWidgetSelect(false);
}
void ViewMain::longPress()
bool ViewMain::onLongPress()
{
if (isAppMode()) {
int view = getCurrentMainView();
@@ -350,17 +348,8 @@ void ViewMain::longPress()
} else {
enableWidgetSelect(true);
}
}
void ViewMain::long_pressed(lv_event_t* e)
{
auto obj = lv_event_get_target(e);
// kill subsequent CLICKED event
lv_obj_clear_state(obj, LV_STATE_PRESSED);
lv_indev_wait_release(lv_indev_get_act());
auto view = (ViewMain*)lv_obj_get_user_data(obj);
if (view) view->longPress();
return false;
}
void ViewMain::show(bool visible)
+1 -2
View File
@@ -72,7 +72,7 @@ class ViewMain : public NavWindow
void onClicked() override;
void onCancel() override;
void openMenu();
void longPress();
bool onLongPress() override;
void show(bool visible = true) override;
void showTopBarEdgeTxButton();
@@ -103,7 +103,6 @@ class ViewMain : public NavWindow
// Set topbar visibility [0.0 -> 1.0]
void setTopbarVisible(float visible);
static void long_pressed(lv_event_t* e);
static void ws_timer(lv_timer_t* t);
#if defined(HARDWARE_KEYS)
+2 -1
View File
@@ -144,9 +144,10 @@ void Widget::setFullscreen(bool enable)
update();
}
void Widget::onLongPress()
bool Widget::onLongPress()
{
if (!fullscreen) ButtonBase::onLongPress();
return true;
}
const ZoneOption* Widget::getOptions() const
+1 -1
View File
@@ -97,7 +97,7 @@ class Widget : public ButtonBase
lv_point_t borderPts[5];
void onCancel() override;
void onLongPress() override;
bool onLongPress() override;
virtual void onFullscreen(bool enable) {}
void openMenu();